Author: mesyeti <mesyeti@mesyeti.uk>
make . work on pointers
basic/source/frontend/c89.c | 14 ++++++++++++-- basic/source/semanticAnalysis.c | 4 ++++
diff --git a/basic/source/frontend/c89.c b/basic/source/frontend/c89.c index 465486d00c13b8885782044dc74308051d9451f3..5294a3098d097ffd76a25ef0c420532b3f766c32 100644 --- a/basic/source/frontend/c89.c +++ b/basic/source/frontend/c89.c @@ -120,8 +120,18 @@ case TOKEN_EQUAL: fprintf(out, "=="); break; case TOKEN_LESS: fprintf(out, "<"); break; case TOKEN_GREATER: fprintf(out, ">"); break; case TOKEN_ASSIGN: fprintf(out, "="); break; - case TOKEN_DOT: fprintf(out, "."); break; - default: assert(0); + case TOKEN_DOT: { + UsedType type = SemanticAnalysis_NodeAsUsedType(node->bin.left); + + if (type.ptr) { + fprintf(out, "->"); + } + else { + fprintf(out, "."); + } + break; + } + default: assert(0); } CompileExprNode(node->bin.right); diff --git a/basic/source/semanticAnalysis.c b/basic/source/semanticAnalysis.c index 8e98536f94be2c390d139f5f9bcf862b1f8f13d6..f3c6326aed9182df120d911c44d66cb35c876fce 100644 --- a/basic/source/semanticAnalysis.c +++ b/basic/source/semanticAnalysis.c @@ -104,6 +104,10 @@ return GET_PRIM("unit", 0); } static UsedType EvalDot(Node* node, UsedType left) { + if (left.ptr > 1) { + PrintError(node->i.err, "Dot operator only works on `Struct*` or `Struct` value"); + } + Type* leftType = State_GetTypeFromUsed(left); if (node->bin.right->i.type != NODE_IDENTIFIER) {