added Bool Not to expression

This commit is contained in:
Felix Müller 2024-06-03 13:54:03 +02:00
parent 523a9f19cc
commit 8a2eeb63b8
1 changed files with 48 additions and 1 deletions

View File

@ -450,6 +450,48 @@ int createBoolOperation(Expression *ParentExpression, AST_NODE_PTR currentNode){
return 0; return 0;
} }
int createBoolNotOperation(Expression *ParentExpression, AST_NODE_PTR currentNode){
//fill kind and Nodeptr
ParentExpression->impl.operation.kind = Boolean;
ParentExpression->impl.operation.nodePtr = currentNode;
//fill Operand
Expression* expression = createExpression(currentNode->children[0]);
if(NULL == expression){
return 1;
}
g_array_append_val(ParentExpression->impl.operation.operands , expression);
ParentExpression->impl.operation.impl.boolean = BooleanNot;
Type* Operand = ((Expression**)ParentExpression->impl.operation.operands)[0]->result;
Type* result = malloc(sizeof(Type));
result->nodePtr = currentNode;
if (Operand->kind == TypeKindBox || Operand->kind == TypeKindReference){
return 1;
}
if(Operand->kind == TypeKindPrimitive){
if(Operand->impl.primitive == Float){
return 1;
}
result->kind = Operand->kind;
result->impl = Operand->impl;
}else if(Operand->kind == TypeKindComposite){
if(Operand->impl.composite.primitive == Float){
return 1;
}
result->kind = Operand->kind;
result->impl = Operand->impl;
}
ParentExpression->result = result;
return 0;
}
Expression *createExpression(AST_NODE_PTR currentNode){ Expression *createExpression(AST_NODE_PTR currentNode){
Expression *expression = malloc(sizeof(Expression)); Expression *expression = malloc(sizeof(Expression));
expression->nodePtr = currentNode; expression->nodePtr = currentNode;
@ -509,14 +551,19 @@ Expression *createExpression(AST_NODE_PTR currentNode){
case AST_BoolOr: case AST_BoolOr:
case AST_BoolXor: case AST_BoolXor:
expression->kind = ExpressionKindOperation; expression->kind = ExpressionKindOperation;
if(createRelationalOperation(expression,currentNode)){ if(createBoolOperation(expression,currentNode)){
return NULL; return NULL;
} }
case AST_BoolNot: case AST_BoolNot:
expression->kind= ExpressionKindOperation;
if(createBoolNotOperation(expression, currentNode)){
return NULL;
}
case AST_BitAnd: case AST_BitAnd:
case AST_BitOr: case AST_BitOr:
case AST_BitXor: case AST_BitXor:
case AST_BitNot: case AST_BitNot:
case AST_IdentList: case AST_IdentList: