Tons of stuff. Regex still a work in progress, along with related template member function scoping bugs
This commit is contained in:
@@ -267,7 +267,7 @@ void ASTTransformation::thirdPass(NodeTree<ASTData>* ast, NodeTree<Symbol>* pars
|
||||
//Note that this pass can instantiate class AND function templates
|
||||
for (NodeTree<Symbol>* i : children) {
|
||||
if (i->getDataRef()->getName() == "type_def") {
|
||||
if (i->getChildren()[1]->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 up the class templates
|
||||
std::vector<NodeTree<Symbol>*> typedefChildren = i->getChildren();
|
||||
std::string name = concatSymbolTree(typedefChildren[0]);
|
||||
@@ -751,6 +751,7 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
|
||||
std::cerr << "///////////////////////////////////////////////////////////////////////////////" << std::endl;
|
||||
std::cerr << "Ambigious program when parsed by this grammer! This is a bug, please report it." << std::endl;
|
||||
std::cerr << "///////////////////////////////////////////////////////////////////////////////" << std::endl;
|
||||
std::cerr << concatSymbolTree(from) << std::endl;
|
||||
throw "Ambigious parse!";
|
||||
} else {
|
||||
// Should get rid of this eventually. Right now it handles cases like sign, alpha, a comma, etc
|
||||
@@ -961,6 +962,8 @@ NodeTree<ASTData>* ASTTransformation::templateClassLookup(NodeTree<ASTData>* sco
|
||||
auto possibleMatches = scopeLookup(scope, lookup);
|
||||
std::cout << "Template Class instantiation has " << possibleMatches.size() << " possible matches." << std::endl;
|
||||
for (auto i : possibleMatches) {
|
||||
if (i->getDataRef()->type != type_def)
|
||||
continue;
|
||||
NodeTree<Symbol>* templateSyntaxTree = i->getDataRef()->valueType->templateDefinition;
|
||||
|
||||
auto nameTraitsPairs = makeTemplateNameTraitPairs(templateSyntaxTree->getChildren()[1]);
|
||||
@@ -1108,6 +1111,8 @@ NodeTree<ASTData>* ASTTransformation::templateFunctionLookup(NodeTree<ASTData>*
|
||||
std::cout << "Template Function instantiation has " << possibleMatches.size() << " possible matches." << std::endl;
|
||||
int index = 1;
|
||||
for (auto i : possibleMatches) {
|
||||
if (i->getDataRef()->type != function)
|
||||
continue;
|
||||
std::cout << "Possibility " << index++ << std::endl;
|
||||
NodeTree<Symbol>* templateSyntaxTree = i->getDataRef()->valueType->templateDefinition;
|
||||
if (!templateSyntaxTree) {
|
||||
@@ -1239,6 +1244,10 @@ std::vector<NodeTree<ASTData>*> ASTTransformation::scopeLookup(NodeTree<ASTData>
|
||||
|
||||
std::vector<NodeTree<ASTData>*> ASTTransformation::scopeLookup(NodeTree<ASTData>* scope, std::string lookup, bool includeModules, std::set<NodeTree<ASTData>*> visited) {
|
||||
std::cout << "Scp]|[e looking up " << lookup << std::endl;
|
||||
std::cout << "current: " << scope->getDataRef()->toString() << std::endl;
|
||||
for (auto i : scope->getDataRef()->scope)
|
||||
std::cout << "\t" << i.first << std::endl;
|
||||
//std::cout << i.first << " : " << i.second->toString() << std::endl;
|
||||
// Don't visit this node again when looking for the smae lookup. Note that we don't prevent coming back for the scope operator, as that should be able to come back.
|
||||
if (visited.find(scope) != visited.end())
|
||||
return std::vector<NodeTree<ASTData>*>();
|
||||
@@ -1510,7 +1519,7 @@ NodeTree<ASTData>* ASTTransformation::findOrInstantiateFunctionTemplate(std::vec
|
||||
auto unsliced = children[1]->getChildren();
|
||||
std::vector<NodeTree<Symbol>*> templateParamInstantiationNodes = slice(unsliced, 1 , -2, 2);//skip <, >, and commas
|
||||
for (int i = 0; i < templateParamInstantiationNodes.size(); i++) {
|
||||
Type* instType = typeFromTypeNode(templateParamInstantiationNodes[i],scope, templateTypeReplacements);
|
||||
Type* instType = typeFromTypeNode(templateParamInstantiationNodes[i], scope, templateTypeReplacements);
|
||||
instTypeString += (instTypeString == "" ? instType->toString() : "," + instType->toString());
|
||||
templateActualTypes.push_back(instType);
|
||||
}
|
||||
@@ -1559,7 +1568,8 @@ NodeTree<ASTData>* ASTTransformation::findOrInstantiateFunctionTemplate(std::vec
|
||||
std::cout << ", " << i << " : " << templateChildren[i]->getDataRef()->getName();
|
||||
std::cout << std::endl;
|
||||
|
||||
instantiatedFunction = new NodeTree<ASTData>("function", ASTData(function, Symbol(scopelessFullyInstantiatedName, true), typeFromTypeNode(templateChildren[templateChildren.size()-2], scope, newTemplateTypeReplacement)));
|
||||
// return type should be looked up in template's scope
|
||||
instantiatedFunction = new NodeTree<ASTData>("function", ASTData(function, Symbol(scopelessFullyInstantiatedName, true), typeFromTypeNode(templateChildren[templateChildren.size()-2], templateDefinition, newTemplateTypeReplacement)));
|
||||
addToScope("~enclosing_scope", templateDefinition->getDataRef()->scope["~enclosing_scope"][0], instantiatedFunction);
|
||||
addToScope(scopelessFullyInstantiatedName, instantiatedFunction, templateDefinition->getDataRef()->scope["~enclosing_scope"][0]);
|
||||
templateDefinition->getDataRef()->scope["~enclosing_scope"][0]->addChild(instantiatedFunction); // Add this object the the highest scope's
|
||||
|
||||
+6
-1
@@ -426,8 +426,13 @@ bool RNGLRParser::fullyReducesToNull(ParseRule* rule) {
|
||||
}
|
||||
|
||||
bool RNGLRParser::reducesToNull(ParseRule* rule) {
|
||||
auto itr = reduceToNullMap.find(rule);
|
||||
if (itr != reduceToNullMap.end())
|
||||
return itr->second;
|
||||
std::vector<Symbol> avoidList;
|
||||
return reducesToNull(rule, avoidList);
|
||||
auto val = reducesToNull(rule, avoidList);
|
||||
reduceToNullMap[rule] = val;
|
||||
return val;
|
||||
}
|
||||
|
||||
bool RNGLRParser::reducesToNull(ParseRule* rule, std::vector<Symbol> avoidList) {
|
||||
|
||||
+3
-8
@@ -148,15 +148,10 @@ int RegEx::longMatch(std::string stringToMatch) {
|
||||
//Go through every current state. Check to see if it is goal, if so update last goal.
|
||||
//Also, add each state's advance to nextStates
|
||||
for (std::vector<RegExState*>::size_type j = 0; j < currentStates.size(); j++) {
|
||||
if (currentStates[j]->isGoal()) {
|
||||
if (currentStates[j]->isGoal())
|
||||
lastMatch = i;
|
||||
//std::cout << "Hit goal at " << i << " character: " << stringToMatch[i-1] << std::endl;
|
||||
} else {
|
||||
//std::cout << "currentState " << j << ", " << currentStates[j]->toString() << " is not goal" <<std::endl;
|
||||
}
|
||||
std::vector<RegExState*>* addStates = currentStates[j]->advance(stringToMatch.at(i));
|
||||
nextStates.insert(nextStates.end(), addStates->begin(), addStates->end());
|
||||
delete addStates;
|
||||
std::vector<RegExState*> addStates = currentStates[j]->advance(stringToMatch.at(i));
|
||||
nextStates.insert(nextStates.end(), addStates.begin(), addStates.end());
|
||||
}
|
||||
//Now, clear our current states and add eaczh one of our addStates if it is not already in current states
|
||||
|
||||
|
||||
+3
-3
@@ -20,11 +20,11 @@ bool RegExState::characterIs(char inCharacter) {
|
||||
return character == inCharacter;
|
||||
}
|
||||
|
||||
std::vector<RegExState*>* RegExState::advance(char advanceCharacter) {
|
||||
std::vector<RegExState*>* advanceStates = new std::vector<RegExState*>();
|
||||
std::vector<RegExState*> RegExState::advance(char advanceCharacter) {
|
||||
std::vector<RegExState*> advanceStates;
|
||||
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++) {
|
||||
if (nextStates[i] != NULL && nextStates[i]->characterIs(advanceCharacter))
|
||||
advanceStates->push_back(nextStates[i]);
|
||||
advanceStates.push_back(nextStates[i]);
|
||||
}
|
||||
return advanceStates;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user