-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate Scala code for literal definitions
- Loading branch information
1 parent
2efe884
commit 1ce2e45
Showing
14 changed files
with
158 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
#include "DefineFinderAction.h" | ||
|
||
DefineFinderAction::DefineFinderAction(IR &ir) : ir(ir) {} | ||
|
||
void DefineFinderAction::ExecuteAction() { | ||
getCompilerInstance().getPreprocessor().addPPCallbacks( | ||
std::unique_ptr<clang::PPCallbacks>( | ||
new DefineFinder(ir, getCompilerInstance()))); | ||
|
||
clang::PreprocessOnlyAction::ExecuteAction(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#include "Define.h" | ||
|
||
Define::Define(const std::string &name, const std::string &type) | ||
: TypeAndName(name, type) {} | ||
Define::Define(std::string name) : name(std::move(name)) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "LiteralDefine.h" | ||
|
||
LiteralDefine::LiteralDefine(std::string name, std::string literal) | ||
: Define(std::move(name)), literal(std::move(literal)) {} | ||
|
||
LiteralDefine::LiteralDefine(std::string name, std::string literal, | ||
std::string type) | ||
: Define(std::move(name)), literal(std::move(literal)), | ||
type(std::move(type)) {} | ||
|
||
llvm::raw_ostream &operator<<(llvm::raw_ostream &s, | ||
const LiteralDefine &literalDefine) { | ||
s << " val " << literalDefine.name; | ||
if (!literalDefine.type.empty()) { | ||
s << ": " << literalDefine.type; | ||
} | ||
s << " = " << literalDefine.literal << "\n"; | ||
return s; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef SCALA_NATIVE_BINDGEN_LITERALDEFINE_H | ||
#define SCALA_NATIVE_BINDGEN_LITERALDEFINE_H | ||
|
||
#include "Define.h" | ||
#include <llvm/Support/raw_ostream.h> | ||
|
||
class LiteralDefine : Define { | ||
public: | ||
LiteralDefine(std::string name, std::string literal); | ||
|
||
LiteralDefine(std::string name, std::string literal, std::string type); | ||
|
||
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &s, | ||
const LiteralDefine &literalDefine); | ||
|
||
private: | ||
std::string literal; | ||
std::string type; // might be empty | ||
}; | ||
|
||
#endif // SCALA_NATIVE_BINDGEN_LITERALDEFINE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#define STRING "Hello, World!" | ||
|
||
#define INT 42 | ||
// #define LONG 10000000000 // this will fail | ||
#define FLOAT 5.6 | ||
|
||
#define NEW_INT INT // unsupported | ||
|
||
extern int a; | ||
#define MY_A a // unsupported |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.scalanative.bindgen.samples | ||
|
||
import scala.scalanative._ | ||
import scala.scalanative.native._ | ||
|
||
object DefineDefines { | ||
val STRING: native.CString = c"Hello, World!" | ||
val INT = 42 | ||
val FLOAT = 5.6 | ||
} |