From ab70e5ea3a1116cf50b72969eb1abd854a13febc Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Wed, 11 Aug 2021 18:19:28 +0200 Subject: [PATCH] WIP: Working on accessor dependeny generation for `new A().thing.thing` --- source/tlang/compiler/symbols/expressions.d | 5 + source/tlang/compiler/typecheck/dependency.d | 122 +++++++++++++++++-- 2 files changed, 117 insertions(+), 10 deletions(-) diff --git a/source/tlang/compiler/symbols/expressions.d b/source/tlang/compiler/symbols/expressions.d index c7dca03d..ffb7d57a 100644 --- a/source/tlang/compiler/symbols/expressions.d +++ b/source/tlang/compiler/symbols/expressions.d @@ -22,6 +22,11 @@ public class OperatorExpression : Expression { this.operator = operator; } + + public SymbolType getOperator() + { + return operator; + } } public class UnaryOperatorExpression : OperatorExpression diff --git a/source/tlang/compiler/typecheck/dependency.d b/source/tlang/compiler/typecheck/dependency.d index 5af8835b..ab73e07f 100644 --- a/source/tlang/compiler/typecheck/dependency.d +++ b/source/tlang/compiler/typecheck/dependency.d @@ -367,10 +367,17 @@ public class DNodeGenerator * Extract the variable name * I actually forgot how this worked lmao */ - // VariableEx pression varExp = cast(VariableExpression)exp; - // Variable variable = varExp.get + VariableExpression varExp = cast(VariableExpression)exp; + string path = varExp.getName(); - // gprintln(varExp); + /* TODO: We must now */ + + /* TODO: We cannot really get much info about ourselves */ + /* TODO: How would we look this up */ + /* TODO: Perhaps the dot operator should be special? */ + + + } /** @@ -381,14 +388,109 @@ public class DNodeGenerator /* Get the binary operator expression */ BinaryOperatorExpression binOp = cast(BinaryOperatorExpression)exp; - /* Process left and right */ - DNode leftNode = expressionPass(binOp.getLeftExpression(), context); - DNode rightNode = expressionPass(binOp.getRightExpression(), context); + - /* Require the evaluation of these */ - /* TODO: Add specific DNode type dependent on the type of operator */ - dnode.needs(leftNode); - dnode.needs(rightNode); + /** + * If the operator is a dot operator + * + * We then treat that as an accessor + * + * Example: func().p1 + * Example: new A().p1 + */ + if(binOp.getOperator() == SymbolType.DOT) + { + /** + * Get the left-node (the thing being accessed) + * + * Either a `new A()`, `A()` + */ + Expression leftExp = binOp.getLeftExpression(); + + + /** + * Process the right-hand side expression + * but we should give it the Context that + * it is accessing some sort of class for example + * such that resolution can work properly + * (hence the need for `Context` in this function) + * + * 1. The Container is the type of the object and + * we then call expresssionPass on it which + * will eensure static init of class type etc + */ + + /* The NewExpression */ + NewExpression newExpression = cast(NewExpression)leftExp; + + /* Get the FunctionCall */ + FunctionCall constructorCall = newExpression.getFuncCall(); + + /* Get the name of the class the function call referes to */ + string className = constructorCall.getName(); + Type type = tc.getType(context.container, className); + + Clazz clazzType = cast(Clazz)type; + Container clazzContainer = cast(Container)clazzType; + + + + + Context objectContext = new Context(clazzContainer, InitScope.VIRTUAL); + + + /** + * Pass the newExpression and static init the class + * using current context + * + * We now know the class is static inited, and also + * the object + */ + DNode lhsNode = expressionPass(leftExp, context); + + /** + * Now using this pass the right-hand side with context + * being that the object access has virtual (static and + * non-static access as it is, well, an object `new A()`) + * + * Context being eithin the object and its class + */ + DNode rhsNode = expressionPass(binOp.getRightExpression(), objectContext); + + + // if(cast(NewExpression)leftExp) + + /** + * TODO + * + * 1. Split up and recurse down the path (rhsExpression) + * 2. Above is done already in varExp (well needs to be implemented) + * 3. Make the rhsNode finanly depend on lhsNode + * 4. dnode (whole expression, dot operator expresiosn) relies on rhsNode + * + */ + dnode.needs(lhsNode); + lhsNode.needs(rhsNode); + + + + } + /** + * Anything else are mutually exlsuive (i.e. not chained) + * + * FIXME: For now + */ + else + { + /* Process left and right */ + DNode leftNode = expressionPass(binOp.getLeftExpression(), context); + DNode rightNode = expressionPass(binOp.getRightExpression(), context); + + /* Require the evaluation of these */ + /* TODO: Add specific DNode type dependent on the type of operator */ + dnode.needs(leftNode); + dnode.needs(rightNode); + } } else {