Skip to content

Commit 7455ee5

Browse files
committed
Always use val
1 parent 762e66e commit 7455ee5

File tree

9 files changed

+15
-28
lines changed

9 files changed

+15
-28
lines changed

bindgen/ir/IR.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,8 @@ std::string IR::getDefineForVar(const std::string &varName) const {
290290
return "";
291291
}
292292

293-
Variable *IR::addVariable(const std::string &name, const std::string &type,
294-
bool isConst) {
295-
Variable *variable = new Variable(name, type, isConst);
293+
Variable *IR::addVariable(const std::string &name, const std::string &type) {
294+
Variable *variable = new Variable(name, type);
296295
variables.push_back(variable);
297296
return variable;
298297
}

bindgen/ir/IR.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ class IR {
4141

4242
void addVarDefine(std::string name, Variable *variable);
4343

44-
Variable *addVariable(const std::string &name, const std::string &type,
45-
bool isConst);
44+
Variable *addVariable(const std::string &name, const std::string &type);
4645

4746
/**
4847
* @return true if there are no functions, types,

bindgen/ir/VarDefine.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@ VarDefine::VarDefine(std::string name, Variable *variable)
55

66
llvm::raw_ostream &operator<<(llvm::raw_ostream &s,
77
const VarDefine &varDefine) {
8-
s << " @name(\"" << varDefine.variable->getName() << "\")\n";
9-
if (varDefine.variable->getIsConst()) {
10-
s << " val ";
11-
} else {
12-
s << " def ";
13-
}
14-
s << varDefine.getName() << ": " << varDefine.variable->getType()
15-
<< " = native.extern\n";
8+
s << " @name(\"" << varDefine.variable->getName() << "\")\n"
9+
<< " val " << varDefine.getName() << ": "
10+
<< varDefine.variable->getType() << " = native.extern\n";
1611
return s;
1712
}

bindgen/ir/Variable.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
#include "Variable.h"
22

3-
Variable::Variable(const std::string &name, const std::string &type,
4-
bool isConst)
5-
: TypeAndName(name, type), isConst(isConst) {}
6-
7-
bool Variable::getIsConst() { return isConst; }
3+
Variable::Variable(const std::string &name, const std::string &type)
4+
: TypeAndName(name, type) {}

bindgen/ir/Variable.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55

66
class Variable : public TypeAndName {
77
public:
8-
Variable(const std::string &name, const std::string &type, bool isConst);
9-
10-
bool getIsConst();
11-
12-
private:
13-
bool isConst;
8+
Variable(const std::string &name, const std::string &type);
149
};
1510

1611
#endif // SCALA_NATIVE_BINDGEN_VARIABLE_H

bindgen/visitor/TreeVisitor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ bool TreeVisitor::VisitVarDecl(clang::VarDecl *varDecl) {
165165
std::string variableName = varDecl->getName().str();
166166
std::string type =
167167
handleReservedWords(typeTranslator.Translate(varDecl->getType()));
168-
Variable *variable = ir.addVariable(
169-
variableName, type, varDecl->getType().isConstQualified());
168+
Variable *variable = ir.addVariable(variableName, type);
170169
/* check if there is a macro for the variable.
171170
* Macros were saved by DefineFinder */
172171
std::string macroName = ir.getDefineForVar(variableName);

tests/samples/VarDefine.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#include "VarDefine.h"
22

33
int a = 23;
4+
const int constInt = 10;
5+
const int *constIntPointer = 0;

tests/samples/VarDefine.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import scala.scalanative.native._
77
@native.extern
88
object VarDefine {
99
@name("a")
10-
def A: native.CInt = native.extern
10+
val A: native.CInt = native.extern
1111
@name("constInt")
1212
val CONST_INT: native.CInt = native.extern
1313
@name("constIntPointer")
14-
def CONST_INT_POINTER: native.Ptr[native.CInt] = native.extern
14+
val CONST_INT_POINTER: native.Ptr[native.CInt] = native.extern
1515
}

tests/samples/src/test/scala/org/scalanative/bindgen/samples/VarDefineTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ object VarDefineTests extends TestSuite {
66
val tests = Tests {
77
'getA - {
88
assert(VarDefine.A == 23)
9+
assert(VarDefine.CONST_INT == 10)
910
}
1011
}
1112
}

0 commit comments

Comments
 (0)