From c22cadeed7ae6ef475ac344ff623a242808521c4 Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Sat, 9 May 2015 03:13:40 -0400 Subject: [PATCH] The template part of the new syntax! Gotta go transform all of stdlib and the tests now and see if any other bugs pop up --- krakenGrammer.kgm | 32 ++++---- src/ASTTransformation.cpp | 73 +++++++++---------- src/Importer.cpp | 2 +- .../test_negative_number_unary.krak.c | 10 --- .../test_negative_number_unary.krak.h | 27 ------- .../test_negative_number_unary.krak.results | 0 .../test_negative_number_unary.krak.sh | 2 - tests/test_newSyntax.krak | 2 - tests/test_newSyntaxTemplate.expected_results | 3 + tests/test_newSyntaxTemplate.krak | 36 +++++++++ 10 files changed, 94 insertions(+), 93 deletions(-) delete mode 100644 tests/test_negative_number_unary.krak/test_negative_number_unary.krak.c delete mode 100644 tests/test_negative_number_unary.krak/test_negative_number_unary.krak.h delete mode 100644 tests/test_negative_number_unary.krak/test_negative_number_unary.krak.results delete mode 100755 tests/test_negative_number_unary.krak/test_negative_number_unary.krak.sh create mode 100644 tests/test_newSyntaxTemplate.expected_results create mode 100644 tests/test_newSyntaxTemplate.krak diff --git a/krakenGrammer.kgm b/krakenGrammer.kgm index 56d8601..8c143ab 100644 --- a/krakenGrammer.kgm +++ b/krakenGrammer.kgm @@ -1,6 +1,6 @@ Goal = translation_unit ; translation_unit = WS unorderd_list_part WS ; -unorderd_list_part = import WS unorderd_list_part | function WS unorderd_list_part | type_def WS SEMI WS unorderd_list_part | if_comp WS unorderd_list_part | simple_passthrough WS unorderd_list_part | declaration_statement WS SEMI WS unorderd_list_part | import | function | type_def WS SEMI | if_comp | simple_passthrough | declaration_statement WS SEMI ; +unorderd_list_part = import WS unorderd_list_part | function WS unorderd_list_part | type_def line_end WS unorderd_list_part | if_comp WS unorderd_list_part | simple_passthrough WS unorderd_list_part | declaration_statement line_end WS unorderd_list_part | import | function | type_def line_end | if_comp | simple_passthrough | declaration_statement line_end ; type = type WS "\*" | "void" | "int" | "float" | "double" | "char" | scoped_identifier | scoped_identifier WS template_inst ; dec_type = ":" WS type ; @@ -12,18 +12,26 @@ template_dec = "<" WS template_param_list WS ">" ; template_param_list = template_param_list WS "," WS template_param | template_param ; template_param = identifier WS traits | identifier ; -import = "import" WS identifier WS SEMI | "import" WS identifier WS ":" WS "\*" WS SEMI | "import" WS identifier WS ":" WS import_list WS SEMI ; +import = "import" WS identifier line_end | "import" WS identifier WS ":" WS "\*" line_end | "import" WS identifier WS ":" WS import_list line_end ; import_list = identifier | identifier WS "," WS import_list ; # all for optional semicolons line_break = " +" ; -actual_white = "( | )+" | line_break | line_break actual_white | "( | )+" actual_white ; +# why use line_white here but not below? who knows. It's wayy faster this way. Or maybe when I changed it there was a typing mistake. Noone knows. +line_white = "( | )+" ; +actual_white = line_white | line_break | line_break actual_white | line_white actual_white ; # Why is WS comment necessary? The null case SHOULD handle it, I think. I'm just a tad worred...... WS = actual_white | WS comment WS | WS comment | ; # cpp_comment lets us do stuff like ending a statement with a cpp comment - c comments already work as they don't eat the return -SEMI = ";" | line_break | cpp_comment ; -#SEMI = ";" ; + +maybe_line_white = "( | )+" | ; +line_end = maybe_line_white ";" | maybe_line_white line_break | maybe_line_white cpp_comment ; + +# line_end = "( | )+" ";" | "( | )+" line_break | "( | )+" cpp_comment | ";" | line_break | cpp_comment ; +# line_end = WS ";" | WS line_break | WS cpp_comment ; +# line_end = "( | )+" ending | ending ; +# ending = ";" | line_break | cpp_comment ; if_comp = "__if_comp__" WS identifier WS if_comp_pred ; if_comp_pred = code_block | simple_passthrough ; @@ -44,7 +52,7 @@ triple_quoted_string = "\"\"\"((\"\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+\"\")|((`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'| |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )+))*\"\"\"" ; -identifier = alpha | alpha alphanumeric ; +identifier = alpha_alphanumeric ; scope_op = ":" ":" ; scoped_identifier = scoped_identifier WS scope_op WS identifier | identifier ; @@ -64,7 +72,7 @@ parameter = boolean_expression ; type_def = "typedef" WS identifier WS type | "typedef" WS identifier WS template_dec WS "{" WS declaration_block WS "}" | "typedef" WS identifier WS "{" WS declaration_block WS "}" | "typedef" WS identifier WS template_dec WS traits WS "{" WS declaration_block WS "}" | "typedef" WS identifier WS traits WS "{" WS declaration_block WS "}" ; -declaration_block = declaration_statement WS SEMI WS declaration_block | function WS declaration_block | declaration_statement WS SEMI | function | ; +declaration_block = declaration_statement line_end WS declaration_block | function WS declaration_block | declaration_statement line_end | function | ; traits = "\(" WS trait_list WS "\)" ; trait_list = trait_list WS "," WS scoped_identifier | scoped_identifier ; @@ -72,14 +80,14 @@ if_statement = "if" WS "\(" WS boolean_expression WS "\)" WS statement | "if" WS while_loop = "while" WS boolean_expression WS statement ; -for_loop = "for" WS "\(" WS statement WS boolean_expression WS SEMI WS statement WS "\)" WS statement ; +for_loop = "for" WS "\(" WS statement WS boolean_expression line_end WS statement WS "\)" WS statement ; return_statement = "return" | "return" WS boolean_expression ; code_block = "{" WS statement_list WS "}" | "{" WS "}" ; statement_list = statement_list WS statement | statement ; -statement = if_statement | while_loop | for_loop | return_statement WS SEMI | boolean_expression WS SEMI | assignment_statement WS SEMI | declaration_statement WS SEMI | code_block | if_comp | simple_passthrough ; +statement = if_statement | while_loop | for_loop | return_statement line_end | boolean_expression line_end | assignment_statement line_end | declaration_statement line_end | code_block | if_comp | simple_passthrough ; function_call = unarad "\(" WS opt_parameter_list WS "\)" ; boolean_expression = boolean_expression WS "\|\|" WS and_boolean_expression | and_boolean_expression ; @@ -97,15 +105,13 @@ access_operation = unarad "." identifier | unarad "->" identifier ; assignment_statement = factor WS "=" WS boolean_expression | factor WS "\+=" WS boolean_expression | factor WS "-=" WS boolean_expression | factor WS "\*=" WS boolean_expression | factor WS "/=" WS boolean_expression ; declaration_statement = "var" WS identifier WS dec_type WS "=" WS boolean_expression | "var" WS identifier WS dec_type | "var" WS identifier WS "." WS identifier WS "\(" WS opt_parameter_list WS "\)" WS dec_type ; - -alphanumeric = alphanumeric numeric | alphanumeric alpha | numeric | alpha ; hexadecimal = "0x(1|2|3|4|5|6|7|8|9|a|b|c|d|e|f)+" ; integer = numeric | hexadecimal ; -floating_literal = numeric "." numeric | numeric "." numeric alpha ; +floating_literal = numeric "." numeric ; bool = "true" | "false" ; character = "'(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'| |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|\"|Z|X|C|V|B|N|M|<|>|\?| )'" ; -alpha = "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|_)+" ; +alpha_alphanumeric = "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|_)(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|_|0|1|2|3|4|5|6|7|8|9)*" ; numeric = "(0|1|2|3|4|5|6|7|8|9)+" ; string = triple_quoted_string | "\"(`|1|2|3|4|5|6|7|8|9|0|-|=| |q|w|e|r|t|y|u|i|o|p|[|]|\\|a|s|d|f|g|h|j|k|l|;|'| |z|x|c|v|b|n|m|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|Q|W|E|R|T|Y|U|I|O|P|{|}|\||A|S|D|F|G|H|J|K|L|:|Z|X|C|V|B|N|M|<|>|\?| )*\"" ; diff --git a/src/ASTTransformation.cpp b/src/ASTTransformation.cpp index edc22a8..087690e 100644 --- a/src/ASTTransformation.cpp +++ b/src/ASTTransformation.cpp @@ -37,7 +37,6 @@ ASTTransformation::ASTTransformation(Importer *importerIn) { } ASTTransformation::~ASTTransformation() { - // } //First pass defines all type_defs (objects and ailises), and if_comp/simple_passthrough @@ -50,11 +49,7 @@ NodeTree* ASTTransformation::firstPass(std::string fileName, NodeTree* i : children) { if (i->getDataRef()->getName() == "type_def") { - std::string name; - if (i->getChildren()[0]->getData().getName() == "template_dec") // It's a template - name = concatSymbolTree(i->getChildren()[1]); - else //It's not - name = concatSymbolTree(i->getChildren()[0]); + std::string name = concatSymbolTree(i->getChildren()[0]); NodeTree* firstDec = addToScope("~enclosing_scope", translationUnit, new NodeTree("type_def", ASTData(type_def, Symbol(name, true, name)))); addToScope(name, firstDec, translationUnit); translationUnit->addChild(firstDec); @@ -62,16 +57,16 @@ NodeTree* ASTTransformation::firstPass(std::string fileName, NodeTreegetChildren(); - if (typedefChildren[0]->getData().getName() == "template_dec") { + if (typedefChildren.size()>1 && typedefChildren[1]->getData().getName() == "template_dec") { if (typedefChildren.size() > 2 && typedefChildren[2]->getData().getName() == "traits") firstDec->getDataRef()->valueType = new Type(template_type, i, parseTraits(i->getChildren()[2])); else firstDec->getDataRef()->valueType = new Type(template_type, i); - } - else if (typedefChildren.size() > 1 && typedefChildren[1]->getData().getName() == "traits") + } else if (typedefChildren.size() > 1 && typedefChildren[1]->getData().getName() == "traits") { firstDec->getDataRef()->valueType = new Type(firstDec, parseTraits(i->getChildren()[1])); - else if (typedefChildren.size() == 1 || typedefChildren[1]->getData().getName() != "type") //We don't make the type for alises, because the second pass will assign it the type it points to + } else if (typedefChildren.size() == 1 || typedefChildren[1]->getData().getName() != "type") { //We don't make the type for alises, because the second pass will assign it the type it points to firstDec->getDataRef()->valueType = new Type(firstDec); + } } else if (i->getDataRef()->getName() == "if_comp") { std::cout << "IF COMP" << std::endl; @@ -143,7 +138,7 @@ void ASTTransformation::secondPass(NodeTree* ast, NodeTree* par //Note that this pass can instantiate class templates for (NodeTree* i : children) { if (i->getDataRef()->getName() == "type_def") { - if (i->getChildren()[0]->getData().getName() == "template_dec") // It's a template + if (i->getChildren().size()>1 && i->getChildren()[1]->getData().getName() == "template_dec") // It's a template continue; //We've already set upt the class templates std::vector*> typedefChildren = i->getChildren(); std::string name = concatSymbolTree(typedefChildren[0]); @@ -189,8 +184,8 @@ void ASTTransformation::secondPassDoClassInsides(NodeTree* typeDef, std NodeTree* ASTTransformation::secondPassDeclaration(NodeTree* from, NodeTree* scope, std::map templateTypeReplacements) { //Check here for method call (an error here) NodeTree* decStmt = addToScope("~enclosing_scope", scope, new NodeTree("declaration_statement", ASTData(declaration_statement))); - std::string newIdentifierStr = concatSymbolTree(from->getChildren()[1]); - Type* identifierType = typeFromTypeNode(from->getChildren()[0], scope, templateTypeReplacements); + std::string newIdentifierStr = concatSymbolTree(from->getChildren()[0]); + Type* identifierType = typeFromTypeNode(from->getChildren()[2], scope, templateTypeReplacements); std::cout << "Declaring an identifier " << newIdentifierStr << " to be of type " << identifierType->toString() << std::endl; NodeTree* newIdentifier = addToScope("~enclosing_scope", decStmt, new NodeTree("identifier", ASTData(identifier, Symbol(newIdentifierStr, true), identifierType))); //scope->getDataRef()->scope[newIdentifierStr].push_back(newIdentifier); @@ -206,21 +201,21 @@ NodeTree* ASTTransformation::secondPassFunction(NodeTree* from, std::vector*> children = from->getChildren(); NodeTree* functionDef = NULL; std::string functionName; - if (children[0]->getData().getName() == "template_dec") { - functionName = concatSymbolTree(children[2]); + if (children[1]->getData().getName() == "template_dec") { + functionName = concatSymbolTree(children[0]); functionDef = new NodeTree("function", ASTData(function, Symbol(functionName, true), new Type(template_type, from))); addToScope("~enclosing_scope", scope, functionDef); addToScope(functionName, functionDef, scope); std::map yetToBeInstantiatedTemplateTypes; //So that template types (like T) that have not been placed yet are found and given //a special Type() - baseType = template_type_type - for (auto i : slice(children[0]->getChildren(), 1, -1, 2)) {//skip commas + for (auto i : slice(children[1]->getChildren(), 1, -1, 2)) {//skip commas if (i->getChildren().size() == 1) yetToBeInstantiatedTemplateTypes[concatSymbolTree(i)] = new Type(template_type_type); //This may have to be combined with templateTypeReplacements if we do templated member functions inside of templated classes else //has traits yetToBeInstantiatedTemplateTypes[concatSymbolTree(i->getChildren()[0])] = new Type(template_type_type, parseTraits(i->getChildren()[1])); //This may have to be combined with templateTypeReplacements if we do templated member functions inside of templated classes } // Just to see, I don't think templated functions actually need parameters at this point, and we might not have enough info anyway... - auto transChildren = transformChildren(slice(children,3,-2), std::set(), functionDef, std::vector(), yetToBeInstantiatedTemplateTypes); + auto transChildren = transformChildren(slice(children,2,-3), std::set(), functionDef, std::vector(), yetToBeInstantiatedTemplateTypes); std::cout << "Template function " << functionName << " has these parameters: "; for (auto i : transChildren) std::cout << "||" << i->getDataRef()->toString() << "|| "; @@ -256,7 +251,7 @@ void ASTTransformation::thirdPass(NodeTree* ast, NodeTree* pars //Note that this pass can instantiate class AND function templates for (NodeTree* i : children) { if (i->getDataRef()->getName() == "type_def") { - if (i->getChildren()[0]->getData().getName() == "template_dec") // It's a template + if (i->getChildren()[1]->getData().getName() == "template_dec") // It's a template continue; //We've already set up the class templates std::vector*> typedefChildren = i->getChildren(); std::string name = concatSymbolTree(typedefChildren[0]); @@ -274,7 +269,7 @@ void ASTTransformation::thirdPass(NodeTree* ast, NodeTree* pars } } else if (i->getDataRef()->getName() == "function") { //Do prototypes of functions - if (i->getChildren()[0]->getData().getName() == "template_dec") + if (i->getChildren()[1]->getData().getName() == "template_dec") continue; //We've already set up function templates thirdPassFunction(i, searchScopeForFunctionDef(ast, i, std::map()), std::map()); } @@ -329,7 +324,8 @@ NodeTree* ASTTransformation::searchScopeForFunctionDef(NodeTree* from, NodeTree* functionDef, std::map templateTypeReplacements) { - NodeTree* codeBlock = from->getChildren()[from->getChildren().size()-1]; + //NodeTree* codeBlock = from->getChildren()[from->getChildren().size()-1]; + NodeTree* codeBlock = from->getChildren().back(); functionDef->addChild(transform(codeBlock, functionDef, std::vector(), templateTypeReplacements)); } @@ -378,8 +374,8 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree skipChildren.insert(1); } else { //Is a struct or class Type* objectType = NULL; - if (children[0]->getData().getName() == "template_dec") { - typeAlias = concatSymbolTree(children[1]); + if (children[1]->getData().getName() == "template_dec") { + typeAlias = concatSymbolTree(children[0]); std::cout << "Template Type!"<getDataRef()->scope[typeAlias][0]; //The node for this type_def has already been made by translation_unit. //This is done so that types that reference each other can be declared in any order @@ -406,20 +402,20 @@ NodeTree* ASTTransformation::transform(NodeTree* from, NodeTree //Templates are done here. No need to go farther - if (children[0]->getData().getName() == "template_dec") + if (children[1]->getData().getName() == "template_dec") return newNode; scope = newNode; } else if (name == "function") { std::string functionName; //If this is a function template - if (children[0]->getData().getName() == "template_dec") { - functionName = concatSymbolTree(children[2]); + if (children[1]->getData().getName() == "template_dec") { + functionName = concatSymbolTree(children[0]); newNode = new NodeTree(name, ASTData(function, Symbol(functionName, true), new Type(template_type, from))); addToScope(functionName, newNode, scope); addToScope("~enclosing_scope", scope, newNode); std::map yetToBeInstantiatedTemplateTypes; //So that template types (like T) that have not been placed yet are found and given //a special Type() - baseType = template_type_type - for (auto i : slice(children[0]->getChildren(), 1, -1, 2)) //skip commas + for (auto i : slice(children[1]->getChildren(), 1, -1, 2)) //skip commas yetToBeInstantiatedTemplateTypes[concatSymbolTree(i)] = new Type(template_type_type); //This may have to be combined with templateTypeReplacements if we do templated member functions inside of templated classes auto transChildren = transformChildren(slice(children,3,-2), std::set(), newNode, types, yetToBeInstantiatedTemplateTypes); @@ -902,7 +898,7 @@ NodeTree* ASTTransformation::templateClassLookup(NodeTree* sco for (auto i : possibleMatches) { NodeTree* templateSyntaxTree = i->getDataRef()->valueType->templateDefinition; - auto nameTraitsPairs = makeTemplateNameTraitPairs(templateSyntaxTree->getChildren()[0]); + auto nameTraitsPairs = makeTemplateNameTraitPairs(templateSyntaxTree->getChildren()[1]); //Check if sizes match between the placeholder and actual template types if (nameTraitsPairs.size() != templateInstantiationTypes.size()) continue; @@ -969,7 +965,7 @@ NodeTree* ASTTransformation::templateFunctionLookup(NodeTree* continue; } - auto nameTraitsPairs = makeTemplateNameTraitPairs(templateSyntaxTree->getChildren()[0]); + auto nameTraitsPairs = makeTemplateNameTraitPairs(templateSyntaxTree->getChildren()[1]); //Check if sizes match between the placeholder and actual template types if (nameTraitsPairs.size() != templateInstantiationTypes.size()) continue; @@ -1002,14 +998,14 @@ NodeTree* ASTTransformation::templateFunctionLookup(NodeTree* if (!traitsEqual) continue; - std::vector*> functionParameters = slice(templateSyntaxTree->getChildren(), 3, -2, 2); //skip template, return type, name, intervening commas, and the code block + std::vector*> functionParameters = slice(templateSyntaxTree->getChildren(), 2, -3, 2); //skip name, intervening commas, return type, and the code block std::cout << functionParameters.size() << " " << types.size() << std::endl; if (functionParameters.size() != types.size()) continue; bool parameterTypesMatch = true; for (int j = 0; j < functionParameters.size(); j++) { - auto paramType = typeFromTypeNode(functionParameters[j]->getChildren()[0], scope, typeMap); + auto paramType = typeFromTypeNode(functionParameters[j]->getChildren()[2], scope, typeMap); std::cout << "Template param type: " << paramType->toString() << " : Needed Type: " << types[j].toString() << std::endl; if (*paramType != types[j]) { parameterTypesMatch = false; @@ -1244,7 +1240,7 @@ Type* ASTTransformation::typeFromTypeNode(NodeTree* typeNode, NodeTree* templateSyntaxTree = templateDefinition->getDataRef()->valueType->templateDefinition; //Create a new map of template type names to actual types. - std::vector*> templateParamPlaceholderNodes = slice(templateSyntaxTree->getChildren()[0]->getChildren(), 1, -2, 2); //Don't get beginning or end for < or >, skip commas in the middle + std::vector*> templateParamPlaceholderNodes = slice(templateSyntaxTree->getChildren()[1]->getChildren(), 1, -2, 2); //Don't get beginning or end for < or >, skip commas in the middle std::map newTemplateTypeReplacement; for (int i = 0; i < templateParamInstantiationTypes.size(); i++) newTemplateTypeReplacement[concatSymbolTree(templateParamPlaceholderNodes[i])] = templateParamInstantiationTypes[i]; @@ -1343,18 +1339,14 @@ NodeTree* ASTTransformation::findOrInstantiateFunctionTemplate(std::vec NodeTree* templateSyntaxTree = templateDefinition->getDataRef()->valueType->templateDefinition; // Makes a map between the names of the template placeholder parameters and the provided types - std::map newTemplateTypeReplacement = makeTemplateFunctionTypeMap(templateSyntaxTree->getChildren()[0], templateActualTypes); + std::map newTemplateTypeReplacement = makeTemplateFunctionTypeMap(templateSyntaxTree->getChildren()[1], templateActualTypes); std::vector*> templateChildren = templateSyntaxTree->getChildren(); for (int i = 0; i < templateChildren.size(); i++) std::cout << ", " << i << " : " << templateChildren[i]->getDataRef()->getName(); std::cout << std::endl; - instantiatedFunction = new NodeTree("function", ASTData(function, Symbol(fullyInstantiatedName, true), typeFromTypeNode(templateChildren[1], scope, newTemplateTypeReplacement))); - std::set skipChildren; - skipChildren.insert(0); - skipChildren.insert(1); - skipChildren.insert(2); + instantiatedFunction = new NodeTree("function", ASTData(function, Symbol(fullyInstantiatedName, true), typeFromTypeNode(templateChildren[templateChildren.size()-2], scope, newTemplateTypeReplacement))); //scope->getDataRef()->scope[fullyInstantiatedName].push_back(instantiatedFunction); //instantiatedFunction->getDataRef()->scope["~enclosing_scope"].push_back(templateDefinition->getDataRef()->scope["~enclosing_scope"][0]); //Instantiated Template Function's scope is it's template's definition's scope addToScope("~enclosing_scope", templateDefinition->getDataRef()->scope["~enclosing_scope"][0], instantiatedFunction); @@ -1367,8 +1359,13 @@ NodeTree* ASTTransformation::findOrInstantiateFunctionTemplate(std::vec //topScope->getDataRef()->scope[fullyInstantiatedName].push_back(instantiatedFunction); //topScope->addChild(instantiatedFunction); //Add this object the the highest scope's + std::set skipChildren; + skipChildren.insert(0); + skipChildren.insert(1); + skipChildren.insert(templateSyntaxTree->getChildren().size()-3); + skipChildren.insert(templateSyntaxTree->getChildren().size()-2); std::cout << "About to do children of " << functionName << " to " << fullyInstantiatedName << std::endl; - instantiatedFunction->addChildren(transformChildren(templateSyntaxTree->getChildren(), skipChildren, instantiatedFunction, std::vector(), newTemplateTypeReplacement)); + instantiatedFunction->addChildren(transformChildren(templateSyntaxTree->getChildren(), skipChildren, instantiatedFunction, std::vector(), newTemplateTypeReplacement)); std::cout << "Fully Instantiated function " << functionName << " to " << fullyInstantiatedName << std::endl; return instantiatedFunction; diff --git a/src/Importer.cpp b/src/Importer.cpp index 8d04470..bd587e0 100644 --- a/src/Importer.cpp +++ b/src/Importer.cpp @@ -23,7 +23,7 @@ Importer::Importer(Parser* parserIn, std::vector includePaths, std: removeSymbols.push_back(Symbol("fun", true)); removeSymbols.push_back(Symbol(";", true)); - removeSymbols.push_back(Symbol("SEMI", false)); + removeSymbols.push_back(Symbol("line_end", false)); removeSymbols.push_back(Symbol("{", true)); removeSymbols.push_back(Symbol("}", true)); removeSymbols.push_back(Symbol("(", true)); diff --git a/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.c b/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.c deleted file mode 100644 index 8200aba..0000000 --- a/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "test_negative_number_unary.krak.h" - -/** - * Variable Declarations - */ - -/** - * Function Definitions - */ - diff --git a/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.h b/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.h deleted file mode 100644 index 34251d0..0000000 --- a/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.h +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -/** - * Plain Typedefs - */ - -/** - * Import Includes - */ - -/** - * Top Level C Passthrough - */ - -/** - * Extern Variable Declarations - */ - -/** - * Class Structs - */ - -/** - * Function Prototypes - */ - diff --git a/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.results b/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.results deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.sh b/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.sh deleted file mode 100755 index 9673afa..0000000 --- a/tests/test_negative_number_unary.krak/test_negative_number_unary.krak.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -cc -std=c99 test_negative_number_unary.krak.c -o test_negative_number_unary.krak \ No newline at end of file diff --git a/tests/test_newSyntax.krak b/tests/test_newSyntax.krak index 2cca6b2..d4bf712 100644 --- a/tests/test_newSyntax.krak +++ b/tests/test_newSyntax.krak @@ -18,5 +18,3 @@ fun main() : int { return 0 } - - diff --git a/tests/test_newSyntaxTemplate.expected_results b/tests/test_newSyntaxTemplate.expected_results new file mode 100644 index 0000000..0ff8baa --- /dev/null +++ b/tests/test_newSyntaxTemplate.expected_results @@ -0,0 +1,3 @@ +yeah new syntax: 7, 6 +yeah new syntax: 6, 7 +yeah new syntax: 7, 6 diff --git a/tests/test_newSyntaxTemplate.krak b/tests/test_newSyntaxTemplate.krak new file mode 100644 index 0000000..d31ff99 --- /dev/null +++ b/tests/test_newSyntaxTemplate.krak @@ -0,0 +1,36 @@ + + +typedef Swapper { + fun doit(a: T*, b: T*) : void { + var temp: T = *a; + *a = *b; + *b = temp; + } +} + + +fun swap(a: T*, b: T*) : void { + var temp: T = *a + *a = *b + *b = temp; +} + +fun print2int(a: int, b: int) : void { + simple_passthrough(a = a, b = b::) """ + printf("yeah new syntax: %d, %d\n", a, b); + """ +} + + +fun main() : int { + var i: int = 7; + var j: int = 6; + print2int(i,j) + swap(&i, &j) + print2int(i,j) + var it: Swapper + it.doit(&i,&j); + print2int(i,j) + return 0 +} +