-
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.
Allow custom types to specify a dereference_type for operator[]
- Loading branch information
1 parent
c980a84
commit 026c015
Showing
6 changed files
with
125 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FUNC_DECL | ||
SCALAR_TYPE (VOID) | ||
STMT_BLOCK | ||
DECL_STMT | ||
NAMED_TYPE (std::vector) | ||
NAMED_TYPE (std::vector) | ||
SCALAR_TYPE (INT) | ||
VAR (x_0) | ||
NO_INITIALIZATION | ||
EXPR_STMT | ||
FUNCTION_CALL_EXPR | ||
MEMBER_ACCESS_EXPR (resize) | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (2) | ||
EXPR_STMT | ||
FUNCTION_CALL_EXPR | ||
MEMBER_ACCESS_EXPR (resize) | ||
SQ_BKT_EXPR | ||
VAR_EXPR | ||
VAR (x_0) | ||
INT_CONST (1) | ||
INT_CONST (1) | ||
void bar (void) { | ||
std::vector<std::vector<int>> x_0; | ||
x_0.resize(2); | ||
(x_0[1]).resize(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,29 @@ | ||
FUNC_DECL | ||
SCALAR_TYPE (VOID) | ||
STMT_BLOCK | ||
DECL_STMT | ||
NAMED_TYPE (std::vector) | ||
NAMED_TYPE (std::vector) | ||
SCALAR_TYPE (INT) | ||
VAR (var0) | ||
NO_INITIALIZATION | ||
EXPR_STMT | ||
FUNCTION_CALL_EXPR | ||
MEMBER_ACCESS_EXPR (resize) | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (2) | ||
EXPR_STMT | ||
FUNCTION_CALL_EXPR | ||
MEMBER_ACCESS_EXPR (resize) | ||
SQ_BKT_EXPR | ||
VAR_EXPR | ||
VAR (var0) | ||
INT_CONST (1) | ||
INT_CONST (1) | ||
void bar (void) { | ||
std::vector<std::vector<int>> var0; | ||
var0.resize(2); | ||
(var0[1]).resize(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,31 @@ | ||
#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 "builder/lib/utils.h" | ||
#include <iostream> | ||
using builder::dyn_var; | ||
using builder::static_var; | ||
|
||
|
||
template <typename T> | ||
struct vector: public builder::custom_type<T> { | ||
static constexpr const char* type_name = "std::vector"; | ||
typedef T dereference_type; | ||
dyn_var<void(int)> resize = builder::with_name("resize"); | ||
}; | ||
|
||
static void bar(void) { | ||
dyn_var<vector<vector<int>>> x; | ||
x.resize(2); | ||
x[1].resize(1); | ||
} | ||
|
||
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_code(ast, std::cout, 0); | ||
return 0; | ||
} |