Compare commits

..

No commits in common. "70a378803076ba43b6b30209bc8a7b2d89c8ff47" and "4c5473827ea312e4bf3706f2d0747e072db6ffc0" have entirely different histories.

10 changed files with 24 additions and 64 deletions

View File

@ -13,17 +13,17 @@ public class ConstructorNode extends MethodNode implements Visitable {
public AccessModifierNode accessType;
public String identifier;
public List<ParameterNode> parameters = new ArrayList<>();
public BlockNode block;
public BlockNode body;
public ConstructorNode(AccessModifierNode accessType, String identifier) {
this.accessType = accessType;
this.identifier = identifier;
}
public ConstructorNode(String accessType, String identifier, BlockNode block) {
public ConstructorNode(String accessType, String identifier, BlockNode body) {
this.accessType = new AccessModifierNode(accessType);
this.identifier = identifier;
this.block = block;
this.body = body;
}
public void addParameter(ParameterNode parameterNode) {

View File

@ -12,7 +12,6 @@ public class DecrementNode implements IStatementExpressionNode {
public AssignableNode assignableExpression;
public DecrementNode(CrementType crementType, AssignableNode assignableExpression) {
this.crementType = crementType;
this.assignableExpression = assignableExpression;
}

View File

@ -11,7 +11,6 @@ public class IncrementNode implements IStatementExpressionNode {
public AssignableNode assignableExpression;
public IncrementNode(CrementType crementType, AssignableNode assignableExpression) {
this.crementType = crementType;
this.assignableExpression = assignableExpression;
}

View File

@ -13,7 +13,7 @@ public class MethodCallNode implements IStatementNode {
public TargetNode target;
public List<ChainedMethodNode> chainedMethods = new ArrayList<>();
public String identifier;
public List<IExpressionNode> parameters = new ArrayList<>();
public List<IExpressionNode> expressions = new ArrayList<>();
public MethodCallNode(TargetNode target, String identifier) {
this.target = target;
@ -24,8 +24,8 @@ public class MethodCallNode implements IStatementNode {
chainedMethods.add(chainedMethode);
}
public void addExpression(IExpressionNode parameter) {
parameters.add(parameter);
public void addExpression(IExpressionNode expression) {
expressions.add(expression);
}
@Override

View File

@ -16,9 +16,6 @@ public class BlockNode implements ASTNode, Visitable {
public void addStatement(IStatementNode statement) {
statements.add(statement);
if(statement instanceof ReturnNode) {
hasReturnStatement = true;
}
}
@Override

View File

@ -10,7 +10,8 @@ import ast.expressions.binaryexpressions.NonCalculationNode;
import ast.expressions.unaryexpressions.MemberAccessNode;
import ast.expressions.unaryexpressions.NotNode;
import ast.expressions.unaryexpressions.UnaryNode;
import ast.members.*;
import ast.members.ConstructorNode;
import ast.members.MemberNode;
import ast.parameters.ParameterNode;
import ast.statementexpressions.AssignNode;
import ast.statementexpressions.AssignableNode;
@ -22,7 +23,6 @@ import ast.statementexpressions.methodcallstatementnexpressions.ChainedMethodNod
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
import ast.statements.*;
import ast.type.AccessModifierNode;
import ast.type.type.*;
import ast.type.EnumValueNode;
import ast.type.ValueNode;
@ -55,47 +55,15 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitConstructorDeclaration(SimpleJavaParser.ConstructorDeclarationContext ctx) {
ConstructorNode constructorNode = new ConstructorNode(ctx.AccessModifier().getText(), ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
if(ctx.parameterList() != null) {
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
constructorNode.addParameter((ParameterNode) visit(parameter));
}
}
return constructorNode;
}
@Override
public ASTNode visitMethodDeclaration(SimpleJavaParser.MethodDeclarationContext ctx) {
if(ctx.MainMethodDeclaration() != null) {
return new MainMethodNode((BlockNode) visit(ctx.blockStatement()));
} else {
if(ctx.type() != null) {
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), createTypeNode(ctx.type().getText()), false, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
if(ctx.parameterList() != null) {
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
methodNode.addParameter((ParameterNode) visit(parameter));
}
}
return methodNode;
} else {
MethodNode methodNode = new MethodNode(ctx.AccessModifier().getText(), null, true, ctx.Identifier().getText(), (BlockNode) visit(ctx.blockStatement()));
if(ctx.parameterList() != null) {
for(SimpleJavaParser.ParameterContext parameter : ctx.parameterList().parameter()) {
methodNode.addParameter((ParameterNode) visit(parameter));
}
}
return methodNode;
}
}
}
@Override
public ASTNode visitFieldDeclaration(SimpleJavaParser.FieldDeclarationContext ctx) {
return new FieldNode(new AccessModifierNode(ctx.AccessModifier().getText()), createTypeNode(ctx.type().getText()), ctx.Identifier().getText());
}
@Override
public ASTNode visitParameter(SimpleJavaParser.ParameterContext ctx) {
return new ParameterNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText());
return new ParameterNode(new TypeNode(ctx.type().getText()), ctx.Identifier().getText());
}
@Override
@ -125,7 +93,7 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
@Override
public ASTNode visitLocalVariableDeclaration(SimpleJavaParser.LocalVariableDeclarationContext ctx) {
return new LocalVariableDeclarationNode(createTypeNode(ctx.type().getText()), ctx.Identifier().getText(), ctx.Assign().getText(), (IExpressionNode) visit(ctx.expression()));
return new LocalVariableDeclarationNode(new TypeNode(ctx.type().getText()), ctx.Identifier().getText(), ctx.Assign().getText(), (IExpressionNode) visit(ctx.expression()));
}
@Override
@ -134,9 +102,6 @@ public class ASTBuilder extends SimpleJavaBaseVisitor<ASTNode> {
for(SimpleJavaParser.StatementContext statement : ctx.statement()) {
blockNode.addStatement((IStatementNode) visit(statement));
}
if(!blockNode.hasReturnStatement) {
blockNode.addStatement(new ReturnNode(null));
}
return blockNode;
}

View File

@ -228,10 +228,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
return null;
}
/*@Override
@Override
public TypeCheckResult analyze(ForNode toCheck) {
return null;
}*/
}
@Override
public TypeCheckResult analyze(AssignNode toCheck) {

View File

@ -38,7 +38,7 @@ public interface SemanticVisitor {
TypeCheckResult analyze(ElseNode toCheck);
//TypeCheckResult analyze(ForNode toCheck);
TypeCheckResult analyze(ForNode toCheck);
TypeCheckResult analyze(AssignNode toCheck);

View File

@ -42,7 +42,7 @@ public class Mocker {
//Statements
//Block
methodNode.block = new ast.statements.BlockNode();
methodNode.block = new ast.block.BlockStatementNode();
c.members.add(methodNode);
@ -57,7 +57,7 @@ public class Mocker {
ClassNode c = new ClassNode();
MethodNode methodNode = new MethodNode();
methodNode.block = new ast.statements.BlockNode();
methodNode.block = new ast.block.BlockStatementNode();
methodNode.setType(new BaseType(TypeEnum.INT));
methodNode.setIdentifier("testMethod");
@ -65,7 +65,7 @@ public class Mocker {
c.members.add(methodNode);
MethodNode methodNode1 = new MethodNode();
methodNode1.block = new ast.statements.BlockNode();
methodNode1.block = new ast.block.BlockStatementNode();
methodNode1.setType(new BaseType(TypeEnum.INT));
methodNode1.setIdentifier("testMethod");
@ -83,13 +83,13 @@ public class Mocker {
ClassNode c = new ClassNode();
MethodNode methodNode = new MethodNode();
methodNode.block = new ast.statements.BlockNode();
methodNode.block = new ast.block.BlockStatementNode();
methodNode.setIdentifier("testMethod");
c.members.add(methodNode);
MethodNode methodNode1 = new MethodNode();
methodNode1.block = new ast.statements.BlockNode();
methodNode1.block = new ast.block.BlockStatementNode();
methodNode1.setIdentifier("testMethod1");
c.members.add(methodNode1);

View File

@ -1,10 +1,10 @@
package semantic;
import ast.*;
import ast.members.FieldNode;
import ast.members.MemberNode;
import ast.members.MethodNode;
import ast.parameters.ParameterNode;
import ast.member.FieldNode;
import ast.member.MemberNode;
import ast.member.MethodNode;
import ast.parameter.ParameterNode;
import org.junit.jupiter.api.Test;
import semantic.exeptions.AlreadyDeclearedException;