From af2a28ae4fa1e0a2ec686117198d9cbc9afd6a5f Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Tue, 17 Mar 2015 21:06:31 -0400 Subject: [PATCH] Fix chained indirect templates: template |T| fun(|vector| a) { return a.at(0); }, etc --- src/ASTTransformation.cpp | 21 +- ..._chainedIndirectTemplates.expected_results | 1 + tests/test_chainedIndirectTemplates.krak | 15 ++ .../test_topLevelVarInit/test_topLevelVarInit | Bin 11000 -> 0 bytes .../test_topLevelVarInit.c | 225 ------------------ .../test_topLevelVarInit.h | 116 --------- .../test_topLevelVarInit.results | 1 - .../test_topLevelVarInit.sh | 2 - 8 files changed, 31 insertions(+), 350 deletions(-) create mode 100644 tests/test_chainedIndirectTemplates.expected_results create mode 100644 tests/test_chainedIndirectTemplates.krak delete mode 100755 tests/test_topLevelVarInit/test_topLevelVarInit delete mode 100644 tests/test_topLevelVarInit/test_topLevelVarInit.c delete mode 100644 tests/test_topLevelVarInit/test_topLevelVarInit.h delete mode 100644 tests/test_topLevelVarInit/test_topLevelVarInit.results delete mode 100755 tests/test_topLevelVarInit/test_topLevelVarInit.sh 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 4ed2f7ab08e1408f85d355aab87e4345dc74a411..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11000 zcmb<-^>JfjWMqH=CI&kO5N`pC16T+`GB8vqgSlYBfx&`-gTaA8jzOA%je&uIm4Sf) zrp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cLlrv{(_BrNF_W-rXdUr;k);Rox7I6(EIt4B)?44?rmQ2qg}kAs;BqG9?$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