Fixed some mem things, found an odd parsing bug where a // comment before a function definition at top level does not parse. Deferring for now.

This commit is contained in:
Nathan Braswell
2014-07-20 20:42:26 -07:00
parent 93a170408f
commit eae538907d
3 changed files with 23 additions and 11 deletions

View File

@@ -7,10 +7,6 @@ type = type WS "\*" | "void" | "int" | "float" | "double" | "char" | identifier
template_inst = "<" WS type_list WS ">" ;
type_list = type_list WS "," WS type | type ;
#What does that even mean?
#some
#
#
template_dec = "template" WS "<" WS template_param_list WS ">" ;
template_param_list = template_param_list WS "," WS template_param | template_param ;
template_param = identifier WS traits | identifier ;

View File

@@ -331,13 +331,13 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
if (types.size()) {
newNode = functionLookup(scope, lookupName, types);
if (newNode == NULL) {
std::cout << "scope lookup error! Could not find " << lookupName << " in identifier " << std::endl;
std::cout << "scope lookup error! Could not find " << lookupName << " in identifier (functionLookup)" << std::endl;
throw "LOOKUP ERROR: " + lookupName;
}
} else {
auto possibleMatches = scopeLookup(scope, lookupName);
if (!possibleMatches.size()) {
std::cout << "scope lookup error! Could not find " << lookupName << " in identifier " << std::endl;
std::cout << "scope lookup error! Could not find " << lookupName << " in identifier (scopeLookup)" << std::endl;
throw "LOOKUP ERROR: " + lookupName;
}
newNode = possibleMatches[0];
@@ -883,6 +883,10 @@ NodeTree<ASTData>* ASTTransformation::templateFunctionLookup(NodeTree<ASTData>*
for (auto i : possibleMatches) {
std::cout << "Possibility " << index++ << std::endl;
NodeTree<Symbol>* templateSyntaxTree = i->getDataRef()->valueType->templateDefinition;
if (!templateSyntaxTree) {
std::cout << "Not a template, skipping" << std::endl;
continue;
}
auto nameTraitsPairs = makeTemplateNameTraitPairs(templateSyntaxTree->getChildren()[0]);
//Check if sizes match between the placeholder and actual template types
@@ -975,6 +979,12 @@ std::map<std::string, Type*> ASTTransformation::makeTemplateFunctionTypeMap(Node
}
std::vector<NodeTree<ASTData>*> ASTTransformation::scopeLookup(NodeTree<ASTData>* scope, std::string lookup) {
//We first check to see if it's one of the special reserved identifiers (only this, for now) and return early if it is.
auto LLElementIterator = languageLevelReservedWords.find(lookup);
if (LLElementIterator != languageLevelReservedWords.end()) {
std::cout << "found it at language level as reserved word." << std::endl;
return LLElementIterator->second;
}
std::vector<NodeTree<ASTData>*> matches;
std::map<std::string, std::vector<NodeTree<ASTData>*>> scopeMap = scope->getDataRef()->scope;
auto possibleMatches = scopeMap.find(lookup);

View File

@@ -22,6 +22,7 @@ void free(char* memPtr) {
}
}
/* we have a template version so we don't have to cast */
template <T> void free(T* memPtr) {
__if_comp__ __C__ {
__simple_passthrough__ """
@@ -41,7 +42,6 @@ template <T> int sizeof() {
return result;
}
template <T> T* new(int count) {
return malloc( sizeof<T>() * count );
}
@@ -50,18 +50,24 @@ template <T> T* new() {
return new<T>(1);
}
template <T> void delete(T* toDelete, int itemDestructCount) {
/* We specilize on the trait Destructable to decide on whether or not the destructor should be called */
template <T> void delete(T* toDelete, int itemCount) {
delete<T>(toDelete);
}
template <T(Destructable)> void delete(T* toDelete, int itemCount) {
for (int i = 0; i < itemDestructCount; i++;)
toDelete[i].destruct();
delete<T>(toDelete);
}
/* We specilize on the trait Destructable to decide on whether or not the destructor should be called */
template <T> void delete(T* toDelete) {
delete<T>(toDelete, true);
free(toDelete);
}
template <T> void delete(T* toDelete, bool destruct) {
template <T(Destructable)> void delete(T* toDelete) {
if (destruct)
toDelete->destruct();
free<T>(toDelete);
free(toDelete);
}