-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for defer init for dyn_var
- Loading branch information
1 parent
39e1807
commit 5dd99a4
Showing
4 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
void foo (void) { | ||
int obj_0; | ||
int x_1 = 0; | ||
if (x_1) { | ||
obj_0 = 1; | ||
} else { | ||
obj_0 = 2; | ||
} | ||
} | ||
|
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 @@ | ||
void foo (void) { | ||
int var0; | ||
int var1 = 0; | ||
if (var1) { | ||
var0 = 1; | ||
} else { | ||
var0 = 2; | ||
} | ||
} | ||
|
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,36 @@ | ||
// Include the headers | ||
#include "blocks/c_code_generator.h" | ||
#include "builder/dyn_var.h" | ||
#include "builder/lib/utils.h" | ||
#include "builder/static_var.h" | ||
#include <iostream> | ||
|
||
// Include the BuildIt types | ||
using builder::dyn_var; | ||
using builder::static_var; | ||
|
||
|
||
struct external_object_t { | ||
dyn_var<int> member = builder::defer_init(); | ||
}; | ||
|
||
static void foo(external_object_t &obj) { | ||
// Init not | ||
obj.member.deferred_init(); | ||
|
||
dyn_var<int> x = 0; | ||
if (x) { | ||
obj.member = 1; | ||
} else { | ||
obj.member = 2; | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
external_object_t obj; | ||
|
||
builder::builder_context context; | ||
block::c_code_generator::generate_code(context.extract_function_ast(foo, "foo", obj), std::cout, 0); | ||
return 0; | ||
} |