Skip to content

Commit

Permalink
Change def to val
Browse files Browse the repository at this point in the history
  • Loading branch information
kornilova203 committed Jun 25, 2018
1 parent 6f89305 commit 582d04b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
4 changes: 1 addition & 3 deletions bindgen/ir/IR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) {
}

for (const auto &varDefine : ir.varDefines) {
s << " @name(\"" << varDefine.getVarName() << "\")\n"
<< " def " << varDefine.getName() << ": " << varDefine.getType()
<< " = native.extern\n";
s << varDefine;
}

for (const auto &func : ir.functions) {
Expand Down
8 changes: 8 additions & 0 deletions bindgen/ir/VarDefine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ VarDefine::VarDefine(std::string name, std::string varName, std::string type)
std::string VarDefine::getVarName() const { return varName; }

std::string VarDefine::getType() const { return type; }

llvm::raw_ostream &operator<<(llvm::raw_ostream &s,
const VarDefine &varDefine) {
s << " @name(\"" << varDefine.getVarName() << "\")\n"
<< " val " << varDefine.getName() << ": " << varDefine.getType()
<< " = native.extern\n";
return s;
}
4 changes: 4 additions & 0 deletions bindgen/ir/VarDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define SCALA_NATIVE_BINDGEN_VARDEFINE_H

#include "Define.h"
#include <llvm/Support/raw_ostream.h>

class VarDefine : public Define {
public:
Expand All @@ -11,6 +12,9 @@ class VarDefine : public Define {

std::string getType() const;

friend llvm::raw_ostream &operator<<(llvm::raw_ostream &s,
const VarDefine &varDefine);

private:
std::string varName;
std::string type;
Expand Down
2 changes: 0 additions & 2 deletions tests/samples/VarDefine.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "VarDefine.h"

int a = 23;

int getA() { return a; }
2 changes: 0 additions & 2 deletions tests/samples/VarDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ extern int c;

extern float f;
#define __PRIVATE f // should be filtered

int getA();
3 changes: 1 addition & 2 deletions tests/samples/VarDefine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ import scala.scalanative.native._
@native.extern
object VarDefine {
@name("a")
def A: native.CInt = native.extern
def getA(): native.CInt = native.extern
val A: native.CInt = native.extern
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import utest._
object VarDefineTests extends TestSuite {
val tests = Tests {
'getA - {
assert(VarDefine.getA() == 23)
assert(VarDefine.A == 23)
}
}
}

0 comments on commit 582d04b

Please sign in to comment.