diff --git a/src/main/java/CompilerInput.txt b/src/main/java/CompilerInput.txt index b784cf7..918c686 100644 --- a/src/main/java/CompilerInput.txt +++ b/src/main/java/CompilerInput.txt @@ -5,9 +5,7 @@ public class Example { public static int testMethod(char b){ int a; - boolean b; - char c; - b = 3; + int a; } diff --git a/src/main/java/ast/ClassNode.java b/src/main/java/ast/ClassNode.java index 2f09f41..947a977 100644 --- a/src/main/java/ast/ClassNode.java +++ b/src/main/java/ast/ClassNode.java @@ -11,7 +11,7 @@ import java.util.List; import bytecode.visitor.ClassVisitor; import semantic.SemanticVisitor; import typechecker.TypeCheckResult; -import typechecker.Visitable; +import visitor.Visitable; public class ClassNode implements ASTNode, Visitable { public String identifier; diff --git a/src/main/java/ast/ProgramNode.java b/src/main/java/ast/ProgramNode.java index 116c5a2..1aac1b1 100644 --- a/src/main/java/ast/ProgramNode.java +++ b/src/main/java/ast/ProgramNode.java @@ -6,7 +6,7 @@ import java.util.List; import bytecode.visitor.ProgramVisitor; import semantic.SemanticVisitor; import typechecker.TypeCheckResult; -import typechecker.Visitable; +import visitor.Visitable; public class ProgramNode implements ASTNode, Visitable{ public List classes = new ArrayList<>(); diff --git a/src/main/java/ast/VarNode.java b/src/main/java/ast/VarNode.java index 7ef6350..9349eb4 100644 --- a/src/main/java/ast/VarNode.java +++ b/src/main/java/ast/VarNode.java @@ -2,7 +2,7 @@ package ast; import semantic.SemanticVisitor; import typechecker.TypeCheckResult; -import typechecker.Visitable; +import visitor.Visitable; public class VarNode implements ASTNode, Visitable { diff --git a/src/main/java/ast/expression/BinaryExpressionNode.java b/src/main/java/ast/expression/BinaryExpressionNode.java index 9260d3b..c912408 100644 --- a/src/main/java/ast/expression/BinaryExpressionNode.java +++ b/src/main/java/ast/expression/BinaryExpressionNode.java @@ -2,8 +2,9 @@ package ast.expression; import semantic.SemanticVisitor; import typechecker.TypeCheckResult; +import visitor.Visitable; -public class BinaryExpressionNode implements ExpressionNode { +public class BinaryExpressionNode implements ExpressionNode, Visitable { public ExpressionNode left; public ExpressionNode right; public String operator; // Stores the operator as a string (e.g., "+", "-", "&&") @@ -16,6 +17,6 @@ public class BinaryExpressionNode implements ExpressionNode { @Override public TypeCheckResult accept(SemanticVisitor visitor) { - return null; + return visitor.analyze(this); } } \ No newline at end of file diff --git a/src/main/java/ast/expression/ExpressionNode.java b/src/main/java/ast/expression/ExpressionNode.java index 7e9be2d..e790795 100644 --- a/src/main/java/ast/expression/ExpressionNode.java +++ b/src/main/java/ast/expression/ExpressionNode.java @@ -1,7 +1,7 @@ package ast.expression; import ast.ASTNode; -import typechecker.Visitable; +import visitor.Visitable; public interface ExpressionNode extends ASTNode, Visitable { diff --git a/src/main/java/ast/expression/IdentifierExpressionNode.java b/src/main/java/ast/expression/IdentifierExpressionNode.java index 0ad57d0..1bb8d56 100644 --- a/src/main/java/ast/expression/IdentifierExpressionNode.java +++ b/src/main/java/ast/expression/IdentifierExpressionNode.java @@ -1,11 +1,15 @@ package ast.expression; +import ast.type.TypeNode; import semantic.SemanticVisitor; -import typechecker.TypeCheckResult; -import typechecker.Visitable; -public class IdentifierExpressionNode implements ExpressionNode { +import typechecker.TypeCheckResult; +import visitor.Visitable; + +public class IdentifierExpressionNode implements ExpressionNode, Visitable { public String name; + public TypeNode type; + public IdentifierExpressionNode(String name) { this.name = name; @@ -13,6 +17,6 @@ public class IdentifierExpressionNode implements ExpressionNode { @Override public TypeCheckResult accept(SemanticVisitor visitor) { - return null; + return visitor.analyze(this); } } diff --git a/src/main/java/ast/expression/UnaryExpressionNode.java b/src/main/java/ast/expression/UnaryExpressionNode.java index 2c93670..24d1832 100644 --- a/src/main/java/ast/expression/UnaryExpressionNode.java +++ b/src/main/java/ast/expression/UnaryExpressionNode.java @@ -2,8 +2,9 @@ package ast.expression; import semantic.SemanticVisitor; import typechecker.TypeCheckResult; +import visitor.Visitable; -public class UnaryExpressionNode implements ExpressionNode { +public class UnaryExpressionNode implements ExpressionNode, Visitable { public ExpressionNode expression; public String operator; // Stores the operator (e.g., "-", "!") @@ -14,6 +15,6 @@ public class UnaryExpressionNode implements ExpressionNode { @Override public TypeCheckResult accept(SemanticVisitor visitor) { - return null; + return visitor.analyze(this); } } diff --git a/src/main/java/ast/member/ConstructorNode.java b/src/main/java/ast/member/ConstructorNode.java index c729dc1..998d727 100644 --- a/src/main/java/ast/member/ConstructorNode.java +++ b/src/main/java/ast/member/ConstructorNode.java @@ -2,7 +2,7 @@ package ast.member; import ast.type.AccessTypeNode; import bytecode.visitor.MethodVisitor; -import typechecker.Visitable; +import visitor.Visitable; public class ConstructorNode extends MethodNode implements Visitable { public ConstructorNode(AccessTypeNode visibility, String name) { diff --git a/src/main/java/ast/member/FieldNode.java b/src/main/java/ast/member/FieldNode.java index 70880c5..60c5411 100644 --- a/src/main/java/ast/member/FieldNode.java +++ b/src/main/java/ast/member/FieldNode.java @@ -5,7 +5,7 @@ import ast.type.TypeNode; import bytecode.visitor.ClassVisitor; import semantic.SemanticVisitor; import typechecker.TypeCheckResult; -import typechecker.Visitable; +import visitor.Visitable; public class FieldNode implements MemberNode, Visitable { public AccessTypeNode accessTypeNode; diff --git a/src/main/java/ast/member/MethodNode.java b/src/main/java/ast/member/MethodNode.java index 88ed182..c50f6af 100644 --- a/src/main/java/ast/member/MethodNode.java +++ b/src/main/java/ast/member/MethodNode.java @@ -3,15 +3,15 @@ package ast.member; import ast.parameter.ParameterListNode; import ast.statement.StatementNode; import ast.type.AccessTypeNode; -import ast.type.TypeNode; import java.util.ArrayList; import java.util.List; +import ast.type.TypeNode; import bytecode.visitor.MethodVisitor; import semantic.SemanticVisitor; import typechecker.TypeCheckResult; -import typechecker.Visitable; +import visitor.Visitable; public class MethodNode implements MemberNode, Visitable { public AccessTypeNode visibility; diff --git a/src/main/java/ast/statement/AssignmentStatementNode.java b/src/main/java/ast/statement/AssignmentStatementNode.java index 7efbd73..9f6a395 100644 --- a/src/main/java/ast/statement/AssignmentStatementNode.java +++ b/src/main/java/ast/statement/AssignmentStatementNode.java @@ -4,7 +4,7 @@ import ast.VarNode; import ast.expression.ExpressionNode; import semantic.SemanticVisitor; import typechecker.TypeCheckResult; -import typechecker.Visitable; +import visitor.Visitable; public class AssignmentStatementNode extends StatementNode implements Visitable { public VarNode varNode; diff --git a/src/main/java/ast/statement/IfStatementNode.java b/src/main/java/ast/statement/IfStatementNode.java index 93eec91..3f585dd 100644 --- a/src/main/java/ast/statement/IfStatementNode.java +++ b/src/main/java/ast/statement/IfStatementNode.java @@ -1,6 +1,8 @@ package ast.statement; import ast.expression.ExpressionNode; +import semantic.SemanticVisitor; +import typechecker.TypeCheckResult; public class IfStatementNode extends StatementNode { public ExpressionNode condition; @@ -12,4 +14,9 @@ public class IfStatementNode extends StatementNode { this.thenStatement = thenStatement; this.elseStatement = elseStatement; } + + @Override + public TypeCheckResult accept(SemanticVisitor visitor) { + return visitor.analyze(this); + } } \ No newline at end of file diff --git a/src/main/java/ast/statement/ReturnStatementNode.java b/src/main/java/ast/statement/ReturnStatementNode.java index 4ca4dfa..c5e4d6b 100644 --- a/src/main/java/ast/statement/ReturnStatementNode.java +++ b/src/main/java/ast/statement/ReturnStatementNode.java @@ -1,6 +1,8 @@ package ast.statement; import ast.expression.ExpressionNode; +import semantic.SemanticVisitor; +import typechecker.TypeCheckResult; public class ReturnStatementNode extends StatementNode { public ExpressionNode expression; @@ -8,4 +10,9 @@ public class ReturnStatementNode extends StatementNode { public ReturnStatementNode(ExpressionNode expression) { this.expression = expression; } + + @Override + public TypeCheckResult accept(SemanticVisitor visitor) { + return visitor.analyze(this); + } } \ No newline at end of file diff --git a/src/main/java/ast/statement/StatementNode.java b/src/main/java/ast/statement/StatementNode.java index 6c90f8c..eff1804 100644 --- a/src/main/java/ast/statement/StatementNode.java +++ b/src/main/java/ast/statement/StatementNode.java @@ -1,7 +1,8 @@ package ast.statement; import ast.ASTNode; +import visitor.Visitable; -public abstract class StatementNode implements ASTNode { +public abstract class StatementNode implements ASTNode, Visitable { } diff --git a/src/main/java/ast/statement/VariableDeclarationStatementNode.java b/src/main/java/ast/statement/VariableDeclarationStatementNode.java index e7f6e32..4302177 100644 --- a/src/main/java/ast/statement/VariableDeclarationStatementNode.java +++ b/src/main/java/ast/statement/VariableDeclarationStatementNode.java @@ -1,7 +1,9 @@ package ast.statement; -import ast.type.TypeNode; import ast.expression.ExpressionNode; +import ast.type.TypeNode; +import semantic.SemanticVisitor; +import typechecker.TypeCheckResult; public class VariableDeclarationStatementNode extends StatementNode { public TypeNode type; @@ -12,4 +14,9 @@ public class VariableDeclarationStatementNode extends StatementNode { this.identifier = identifier; this.expression = expression; } + + @Override + public TypeCheckResult accept(SemanticVisitor visitor) { + return visitor.analyze(this); + } } \ No newline at end of file diff --git a/src/main/java/ast/statement/WhileStatementNode.java b/src/main/java/ast/statement/WhileStatementNode.java index e6a10b1..a3f4007 100644 --- a/src/main/java/ast/statement/WhileStatementNode.java +++ b/src/main/java/ast/statement/WhileStatementNode.java @@ -1,6 +1,8 @@ package ast.statement; import ast.expression.ExpressionNode; +import semantic.SemanticVisitor; +import typechecker.TypeCheckResult; public class WhileStatementNode extends StatementNode { public ExpressionNode condition; @@ -10,4 +12,9 @@ public class WhileStatementNode extends StatementNode { this.condition = condition; this.body = body; } + + @Override + public TypeCheckResult accept(SemanticVisitor visitor) { + return visitor.analyze(this); + } } diff --git a/src/main/java/ast/type/BaseTypeNode.java b/src/main/java/ast/type/BaseTypeNode.java index 81cdf43..2d871ab 100644 --- a/src/main/java/ast/type/BaseTypeNode.java +++ b/src/main/java/ast/type/BaseTypeNode.java @@ -1,6 +1,8 @@ package ast.type; -public class BaseTypeNode implements TypeNode{ +import ast.ASTNode; + +public class BaseTypeNode implements ASTNode, TypeNode { public EnumTypeNode enumType; diff --git a/src/main/java/ast/type/ReferenceTypeNode.java b/src/main/java/ast/type/ReferenceTypeNode.java index 1937054..88225f3 100644 --- a/src/main/java/ast/type/ReferenceTypeNode.java +++ b/src/main/java/ast/type/ReferenceTypeNode.java @@ -1,4 +1,6 @@ package ast.type; -public class ReferenceTypeNode implements TypeNode{ +import ast.ASTNode; + +public class ReferenceTypeNode implements ASTNode, TypeNode { } diff --git a/src/main/java/bytecode/Mapper.java b/src/main/java/bytecode/Mapper.java index fb4f484..08985a6 100644 --- a/src/main/java/bytecode/Mapper.java +++ b/src/main/java/bytecode/Mapper.java @@ -2,6 +2,7 @@ package bytecode; import ast.type.*; import org.objectweb.asm.Opcodes; +import ast.type.BaseTypeNode; public class Mapper { public int mapAccesTypeToOpcode(AccessTypeNode type) { diff --git a/src/main/java/parser/ASTBuilder.java b/src/main/java/parser/ASTBuilder.java index 3cff8a7..ee61b9b 100644 --- a/src/main/java/parser/ASTBuilder.java +++ b/src/main/java/parser/ASTBuilder.java @@ -13,10 +13,12 @@ import ast.parameter.ParameterNode; import ast.statement.*; import ast.type.*; import org.antlr.v4.runtime.tree.TerminalNode; + import java.util.ArrayList; import java.util.List; import parser.generated.*; import parser.generated.SimpleJavaParser.LiteralContext; +import ast.type.BaseTypeNode; public class ASTBuilder extends SimpleJavaBaseVisitor { @Override @@ -74,9 +76,9 @@ public class ASTBuilder extends SimpleJavaBaseVisitor { @Override public ASTNode visitParameter(SimpleJavaParser.ParameterContext ctx) { - TypeNode type = (TypeNode) visit(ctx.type()); + TypeNode typeNode = (TypeNode) visit(ctx.type()); String identifier = ctx.IDENTIFIER().getText(); - return new ParameterNode(type, identifier); + return new ParameterNode(typeNode, identifier); } @Override diff --git a/src/main/java/semantic/Scope.java b/src/main/java/semantic/Scope.java new file mode 100644 index 0000000..ab5c0cb --- /dev/null +++ b/src/main/java/semantic/Scope.java @@ -0,0 +1,36 @@ +package semantic; + +import ast.type.TypeNode; + +import java.util.HashMap; +import java.util.Stack; + +public class Scope { + + private Stack> localVars; + + public void addLocalVar(String name, TypeNode type) { + if (this.contains(name)) { + throw new RuntimeException("Variable " + name + " already exists in this scope"); + } + localVars.peek().put(name, type); + } + + public boolean contains(String name) { + for (HashMap map : localVars) { + if (map.containsKey(name)) { + return true; + } + } + return false; + } + + public void pushScope() { + localVars.push(new HashMap()); + } + + public void popScope() { + localVars.pop(); + } + +} diff --git a/src/main/java/semantic/SemanticAnalyzer.java b/src/main/java/semantic/SemanticAnalyzer.java index 06eab00..7a6002b 100644 --- a/src/main/java/semantic/SemanticAnalyzer.java +++ b/src/main/java/semantic/SemanticAnalyzer.java @@ -2,101 +2,145 @@ package semantic; import ast.*; -import ast.expression.ExpressionNode; -import ast.member.ConstructorNode; +import ast.expression.BinaryExpressionNode; +import ast.expression.IdentifierExpressionNode; +import ast.expression.UnaryExpressionNode; import ast.member.FieldNode; import ast.member.MemberNode; import ast.member.MethodNode; -import ast.statement.AssignmentStatementNode; -import ast.statement.StatementNode; +import ast.statement.*; + import java.util.ArrayList; import java.util.List; -import ast.type.TypeNode; import typechecker.TypeCheckResult; public class SemanticAnalyzer implements SemanticVisitor { - private ArrayList currentFields = new ArrayList<>(); + private ArrayList currentFields = new ArrayList<>(); - public static ASTNode generateTast(ASTNode node) throws RuntimeException { - SemanticAnalyzer semanticCheck = new SemanticAnalyzer(); - ProgramNode programNode = (ProgramNode) node; - var result = programNode.accept(semanticCheck); - if (result.isValid()) { - return node; - } else { - throw new RuntimeException("Not Valid"); - } - } + private Scope currentScope; - @Override - public TypeCheckResult analyze(ProgramNode node) { - - var valid = true; - - List classes = node.classes; - for (ClassNode classNode : classes) { - var result = classNode.accept(this); - valid = valid && result.isValid(); - } - return new TypeCheckResult(valid, null); - } - - @Override - public TypeCheckResult analyze(ClassNode classNode) { - var valid = true; - List members = classNode.members; - for (MemberNode memberNode : members) { - if (memberNode instanceof FieldNode fieldNode) { - var result = fieldNode.accept(this); - valid = valid && result.isValid(); - } else if (memberNode instanceof MethodNode methodNode) { - var result = methodNode.accept(this); - valid = valid && result.isValid(); - } + public static ASTNode generateTast(ASTNode node) throws RuntimeException { + SemanticAnalyzer semanticCheck = new SemanticAnalyzer(); + ProgramNode programNode = (ProgramNode) node; + var result = programNode.accept(semanticCheck); + if (result.isValid()) { + return node; + } else { + throw new RuntimeException("Not Valid"); + } } - return new TypeCheckResult(valid, null); + @Override + public TypeCheckResult analyze(ProgramNode node) { - } + var valid = true; - @Override - public TypeCheckResult analyze(MethodNode methodNode) { - var valid = true; - List statements = methodNode.statements; - for (StatementNode statement : statements) { - if(statement instanceof AssignmentStatementNode assignmentStatementNode) { - var result = assignmentStatementNode.accept(this); - valid = valid && result.isValid(); - } + List classes = node.classes; + for (ClassNode classNode : classes) { + var result = classNode.accept(this); + valid = valid && result.isValid(); + } + return new TypeCheckResult(valid, null); } - return new TypeCheckResult(valid, null); - } - @Override - public TypeCheckResult analyze(FieldNode toCheck) { - if(currentFields.contains(toCheck.identifier)){ - throw new RuntimeException(toCheck.identifier + " Is Already Declared"); - }else { - currentFields.add(toCheck.identifier); + @Override + public TypeCheckResult analyze(ClassNode classNode) { + var valid = true; + List members = classNode.members; + for (MemberNode memberNode : members) { + if (memberNode instanceof FieldNode fieldNode) { + var result = fieldNode.accept(this); + valid = valid && result.isValid(); + } else if (memberNode instanceof MethodNode methodNode) { + var result = methodNode.accept(this); + valid = valid && result.isValid(); + } + } + + return new TypeCheckResult(valid, null); + } - return new TypeCheckResult(true, null); - } - @Override - public TypeCheckResult analyze(AssignmentStatementNode assignmentStatementNode) { - if(assignmentStatementNode.expression instanceof LiteralNode literalNode) { - TypeCheckResult varResult = assignmentStatementNode.varNode.accept(this); - TypeCheckResult expressionResult = assignmentStatementNode.expression.accept(this); + @Override + public TypeCheckResult analyze(MethodNode methodNode) { + var valid = true; + + currentLocalScope.pushScope(); + + List statements = methodNode.statements; + for (StatementNode statement : statements) { + if (statement instanceof AssignmentStatementNode assignmentStatementNode) { + var result = assignmentStatementNode.accept(this); + valid = valid && result.isValid(); + } else if (statement instanceof VariableDeclarationStatementNode variableDeclarationStatementNode) { + var result = variableDeclarationStatementNode.accept(this); + valid = valid && result.isValid(); + } + } + return new TypeCheckResult(valid, null); } - return new TypeCheckResult(true, null); - } - @Override - public TypeCheckResult analyze(VarNode toCheck) { - return new TypeCheckResult(true, null); - } + @Override + public TypeCheckResult analyze(FieldNode toCheck) { + if (currentFields.contains(toCheck.identifier)) { + throw new RuntimeException(toCheck.identifier + " Is Already Declared"); + } else { + currentFields.add(toCheck.identifier); + } + return new TypeCheckResult(true, null); + } + + @Override + public TypeCheckResult analyze(AssignmentStatementNode assignmentStatementNode) { + if (assignmentStatementNode.expression instanceof LiteralNode literalNode) { + TypeCheckResult varResult = assignmentStatementNode.varNode.accept(this); + TypeCheckResult expressionResult = assignmentStatementNode.expression.accept(this); + } + return new TypeCheckResult(true, null); + } + + @Override + public TypeCheckResult analyze(VarNode toCheck) { + return new TypeCheckResult(true, null); + } + + @Override + public TypeCheckResult analyze(BinaryExpressionNode toCheck) { + return null; + } + + @Override + public TypeCheckResult analyze(IdentifierExpressionNode toCheck) { + return null; + } + + @Override + public TypeCheckResult analyze(UnaryExpressionNode toCheck) { + return null; + } + + @Override + public TypeCheckResult analyze(VariableDeclarationStatementNode toCheck) { + + return new TypeCheckResult(true, null); + } + + @Override + public TypeCheckResult analyze(IfStatementNode toCheck) { + return null; + } + + @Override + public TypeCheckResult analyze(ReturnStatementNode toCheck) { + return null; + } + + @Override + public TypeCheckResult analyze(WhileStatementNode toCheck) { + return null; + } } \ No newline at end of file diff --git a/src/main/java/semantic/SemanticVisitor.java b/src/main/java/semantic/SemanticVisitor.java index 57aabf6..99d0cb8 100644 --- a/src/main/java/semantic/SemanticVisitor.java +++ b/src/main/java/semantic/SemanticVisitor.java @@ -4,9 +4,12 @@ package semantic; import ast.ClassNode; import ast.ProgramNode; import ast.VarNode; +import ast.expression.BinaryExpressionNode; +import ast.expression.IdentifierExpressionNode; +import ast.expression.UnaryExpressionNode; import ast.member.FieldNode; import ast.member.MethodNode; -import ast.statement.AssignmentStatementNode; +import ast.statement.*; import typechecker.TypeCheckResult; public interface SemanticVisitor { @@ -22,41 +25,18 @@ public interface SemanticVisitor { TypeCheckResult analyze(AssignmentStatementNode toCheck); TypeCheckResult analyze(VarNode toCheck); -// -// TypeCheckResult typeCheck(ForStmt forStmt); -// -// TypeCheckResult typeCheck(WhileStmt whileStmt); -// -// TypeCheckResult typeCheck(ReturnStmt returnStmt); -// -// TypeCheckResult typeCheck(LocalVarDecl localVarDecl); -// -// TypeCheckResult typeCheck(IfStmt ifStmt); -// -// TypeCheckResult typeCheck(Block block); -// -// TypeCheckResult typeCheck(NewDecl newDecl); -// -// TypeCheckResult typeCheck(MethodCall methodCall); -// -// TypeCheckResult typeCheck(Unary unary); -// -// TypeCheckResult typeCheck(This aThis); -// -// TypeCheckResult typeCheck(Null aNull); -// -// TypeCheckResult typeCheck(LocalOrFieldVar localOrFieldVar); -// -// TypeCheckResult typeCheck(IntegerExpr integerExpr); -// -// TypeCheckResult typeCheck(InstVar instVar); -// -// TypeCheckResult typeCheck(CharExpr charExpr); -// -// TypeCheckResult typeCheck(BoolExpr boolExpr); -// -// TypeCheckResult typeCheck(Binary binary); -// -// TypeCheckResult typeCheck(StringExpr instVar); + TypeCheckResult analyze(BinaryExpressionNode toCheck); + + TypeCheckResult analyze(IdentifierExpressionNode toCheck); + + TypeCheckResult analyze(UnaryExpressionNode toCheck); + + TypeCheckResult analyze(VariableDeclarationStatementNode toCheck); + + TypeCheckResult analyze(IfStatementNode toCheck); + + TypeCheckResult analyze(ReturnStatementNode toCheck); + + TypeCheckResult analyze(WhileStatementNode toCheck); } \ No newline at end of file diff --git a/src/main/java/typechecker/Type.java b/src/main/java/typechecker/Type.java deleted file mode 100644 index 89b1c16..0000000 --- a/src/main/java/typechecker/Type.java +++ /dev/null @@ -1,5 +0,0 @@ -package typechecker; - -public interface Type { - boolean equals(Object obj); -} \ No newline at end of file diff --git a/src/main/java/typechecker/TypeCheckResult.java b/src/main/java/typechecker/TypeCheckResult.java index 9068c0d..12143b2 100644 --- a/src/main/java/typechecker/TypeCheckResult.java +++ b/src/main/java/typechecker/TypeCheckResult.java @@ -1,12 +1,14 @@ package typechecker; +import ast.type.TypeNode; + public class TypeCheckResult { private boolean valid; - private Type type; + private TypeNode type; - public TypeCheckResult(boolean valid, Type type) { + public TypeCheckResult(boolean valid, TypeNode type) { this.valid = valid; this.type = type; } @@ -15,7 +17,7 @@ public class TypeCheckResult { return valid; } - public Type getType() { + public TypeNode getType() { return type; } } \ No newline at end of file diff --git a/src/main/java/typechecker/Typer.java b/src/main/java/typechecker/Typer.java deleted file mode 100644 index 3f8872a..0000000 --- a/src/main/java/typechecker/Typer.java +++ /dev/null @@ -1,9 +0,0 @@ -package typechecker; - -public class Typer { - - public static void Typeify(){ - - } - -} diff --git a/src/main/java/typechecker/Visitable.java b/src/main/java/visitor/Visitable.java similarity index 88% rename from src/main/java/typechecker/Visitable.java rename to src/main/java/visitor/Visitable.java index 111c58f..bd69777 100644 --- a/src/main/java/typechecker/Visitable.java +++ b/src/main/java/visitor/Visitable.java @@ -1,9 +1,10 @@ -package typechecker; +package visitor; import bytecode.visitor.ClassVisitor; import bytecode.visitor.MethodVisitor; import bytecode.visitor.ProgramVisitor; import semantic.SemanticVisitor; +import typechecker.TypeCheckResult; public interface Visitable { default void accept(ProgramVisitor programVisitor) {