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
This commit is contained in:
Tristan B. Kildaire 2021-06-06 22:45:49 +02:00
parent a604f4ca27
commit dc01256e60
3 changed files with 55 additions and 6 deletions

View File

@ -92,7 +92,13 @@ public final class TypeChecker
import compiler.typecheck.dependancy; import compiler.typecheck.dependancy;
dependancyGenerate(this, modulle); 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);
} }
/** /**

View File

@ -16,9 +16,14 @@ import std.conv : to;
*/ */
public string[][string] deps; public string[][string] deps;
public string[] keysOrder;
public void encounter(string entityName, string dependentOn) public void encounter(string entityName, string dependentOn)
{ {
if(entityName !in deps)
{
keysOrder ~= entityName;
}
deps[entityName] ~= dependentOn; deps[entityName] ~= dependentOn;
gprintln("[Encounter] Entity: \""~entityName~"\" set to be dependent on \""~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 * Check if it is in there
* TODO: Use `in`
*/ */
foreach(string key; deps.keys) foreach(string key; deps.keys)
{ {
@ -131,8 +137,15 @@ public void staticInitClass(TypeChecker tc, Clazz clazz)
{ {
Clazz classType = cast(Clazz)variableType; Clazz classType = cast(Clazz)variableType;
/* Static initialize the class */ /* Static initialize the class if it is not this class-type */
staticInitClass(tc, classType); 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 */ /* 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) public void virtualInitClass(TypeChecker tc, Clazz clazz)
{ {

View File

@ -1,15 +1,16 @@
module typeChecking1; module typeChecking1;
A aInstance;
B bInstance; B bInstance;
A aInstance;
int jNumber; int jNumber;
class A class A
{ {
static B bInstanceStatic;
static int jStatic; static int jStatic;
static A aInstanceStatic; static A aInstanceStatic;
static B bInstanceStatic;
B bInstance; B bInstance;
int jInstance; int jInstance;
} }