Only use grand resolver here now that it is implemented

parser_exception_before
Tristan B. V. Kildaire 2021-04-01 08:47:44 +02:00
parent c5f45e6a36
commit 4f32fb9619
3 changed files with 125 additions and 15 deletions

View File

@ -86,9 +86,25 @@ public final class TypeChecker
private void beginCheck()
{
// checkIt(modulle.getStatements(), modulle.getName());
/* First we define global types (so classes) */
gprintln("dd");
checkClasses(modulle);
/* TODO: Then we declare global functions */
checkFunctions(modulle);
/* TODO: Then we declare global variables */
checkIt(modulle);
}
private void checkFunctions(Container c)
{
}
private void checkClass(Clazz clazz)
{
@ -168,18 +184,8 @@ public final class TypeChecker
string[] dotPath = split(parent, '.');
gprintln(dotPath.length);
/* If the name is rooted resolve the name top-down */
if(dotPath.length > 1)
{
namedEntity = getEntity(modulle, parent);
}
/* If the name is not rooted resolve the name bottom up */
else
{
namedEntity = resolver.resolveUp(c, parent);
}
namedEntity=resolver.resolveBest(c, parent);
/* Resolve the name */
namedEntity = resolver.resolveBest(c, parent);
/* If the entity exists */
if(namedEntity)
@ -241,6 +247,8 @@ public final class TypeChecker
}
/**
* Starting from a Container c this makes sure
@ -263,6 +271,7 @@ public final class TypeChecker
/* Declare each type */
foreach(Clazz clazz; classTypes)
{
gprintln("Name: "~resolver.generateName(modulle, clazz));
/**
* Check if the first class found with my name is the one being
* processed, if so then it is fine, if not then error, it has
@ -366,13 +375,16 @@ public final class TypeChecker
/* TODO clazz_21_211 , crashes */
private bool isNameInUse(Container relative, string name)
{
return resolver.resolveBest(relative, name) !is null;
}
private void checkIt(Container c)
{
//gprintln("Processing at path/level: "~path, DebugType.WARNING);
/* First we define types (so classes) */
gprintln("dd");
checkClasses(c);
Statement[] statements = c.getStatements();
string path = c.getName();

View File

@ -15,6 +15,99 @@ public final class Resolver
this.typeChecker = typeChecker;
}
/**
* Given an Entity generate it's full path relative to a given
* container
*/
public string generateName(Container relativeTo, Entity entity)
{
string[] name = generateName_Internal(relativeTo, entity);
string path;
for(ulong i = 0; i < name.length; i++)
{
path ~= name[name.length-1-i];
if(i != name.length-1)
{
path ~= ".";
}
}
return path;
}
private string[] generateName_Internal(Container relativeTo, Entity entity)
{
/**
* If the Entity and Container are the same then
* just returns its name
*/
if(relativeTo == entity)
{
return [relativeTo.getName()];
}
/**
* If the Entity is contained within the Container
*/
else if(isDescendant(relativeTo, entity))
{
string[] items;
Entity currentEntity = entity;
do
{
items ~= currentEntity.getName();
currentEntity = currentEntity.parentOf();
}
while(currentEntity != relativeTo);
/* Add the relative to container */
items ~= relativeTo.getName();
return items;
}
/* If not */
else
{
return null;
}
}
/**
* Returns true if Entity e is C or is within
* (contained under c), false otherwise
*/
public bool isDescendant(Container c, Entity e)
{
/**
* If they are the same
*/
if(c == e)
{
return true;
}
/**
* If not, check descendancy
*/
else
{
Entity currentEntity = e;
do
{
currentEntity = currentEntity.parentOf();
if(currentEntity == c)
{
return true;
}
}
while(currentEntity);
return false;
}
}
public Entity resolveWithin(Container currentContainer, string name)
{
Statement[] statements = currentContainer.getStatements();

View File

@ -23,6 +23,11 @@ protected ubyte k3 = -1;
class Shekshi
{
class myModule
{
}
class G
{
class F