Now Container is an interface and Clazz is a kind-of Type (class-hierachy) and kind-of Container (interface)
Added assertion checks when casting for sanity (all casts to Entity from Container should never break as so far we do not have an object with a kind-of typeID tree that is imp,ementing interface Container and NOT Entity (class)entity_declaration_type_checking
parent
2cf9c07c1d
commit
114f0c5c39
|
@ -266,6 +266,15 @@ public final class TypeChecker
|
||||||
*/
|
*/
|
||||||
private void checkContainer(Container c)
|
private void checkContainer(Container c)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* TODO: Always make sure this holds
|
||||||
|
*
|
||||||
|
* All objects that implement Container so far
|
||||||
|
* are also Entities (hence they have a name)
|
||||||
|
*/
|
||||||
|
Entity containerEntity = cast(Entity)c;
|
||||||
|
assert(containerEntity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all Entities of the Container with order Clazz, Function, Variable
|
* Get all Entities of the Container with order Clazz, Function, Variable
|
||||||
*/
|
*/
|
||||||
|
@ -285,9 +294,9 @@ public final class TypeChecker
|
||||||
/**
|
/**
|
||||||
* If the current entity's name matches the container then error
|
* If the current entity's name matches the container then error
|
||||||
*/
|
*/
|
||||||
else if (cmp(c.getName(), entity.getName()) == 0)
|
else if (cmp(containerEntity.getName(), entity.getName()) == 0)
|
||||||
{
|
{
|
||||||
throw new CollidingNameException(this, c, entity, c);
|
throw new CollidingNameException(this, containerEntity, entity, c);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* If there are conflicting names within the current container
|
* If there are conflicting names within the current container
|
||||||
|
@ -305,7 +314,7 @@ public final class TypeChecker
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string fullPath = resolver.generateName(modulle, entity);
|
string fullPath = resolver.generateName(modulle, entity);
|
||||||
string containerNameFullPath = resolver.generateName(modulle, c);
|
string containerNameFullPath = resolver.generateName(modulle, containerEntity);
|
||||||
gprintln("Entity \"" ~ fullPath
|
gprintln("Entity \"" ~ fullPath
|
||||||
~ "\" is allowed to be defined within container \""
|
~ "\" is allowed to be defined within container \""
|
||||||
~ containerNameFullPath ~ "\"");
|
~ containerNameFullPath ~ "\"");
|
||||||
|
@ -399,6 +408,15 @@ public final class TypeChecker
|
||||||
*/
|
*/
|
||||||
private void checkClassNames(Container c)
|
private void checkClassNames(Container c)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* TODO: Always make sure this holds
|
||||||
|
*
|
||||||
|
* All objects that implement Container so far
|
||||||
|
* are also Entities (hence they have a name)
|
||||||
|
*/
|
||||||
|
Entity containerEntity = cast(Entity)c;
|
||||||
|
assert(containerEntity);
|
||||||
|
|
||||||
/* Get all types (Clazz so far) */
|
/* Get all types (Clazz so far) */
|
||||||
Clazz[] classTypes;
|
Clazz[] classTypes;
|
||||||
|
|
||||||
|
@ -431,21 +449,21 @@ public final class TypeChecker
|
||||||
Parser.expect("Cannot define class \"" ~ resolver.generateName(modulle,
|
Parser.expect("Cannot define class \"" ~ resolver.generateName(modulle,
|
||||||
clazz) ~ "\" as one with same name, \"" ~ resolver.generateName(modulle,
|
clazz) ~ "\" as one with same name, \"" ~ resolver.generateName(modulle,
|
||||||
resolver.resolveUp(c, clazz.getName())) ~ "\" exists in container \"" ~ resolver.generateName(
|
resolver.resolveUp(c, clazz.getName())) ~ "\" exists in container \"" ~ resolver.generateName(
|
||||||
modulle, c) ~ "\"");
|
modulle, containerEntity) ~ "\"");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Get the current container's parent container */
|
/* Get the current container's parent container */
|
||||||
Container parentContainer = c.parentOf();
|
Container parentContainer = containerEntity.parentOf();
|
||||||
|
|
||||||
/* Don't allow a class to be named after it's container */
|
/* Don't allow a class to be named after it's container */
|
||||||
// if(!parentContainer)
|
// if(!parentContainer)
|
||||||
// {
|
// {
|
||||||
if (cmp(c.getName(), clazz.getName()) == 0)
|
if (cmp(containerEntity.getName(), clazz.getName()) == 0)
|
||||||
{
|
{
|
||||||
Parser.expect("Class \"" ~ resolver.generateName(modulle,
|
Parser.expect("Class \"" ~ resolver.generateName(modulle,
|
||||||
clazz) ~ "\" cannot be defined within container with same name, \"" ~ resolver.generateName(
|
clazz) ~ "\" cannot be defined within container with same name, \"" ~ resolver.generateName(
|
||||||
modulle, c) ~ "\"");
|
modulle, containerEntity) ~ "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Loop througn Container ENtitys here */
|
/* TODO: Loop througn Container ENtitys here */
|
||||||
|
|
|
@ -38,13 +38,22 @@ public final class Resolver
|
||||||
|
|
||||||
private string[] generateName_Internal(Container relativeTo, Entity entity)
|
private string[] generateName_Internal(Container relativeTo, Entity entity)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* TODO: Always make sure this holds
|
||||||
|
*
|
||||||
|
* All objects that implement Container so far
|
||||||
|
* are also Entities (hence they have a name)
|
||||||
|
*/
|
||||||
|
Entity containerEntity = cast(Entity) relativeTo;
|
||||||
|
assert(containerEntity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the Entity and Container are the same then
|
* If the Entity and Container are the same then
|
||||||
* just returns its name
|
* just returns its name
|
||||||
*/
|
*/
|
||||||
if (relativeTo == entity)
|
if (relativeTo == entity)
|
||||||
{
|
{
|
||||||
return [relativeTo.getName()];
|
return [containerEntity.getName()];
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* If the Entity is contained within the Container
|
* If the Entity is contained within the Container
|
||||||
|
@ -57,12 +66,22 @@ public final class Resolver
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
items ~= currentEntity.getName();
|
items ~= currentEntity.getName();
|
||||||
currentEntity = currentEntity.parentOf();
|
|
||||||
|
/**
|
||||||
|
* TODO: Make sure this condition holds
|
||||||
|
*
|
||||||
|
* So far all objects we have being used
|
||||||
|
* of which are kind-of Containers are also
|
||||||
|
* and ONLY also kind-of Entity's hence the
|
||||||
|
* cast should never fail
|
||||||
|
*/
|
||||||
|
assert(cast(Entity) currentEntity.parentOf());
|
||||||
|
currentEntity = cast(Entity)(currentEntity.parentOf());
|
||||||
}
|
}
|
||||||
while (currentEntity != relativeTo);
|
while (currentEntity != relativeTo);
|
||||||
|
|
||||||
/* Add the relative to container */
|
/* Add the relative to container */
|
||||||
items ~= relativeTo.getName();
|
items ~= containerEntity.getName();
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +114,16 @@ public final class Resolver
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
currentEntity = currentEntity.parentOf();
|
/**
|
||||||
|
* TODO: Make sure this condition holds
|
||||||
|
*
|
||||||
|
* So far all objects we have being used
|
||||||
|
* of which are kind-of Containers are also
|
||||||
|
* and ONLY also kind-of Entity's hence the
|
||||||
|
* cast should never fail
|
||||||
|
*/
|
||||||
|
assert(cast(Entity) currentEntity.parentOf());
|
||||||
|
currentEntity = cast(Entity)(currentEntity.parentOf());
|
||||||
|
|
||||||
if (currentEntity == c)
|
if (currentEntity == c)
|
||||||
{
|
{
|
||||||
|
@ -153,7 +181,16 @@ public final class Resolver
|
||||||
/* If we didn't then try go up a container */
|
/* If we didn't then try go up a container */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Container possibleParent = currentContainer.parentOf();
|
/**
|
||||||
|
* TODO: Make sure this condition holds
|
||||||
|
*
|
||||||
|
* So far all objects we have being used
|
||||||
|
* of which are kind-of Containers are also
|
||||||
|
* and ONLY also kind-of Entity's hence the
|
||||||
|
* cast should never fail
|
||||||
|
*/
|
||||||
|
assert(cast(Entity) currentContainer);
|
||||||
|
Container possibleParent = (cast(Entity) currentContainer).parentOf();
|
||||||
|
|
||||||
/* Can we go up */
|
/* Can we go up */
|
||||||
if (possibleParent)
|
if (possibleParent)
|
||||||
|
@ -180,6 +217,15 @@ public final class Resolver
|
||||||
*/
|
*/
|
||||||
public Entity resolveBest(Container c, string name)
|
public Entity resolveBest(Container c, string name)
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* TODO: Always make sure this holds
|
||||||
|
*
|
||||||
|
* All objects that implement Container so far
|
||||||
|
* are also Entities (hence they have a name)
|
||||||
|
*/
|
||||||
|
Entity containerEntity = cast(Entity) c;
|
||||||
|
assert(containerEntity);
|
||||||
|
|
||||||
string[] path = split(name, '.');
|
string[] path = split(name, '.');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -218,7 +264,7 @@ public final class Resolver
|
||||||
/* TODO: Add module name check here */
|
/* TODO: Add module name check here */
|
||||||
|
|
||||||
/* If the root is the current container */
|
/* If the root is the current container */
|
||||||
if(cmp(path[0], c.getName()) == 0)
|
if (cmp(path[0], containerEntity.getName()) == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* If only 1 left then just grab it */
|
/* If only 1 left then just grab it */
|
||||||
|
|
Loading…
Reference in New Issue