From 440154b2284c65f5623b641341205f6a06726ce4 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 4 Jun 2021 13:39:11 +0200 Subject: [PATCH] Visitation by UFOs, damn --- .../tlang/compiler/symbols/typing/visitor.d | 2 - source/tlang/compiler/typecheck/core.d | 75 +++++++++++++++---- source/tlang/compiler/typecheck/visitor.d | 75 +++++++++++++++++++ .../testing/basic1_typedeclrationchecking.t | 2 +- 4 files changed, 136 insertions(+), 18 deletions(-) delete mode 100644 source/tlang/compiler/symbols/typing/visitor.d create mode 100644 source/tlang/compiler/typecheck/visitor.d diff --git a/source/tlang/compiler/symbols/typing/visitor.d b/source/tlang/compiler/symbols/typing/visitor.d deleted file mode 100644 index b3522d2c..00000000 --- a/source/tlang/compiler/symbols/typing/visitor.d +++ /dev/null @@ -1,2 +0,0 @@ -module compiler.symbols.typing.visitor; - diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index f718180d..fa1bcda1 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -34,27 +34,28 @@ public final class TypeChecker { this.modulle = modulle; resolver = new Resolver(this); + /* TODO: Module check?!?!? */ + initTree(); + } + import compiler.typecheck.visitor; + private VTreeNode root; + private void initTree() + { + root = new VTreeNode(modulle); } - private Statement[] visistedStatements; - public void visit(Statement statement) + // private Statement[] visistedStatements; + public void visit(VTreeNode level, Statement statement) { - visistedStatements ~= statement; + // visistedStatements ~= statement; + level.addChild(new VTreeNode(statement)); } - public bool hasVisited(Statement statementInQuestion) + public VTreeNode hasVisited(Statement statementInQuestion) { - foreach(Statement statement; visistedStatements) - { - if(statement == statementInQuestion) - { - return true; - } - } - - return false; + return root.isInTree(statementInQuestion); } /** @@ -120,8 +121,43 @@ public final class TypeChecker * TODO: Should we also do expression parsing or rather do another call for that * mmmmh */ + // private VTreeNode currentNode; private void checkTypedEntitiesTypeNames(Container c) { + /* This VTreeNode */ + VTreeNode thisNode; + + if(c == modulle) + { + thisNode = root; + } + else + { + /* Create a VTreeNode for this Statement */ + assert(cast(Statement)c); + thisNode = new VTreeNode(cast(Statement)c); + + gprintln("dsdf"); + + /* Get my parent's VTreeNode */ + /* TODO: This parent of, ah we should make functions be containers, like we gonna need that for constutcor processing etc, and fucntions, mutual recursion there too */ + Statement cS = cast(Statement)c; + VTreeNode parentNode = hasVisited(cast(Statement)cS.parentOf()); + + gprintln("dsdf"); + gprintln(parentNode); + gprintln(c); + + /* TODO: We should do this recursively rather, because we exit it is fine technically so the tree will be valid */ + + /* Child-self to parent VTreeNode */ + parentNode.addChild(thisNode); + gprintln("dsdf"); + } + + + + TypedEntity[] typedEntities; foreach (Statement statement; c.getStatements()) @@ -151,7 +187,9 @@ public final class TypeChecker /* TODO: Visit it (mark it as such) */ - visit(type); + VTreeNode thisEntity = new VTreeNode(typedEntity); + + /* TODO: Check type here */ @@ -159,6 +197,9 @@ public final class TypeChecker if(cast(Number)type) { /* TODO: Mark it as ready-for-reference */ + + /* TODO: Expression checking */ + thisNode.addChild(thisEntity); } else @@ -179,12 +220,16 @@ public final class TypeChecker gprintln("Container we are in matches type of TypedEdntity being processed"); /* TODO: In that case mark the entity as fine */ - clazzType.mark(); + thisNode.addChild(thisEntity); + // clazzType.mark(); } /* If the type is visited already (good for rwcuasiev case mutal class references) */ else if(hasVisited(clazzType)) { /* TODO: This could actually solve the abive too? */ + /* This is basically saying the TypedEntity's type is a CLass that has been visited so we can assume it is safe to add */ + /* We don't wanna visit it again (as stackoevrflow) from mutaul recursion then */ + thisNode.addChild(thisEntity); } else { diff --git a/source/tlang/compiler/typecheck/visitor.d b/source/tlang/compiler/typecheck/visitor.d new file mode 100644 index 00000000..7858ae59 --- /dev/null +++ b/source/tlang/compiler/typecheck/visitor.d @@ -0,0 +1,75 @@ +module compiler.typecheck.visitor; + +import compiler.symbols.data; + +public final class VisitorTree +{ + private VTreeNode root; + + this(VTreeNode root) + { + this.root = root; + } +} + +public final class VTreeNode +{ + private VTreeNode[] children; + private Statement statement; + + this(Statement statement) + { + this.statement = statement; + } + + public void addChild(VTreeNode newChild) + { + children ~= newChild; + } + + public Statement getStatement() + { + return statement; + } + + public VTreeNode[] getChildren() + { + return children; + } + + public VTreeNode isInTree(Statement statement) + { + /* If this node is the one being searched for */ + if(this.getStatement() == statement) + { + return this; + } + /* If not */ + else + { + /* Get all this node's children */ + VTreeNode[] children = this.getChildren(); + + /* Make sure there are children */ + if(children.length) + { + /* Any of the children */ + foreach(VTreeNode child; children) + { + if(child.isInTree(statement)) + { + return child; + } + } + + /* If above fails, then not found */ + return null; + } + /* If there are no children then not found */ + else + { + return null; + } + } + } +} \ No newline at end of file diff --git a/source/tlang/testing/basic1_typedeclrationchecking.t b/source/tlang/testing/basic1_typedeclrationchecking.t index 07da25f3..8948ac0d 100644 --- a/source/tlang/testing/basic1_typedeclrationchecking.t +++ b/source/tlang/testing/basic1_typedeclrationchecking.t @@ -29,7 +29,7 @@ protected Them.Container fsdhsdj; class kl { - Shekshi l = new Shekshi(); + Shekshi l; kl o; }