Variable declaration added now
This commit is contained in:
@@ -340,7 +340,7 @@ std::pair<std::string, std::string> CGenerator::generateTranslationUnit(std::str
|
||||
std::string prefixed_option_name = prefixIfNeeded(scopePrefix(declaration),option_name);
|
||||
functionDefinitions += " else if (this->flag == " + declarationData.symbol.getName() + "__" + option_name + ") {\n";
|
||||
NodeTree<ASTData>* method = nullptr;
|
||||
if (method = getMethod(child->getDataRef()->valueType, "operator==", std::vector<Type>{*child->getDataRef()->valueType})) {
|
||||
if ((method = getMethod(child->getDataRef()->valueType, "operator==", std::vector<Type>{*child->getDataRef()->valueType}))) {
|
||||
bool is_reference = method->getDataRef()->valueType->parameterTypes[0]->is_reference;
|
||||
|
||||
auto itemTypeVector = std::vector<Type>{child->getDataRef()->valueType->withIncreasedIndirection()};
|
||||
@@ -388,7 +388,7 @@ std::pair<std::string, std::string> CGenerator::generateTranslationUnit(std::str
|
||||
elsePrefix = "else";
|
||||
NodeTree<ASTData>* method = nullptr;
|
||||
auto itemTypeVector = std::vector<Type>{child->getDataRef()->valueType->withIncreasedIndirection()};
|
||||
if (method = getMethod(child->getDataRef()->valueType, "copy_construct", itemTypeVector)) {
|
||||
if ((method = getMethod(child->getDataRef()->valueType, "copy_construct", itemTypeVector))) {
|
||||
functionDefinitions += " " + generateMethodIfExists(child->getDataRef()->valueType, "copy_construct",
|
||||
"&this->" + prefixed_option_name + ", &in->" + prefixed_option_name, itemTypeVector) + ";\n";
|
||||
} else {
|
||||
@@ -406,7 +406,7 @@ std::pair<std::string, std::string> CGenerator::generateTranslationUnit(std::str
|
||||
functionDefinitions += " " + elsePrefix + " if (this->flag == " + declarationData.symbol.getName() + "__" + option_name + ") {\n";
|
||||
elsePrefix = "else";
|
||||
NodeTree<ASTData>* method = nullptr;
|
||||
if (method = getMethod(child->getDataRef()->valueType, "destruct", std::vector<Type>())) {
|
||||
if ((method = getMethod(child->getDataRef()->valueType, "destruct", std::vector<Type>()))) {
|
||||
functionDefinitions += " " + generateMethodIfExists(child->getDataRef()->valueType, "destruct",
|
||||
"&this->" + option_name, std::vector<Type>()) + ";\n";
|
||||
}
|
||||
@@ -423,14 +423,14 @@ std::pair<std::string, std::string> CGenerator::generateTranslationUnit(std::str
|
||||
auto paramType = child->getDataRef()->valueType->parameterTypes[0];
|
||||
auto itemTypeVector = std::vector<Type>{paramType->withIncreasedIndirection()};
|
||||
functionDefinitions += "/*" + ValueTypeToCType(paramType, "") + "*/\n";
|
||||
if (method = getMethod(paramType, "copy_construct", itemTypeVector)) {
|
||||
if ((method = getMethod(paramType, "copy_construct", itemTypeVector))) {
|
||||
functionDefinitions += " " + generateMethodIfExists(paramType, "copy_construct",
|
||||
"&toRet." + prefixIfNeeded(scopePrefix(declaration),orig_fun_name) + ", &in", itemTypeVector) + ";\n";
|
||||
} else {
|
||||
functionDefinitions += " toRet." + prefixIfNeeded(scopePrefix(declaration),orig_fun_name) + " = in;\n";
|
||||
}
|
||||
|
||||
if (method = getMethod(paramType, "destruct", std::vector<Type>())) {
|
||||
if ((method = getMethod(paramType, "destruct", std::vector<Type>()))) {
|
||||
functionDefinitions += " " + generateMethodIfExists(paramType, "destruct",
|
||||
"&in", std::vector<Type>()) + ";\n";
|
||||
} }
|
||||
|
||||
@@ -685,8 +685,8 @@ obj assignment_statement (Object) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
fun ast_declaration_statement_ptr(): *ast_node {
|
||||
var to_ret.construct(): declaration_statement
|
||||
fun ast_declaration_statement_ptr(ident: *ast_node): *ast_node {
|
||||
var to_ret.construct(ident): declaration_statement
|
||||
var ptr = new<ast_node>()
|
||||
ptr->copy_construct(&ast_node::declaration_statement(to_ret))
|
||||
return ptr
|
||||
@@ -698,23 +698,22 @@ fun is_declaration_statement(node: *ast_node): bool {
|
||||
return false
|
||||
}
|
||||
obj declaration_statement (Object) {
|
||||
var scope: map<string, vector<*ast_node>>
|
||||
fun construct(): *declaration_statement {
|
||||
scope.construct()
|
||||
var identifier: *ast_node
|
||||
fun construct(identifier_in: *ast_node): *declaration_statement {
|
||||
identifier = identifier_in
|
||||
return this
|
||||
}
|
||||
fun copy_construct(old: *declaration_statement) {
|
||||
scope.copy_construct(&old->scope)
|
||||
identifier = old->identifier
|
||||
}
|
||||
fun destruct() {
|
||||
scope.destruct()
|
||||
}
|
||||
fun operator=(other: ref declaration_statement) {
|
||||
destruct()
|
||||
copy_construct(&other)
|
||||
}
|
||||
fun operator==(other: ref declaration_statement): bool {
|
||||
return true
|
||||
return identifier == other.identifier
|
||||
}
|
||||
}
|
||||
fun ast_if_comp_ptr(): *ast_node {
|
||||
@@ -882,7 +881,7 @@ fun get_ast_children(node: *ast_node): vector<*ast_node> {
|
||||
ast_node::continue_statement(backing) return vector<*ast_node>()
|
||||
ast_node::defer_statement(backing) return vector<*ast_node>()
|
||||
ast_node::assignment_statement(backing) return vector<*ast_node>()
|
||||
ast_node::declaration_statement(backing) return vector<*ast_node>()
|
||||
ast_node::declaration_statement(backing) return vector(backing.identifier)
|
||||
ast_node::if_comp(backing) return vector<*ast_node>(backing.statement)
|
||||
ast_node::simple_passthrough(backing) return vector<*ast_node>()
|
||||
ast_node::function_call(backing) return vector(backing.func) + backing.parameters
|
||||
@@ -936,7 +935,7 @@ fun get_ast_scope(node: *ast_node): *map<string,vector<*ast_node>> {
|
||||
ast_node::continue_statement() return &node->continue_statement.scope
|
||||
ast_node::defer_statement() return &node->defer_statement.scope
|
||||
ast_node::assignment_statement() return &node->assignment_statement.scope
|
||||
ast_node::declaration_statement() return &node->declaration_statement.scope
|
||||
ast_node::declaration_statement() return null<map<string,vector<*ast_node>>>()
|
||||
ast_node::if_comp() return null<map<string,vector<*ast_node>>>()
|
||||
ast_node::simple_passthrough() return &node->simple_passthrough.scope
|
||||
ast_node::function_call() return null<map<string,vector<*ast_node>>>()
|
||||
|
||||
@@ -93,6 +93,7 @@ obj ast_transformation (Object) {
|
||||
ast_to_syntax.set(function_node, child)
|
||||
} else if (child->data.name == "declaration_statement") {
|
||||
// second pass declaration can actually just call a normal transform (but maybe should be it's own method to do so because typedef has to do it too?)...
|
||||
translation_unit->translation_unit.children.add(transform_declaration_statement(child, translation_unit))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -183,6 +184,8 @@ obj ast_transformation (Object) {
|
||||
return transform_simple_passthrough(node, scope)
|
||||
} else if (name == "statement") {
|
||||
return transform_statement(node, scope)
|
||||
} else if (name == "declaration_statement") {
|
||||
return transform_declaration_statement(node, scope)
|
||||
} else if (name == "return_statement") {
|
||||
return transform_return_statement(node, scope)
|
||||
} else if (name == "function_call") {
|
||||
@@ -265,6 +268,10 @@ obj ast_transformation (Object) {
|
||||
new_statement->statement.child = transform(node->children[0], scope)
|
||||
return new_statement
|
||||
}
|
||||
fun transform_declaration_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||
var declaration = ast_declaration_statement_ptr(ast_identifier_ptr(concat_symbol_tree(get_node("identifier", node)), transform_type(get_node("type", node), scope, map<string, *type>())))
|
||||
return declaration
|
||||
}
|
||||
fun transform_return_statement(node: *tree<symbol>, scope: *ast_node): *ast_node {
|
||||
return ast_return_statement_ptr(transform(node->children[0], scope))
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ obj c_generator (Object) {
|
||||
top_level_c_passthrough += generate_simple_passthrough(backing.statement->statement.child)
|
||||
}
|
||||
ast_node::simple_passthrough(backing) top_level_c_passthrough += generate_simple_passthrough(child)
|
||||
ast_node::declaration_statement(backing) variable_declarations += generate_declaration_statement(child) + ";\n"
|
||||
ast_node::function(backing) {
|
||||
// make sure not a template
|
||||
// or a passthrough
|
||||
@@ -83,6 +84,10 @@ obj c_generator (Object) {
|
||||
return node->simple_passthrough.passthrough_str
|
||||
}
|
||||
fun generate_statement(node: *ast_node): string return generate(node->statement.child) + ";\n";
|
||||
fun generate_declaration_statement(node: *ast_node): string {
|
||||
var identifier = node->declaration_statement.identifier
|
||||
return type_to_c(identifier->identifier.type) + " " + identifier->identifier.name
|
||||
}
|
||||
fun generate_return_statement(node: *ast_node): string return string("return ") + generate(node->return_statement.return_value);
|
||||
fun generate_value(node: *ast_node): string return node->value.string_value;
|
||||
fun generate_code_block(node: *ast_node): string {
|
||||
@@ -114,6 +119,7 @@ obj c_generator (Object) {
|
||||
ast_node::if_comp(backing) return generate_if_comp(node)
|
||||
ast_node::simple_passthrough(backing) return generate_simple_passthrough(node)
|
||||
ast_node::statement(backing) return generate_statement(node)
|
||||
ast_node::declaration_statement(backing) return generate_declaration_statement(node)
|
||||
ast_node::function(backing) return generate_function(node)
|
||||
ast_node::function_call(backing) return generate_function_call(node)
|
||||
ast_node::code_block(backing) return generate_code_block(node)
|
||||
|
||||
@@ -9,8 +9,10 @@ fun simple_print(to_print: int) {
|
||||
printf("%d", to_print);
|
||||
"""
|
||||
}
|
||||
var a = 1
|
||||
var b = 2
|
||||
/*var a = 1*/
|
||||
/*var b = 2*/
|
||||
var a:int
|
||||
var b:int
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ fun some_other_function(in: bool): float {
|
||||
return 0.0
|
||||
}
|
||||
fun main(): int {
|
||||
var a_declaration:int
|
||||
/*var another_declaration = 9*/
|
||||
simple_print("Hello World!\n")
|
||||
simple_print(1337)
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user