mirror of https://github.com/tbklang/tlang.git
Compare commits
5 Commits
c30a514812
...
bb3d94ddb9
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | bb3d94ddb9 | |
Tristan B. Velloza Kildaire | 33473f5f2f | |
Tristan B. Velloza Kildaire | a659cb510c | |
Tristan B. Velloza Kildaire | 1877799285 | |
Tristan B. Velloza Kildaire | bfb822b892 |
|
@ -73,8 +73,42 @@ public final class Program : Container
|
|||
|
||||
public bool replace(Statement thiz, Statement that)
|
||||
{
|
||||
// TODO: Implement me
|
||||
return false;
|
||||
/* We cannot replace ourselves */
|
||||
if(thiz == this)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/* If not ourselves, then search our body */
|
||||
else
|
||||
{
|
||||
/* Check for module replacement */
|
||||
for(size_t i = 0; i < this.modules.length; i++)
|
||||
{
|
||||
Module mod = this.modules[i];
|
||||
|
||||
/* If we are replacing a module */
|
||||
if(thiz == mod)
|
||||
{
|
||||
this.modules[i] = cast(Module)that;
|
||||
that.parentTo(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for replacement WITHIN each module */
|
||||
for(size_t i = 0; i < this.modules.length; i++)
|
||||
{
|
||||
Module mod = this.modules[i];
|
||||
|
||||
/* If we are replacing WITHIN a module */
|
||||
if(mod.replace(thiz, that))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void addStatement(Statement statement)
|
||||
|
|
|
@ -129,24 +129,22 @@ public class MetaProcessor
|
|||
import tlang.compiler.symbols.data : VariableExpression;
|
||||
import std.string : cmp;
|
||||
|
||||
import tlang.compiler.typecheck.resolution : Resolver;
|
||||
|
||||
private AliasDeclaration[] findAliasesFrom(Container from)
|
||||
{
|
||||
Resolver resolver = tc.getResolver(); // TODO: Remove from here, make a field
|
||||
|
||||
// Predicate to only find aliases (amongst all the different types of statements)
|
||||
bool isAliasDecl(Statement stmt) { return cast(AliasDeclaration)stmt !is null; }
|
||||
Statement[] declaredAliasesStmts;
|
||||
resolver.collectUpwards(from, predicateOf!(isAliasDecl), declaredAliasesStmts);
|
||||
return cast(AliasDeclaration[])declaredAliasesStmts;
|
||||
}
|
||||
|
||||
private void doAliasExpression(Container container, Statement curStmt)
|
||||
{
|
||||
bool oldCode = false;
|
||||
|
||||
import tlang.compiler.typecheck.resolution : Resolver;
|
||||
Resolver resolver = tc.getResolver();
|
||||
|
||||
// Discover all declared aliases in current container
|
||||
// TODO: Ordering might be a parameter to set (as this discovers alias declared even AFTER they are used)
|
||||
bool isAliasDecl(Statement stmt)
|
||||
{
|
||||
return cast(AliasDeclaration)stmt !is null;
|
||||
}
|
||||
Statement[] declaredAliasesStmts;
|
||||
resolver.collectUpwards(container, predicateOf!(isAliasDecl), declaredAliasesStmts);
|
||||
AliasDeclaration[] declaredAliases = cast(AliasDeclaration[])declaredAliasesStmts;
|
||||
|
||||
DEBUG(format("All aliases available from (cntnr:%s, stmt=%s) upwards: %s", container, curStmt, declaredAliases));
|
||||
DEBUG(format("doAliasExpression(cntnr:%s, stmt=%s)", container, curStmt));
|
||||
|
||||
// Find any VariableExpression(s) from curStmt (TODO: should be container or nah?)
|
||||
MStatementSearchable searchableStmt = cast(MStatementSearchable)curStmt;
|
||||
|
@ -163,6 +161,10 @@ public class MetaProcessor
|
|||
// furthest when obtained from the resolver, so any
|
||||
// tie breaking would be the logically closest
|
||||
// alias with the same name)
|
||||
//
|
||||
// Achor the search to start from the VarExp
|
||||
AliasDeclaration[] declaredAliases = findAliasesFrom(varExp.parentOf());
|
||||
DEBUG("DeclAlis: ", declaredAliases);
|
||||
AliasDeclaration[] matched;
|
||||
string varExpIdent = varExp.getName();
|
||||
bool filterAliasesToName(AliasDeclaration aliasDecl)
|
||||
|
|
|
@ -9,9 +9,13 @@ int cnt()
|
|||
|
||||
alias expr = cnt();
|
||||
|
||||
alias inner = 1;
|
||||
|
||||
int main()
|
||||
{
|
||||
alias inner = 0;
|
||||
int i = expr;
|
||||
int p = expr;
|
||||
return i+p;
|
||||
int o = inner;
|
||||
return i+p+o;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue