TODO: Restarting dependency stuff

This commit is contained in:
Tristan B. Kildaire 2021-06-06 17:56:31 +02:00
parent d6c38eee34
commit 420ec5060d
2 changed files with 254 additions and 201 deletions

View File

@ -89,7 +89,10 @@ public final class TypeChecker
/* TODO: Process class ? vars funcs ?*/ /* TODO: Process class ? vars funcs ?*/
gprintln(deps); import compiler.typecheck.dependancy;
dependancyGenerate(this, modulle);
//gprintln(deps);
} }
/** /**
@ -141,162 +144,162 @@ public final class TypeChecker
// private VTreeNode currentNode; // private VTreeNode currentNode;
private void checkTypedEntitiesTypeNames(Container c) private void checkTypedEntitiesTypeNames(Container c)
{ {
// /* This VTreeNode */ /* This VTreeNode */
// VTreeNode thisNode; VTreeNode thisNode;
// if(c == modulle) if(c == modulle)
// { {
// thisNode = root; thisNode = root;
// } }
// else else
// { {
// /* Create a VTreeNode for this Statement */ /* Create a VTreeNode for this Statement */
// assert(cast(Statement)c); assert(cast(Statement)c);
// thisNode = new VTreeNode(cast(Statement)c); thisNode = new VTreeNode(cast(Statement)c);
// gprintln("dsdf"); gprintln("dsdf");
// /* Get my parent's VTreeNode */ /* 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 */ /* 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; Statement cS = cast(Statement)c;
// VTreeNode parentNode = hasVisited(cast(Statement)cS.parentOf()); VTreeNode parentNode = hasVisited(cast(Statement)cS.parentOf());
// gprintln("dsdf"); gprintln("dsdf");
// gprintln(parentNode); gprintln(parentNode);
// gprintln(c); gprintln(c);
// /* TODO: My grand resolver fuuuuck the parent is not in da tree */ /* TODO: My grand resolver fuuuuck the parent is not in da tree */
// /* TODO: Static classes moment */ /* TODO: Static classes moment */
// /* TODO: We should do this recursively rather, because we exit it is fine technically so the tree will be valid */ /* 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 */ /* Child-self to parent VTreeNode */
// parentNode.addChild(thisNode); parentNode.addChild(thisNode);
// gprintln("dsdf"); gprintln("dsdf");
// } }
// TypedEntity[] typedEntities; TypedEntity[] typedEntities;
// foreach (Statement statement; c.getStatements())
// {
// if (statement !is null && cast(TypedEntity) statement)
// {
// typedEntities ~= cast(TypedEntity) statement;
// }
// }
// /* Attempt to resolve the types of the variables */
// foreach(TypedEntity typedEntity; typedEntities)
// {
// /* TypedEntity's type */
// string typeString = typedEntity.getType();
// /* TODO: Resolve type here (either built-in or class type) */
// Type type = getType(c, typeString);
// /* Make sure type is valid */
// if(!type)
// {
// Parser.expect("Invalid type \""~typeString~"\"");
// }
// gprintln("Type: "~to!(string)(type));
// /* TODO: Visit it (mark it as such) */
// VTreeNode thisEntity = new VTreeNode(typedEntity);
// /* TODO: Check type here */
// /* If it is primitive then no further checking */
// if(cast(Number)type)
// {
// /* TODO: Mark it as ready-for-reference */
// /* TODO: Expression checking */
// thisNode.addChild(thisEntity);
// }
// 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 */
// 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
// {
// /* 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);
// }
// }
// }
// }
/**
* Get all classes
*/
Clazz[] classes;
foreach (Statement statement; c.getStatements()) foreach (Statement statement; c.getStatements())
{ {
if (statement !is null && cast(Clazz) statement) if (statement !is null && cast(TypedEntity) statement)
{ {
classes ~= cast(Clazz) statement; typedEntities ~= cast(TypedEntity) statement;
} }
} }
/** /* Attempt to resolve the types of the variables */
* TODO: Here I am testing on dependeny constrtuction foreach(TypedEntity typedEntity; typedEntities)
* 1. Only for classes
* 2. Only for their static member (assignment is assumed not to happen)
*/
foreach(Clazz currentClass; classes)
{ {
gprintln("DependencyConstruction: Class Container found '"~to!(string)(currentClass)~"'"); /* TypedEntity's type */
string typeString = typedEntity.getType();
/* Mark this as reliant on modulle (then) */ /* TODO: Resolve type here (either built-in or class type) */
Type type = getType(c, typeString);
/* Make sure type is valid */
if(!type)
{
Parser.expect("Invalid type \""~typeString~"\"");
}
gprintln("Type: "~to!(string)(type));
/* TODO: Visit it (mark it as such) */
VTreeNode thisEntity = new VTreeNode(typedEntity);
/* TODO: Check type here */
/* If it is primitive then no further checking */
if(cast(Number)type)
{
/* TODO: Mark it as ready-for-reference */
/* TODO: Expression checking */
thisNode.addChild(thisEntity);
}
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 */
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
{
/* 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);
}
}
}
/* Check recursively */
checkClass_DepTest(currentClass);
} }
// /**
// * Get all classes
// */
// Clazz[] classes;
// foreach (Statement statement; c.getStatements())
// {
// if (statement !is null && cast(Clazz) statement)
// {
// classes ~= cast(Clazz) statement;
// }
// }
// /**
// * TODO: Here I am testing on dependeny constrtuction
// * 1. Only for classes
// * 2. Only for their static member (assignment is assumed not to happen)
// */
// foreach(Clazz currentClass; classes)
// {
// gprintln("DependencyConstruction: Class Container found '"~to!(string)(currentClass)~"'");
// /* Mark this as reliant on modulle (then) */
// /* Check recursively */
// checkClass_DepTest(currentClass);
// }
} }
@ -304,87 +307,87 @@ public final class TypeChecker
* Dependency encountering * Dependency encountering
* *
* TODO: Move to own module * TODO: Move to own module
*/ // */
private string[][string] deps; // public string[][string] deps;
private void encounter(string entityName, string dependentOn) // public void encounter(string entityName, string dependentOn)
{ // {
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~"\"");
} // }
private void checkClass_DepTest(Clazz c) // private void checkClass_DepTest(Clazz c)
{ // {
/** // /**
* Get all static entities in class // * Get all static entities in class
*/ // */
Entity[] staticMembers; // Entity[] staticMembers;
foreach (Statement statement; c.getStatements()) // foreach (Statement statement; c.getStatements())
{ // {
if (statement !is null && cast(Entity) statement) // if (statement !is null && cast(Entity) statement)
{ // {
Entity member = cast(Entity)statement; // Entity member = cast(Entity)statement;
if(member.getModifierType() == InitScope.STATIC) // if(member.getModifierType() == InitScope.STATIC)
{ // {
staticMembers ~= cast(Entity) statement; // staticMembers ~= cast(Entity) statement;
} // }
} // }
} // }
gprintln("Static members: "~to!(string)(staticMembers)); // gprintln("Static members: "~to!(string)(staticMembers));
/** // /**
* Processes all Class definitions (first, ordered) // * Processes all Class definitions (first, ordered)
* Fucntions and Variables (TODO: I cannot recall that ordering) // * Fucntions and Variables (TODO: I cannot recall that ordering)
*/ // */
foreach(Entity staticMember; staticMembers) // foreach(Entity staticMember; staticMembers)
{ // {
/** // /**
* Handle static member classes (Class) // * Handle static member classes (Class)
*/ // */
if(cast(Clazz)staticMember) // if(cast(Clazz)staticMember)
{ // {
/* The class must be dependent on the current class */ // /* The class must be dependent on the current class */
gprintln("fdhjdfshjfd"); // gprintln("fdhjdfshjfd");
/* Full path of thing depending on something else */ // /* Full path of thing depending on something else */
string dependee = resolver.generateName(modulle, staticMember); // string dependee = resolver.generateName(modulle, staticMember);
/* Full path of the thing it is dependent on */ // /* Full path of the thing it is dependent on */
string dependency = resolver.generateName(modulle, c); // string dependency = resolver.generateName(modulle, c);
/* Add this to the dependency list fpr the current dependent staticMemberType */ // /* Add this to the dependency list fpr the current dependent staticMemberType */
encounter(dependee, dependency); // encounter(dependee, dependency);
/* If the static member is a class then apply the logic recursively to it */ // /* If the static member is a class then apply the logic recursively to it */
Clazz staticMemberClass = cast(Clazz)staticMember; // Clazz staticMemberClass = cast(Clazz)staticMember;
checkTypedEntitiesTypeNames(staticMemberClass); // checkTypedEntitiesTypeNames(staticMemberClass);
} // }
/** // /**
* Handle static member functions/variables (Function/Variable) // * Handle static member functions/variables (Function/Variable)
*/ // */
else if(cast(TypedEntity)staticMember) // else if(cast(TypedEntity)staticMember)
{ // {
/* Typed static member */ // /* Typed static member */
TypedEntity typedStaticMember = cast(TypedEntity)staticMember; // TypedEntity typedStaticMember = cast(TypedEntity)staticMember;
/* Get the Type of the member */ // /* Get the Type of the member */
Type staticMemberType = getType(c, typedStaticMember.getType()); // Type staticMemberType = getType(c, typedStaticMember.getType());
/* Full path of thing depending on something else */ // /* Full path of thing depending on something else */
string dependee = resolver.generateName(modulle, typedStaticMember); // string dependee = resolver.generateName(modulle, typedStaticMember);
/* Full path of the thing it is dependent on */ // /* Full path of the thing it is dependent on */
string dependency = resolver.generateName(modulle, staticMemberType); // string dependency = resolver.generateName(modulle, staticMemberType);
/* Add this to the dependency list fpr the current dependent staticMemberType */ // /* Add this to the dependency list fpr the current dependent staticMemberType */
encounter(dependee, dependency); // encounter(dependee, dependency);
} // }
else // else
{ // {
assert(false); // assert(false);
} // }
} // }
} // }

View File

@ -0,0 +1,50 @@
module compiler.typecheck.dependancy;
import gogga;
import compiler.symbols.data;
import compiler.typecheck.core;
import std.conv : to;
/**
* A list of all the full-paths of entities and what they rely on
*
* TODO:
* So far we are looking at types and seeing what they depend on, not yet
* for assignments. When we get to assignments we should then add more
*/
public string[][string] deps;
public void encounter(string entityName, string dependentOn)
{
deps[entityName] ~= dependentOn;
gprintln("[Encounter] Entity: \""~entityName~"\" set to be dependent on \""~dependentOn~"\"");
}
public void dependancyGenerate(TypeChecker tc, Container container)
{
/**
* The Container Entity
*/
Entity containerEntity = cast(Entity)container;
assert(containerEntity);
string containerEntityName = tc.getResolver().generateName(tc.getModule(), containerEntity);
/**
* Get all Entities
*/
Entity[] containerEntities;
foreach (Statement statement; container.getStatements())
{
if (statement !is null && cast(Entity) statement)
{
containerEntities ~= cast(Entity) statement;
}
}
gprintln("[dependencyGenerate] Container: \""~containerEntityName~"\" has the following members:\n\n"~to!(string)(containerEntities));
/**
* Process all entities
*/
}