Saving work pre-references

This commit is contained in:
Nathan Braswell
2015-07-13 12:16:30 -04:00
parent 07e54f67fb
commit 8c490908d4
14 changed files with 221 additions and 32 deletions

View File

@@ -389,7 +389,12 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
} else {
auto possibleMatches = scopeLookup(scope, lookupName);
if (!possibleMatches.size()) {
std::cerr << std::endl;
std::cerr << "scope lookup error! Could not find " << lookupName << " in identifier (scopeLookup)" << std::endl;
std::cerr << "lookup failedin file " << getUpperTranslationUnit(scope)->getDataRef()->symbol.getName() << std::endl;
std::cerr << "note that this might not be the file where the error is" << std::endl;
std::cerr << "obj.non_existant_member would fail in the file that defines obj's type, for instance" << std::endl;
std::cerr << std::endl;
throw "LOOKUP ERROR: " + lookupName;
}
// can't cull out functiokns b/c we might want them as values

View File

@@ -636,9 +636,23 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
if (name == "[]")
return "(" + generate(children[1], enclosingObject, true, enclosingFunction) + ")[" + generate(children[2],enclosingObject, true, enclosingFunction) + "]";
if (name == "+" || name == "-" || name == "*" || name == "/" || name == "==" || name == ">=" || name == "<=" || name == "!="
|| name == "<" || name == ">" || name == "%" || name == "=" || name == "+=" || name == "-=" || name == "*=" || name == "/=" || name == "||"
|| name == "&&") {
|| name == "<" || name == ">" || name == "%" || name == "=" || name == "+=" || name == "-=" || name == "*=" || name == "/=") {
return "((" + generate(children[1], enclosingObject, true, enclosingFunction) + ")" + name + "(" + generate(children[2], enclosingObject, true, enclosingFunction) + "))";
} else if (name == "&&" || name == "||") {
// b/c short circuiting, these have to be done seperately
CCodeTriple lhs = generate(children[1], enclosingObject, true, enclosingFunction);
CCodeTriple rhs = generate(children[2], enclosingObject, true, enclosingFunction);
output.preValue = lhs.preValue;
std::string shortcircuit_result = "shortcircuit_result" + getID();
output.preValue += "bool " + shortcircuit_result + " = " + lhs.value + ";\n";
output.preValue += lhs.postValue;
output.preValue += "if (" + std::string(name == "||" ? "!":"") + shortcircuit_result + ") { \n";
output.preValue += rhs.preValue;
output.preValue += shortcircuit_result + " = " + rhs.value + ";\n";
output.preValue += rhs.postValue;
output.preValue += "}\n";
output.value = shortcircuit_result;
return output;
} else if (name == "." || name == "->") {
if (children.size() == 1)
return "/*dot operation with one child*/" + generate(children[0], enclosingObject, true, enclosingFunction).oneString() + "/*end one child*/";