From dc01256e602c2b0dac70288d80fde5072667277f Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sun, 6 Jun 2021 22:45:49 +0200 Subject: [PATCH] Fuck this is complicated (1/2) Going to need proper tree and also usign static now in a way that is legal but want it to be illegal to test for loops --- source/tlang/compiler/typecheck/core.d | 8 +++- source/tlang/compiler/typecheck/dependancy.d | 46 ++++++++++++++++++- .../typecheck/basic_dependence_correct1.t | 7 +-- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/source/tlang/compiler/typecheck/core.d b/source/tlang/compiler/typecheck/core.d index 1c913f7..8b28a12 100644 --- a/source/tlang/compiler/typecheck/core.d +++ b/source/tlang/compiler/typecheck/core.d @@ -92,7 +92,13 @@ public final class TypeChecker import compiler.typecheck.dependancy; dependancyGenerate(this, modulle); - gprintln("Final deps: "~to!(string)(deps)); + string depsString; + foreach(string key; keysOrder) + { + depsString ~= key~": "~to!(string)(deps[key])~", "; + } + gprintln("Final deps: "~to!(string)(depsString)); + findEnd(this); } /** diff --git a/source/tlang/compiler/typecheck/dependancy.d b/source/tlang/compiler/typecheck/dependancy.d index c4178f2..17da395 100644 --- a/source/tlang/compiler/typecheck/dependancy.d +++ b/source/tlang/compiler/typecheck/dependancy.d @@ -16,9 +16,14 @@ import std.conv : to; */ public string[][string] deps; +public string[] keysOrder; public void encounter(string entityName, string dependentOn) { + if(entityName !in deps) + { + keysOrder ~= entityName; + } deps[entityName] ~= dependentOn; gprintln("[Encounter] Entity: \""~entityName~"\" set to be dependent on \""~dependentOn~"\""); } @@ -63,6 +68,7 @@ public bool hasDepChecked(TypeChecker tc, Entity entity) /** * Check if it is in there + * TODO: Use `in` */ foreach(string key; deps.keys) { @@ -131,8 +137,15 @@ public void staticInitClass(TypeChecker tc, Clazz clazz) { Clazz classType = cast(Clazz)variableType; - /* Static initialize the class */ - staticInitClass(tc, classType); + /* Static initialize the class if it is not this class-type */ + if(classType != clazz) + { + /* Set this class to be dependent on the class of the class-type */ + encounter(tc, clazz, classType); + + /* Initialize (statically) the class referred to by the class-type */ + staticInitClass(tc, classType); + } } @@ -145,10 +158,39 @@ public void staticInitClass(TypeChecker tc, Clazz clazz) /* TODO: Add assignment support */ } } + + encounter(tc, staticMember, staticMember); } } +public bool isClassMember(TypeChecker tc, Clazz c, string memberName) +{ + return false; +} + +public string findEnd(TypeChecker tc) +{ + string end; + + foreach(string entityPath; deps.keys) + { + string[] dependencies = deps[entityPath]; + + foreach(string dependency; dependencies) + { + /* Check if the dependency has only itself */ + string visitedNode = dependency; + string[] visistedNodeDependencies = deps[visitedNode]; + + + + } + } + + return end; +} + public void virtualInitClass(TypeChecker tc, Clazz clazz) { diff --git a/source/tlang/testing/typecheck/basic_dependence_correct1.t b/source/tlang/testing/typecheck/basic_dependence_correct1.t index 24abac7..103f871 100644 --- a/source/tlang/testing/typecheck/basic_dependence_correct1.t +++ b/source/tlang/testing/typecheck/basic_dependence_correct1.t @@ -1,15 +1,16 @@ module typeChecking1; - -A aInstance; B bInstance; +A aInstance; + int jNumber; class A { + static B bInstanceStatic; static int jStatic; static A aInstanceStatic; - static B bInstanceStatic; + B bInstance; int jInstance; }