diff --git a/source/tlang/compiler/symbols/data.d b/source/tlang/compiler/symbols/data.d index add659c..16a3330 100644 --- a/source/tlang/compiler/symbols/data.d +++ b/source/tlang/compiler/symbols/data.d @@ -70,6 +70,7 @@ public class Program public class Statement { private Container container; + private bool marked; public final void parentTo(Container container) { @@ -80,6 +81,22 @@ public class Statement { return container; } + + /** + * Returns the ready-to-reference state of this Statement + */ + public bool isMarked() + { + return marked; + } + + /** + * Marks this Statement as ready-to-reference + */ + public void mark() + { + marked = true; + } } public enum AccessorType diff --git a/source/tlang/compiler/symbols/typing/visitor.d b/source/tlang/compiler/symbols/typing/visitor.d new file mode 100644 index 0000000..b3522d2 --- /dev/null +++ b/source/tlang/compiler/symbols/typing/visitor.d @@ -0,0 +1,2 @@ +module compiler.symbols.typing.visitor; + diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index 7d9bb63..9b7d247 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -37,6 +37,26 @@ public final class TypeChecker } + + private Statement[] visistedStatements; + public void visit(Statement statement) + { + visistedStatements ~= statement; + } + + public bool hasVisited(Statement statementInQuestion) + { + foreach(Statement statement; visistedStatements) + { + if(statement == statementInQuestion) + { + return true; + } + } + + return false; + } + /** * I guess this should be called rather * when processing assignments but I also @@ -79,10 +99,23 @@ public final class TypeChecker return foundType; } + private void checkClass(Clazz clazz) + { + gprintln("Checking class now..."); + + /* TODO: Get all typed entities */ + + + /* TODO: Check things ithin */ + checkTypedEntitiesTypeNames(clazz); + } + /** * Checks all TypedEntity(s) (so Variables and Functions) * such that their types (variable type/return type) are * valid type names + * + * This is called on a Container */ private void checkTypedEntitiesTypeNames(Container c) { @@ -111,7 +144,57 @@ public final class TypeChecker Parser.expect("Invalid type \""~typeString~"\""); } - gprintln("TYpe"~to!(string)(type)); + gprintln("Type: "~to!(string)(type)); + + + /* TODO: Visit it (mark it as such) */ + visit(type); + + /* TODO: Check type here */ + + /* If it is primitive then no further checking */ + if(cast(Number)type) + { + /* TODO: Mark it as ready-for-reference */ + + } + else + { + /* If it is a Class type */ + if(cast(Clazz)type) + { + Clazz clazzType = cast(Clazz)type; + + /* TODO: Check constructor */ + + /* TODO: We need to start marking things */ + /* TODO: Do actual checks here now */ + + /* TODO: If the type is of the current class we are in then it is fine? */ + if(clazzType == c) + { + gprintln("Container we are in matches type of TypedEdntity being processed"); + + /* TODO: In that case mark the entity as fine */ + 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? */ + } + else + { + /* TODO: Also make it fine? mmuutal recusive refernce */ + /* TODO: Got it, we NEED a dependency tree, to know chihs is being processed previosuly */ + + /* TODO: Now check this class and follow it's path */ + checkClass(clazzType); + } + + + } + } } } diff --git a/source/tlang/testing/basic1_typedeclrationchecking.t b/source/tlang/testing/basic1_typedeclrationchecking.t index ec645d3..8948ac0 100644 --- a/source/tlang/testing/basic1_typedeclrationchecking.t +++ b/source/tlang/testing/basic1_typedeclrationchecking.t @@ -1,7 +1,7 @@ module myModule; -int x; +int x =1; ubyte y; int a; @@ -29,7 +29,8 @@ protected Them.Container fsdhsdj; class kl { - + Shekshi l; + kl o; } struct structTest @@ -39,6 +40,9 @@ struct structTest class Shekshi { + kl l; + Shekshi p; + struct structTest { @@ -56,7 +60,8 @@ class Shekshi class kl { - + kl o; + Shekshi oo; } int Shekshi2;