* net/loveruby/cflat/ast/ToplevelScope.java: use SemanticException instead of SemanticError for duplicated declarations/definitions.

git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4098 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2008-12-07 08:09:20 +00:00
parent b469db1b82
commit 545515b5e0
2 changed files with 22 additions and 9 deletions

View File

@ -1,3 +1,12 @@
Sun Dec 7 17:09:17 2008 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/ast/ToplevelScope.java: use SemanticException
instead of SemanticError for duplicated declarations/definitions.
Sun Dec 7 17:08:26 2008 Minero Aoki <aamine@loveruby.net>
* test: test declaration override (error path).
Sun Dec 7 16:55:56 2008 Minero Aoki <aamine@loveruby.net>
* test: test declaration override.

View File

@ -28,21 +28,25 @@ public class ToplevelScope extends Scope {
/** Declare variable or function globally. */
// #@@range/declareEntity{
public void declareEntity(Entity ent) {
if (entities.containsKey(ent.name())) {
throw new Error("duplicated declaration: " + ent.name());
public void declareEntity(Entity entity) throws SemanticException {
Entity e = entities.get(entity.name());
if (e != null) {
throw new SemanticException("duplicated declaration: " +
entity.name() + ": " +
e.location() + " and " + entity.location());
}
entities.put(ent.name(), ent);
entities.put(entity.name(), entity);
}
// #@@}
/** Define variable or function globally. */
// #@@range/defineEntity{
public void defineEntity(Entity entity) {
Entity ent = entities.get(entity.name());
if (ent != null && ent.isDefined()) {
throw new Error("duplicated definition: " + entity.name() + ": " +
ent.location() + " and " + entity.location());
public void defineEntity(Entity entity) throws SemanticException {
Entity e = entities.get(entity.name());
if (e != null && e.isDefined()) {
throw new SemanticException("duplicated definition: " +
entity.name() + ": " +
e.location() + " and " + entity.location());
}
entities.put(entity.name(), entity);
}