Finished simple array notation, fixed address of operator.

This commit is contained in:
Nathan Braswell
2014-05-06 13:54:53 -04:00
parent 209985310e
commit c4dea26cca
2 changed files with 22 additions and 15 deletions

View File

@@ -23,6 +23,7 @@ ASTTransformation::ASTTransformation(Importer *importerIn) {
languageLevelScope["-="].push_back(new NodeTree<ASTData>("function", ASTData(function, Symbol("-=", true), NULL)));
languageLevelScope["."].push_back(new NodeTree<ASTData>("function", ASTData(function, Symbol(".", true), NULL)));
languageLevelScope["->"].push_back(new NodeTree<ASTData>("function", ASTData(function, Symbol("->", true), NULL)));
languageLevelScope["[]"].push_back(new NodeTree<ASTData>("function", ASTData(function, Symbol("[]", true), NULL)));
}
ASTTransformation::~ASTTransformation() {
@@ -181,8 +182,9 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
} else if (name == "factor") { //Do factor here, as it has all the weird unary operators
//If this is an actual part of an expression, not just a premoted child
//NO SUPPORT FOR CASTING YET
std::string funcName;
if (children.size() == 2) {
std::string funcName = concatSymbolTree(children[0]);
funcName = concatSymbolTree(children[0]);
NodeTree<ASTData>* param;
if (funcName == "*" || funcName == "&" || funcName == "++" || funcName == "--" || funcName == "-" || funcName == "!" || funcName == "~")
param = transform(children[1], scope, types);
@@ -196,16 +198,19 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
std::cout << "scope lookup error! Could not find " << funcName << " in factor " << std::endl;
throw "LOOKUP ERROR: " + funcName;
}
newNode = function;
// newNode = new NodeTree<ASTData>(funcName, ASTData(function_call, Symbol(funcName, true)));
// newNode->addChild(function);
// newNode->addChild(param);
// if (function->getDataRef()->valueType)
// newNode->getDataRef()->valueType = function->getDataRef()->valueType;
// else
// newNode->getDataRef()->valueType = param->getDataRef()->valueType;
return newNode;
return function;
} else if (children.size() >= 4) { //Array brackets []
funcName = "[]";
std::vector<NodeTree<ASTData>*> transformedChildren;
transformedChildren.push_back(transform(children[0], scope, types));
transformedChildren.push_back(transform(children[2], scope, types));
NodeTree<ASTData>* function = doFunction(scope, funcName, transformedChildren);
if (function == NULL) {
std::cout << "scope lookup error! Could not find " << funcName << " in factor " << std::endl;
throw "LOOKUP ERROR: " + funcName;
}
return function;
} else {
return transform(children[0], scope, types); //Just a promoted child, so do it instead
}
@@ -411,10 +416,10 @@ NodeTree<ASTData>* ASTTransformation::doFunction(NodeTree<ASTData>* scope, std::
std::cout<<std::endl;
std::vector<Type> oldTypes = mapNodesToTypes(nodes);
if (lookup == "*" || lookup == "&") {
if (lookup == "*" || lookup == "&" || lookup == "[]") {
Type* newType = oldTypes[0].clone();
lookup == "*" ? newType->indirection-- : newType->indirection++;
newNode->getDataRef()->valueType = newType, std::cout << "Operator " + lookup << std::endl;
lookup == "*" || lookup == "[]" ? newType->indirection-- : newType->indirection++;
newNode->getDataRef()->valueType = newType, std::cout << "Operator " + lookup << " is altering indirection "<< std::endl;
} else {
newNode->getDataRef()->valueType = function->getDataRef()->valueType, std::cout << "Some other ||" << lookup << "||" << std::endl;
}

View File

@@ -198,8 +198,10 @@ std::string CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
if (funcType == function) {
if (name == "++" || name == "--")
return generate(children[1], enclosingObject) + name;
if (name == "*" && children.size() == 2) //Is dereference, not multiplication
return "*(" + generate(children[1], enclosingObject) + ")";
if (name == "*" || name == "&" && children.size() == 2) //Is dereference, not multiplication, or address-of
return name + "(" + generate(children[1], enclosingObject) + ")";
if (name == "[]")
return "(" + generate(children[1], enclosingObject) + ")[" +generate(children[2],enclosingObject) + "]";
if (name == "+" || name == "-" || name == "*" || name == "/" || name == "==" || name == ">=" || name == "<=" || name == "!="
|| name == "<" || name == ">" || name == "%" || name == "+=" || name == "-=" || name == "*=" || name == "/=" || name == "||"
|| name == "&&" || name == "!" )