This is pretty aids not gonna lie
This commit is contained in:
parent
eac31532c7
commit
ea2f27d0b8
|
@ -91,8 +91,8 @@ public final class TypeChecker
|
|||
|
||||
import compiler.typecheck.dependancy;
|
||||
StructuralOrganizer so = new StructuralOrganizer(this);
|
||||
so.checkContainer(modulle);
|
||||
so.printDeps(modulle);
|
||||
so.generate();
|
||||
so.printPool();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,17 +12,26 @@ public final class StructuralOrganizer
|
|||
/* The associated TypeChecker */
|
||||
private TypeChecker tc;
|
||||
|
||||
private TreeNode root;
|
||||
|
||||
this(TypeChecker tc)
|
||||
{
|
||||
this.tc = tc;
|
||||
}
|
||||
|
||||
|
||||
public void generate()
|
||||
{
|
||||
TreeNode node = checkContainer(tc.getModule());
|
||||
//root.addDep(node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a container this method will attempt to build
|
||||
* an implicit dependency tree (by setting the dependencies)
|
||||
* on the Entities contained within
|
||||
*/
|
||||
public void checkContainer(Container container)
|
||||
public TreeNode checkContainer(Container container)
|
||||
{
|
||||
/* Get all Entities */
|
||||
Entity[] entities;
|
||||
|
@ -58,8 +67,14 @@ public final class StructuralOrganizer
|
|||
|
||||
/* TODO: Ensure that we set dependences as A.B.C with A B C all static */
|
||||
|
||||
/* Statically initialize the class */
|
||||
TreeNode classWalkInitDep = staticInitializeClass(classType);
|
||||
|
||||
/* Make the variable dependent on this */
|
||||
TreeNode varNode = poolNode(variable);
|
||||
|
||||
/* Mark the variable as dependent on having sttaic init for class-type class */
|
||||
variable.addDep(classType);
|
||||
varNode.addDep(classWalkInitDep);
|
||||
}
|
||||
|
||||
|
||||
|
@ -67,18 +82,65 @@ public final class StructuralOrganizer
|
|||
if(variable.getAssignment())
|
||||
{
|
||||
/* TODO: Implement me */
|
||||
VariableAssignment varAssign = variable.getAssignment();
|
||||
gprintln("Assignment: "~to!(string)(varAssign));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void printDeps(Container container)
|
||||
private TreeNode[] nodePool;
|
||||
|
||||
public TreeNode poolNode(Entity entity)
|
||||
{
|
||||
foreach(TreeNode node; nodePool)
|
||||
{
|
||||
if(node.getEntity() == entity)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
TreeNode node = new TreeNode(tc, entity);
|
||||
nodePool ~= node;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statically initialize a class
|
||||
*
|
||||
* Outer class first then inner things
|
||||
*
|
||||
* TODO: Possible re-ordering would be needed
|
||||
*/
|
||||
public TreeNode staticInitializeClass(Clazz clazz)
|
||||
{
|
||||
/**
|
||||
* This Class's TreeNode
|
||||
*/
|
||||
TreeNode treeNode = poolNode(clazz);
|
||||
|
||||
/**
|
||||
* Check if the current Clazz has a parent Container
|
||||
* that is a Clazz, then go statically initialize that
|
||||
* first
|
||||
*/
|
||||
if(cast(Clazz)(clazz.parentOf()))
|
||||
{
|
||||
/* Statically initialize the parent class */
|
||||
TreeNode parentNode = staticInitializeClass(cast(Clazz)(clazz.parentOf()));
|
||||
|
||||
/* Set the child class to depend on the parent's static initialization */
|
||||
treeNode.addDep(treeNode);
|
||||
}
|
||||
|
||||
/* Get all Entities */
|
||||
Entity[] entities;
|
||||
foreach(Statement statement; container.getStatements())
|
||||
foreach(Statement statement; clazz.getStatements())
|
||||
{
|
||||
if(statement !is null && cast(Entity)statement)
|
||||
{
|
||||
|
@ -87,18 +149,144 @@ public final class StructuralOrganizer
|
|||
}
|
||||
|
||||
/**
|
||||
* Print all the dependencies
|
||||
* Process static entities
|
||||
*
|
||||
* Here we first want to mark the statics that have basic types
|
||||
* or non-basic class types that match our class
|
||||
*/
|
||||
foreach(Entity entity; entities)
|
||||
{
|
||||
/* Print the Entity's dependencies */
|
||||
gprintln("Entity ("~entity.getName()~") Deps: "~to!(string)(entity.getDeps()), DebugType.WARNING);
|
||||
|
||||
/* if the ENtity is a container then apply recursively */
|
||||
if(cast(Container)entity)
|
||||
if(entity.getModifierType() == InitScope.STATIC)
|
||||
{
|
||||
printDeps(cast(Container)entity);
|
||||
/**
|
||||
* Static Variable declarations
|
||||
*/
|
||||
if(cast(Variable)entity)
|
||||
{
|
||||
/* Variable being declared */
|
||||
Variable variable = cast(Variable)entity;
|
||||
TreeNode variableTNode = poolNode(variable);
|
||||
|
||||
/* Get the variable's type */
|
||||
Type type = tc.getType(clazz, variable.getType());
|
||||
|
||||
/* If the variable's type basic */
|
||||
if(cast(Primitive)type)
|
||||
{
|
||||
/* TODO: Init */
|
||||
/* Immediately set as init, no further static recursion */
|
||||
treeNode.addDep(variableTNode);
|
||||
}
|
||||
/* If the variable's type is class-type */
|
||||
else if(cast(Clazz)type)
|
||||
{
|
||||
/* If it is ours */
|
||||
if(type == clazz)
|
||||
{
|
||||
/* Immediately set as init, no further static recursion */
|
||||
treeNode.addDep(variableTNode);
|
||||
}
|
||||
/* Else init the class AND then the variable */
|
||||
else
|
||||
{
|
||||
//treeNode.addDep(staticInitializeClass(cast(Clazz)type));
|
||||
//treeNode.addDep(variableTNode);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: dik */
|
||||
}
|
||||
|
||||
|
||||
/* TODO: Implement this later */
|
||||
if(variable.getAssignment())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process static entities
|
||||
*
|
||||
* Here we first want to mark the statics that have basic types
|
||||
* or non-basic class types that match our class
|
||||
*/
|
||||
foreach(Entity entity; entities)
|
||||
{
|
||||
if(entity.getModifierType() == InitScope.STATIC)
|
||||
{
|
||||
/**
|
||||
* Static Variable declarations
|
||||
*/
|
||||
if(cast(Variable)entity)
|
||||
{
|
||||
/* Variable being declared */
|
||||
Variable variable = cast(Variable)entity;
|
||||
TreeNode variableTNode = poolNode(variable);
|
||||
|
||||
/* Get the variable's type */
|
||||
Type type = tc.getType(clazz, variable.getType());
|
||||
|
||||
/* If the variable's type basic */
|
||||
if(cast(Primitive)type)
|
||||
{
|
||||
/* TODO: Init */
|
||||
/* Immediately set as init, no further static recursion */
|
||||
//treeNode.addDep(variableTNode);
|
||||
}
|
||||
/* If the variable's type is class-type */
|
||||
else if(cast(Clazz)type)
|
||||
{
|
||||
/* If it is ours */
|
||||
if(type != clazz)
|
||||
{
|
||||
treeNode.addDep(staticInitializeClass(cast(Clazz)type));
|
||||
treeNode.addDep(variableTNode);
|
||||
}
|
||||
/* Else init the class AND then the variable */
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TODO: dik */
|
||||
}
|
||||
|
||||
|
||||
/* TODO: Implement this later */
|
||||
if(variable.getAssignment())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return treeNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a `class A {}` this will make sure all static allocations
|
||||
*
|
||||
*/
|
||||
private void staticInitializeClass_reorder(Clazz)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void printPool()
|
||||
{
|
||||
foreach(TreeNode node; nodePool)
|
||||
{
|
||||
gprintln(node is null);
|
||||
gprintln(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,3 +299,61 @@ public final class StructuralOrganizer
|
|||
*/
|
||||
// public string[]
|
||||
}
|
||||
|
||||
public class TreeNode
|
||||
{
|
||||
private Entity entity;
|
||||
private TreeNode[] deps;
|
||||
private TypeChecker tc;
|
||||
|
||||
this(TypeChecker tc, Entity entity)
|
||||
{
|
||||
this.entity = entity;
|
||||
this.tc = tc;
|
||||
}
|
||||
|
||||
public void addDep(TreeNode node)
|
||||
{
|
||||
/* Only add if not already added */
|
||||
foreach(TreeNode cNode; deps)
|
||||
{
|
||||
if(cNode == node)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
deps ~= node;
|
||||
}
|
||||
|
||||
public TreeNode isDep(Entity entity)
|
||||
{
|
||||
foreach(TreeNode node; deps)
|
||||
{
|
||||
if(node.getEntity() == entity)
|
||||
{
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Entity getEntity()
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
|
||||
public override string toString()
|
||||
{
|
||||
string[] names;
|
||||
foreach(TreeNode node; deps)
|
||||
{
|
||||
names ~= tc.getResolver().generateName(tc.getModule(), node.getEntity());
|
||||
}
|
||||
|
||||
return "TreeNode ("~entity.getName()~"): "~to!(string)(names);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
module typeChecking1;
|
||||
|
||||
B bInstance;
|
||||
A aInstance;
|
||||
A aInstance = 1;
|
||||
A.C cInstance;
|
||||
|
||||
int jNumber;
|
||||
|
||||
|
@ -11,6 +12,11 @@ class A
|
|||
static int jStatic;
|
||||
static A aInstanceStatic;
|
||||
|
||||
static class C
|
||||
{
|
||||
static int jStatic;
|
||||
}
|
||||
|
||||
B bInstance;
|
||||
int jInstance;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue