Added in the cast function and fixed type promotion (so it would work with pointer arithmatic)

This commit is contained in:
Nathan Braswell
2015-06-19 17:13:06 -04:00
parent 616b955bf9
commit 457998e0ff
7 changed files with 50 additions and 4 deletions

View File

@@ -893,7 +893,19 @@ NodeTree<ASTData>* ASTTransformation::doFunction(NodeTree<ASTData>* scope, std::
// because of the . operator, etc
if (newNode->getDataRef()->valueType == NULL) {
std::cout << "The value type from doFunction was null! (for " << lookup << ")" << std::endl;
newNode->getDataRef()->valueType = oldTypes[oldTypes.size()-1].clone();
Type* newType = nullptr;
if (lookup == "->")
newType = oldTypes.back().clone();
else if (oldTypes.front().getIndirection())
newType = oldTypes.front().clone();
else if (oldTypes.back().getIndirection())
newType = oldTypes.back().clone();
else
newType = (oldTypes.front().baseType > oldTypes.back().baseType) ? oldTypes.front().clone() : oldTypes.back().clone();
//if (!newType)
//newType = oldTypes.back().clone();
newNode->getDataRef()->valueType = newType;
std::cout << "function call to " << lookup << " - " << newNode->getName() << " is now " << newNode->getDataRef()->valueType << std::endl;
}
return newNode;

View File

@@ -542,7 +542,7 @@ CCodeTriple CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
// std::cout << name << " == " << children[0]->getData().symbol.getName() << std::endl;
std::string name = children[0]->getDataRef()->symbol.getName();
ASTType funcType = children[0]->getDataRef()->type;
std::cout << "Doing function: " << name << std::endl;
//std::cout << "Doing function: " << name << std::endl;
//Test for special functions only if what we're testing is, indeed, the definition, not a function call that returns a callable function pointer
if (funcType == function) {
if (name == "++" || name == "--")

View File

@@ -137,6 +137,8 @@ std::string Type::toString(bool showTraits) {
}
for (int i = 0; i < indirection; i++)
typeString += "*";
if (indirection < 0)
typeString += "negative indirection: " + intToString(indirection);
if (traits.size() && showTraits) {
typeString += "[ ";
for (auto i : traits)