Added exception handling

parser.sync-conflict-20210405-185821-O3W7KWN
Tristan B. V. Kildaire 2021-04-01 14:43:49 +02:00
parent ab36f9200d
commit df6433bae2
2 changed files with 17 additions and 13 deletions

View File

@ -159,6 +159,10 @@ public final class TypeChecker
checkClassInherit(c); checkClassInherit(c);
} }
public Resolver getResolver()
{
return resolver;
}
/** /**
* Given a Container `c` this will check all * Given a Container `c` this will check all
@ -200,10 +204,7 @@ public final class TypeChecker
*/ */
if(cmp(c.getName(), entity.getName()) == 0) if(cmp(c.getName(), entity.getName()) == 0)
{ {
string containerPath = resolver.generateName(modulle, c); throw new CollidingNameException(this, c, entity, c);
string entityPath = resolver.generateName(modulle, entity);
throw new CollidingNameException(this, c, entity);
//Parser.expect("Cannot have entity \""~entityPath~"\" with same name as container \""~containerPath~"\"");
} }
/** /**
* If there are conflicting names within the current container * If there are conflicting names within the current container
@ -212,10 +213,7 @@ public final class TypeChecker
*/ */
else if(findPrecedence(c, entity.getName()) != entity) else if(findPrecedence(c, entity.getName()) != entity)
{ {
string preExistingEntity = resolver.generateName(modulle, findPrecedence(c, entity.getName())); throw new CollidingNameException(this, findPrecedence(c, entity.getName()), entity, c);
string entityPath = resolver.generateName(modulle, entity);
throw new CollidingNameException(this, findPrecedence(c, entity.getName()), entity);
//Parser.expect("Cannot have entity \""~entityPath~"\" with same name as entity \""~preExistingEntity~"\" within same container");
} }
/** /**
* Otherwise this Entity is fine * Otherwise this Entity is fine

View File

@ -28,25 +28,31 @@ public final class CollidingNameException : TypeCheckerException
*/ */
private Entity attempted; private Entity attempted;
this(TypeChecker typeChecker, Entity defined, Entity attempted) /**
* The Container we are in
*/
private Container c;
this(TypeChecker typeChecker, Entity defined, Entity attempted, Container c)
{ {
super(typeChecker); super(typeChecker);
this.defined = defined; this.defined = defined;
this.attempted = attempted; this.attempted = attempted;
this.c = c;
/* TODO: Set `msg` */ /* TODO: Set `msg` */
/* TODO: (Gogga it) Generate the error message */ /* TODO: (Gogga it) Generate the error message */
if(isCollidingWithContainer()) if(isCollidingWithContainer())
{ {
string containerPath = typeChecker.getResolver().generateName(modulle, defined); string containerPath = typeChecker.getResolver().generateName(typeChecker.getModule(), defined);
string entityPath = typeChecker.getResolver().generateName(modulle, attempted); string entityPath = typeChecker.getResolver().generateName(typeChecker.getModule(), attempted);
msg = "Cannot have entity \""~entityPath~"\" with same name as container \""~containerPath~"\""; msg = "Cannot have entity \""~entityPath~"\" with same name as container \""~containerPath~"\"";
} }
else else
{ {
string preExistingEntity = resolver.generateName(modulle, findPrecedence(c, entity.getName())); string preExistingEntity = typeChecker.getResolver().generateName(typeChecker.getModule(), typeChecker.findPrecedence(c, attempted.getName()));
string entityPath = resolver.generateName(modulle, entity); string entityPath = typeChecker.getResolver().generateName(typeChecker.getModule(), attempted);
msg = "Cannot have entity \""~entityPath~"\" with same name as entity \""~preExistingEntity~"\" within same container"; msg = "Cannot have entity \""~entityPath~"\" with same name as entity \""~preExistingEntity~"\" within same container";
} }
} }