diff --git a/src/ASTTransformation.cpp b/src/ASTTransformation.cpp index 6b34257..ed3255e 100644 --- a/src/ASTTransformation.cpp +++ b/src/ASTTransformation.cpp @@ -208,12 +208,13 @@ NodeTree* ASTTransformation::secondPassFunction(NodeTree* from, 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); - std::cout << "Template function " << functionName << " has these parameters: "; - for (auto i : transChildren) - std::cout << "||" << i->getDataRef()->toString() << "|| "; - std::cout << "DoneList" << std::endl; - functionDef->addChildren(transChildren); + std::cout << "Template function " << functionName << " has these parameters: "; + for (auto i : transChildren) + std::cout << "||" << i->getDataRef()->toString() << "|| "; + std::cout << "DoneList" << std::endl; + functionDef->addChildren(transChildren); std::cout << "Finished Non-Instantiated Template function " << functionName << std::endl; return functionDef; @@ -1195,6 +1196,15 @@ Type* ASTTransformation::typeFromTypeNode(NodeTree* typeNode, NodeTree |T| fun(|vec| a) { return a.at(0); } + * etc + *******************************************************************************/ + if (instType->baseType == template_type_type) + return instType; templateParamInstantiationTypes.push_back(instType); instTypeString += (instTypeString == "") ? instType->toString(false) : "," + instType->toString(false); } @@ -1346,7 +1356,6 @@ NodeTree* ASTTransformation::findOrInstantiateFunctionTemplate(std::vec std::cout << "About to do children of " << functionName << " to " << fullyInstantiatedName << std::endl; 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/tests/test_chainedIndirectTemplates.expected_results b/tests/test_chainedIndirectTemplates.expected_results new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/tests/test_chainedIndirectTemplates.expected_results @@ -0,0 +1 @@ +2 diff --git a/tests/test_chainedIndirectTemplates.krak b/tests/test_chainedIndirectTemplates.krak new file mode 100644 index 0000000..a84ace0 --- /dev/null +++ b/tests/test_chainedIndirectTemplates.krak @@ -0,0 +1,15 @@ +import vector:*; +import io:*; + +template |T| test(|vector| a) { + return a.at(0); +} + +|int| main() { + |vector| a.construct(); + a.addEnd(2); + println(test(a)); + return 0; +} + + diff --git a/tests/test_topLevelVarInit/test_topLevelVarInit b/tests/test_topLevelVarInit/test_topLevelVarInit deleted file mode 100755 index 4ed2f7a..0000000 Binary files a/tests/test_topLevelVarInit/test_topLevelVarInit and /dev/null differ diff --git a/tests/test_topLevelVarInit/test_topLevelVarInit.c b/tests/test_topLevelVarInit/test_topLevelVarInit.c deleted file mode 100644 index 7342743..0000000 --- a/tests/test_topLevelVarInit/test_topLevelVarInit.c +++ /dev/null @@ -1,225 +0,0 @@ -#include "./test_topLevelVarInit.h" - -/*unknown declaration named translation_unit*/ -/*unknown declaration named translation_unit*/ -/*unknown declaration named translation_unit*/ -/*unknown declaration named translation_unit*/ -/*unknown declaration named translation_unit*/ -/*unknown declaration named translation_unit*/ -/** - * Variable Declarations - */ - -int a; /*identifier*/ -/** - * Function Definitions - */ - - -int main() -{ - println_int(a) ; - return 0; -} -void print_char_P__(char* toPrint) -{ - { - - printf(toPrint); - ; - }; - return; -} -void print_string(string toPrint) -{ - print_char_P__(string__toCharArray(&toPrint) ) ; -} -void print_int(int toPrint) -{ - { - - printf("%d", toPrint); - ; - }; - return; -} -void print_float(float toPrint) -{ - { - - printf("%f", toPrint); - ; - }; - return; -} -void print_double(double toPrint) -{ - { - - printf("%f", toPrint); - ; - }; - return; -} -void println() -{ - print_char_P__("\n") ; -} -void println_char_P__(char* toPrint) -{ - print_char_P__(toPrint) ; - println() ; -} -void println_string(string toPrint) -{ - println_char_P__(string__toCharArray(&toPrint) ) ; -} -void println_int(int toPrint) -{ - print_int(toPrint) ; - println() ; -} -void println_float(float toPrint) -{ - print_float(toPrint) ; - println() ; -} -void delete_lessthan_char_greaterthan__char_P__(char* toDelete) -{ - free(toDelete) ; -} -void delete_lessthan_char_greaterthan__char_P___int(char* toDelete, int itemCount) -{ - delete_lessthan_char_greaterthan__char_P__(toDelete) ; -} -char* malloc_lessthan_char_greaterthan__int(int size) -{ - char* memPtr = 0;; - { - - memPtr = malloc(size); - ; - }; - return memPtr; -} -char* mem_scopeop_new_lessthan_char_greaterthan__int(int count) -{ - return malloc_lessthan_char_greaterthan__int(((sizeof_lessthan_char_greaterthan_() )*(count))) ; -} -char* new_lessthan_char_greaterthan__int(int count) -{ - return malloc_lessthan_char_greaterthan__int(((sizeof_lessthan_char_greaterthan_() )*(count))) ; -} -int sizeof_lessthan_char_greaterthan_() -{ - int result = 0;; - char testObj;; - { - - result = sizeof(testObj); - ; - }; - return result; -}/* Method Definitions for string */ - -string* string__construct(string* this) -{ - vector_lessthan_char_greaterthan___construct(&this->data) ; - return this; -} - -string* string__construct_char_P__(string* this, char* str) -{ - vector_lessthan_char_greaterthan___construct(&this->data) ; - while (*(str)) - { - vector_lessthan_char_greaterthan___addEnd_char(&this->data,*(str)) ; - str = ((str)+(1)); - }; -; - return this; -} - -char* string__toCharArray(string* this) -{ - char* out = mem_scopeop_new_lessthan_char_greaterthan__int(((this->data).size)) ;; - for ( int i = 0;((i)<(((this->data).size))); i++) - (out)[i] = vector_lessthan_char_greaterthan___get_int(&this->data,i) ; -; - return out; -} -/* Done with string */ - -int lesser_lessthan_int_greaterthan__int_int(int a, int b) -{ - if (((a)>(b))) - return b; -; - return a; -}/* Method Definitions for vector */ - -vector_lessthan_char_greaterthan_* vector_lessthan_char_greaterthan___construct(vector_lessthan_char_greaterthan_* this) -{ - this->size = 0; - this->available = 8; - this->data = new_lessthan_char_greaterthan__int(8) ; - return this; -} - -void vector_lessthan_char_greaterthan___destruct(vector_lessthan_char_greaterthan_* this) -{ - delete_lessthan_char_greaterthan__char_P__(this->data) ; -} - -bool vector_lessthan_char_greaterthan___resize_int(vector_lessthan_char_greaterthan_* this, int newSize) -{ - char* newData = new_lessthan_char_greaterthan__int(newSize) ;; - if (!(newData)) - return false; -; - for ( int i = 0;((i)<(lesser_lessthan_int_greaterthan__int_int(this->size, newSize) )); i++) - (newData)[i] = (this->data)[i]; -; - delete_lessthan_char_greaterthan__char_P___int(this->data, 0) ; - this->data = newData; - this->available = newSize; - return true; -} - -char vector_lessthan_char_greaterthan___at_int(vector_lessthan_char_greaterthan_* this, int index) -{ - return vector_lessthan_char_greaterthan___get_int(this,index) ; -} - -char vector_lessthan_char_greaterthan___get_int(vector_lessthan_char_greaterthan_* this, int index) -{ - if (((((index)<(0)))||(((index)>=(this->size))))) - { - return (this->data)[0]; - }; -; - return (this->data)[index]; -} - -char* vector_lessthan_char_greaterthan___getBackingMemory(vector_lessthan_char_greaterthan_* this) -{ - return this->data; -} - -void vector_lessthan_char_greaterthan___set_int_char(vector_lessthan_char_greaterthan_* this, int index, char dataIn) -{ - if (((((index)<(0)))||(((index)>=(this->size))))) - return; -; - (this->data)[index] = dataIn; -} - -void vector_lessthan_char_greaterthan___addEnd_char(vector_lessthan_char_greaterthan_* this, char dataIn) -{ - this->size++; - if (((this->size)>=(this->available))) - vector_lessthan_char_greaterthan___resize_int(this,((this->size)*(2))) ; -; - (this->data)[((this->size)-(1))] = dataIn; -} -/* Done with vector */ diff --git a/tests/test_topLevelVarInit/test_topLevelVarInit.h b/tests/test_topLevelVarInit/test_topLevelVarInit.h deleted file mode 100644 index 78e92ad..0000000 --- a/tests/test_topLevelVarInit/test_topLevelVarInit.h +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include -/*unknown declaration named translation_unit*/ -/*unknown declaration named translation_unit*/ -/*unknown declaration named translation_unit*/ -/*unknown declaration named translation_unit*/ -/*unknown declaration named translation_unit*/ -/*unknown declaration named translation_unit*/ -/** - * Plain Typedefs - */ - -/*typedef string */ -typedef struct __struct_dummy_string__ string; -/*typedef vector */ -/* non instantiated template vector *//*typedef vector */ -typedef struct __struct_dummy_vector_lessthan_char_greaterthan___ vector_lessthan_char_greaterthan_; -/** - * Import Includes - */ - -/** - * Extern Variable Declarations - */ - -extern int a; /*extern identifier*/ -/** - * Class Structs - */ - -struct __struct_dummy_vector_lessthan_char_greaterthan___ { - char* data; - int size; - int available; -}; -struct __struct_dummy_string__ { - vector_lessthan_char_greaterthan_ data; -}; -/** - * Function Prototypes - */ - - -int main(); /*func*/ - -void print_char_P__(char* toPrint); /*func*/ - -void print_string(string toPrint); /*func*/ - -void print_int(int toPrint); /*func*/ - -void print_float(float toPrint); /*func*/ - -void print_double(double toPrint); /*func*/ - -void println(); /*func*/ - -void println_char_P__(char* toPrint); /*func*/ - -void println_string(string toPrint); /*func*/ - -void println_int(int toPrint); /*func*/ - -void println_float(float toPrint); /*func*/ -/* template function delete NoValue */ -/* template function delete NoValue */ -/* template function delete NoValue */ -/* template function delete NoValue */ - -void delete_lessthan_char_greaterthan__char_P__(char* toDelete); /*func*/ - -void delete_lessthan_char_greaterthan__char_P___int(char* toDelete, int itemCount); /*func*/ -/* template function free NoValue */ -/* template function malloc NoValue */ - -char* malloc_lessthan_char_greaterthan__int(int size); /*func*/ - -char* mem_scopeop_new_lessthan_char_greaterthan__int(int count); /*func*/ -/* template function new NoValue */ -/* template function new NoValue */ - -char* new_lessthan_char_greaterthan__int(int count); /*func*/ -/* template function sizeof NoValue */ - -int sizeof_lessthan_char_greaterthan_(); /*func*/ -/* Method Prototypes for string */ - -string* string__construct(string* this); - -string* string__construct_char_P__(string* this, char* str); - -char* string__toCharArray(string* this); -/* Done with string */ -/* template function greater NoValue */ -/* template function lesser NoValue */ - -int lesser_lessthan_int_greaterthan__int_int(int a, int b); /*func*/ -/* Method Prototypes for vector */ - -vector_lessthan_char_greaterthan_* vector_lessthan_char_greaterthan___construct(vector_lessthan_char_greaterthan_* this); - -void vector_lessthan_char_greaterthan___destruct(vector_lessthan_char_greaterthan_* this); - -bool vector_lessthan_char_greaterthan___resize_int(vector_lessthan_char_greaterthan_* this, int newSize); - -char vector_lessthan_char_greaterthan___at_int(vector_lessthan_char_greaterthan_* this, int index); - -char vector_lessthan_char_greaterthan___get_int(vector_lessthan_char_greaterthan_* this, int index); - -char* vector_lessthan_char_greaterthan___getBackingMemory(vector_lessthan_char_greaterthan_* this); - -void vector_lessthan_char_greaterthan___set_int_char(vector_lessthan_char_greaterthan_* this, int index, char dataIn); - -void vector_lessthan_char_greaterthan___addEnd_char(vector_lessthan_char_greaterthan_* this, char dataIn); -/* Done with vector */ diff --git a/tests/test_topLevelVarInit/test_topLevelVarInit.results b/tests/test_topLevelVarInit/test_topLevelVarInit.results deleted file mode 100644 index 573541a..0000000 --- a/tests/test_topLevelVarInit/test_topLevelVarInit.results +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/tests/test_topLevelVarInit/test_topLevelVarInit.sh b/tests/test_topLevelVarInit/test_topLevelVarInit.sh deleted file mode 100755 index 30705f8..0000000 --- a/tests/test_topLevelVarInit/test_topLevelVarInit.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -cc -std=c99 ./test_topLevelVarInit.c -o ./test_topLevelVarInit \ No newline at end of file