Archived
Improved checker code using declaration interfaces and overloaded error
reporting.
This commit is contained in:
+7
-1
@@ -16,10 +16,11 @@ package triangle.abstractSyntaxTrees.declarations;
|
||||
|
||||
import triangle.abstractSyntaxTrees.expressions.Expression;
|
||||
import triangle.abstractSyntaxTrees.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class ConstDeclaration extends Declaration {
|
||||
public class ConstDeclaration extends Declaration implements ConstantDeclaration {
|
||||
|
||||
public ConstDeclaration(Identifier iAST, Expression eAST, SourcePosition position) {
|
||||
super(position);
|
||||
@@ -27,6 +28,11 @@ public class ConstDeclaration extends Declaration {
|
||||
E = eAST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDenoter getType() {
|
||||
return E.type;
|
||||
}
|
||||
|
||||
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
|
||||
return v.visitConstDeclaration(this, arg);
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package triangle.abstractSyntaxTrees.declarations;
|
||||
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
|
||||
public interface ConstantDeclaration {
|
||||
|
||||
TypeDenoter getType();
|
||||
|
||||
}
|
||||
+11
-1
@@ -21,7 +21,7 @@ import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class FuncDeclaration extends Declaration {
|
||||
public class FuncDeclaration extends Declaration implements FunctionDeclaration {
|
||||
|
||||
public FuncDeclaration(Identifier iAST, FormalParameterSequence fpsAST, TypeDenoter tAST, Expression eAST,
|
||||
SourcePosition position) {
|
||||
@@ -36,6 +36,16 @@ public class FuncDeclaration extends Declaration {
|
||||
return v.visitFuncDeclaration(this, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalParameterSequence getFormals() {
|
||||
return FPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDenoter getType() {
|
||||
return T;
|
||||
}
|
||||
|
||||
public final Identifier I;
|
||||
public final FormalParameterSequence FPS;
|
||||
public TypeDenoter T;
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package triangle.abstractSyntaxTrees.declarations;
|
||||
|
||||
import triangle.abstractSyntaxTrees.formals.FormalParameterSequence;
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
|
||||
public interface FunctionDeclaration {
|
||||
|
||||
FormalParameterSequence getFormals();
|
||||
|
||||
TypeDenoter getType();
|
||||
|
||||
}
|
||||
+6
-1
@@ -20,7 +20,7 @@ import triangle.abstractSyntaxTrees.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class ProcDeclaration extends Declaration {
|
||||
public class ProcDeclaration extends Declaration implements ProcedureDeclaration {
|
||||
|
||||
public ProcDeclaration(Identifier iAST, FormalParameterSequence fpsAST, Command cAST, SourcePosition position) {
|
||||
super(position);
|
||||
@@ -33,6 +33,11 @@ public class ProcDeclaration extends Declaration {
|
||||
return v.visitProcDeclaration(this, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalParameterSequence getFormals() {
|
||||
return FPS;
|
||||
}
|
||||
|
||||
public final Identifier I;
|
||||
public final FormalParameterSequence FPS;
|
||||
public final Command C;
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package triangle.abstractSyntaxTrees.declarations;
|
||||
|
||||
import triangle.abstractSyntaxTrees.formals.FormalParameterSequence;
|
||||
|
||||
public interface ProcedureDeclaration {
|
||||
|
||||
FormalParameterSequence getFormals();
|
||||
|
||||
}
|
||||
+6
-1
@@ -19,7 +19,7 @@ import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class VarDeclaration extends Declaration {
|
||||
public class VarDeclaration extends Declaration implements VariableDeclaration {
|
||||
|
||||
public VarDeclaration(Identifier iAST, TypeDenoter tAST, SourcePosition position) {
|
||||
super(position);
|
||||
@@ -27,6 +27,11 @@ public class VarDeclaration extends Declaration {
|
||||
T = tAST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDenoter getType() {
|
||||
return T;
|
||||
}
|
||||
|
||||
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
|
||||
return v.visitVarDeclaration(this, arg);
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package triangle.abstractSyntaxTrees.declarations;
|
||||
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
|
||||
public interface VariableDeclaration {
|
||||
|
||||
TypeDenoter getType();
|
||||
|
||||
}
|
||||
+8
-3
@@ -14,12 +14,13 @@
|
||||
|
||||
package triangle.abstractSyntaxTrees.formals;
|
||||
|
||||
import triangle.abstractSyntaxTrees.declarations.ConstantDeclaration;
|
||||
import triangle.abstractSyntaxTrees.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class ConstFormalParameter extends FormalParameter {
|
||||
public class ConstFormalParameter extends FormalParameter implements ConstantDeclaration {
|
||||
|
||||
public ConstFormalParameter(Identifier iAST, TypeDenoter tAST, SourcePosition position) {
|
||||
super(position);
|
||||
@@ -27,14 +28,18 @@ public class ConstFormalParameter extends FormalParameter {
|
||||
T = tAST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDenoter getType() {
|
||||
return T;
|
||||
}
|
||||
|
||||
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
|
||||
return v.visitConstFormalParameter(this, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object fpAST) {
|
||||
if (fpAST instanceof ConstFormalParameter) {
|
||||
var cfpAST = (ConstFormalParameter) fpAST;
|
||||
if (fpAST instanceof ConstFormalParameter cfpAST) {
|
||||
return T.equals(cfpAST.T);
|
||||
} else {
|
||||
return false;
|
||||
|
||||
+12
-1
@@ -14,12 +14,13 @@
|
||||
|
||||
package triangle.abstractSyntaxTrees.formals;
|
||||
|
||||
import triangle.abstractSyntaxTrees.declarations.FunctionDeclaration;
|
||||
import triangle.abstractSyntaxTrees.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class FuncFormalParameter extends FormalParameter {
|
||||
public class FuncFormalParameter extends FormalParameter implements FunctionDeclaration {
|
||||
|
||||
public FuncFormalParameter(Identifier iAST, FormalParameterSequence fpsAST, TypeDenoter tAST,
|
||||
SourcePosition position) {
|
||||
@@ -33,6 +34,16 @@ public class FuncFormalParameter extends FormalParameter {
|
||||
return v.visitFuncFormalParameter(this, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalParameterSequence getFormals() {
|
||||
return FPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDenoter getType() {
|
||||
return T;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object fpAST) {
|
||||
if (fpAST instanceof FuncFormalParameter) {
|
||||
|
||||
+7
-1
@@ -14,11 +14,12 @@
|
||||
|
||||
package triangle.abstractSyntaxTrees.formals;
|
||||
|
||||
import triangle.abstractSyntaxTrees.declarations.ProcedureDeclaration;
|
||||
import triangle.abstractSyntaxTrees.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class ProcFormalParameter extends FormalParameter {
|
||||
public class ProcFormalParameter extends FormalParameter implements ProcedureDeclaration {
|
||||
|
||||
public ProcFormalParameter(Identifier iAST, FormalParameterSequence fpsAST, SourcePosition position) {
|
||||
super(position);
|
||||
@@ -30,6 +31,11 @@ public class ProcFormalParameter extends FormalParameter {
|
||||
return v.visitProcFormalParameter(this, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormalParameterSequence getFormals() {
|
||||
return FPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object fpAST) {
|
||||
if (fpAST instanceof ProcFormalParameter) {
|
||||
|
||||
+8
-3
@@ -14,12 +14,13 @@
|
||||
|
||||
package triangle.abstractSyntaxTrees.formals;
|
||||
|
||||
import triangle.abstractSyntaxTrees.declarations.VariableDeclaration;
|
||||
import triangle.abstractSyntaxTrees.terminals.Identifier;
|
||||
import triangle.abstractSyntaxTrees.types.TypeDenoter;
|
||||
import triangle.abstractSyntaxTrees.visitors.DeclarationVisitor;
|
||||
import triangle.syntacticAnalyzer.SourcePosition;
|
||||
|
||||
public class VarFormalParameter extends FormalParameter {
|
||||
public class VarFormalParameter extends FormalParameter implements VariableDeclaration {
|
||||
|
||||
public VarFormalParameter(Identifier iAST, TypeDenoter tAST, SourcePosition position) {
|
||||
super(position);
|
||||
@@ -27,14 +28,18 @@ public class VarFormalParameter extends FormalParameter {
|
||||
T = tAST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDenoter getType() {
|
||||
return T;
|
||||
}
|
||||
|
||||
public <TArg, TResult> TResult visit(DeclarationVisitor<TArg, TResult> v, TArg arg) {
|
||||
return v.visitVarFormalParameter(this, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object fpAST) {
|
||||
if (fpAST instanceof VarFormalParameter) {
|
||||
VarFormalParameter vfpAST = (VarFormalParameter) fpAST;
|
||||
if (fpAST instanceof VarFormalParameter vfpAST) {
|
||||
return T.equals(vfpAST.T);
|
||||
} else {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user