-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from AjayBrahmakshatriya/master
Simplified API for custom types (yet again)
- Loading branch information
Showing
6 changed files
with
251 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
FUNC_DECL | ||
SCALAR_TYPE (VOID) | ||
STMT_BLOCK | ||
DECL_STMT | ||
NAMED_TYPE (my_type) | ||
VAR (a_0) | ||
NO_INITIALIZATION | ||
DECL_STMT | ||
NAMED_TYPE (custom_struct0) | ||
VAR (b_1) | ||
NO_INITIALIZATION | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
MEMBER_ACCESS_EXPR (nested) | ||
VAR_EXPR | ||
VAR (a_0) | ||
VAR_EXPR | ||
VAR (b_1) | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
MEMBER_ACCESS_EXPR (mem0) | ||
MEMBER_ACCESS_EXPR (nested) | ||
VAR_EXPR | ||
VAR (a_0) | ||
MEMBER_ACCESS_EXPR (mem0) | ||
VAR_EXPR | ||
VAR (a_0) | ||
EXPR_STMT | ||
MINUS_EXPR | ||
ASSIGN_EXPR | ||
MEMBER_ACCESS_EXPR (mem1) | ||
MEMBER_ACCESS_EXPR (nested) | ||
VAR_EXPR | ||
VAR (a_0) | ||
PLUS_EXPR | ||
MEMBER_ACCESS_EXPR (mem1) | ||
MEMBER_ACCESS_EXPR (nested) | ||
VAR_EXPR | ||
VAR (a_0) | ||
INT_CONST (1) | ||
INT_CONST (1) | ||
struct custom_struct0 { | ||
int mem0; | ||
float mem1; | ||
}; | ||
struct my_type { | ||
custom_struct0 nested; | ||
int mem0; | ||
}; | ||
void bar (void) { | ||
my_type a_0; | ||
custom_struct0 b_1; | ||
a_0.nested = b_1; | ||
(a_0.nested).mem0 = a_0.mem0; | ||
((a_0.nested).mem1 = (a_0.nested).mem1 + 1) - 1; | ||
} | ||
|
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,57 @@ | ||
FUNC_DECL | ||
SCALAR_TYPE (VOID) | ||
STMT_BLOCK | ||
DECL_STMT | ||
NAMED_TYPE (my_type) | ||
VAR (var0) | ||
NO_INITIALIZATION | ||
DECL_STMT | ||
NAMED_TYPE (custom_struct0) | ||
VAR (var1) | ||
NO_INITIALIZATION | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
MEMBER_ACCESS_EXPR (nested) | ||
VAR_EXPR | ||
VAR (var0) | ||
VAR_EXPR | ||
VAR (var1) | ||
EXPR_STMT | ||
ASSIGN_EXPR | ||
MEMBER_ACCESS_EXPR (mem0) | ||
MEMBER_ACCESS_EXPR (nested) | ||
VAR_EXPR | ||
VAR (var0) | ||
MEMBER_ACCESS_EXPR (mem0) | ||
VAR_EXPR | ||
VAR (var0) | ||
EXPR_STMT | ||
MINUS_EXPR | ||
ASSIGN_EXPR | ||
MEMBER_ACCESS_EXPR (mem1) | ||
MEMBER_ACCESS_EXPR (nested) | ||
VAR_EXPR | ||
VAR (var0) | ||
PLUS_EXPR | ||
MEMBER_ACCESS_EXPR (mem1) | ||
MEMBER_ACCESS_EXPR (nested) | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (1) | ||
INT_CONST (1) | ||
struct custom_struct0 { | ||
int mem0; | ||
float mem1; | ||
}; | ||
struct my_type { | ||
custom_struct0 nested; | ||
int mem0; | ||
}; | ||
void bar (void) { | ||
my_type var0; | ||
custom_struct0 var1; | ||
var0.nested = var1; | ||
(var0.nested).mem0 = var0.mem0; | ||
((var0.nested).mem1 = (var0.nested).mem1 + 1) - 1; | ||
} | ||
|
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,44 @@ | ||
#include "blocks/c_code_generator.h" | ||
#include "builder/builder.h" | ||
#include "builder/builder_context.h" | ||
#include "builder/dyn_var.h" | ||
#include "builder/static_var.h" | ||
#include <iostream> | ||
|
||
using builder::as_member; | ||
using builder::dyn_var; | ||
using builder::static_var; | ||
|
||
|
||
struct struct_type { | ||
dyn_var<int> x; | ||
dyn_var<float> y; | ||
}; | ||
|
||
struct my_type { | ||
static constexpr const char* type_name = "my_type"; | ||
dyn_var<struct_type> nested = builder::with_name("nested"); | ||
dyn_var<int> another; | ||
}; | ||
|
||
static void bar(void) { | ||
dyn_var<my_type> a; | ||
dyn_var<struct_type> b; | ||
|
||
a.nested = b; | ||
a.nested.x = a.another; | ||
|
||
a.nested.y++; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
builder::builder_context context; | ||
auto ast = context.extract_function_ast(bar, "bar"); | ||
ast->dump(std::cout, 0); | ||
|
||
block::c_code_generator::generate_struct_decl<dyn_var<struct_type>>(std::cout); | ||
block::c_code_generator::generate_struct_decl<dyn_var<my_type>>(std::cout); | ||
block::c_code_generator::generate_code(ast, std::cout, 0); | ||
return 0; | ||
} |
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,5 @@ | ||
#include "builder/block_type_extractor.h" | ||
|
||
namespace builder { | ||
int type_naming_counter = 0; | ||
} |