Fixed type propagation for dereference and address-of, needs work for all the other operators also. Starting ground work for array notation
This commit is contained in:
@@ -27,6 +27,7 @@ class Type {
|
|||||||
~Type();
|
~Type();
|
||||||
bool const operator==(const Type &other)const;
|
bool const operator==(const Type &other)const;
|
||||||
bool const operator!=(const Type &other)const;
|
bool const operator!=(const Type &other)const;
|
||||||
|
Type* clone();
|
||||||
std::string toString();
|
std::string toString();
|
||||||
ValueType baseType;
|
ValueType baseType;
|
||||||
NodeTree<ASTData>* typeDefinition;
|
NodeTree<ASTData>* typeDefinition;
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ comparator = "==" | "<=" | ">=" | "!=" | "<" | ">" ;
|
|||||||
expression = expression WS "<<" WS term | expression WS ">>" WS shiftand | shiftand ;
|
expression = expression WS "<<" WS term | expression WS ">>" WS shiftand | shiftand ;
|
||||||
shiftand = shiftand WS "-" WS term | shiftand WS "\+" WS term | term ;
|
shiftand = shiftand WS "-" WS term | shiftand WS "\+" WS term | term ;
|
||||||
term = term WS forward_slash WS factor | term WS "\*" WS factor | term WS "%" WS factor | factor ;
|
term = term WS forward_slash WS factor | term WS "\*" WS factor | term WS "%" WS factor | factor ;
|
||||||
factor = "\+\+" WS unarad | unarad WS "\+\+" | "--" WS unarad | unarad WS "--" | "\+" WS unarad | "-" WS unarad | "!" WS unarad | "~" WS unarad | "\(" WS type WS "\)" WS unarad | "\*" WS unarad | "&" WS unarad | unarad ;
|
factor = "\+\+" WS unarad | unarad WS "\+\+" | "--" WS unarad | unarad WS "--" | "\+" WS unarad | "-" WS unarad | "!" WS unarad | "~" WS unarad | "\(" WS type WS "\)" WS unarad | "\*" WS unarad | "&" WS unarad | unarad WS "[" WS expression WS "]" | unarad ;
|
||||||
unarad = number | identifier | function_call | bool | string | character | "\(" WS boolean_expression WS "\)" | access_operation ;
|
unarad = number | identifier | function_call | bool | string | character | "\(" WS boolean_expression WS "\)" | access_operation ;
|
||||||
number = integer | float | double ;
|
number = integer | float | double ;
|
||||||
access_operation = unarad "." identifier | unarad "->" identifier ;
|
access_operation = unarad "." identifier | unarad "->" identifier ;
|
||||||
|
|||||||
@@ -346,8 +346,10 @@ std::vector<NodeTree<ASTData>*> ASTTransformation::transformChildren(std::vector
|
|||||||
|
|
||||||
std::vector<Type> ASTTransformation::mapNodesToTypes(std::vector<NodeTree<ASTData>*> nodes) {
|
std::vector<Type> ASTTransformation::mapNodesToTypes(std::vector<NodeTree<ASTData>*> nodes) {
|
||||||
std::vector<Type> types;
|
std::vector<Type> types;
|
||||||
for (auto i : nodes)
|
for (auto i : nodes) {
|
||||||
|
std::cout << i->getDataRef()->toString() << std::endl;
|
||||||
types.push_back(*(i->getDataRef()->valueType));
|
types.push_back(*(i->getDataRef()->valueType));
|
||||||
|
}
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +403,21 @@ NodeTree<ASTData>* ASTTransformation::doFunction(NodeTree<ASTData>* scope, std::
|
|||||||
NodeTree<ASTData>* function = scopeLookup(scope, lookup, mapNodesToTypes(nodes));
|
NodeTree<ASTData>* function = scopeLookup(scope, lookup, mapNodesToTypes(nodes));
|
||||||
newNode->addChild(function);
|
newNode->addChild(function);
|
||||||
newNode->addChildren(nodes);
|
newNode->addChildren(nodes);
|
||||||
newNode->getDataRef()->valueType = function->getDataRef()->valueType;
|
|
||||||
|
//Specially handle dereference and address of to assign the correct type
|
||||||
|
//We need some significant other type corrections here, maybe to the point of being their own function. (int + float, etc.)
|
||||||
|
for (auto i : nodes)
|
||||||
|
std::cout << i->getDataRef()->toString() << " ";
|
||||||
|
std::cout<<std::endl;
|
||||||
|
|
||||||
|
std::vector<Type> oldTypes = mapNodesToTypes(nodes);
|
||||||
|
if (lookup == "*" || lookup == "&") {
|
||||||
|
Type* newType = oldTypes[0].clone();
|
||||||
|
lookup == "*" ? newType->indirection-- : newType->indirection++;
|
||||||
|
newNode->getDataRef()->valueType = newType, std::cout << "Operator " + lookup << std::endl;
|
||||||
|
} else {
|
||||||
|
newNode->getDataRef()->valueType = function->getDataRef()->valueType, std::cout << "Some other ||" << lookup << "||" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
@@ -436,7 +452,7 @@ NodeTree<ASTData>* ASTTransformation::scopeLookup(NodeTree<ASTData>* scope, std:
|
|||||||
for (int j = 0; j < types.size(); j++) {
|
for (int j = 0; j < types.size(); j++) {
|
||||||
if (types[j] != *(children[j]->getDataRef()->valueType)) {
|
if (types[j] != *(children[j]->getDataRef()->valueType)) {
|
||||||
typesMatch = false;
|
typesMatch = false;
|
||||||
std::cout << "Types do not match between two " << lookup << std::endl;
|
std::cout << "Types do not match between two " << lookup << " " << types[j].toString() << " vs " << children[j]->getDataRef()->valueType->toString() << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,3 +83,7 @@ std::string Type::toString() {
|
|||||||
typeString += "*";
|
typeString += "*";
|
||||||
return typeString;
|
return typeString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Type* Type::clone() {
|
||||||
|
return new Type(baseType, typeDefinition, indirection);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user