mirror of https://github.com/tbklang/tlang.git
Data
- Moved AST manipulation imports to the top - Made `VariableAssignment` cloneable - Made `Variable` cloneable
This commit is contained in:
parent
2411969955
commit
d495a75d75
|
@ -4,6 +4,8 @@ public import tlang.compiler.symbols.check;
|
|||
import std.conv : to;
|
||||
import tlang.compiler.typecheck.dependency.core : Context;
|
||||
|
||||
// AST manipulation interfaces
|
||||
import tlang.compiler.symbols.mcro : MStatementSearchable, MStatementReplaceable, MCloneable;
|
||||
|
||||
/**
|
||||
* TODO: Implement the blow and use them
|
||||
|
@ -438,7 +440,7 @@ public class Function : TypedEntity, Container
|
|||
}
|
||||
}
|
||||
|
||||
public class Variable : TypedEntity, MStatementSearchable, MStatementReplaceable
|
||||
public class Variable : TypedEntity, MStatementSearchable, MStatementReplaceable, MCloneable
|
||||
{
|
||||
/* TODO: Just make this an Expression */
|
||||
private VariableAssignment assignment;
|
||||
|
@ -509,6 +511,33 @@ public class Variable : TypedEntity, MStatementSearchable, MStatementReplaceable
|
|||
return assignment.replace(thiz, that);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones this variable declaration recursively
|
||||
* including its assigned value (`VariableAssignment`)
|
||||
* if any.
|
||||
*
|
||||
* Returns: the cloned `Statement`
|
||||
*/
|
||||
public override Statement clone()
|
||||
{
|
||||
Variable clonedVarDec;
|
||||
|
||||
// Clone the assignment
|
||||
VariableAssignment clonedVarAss = cast(VariableAssignment)this.assignment.clone();
|
||||
|
||||
// Create new variable with same name and identifier
|
||||
clonedVarDec = new Variable(this.type, this.name);
|
||||
|
||||
// Copy all properties across (TODO: Make sure we didn't miss any)
|
||||
clonedVarDec.accessorType = this.accessorType;
|
||||
clonedVarDec.isExternalEntity = this.isExternalEntity;
|
||||
clonedVarDec.assignment = clonedVarAss;
|
||||
clonedVarDec.container = this.container;
|
||||
|
||||
|
||||
return clonedVarDec;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -521,7 +550,7 @@ public import tlang.compiler.symbols.expressions;
|
|||
/**
|
||||
* TODO: Rename to `VariableDeclarationAssignment`
|
||||
*/
|
||||
public class VariableAssignment : Statement, MStatementSearchable, MStatementReplaceable
|
||||
public class VariableAssignment : Statement, MStatementSearchable, MStatementReplaceable, MCloneable
|
||||
{
|
||||
private Expression expression;
|
||||
private Variable variable;
|
||||
|
@ -600,6 +629,29 @@ public class VariableAssignment : Statement, MStatementSearchable, MStatementRep
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones this variable assignment by recursively cloning
|
||||
* the fields within (TODO: finish description)
|
||||
*
|
||||
* Returns: the cloned `Statement`
|
||||
*/
|
||||
public override Statement clone()
|
||||
{
|
||||
// FIXME: Investigate if `Variable`? Must be cloned
|
||||
// ... would cuase infinite recursion and it isn't
|
||||
// ... reaslly a part of the AST (just a helper)
|
||||
// ... hence I do not believe it needs to be cloned
|
||||
// (If for some reason the association eneds to be)
|
||||
// ... updted then `Variable`'s `clone()' can call
|
||||
/// ... `setvariable(clonedVarDec)` (with itself)
|
||||
|
||||
// Clone the expression
|
||||
Expression clonedExpression = cast(Expression)expression.clone();
|
||||
VariableAssignment clonedVarAss = new VariableAssignment(clonedExpression);
|
||||
|
||||
return clonedVarAss;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1519,8 +1571,6 @@ public final class Branch : Entity, Container
|
|||
}
|
||||
}
|
||||
|
||||
import tlang.compiler.symbols.mcro : MStatementSearchable, MStatementReplaceable;
|
||||
|
||||
public final class DiscardStatement : Statement, MStatementSearchable, MStatementReplaceable
|
||||
{
|
||||
private Expression expression;
|
||||
|
|
Loading…
Reference in New Issue