WIP: Working on accessor dependeny generation for `new A().thing.thing`

This commit is contained in:
Tristan B. Kildaire 2021-08-11 18:19:28 +02:00
parent ff5f39c752
commit ab70e5ea3a
2 changed files with 117 additions and 10 deletions

View File

@ -22,6 +22,11 @@ public class OperatorExpression : Expression
{
this.operator = operator;
}
public SymbolType getOperator()
{
return operator;
}
}
public class UnaryOperatorExpression : OperatorExpression

View File

@ -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
{