From 6089598afed3e73e644e57e29c1ade406f3d5d3d Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 4 Jun 2021 11:27:56 +0200 Subject: [PATCH 1/8] WIP --- source/tlang/compiler/typecheck/core.d | 34 ++++++++++++++++++- .../testing/basic1_typedeclrationchecking.t | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index 7d9bb63..ae8e6ff 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -79,6 +79,17 @@ 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 @@ -111,7 +122,28 @@ public final class TypeChecker Parser.expect("Invalid type \""~typeString~"\""); } - gprintln("TYpe"~to!(string)(type)); + gprintln("Type: "~to!(string)(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: 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..1b785d4 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; } struct structTest From cfd81a6b45c81711680ee55b98447e54e529ed00 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 4 Jun 2021 11:31:44 +0200 Subject: [PATCH 2/8] Don't check the type (in class case) when the conatiner we are in is a class AND is the same class as that of the type of the typed entity being checked --- source/tlang/compiler/typecheck/core.d | 16 ++++++++++++++-- .../testing/basic1_typedeclrationchecking.t | 4 ++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index ae8e6ff..c28d62e 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -94,6 +94,8 @@ public final class TypeChecker * 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) { @@ -140,8 +142,18 @@ public final class TypeChecker { Clazz clazzType = cast(Clazz)type; - /* TODO: Now check this class and follow it's path */ - checkClass(clazzType); + /* TODO: If the type is of the current class we are in then it is fine? */ + if(clazzType == c) + { + + } + else + { + /* 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 1b785d4..c1cd956 100644 --- a/source/tlang/testing/basic1_typedeclrationchecking.t +++ b/source/tlang/testing/basic1_typedeclrationchecking.t @@ -30,6 +30,7 @@ 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 { From 09bb089998f808d8f8d6c046e55b2a30ddbc4ac2 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 4 Jun 2021 11:34:18 +0200 Subject: [PATCH 3/8] WIP: Found problem for ongoing recursion, we need a stopping case - we need to mark things --- source/tlang/compiler/typecheck/core.d | 5 ++++- source/tlang/testing/basic1_typedeclrationchecking.t | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index c28d62e..695a7a1 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -142,10 +142,13 @@ public final class TypeChecker { Clazz clazzType = cast(Clazz)type; + /* 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"); } else { diff --git a/source/tlang/testing/basic1_typedeclrationchecking.t b/source/tlang/testing/basic1_typedeclrationchecking.t index c1cd956..1381dfc 100644 --- a/source/tlang/testing/basic1_typedeclrationchecking.t +++ b/source/tlang/testing/basic1_typedeclrationchecking.t @@ -60,7 +60,8 @@ class Shekshi class kl { - + kl o; + Shekshi oo; } int Shekshi2; From 3051d6b66f099a12ca53b95b268d73cccd7a8c4d Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 4 Jun 2021 11:36:58 +0200 Subject: [PATCH 4/8] Added marking capability to Statement --- source/tlang/compiler/symbols/data.d | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/tlang/compiler/symbols/data.d b/source/tlang/compiler/symbols/data.d index 18e1900..e59af66 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 From 6c0a0ec69ea575fa0555905932e5afb033dd476e Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 4 Jun 2021 11:44:51 +0200 Subject: [PATCH 5/8] Idea: /* TODO: Got it, we NEED a dependency tree, to know chihs is being processed previosuly */ --- source/tlang/compiler/typecheck/core.d | 9 +++++++++ source/tlang/testing/basic1_typedeclrationchecking.t | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index 695a7a1..bbc2821 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -134,6 +134,7 @@ public final class TypeChecker if(cast(Number)type) { /* TODO: Mark it as ready-for-reference */ + type.mark(); } else { @@ -142,6 +143,8 @@ public final class TypeChecker { Clazz clazzType = cast(Clazz)type; + /* TODO: Check constructor */ + /* TODO: We need to start marking things */ /* TODO: Do actual checks here now */ @@ -149,9 +152,15 @@ public final class TypeChecker 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(); } 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 1381dfc..6ed9a24 100644 --- a/source/tlang/testing/basic1_typedeclrationchecking.t +++ b/source/tlang/testing/basic1_typedeclrationchecking.t @@ -60,8 +60,7 @@ class Shekshi class kl { - kl o; - Shekshi oo; + } int Shekshi2; From e5873fecb333472a46b06a762c6d7ce53adb0cb2 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 4 Jun 2021 11:55:22 +0200 Subject: [PATCH 6/8] Idea: Added visitation, we don't need marking tbh , we checking visitaion, marking is implcii in that if there is an error, we exit compiation rpocess, else we continue (which implies marked i.e. the type checking succeeded) --- .../tlang/compiler/symbols/typing/visitor.d | 2 ++ source/tlang/compiler/typecheck/core.d | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 source/tlang/compiler/symbols/typing/visitor.d 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 bbc2821..7a332ff 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 @@ -127,6 +147,8 @@ public final class TypeChecker gprintln("Type: "~to!(string)(type)); + /* TODO: Visit it (mark it as such) */ + visit(type); /* TODO: Check type here */ @@ -156,6 +178,11 @@ public final class TypeChecker /* 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 */ From 7bd8bfdde0f2408510157f9d183bb0317339b299 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 4 Jun 2021 11:56:47 +0200 Subject: [PATCH 7/8] Aded back in cause why not. Visitation wil, impy marking in the sense that if we do expression checking then it can only rely on alrady visited. --- source/tlang/testing/basic1_typedeclrationchecking.t | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/tlang/testing/basic1_typedeclrationchecking.t b/source/tlang/testing/basic1_typedeclrationchecking.t index 6ed9a24..1381dfc 100644 --- a/source/tlang/testing/basic1_typedeclrationchecking.t +++ b/source/tlang/testing/basic1_typedeclrationchecking.t @@ -60,7 +60,8 @@ class Shekshi class kl { - + kl o; + Shekshi oo; } int Shekshi2; From 9cf1a181a2c9a63f29db56e23efc256ab5e96c69 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 4 Jun 2021 11:57:25 +0200 Subject: [PATCH 8/8] TIme for expression checking --- source/tlang/compiler/typecheck/core.d | 2 +- source/tlang/testing/basic1_typedeclrationchecking.t | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index 7a332ff..9b7d247 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -156,7 +156,7 @@ public final class TypeChecker if(cast(Number)type) { /* TODO: Mark it as ready-for-reference */ - type.mark(); + } else { diff --git a/source/tlang/testing/basic1_typedeclrationchecking.t b/source/tlang/testing/basic1_typedeclrationchecking.t index 1381dfc..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;