diff --git a/src/test/java/semantic/Mocker.java b/src/test/java/semantic/Mocker.java deleted file mode 100644 index 683b385..0000000 --- a/src/test/java/semantic/Mocker.java +++ /dev/null @@ -1,102 +0,0 @@ -package semantic; - -import ast.*; -import ast.members.FieldNode; -import ast.members.MethodNode; -import ast.parameters.ParameterNode; -import ast.type.AccessModifierNode; -import ast.type.type.*; - -public class Mocker { - - public static ASTNode mockTwoSameFields(){ - ProgramNode p = new ProgramNode(); - - ClassNode c = new ClassNode(); - c.identifier = "testClass"; - - FieldNode f1 = new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"); - - c.members.add(f1); - - FieldNode f2 = new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a"); - - c.members.add(f2); - - p.classes.add(c); - return p; - } - - public static ASTNode mockSimpleMethod(){ - ProgramNode p = new ProgramNode(); - - ClassNode c = new ClassNode(); - - MethodNode methodNode = new MethodNode(); - - //Parameter - ParameterNode parameterNode = new ParameterNode(new BaseType(TypeEnum.INT), "a"); - - methodNode.addParameter(parameterNode); - - //Statements - - //Block - methodNode.block = new ast.statements.BlockNode(); - - c.members.add(methodNode); - - p.classes.add(c); - - return p; - } - - public static ASTNode mockTwoSameMethods(){ - ProgramNode p = new ProgramNode(); - - ClassNode c = new ClassNode(); - - MethodNode methodNode = new MethodNode(); - methodNode.block = new ast.statements.BlockNode(); - methodNode.setType(new BaseType(TypeEnum.INT)); - - methodNode.setIdentifier("testMethod"); - - c.members.add(methodNode); - - MethodNode methodNode1 = new MethodNode(); - methodNode1.block = new ast.statements.BlockNode(); - methodNode1.setType(new BaseType(TypeEnum.INT)); - - methodNode1.setIdentifier("testMethod"); - - c.members.add(methodNode1); - - p.classes.add(c); - - return p; - } - - public static ASTNode mockTwoDifferentMethods(){ - ProgramNode p = new ProgramNode(); - - ClassNode c = new ClassNode(); - - MethodNode methodNode = new MethodNode(); - methodNode.block = new ast.statements.BlockNode(); - methodNode.setIdentifier("testMethod"); - - c.members.add(methodNode); - - MethodNode methodNode1 = new MethodNode(); - methodNode1.block = new ast.statements.BlockNode(); - methodNode1.setIdentifier("testMethod1"); - - c.members.add(methodNode1); - - p.classes.add(c); - - return p; - } - -} diff --git a/src/test/java/semantic/SemanticTest.java b/src/test/java/semantic/SemanticTest.java deleted file mode 100644 index 7b8ad6a..0000000 --- a/src/test/java/semantic/SemanticTest.java +++ /dev/null @@ -1,114 +0,0 @@ -package semantic; - -import ast.*; -import ast.members.FieldNode; -import ast.members.MemberNode; -import ast.members.MethodNode; -import ast.parameters.ParameterNode; - -import org.junit.jupiter.api.Test; -import semantic.exeptions.AlreadyDeclearedException; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -public class SemanticTest { - - -// @Test -// public void alreadyDeclaredLocalFieldVar() { -// ProgramNode programNode = new ProgramNode(); -// List classList = new ArrayList<>(); -// AccessTypeNode accessTypeNode = new AccessTypeNode(EnumAccessTypeNode.PUBLIC); -// ClassNode classNode = new ClassNode(accessTypeNode, "testClass"); -// -// SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer(); -// ASTNode tast = semanticAnalyzer.generateTast(ast); -// -// MemberNode memberNode2 = new FieldNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "testVar"); -// classNode.members.add(memberNode2); -// -// classList.add(classNode); -// programNode.classes = classList; -// -// ASTNode typedAst = SemanticAnalyzer.generateTast(programNode); -// -// assertEquals(1, SemanticAnalyzer.errors.size()); -// assertInstanceOf(AlreadyDeclearedException.class, SemanticAnalyzer.errors.getFirst()); -// assertNull(typedAst); -// } -// -// @Test -// public void shouldWorkWithNoError() { -// ProgramNode programNode = new ProgramNode(); -// List classList = new ArrayList<>(); -// AccessTypeNode accessTypeNode = new AccessTypeNode(EnumAccessTypeNode.PUBLIC); -// ClassNode classNode = new ClassNode(accessTypeNode, "testClass"); -// -// SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer(); -// ASTNode tast = semanticAnalyzer.generateTast(ast); -// -// assertEquals(semanticAnalyzer.errors.size(), 0); -// assertNotNull(tast); -// -// MemberNode memberNode3 = getMemberNode(accessTypeNode); -// classNode.members.add(memberNode3); -// -// classList.add(classNode); -// programNode.classes = classList; -// -// ASTNode typedAst = SemanticAnalyzer.generateTast(programNode); -// -// assertEquals(0, SemanticAnalyzer.errors.size()); -// assertEquals(programNode, typedAst); -// } -// -// /** -// * This method is used to create a MemberNode representing a method. -// * It first creates a list of ParameterNodes and adds a ParameterNode to it. -// * Then, it creates a ParameterListNode using the list of ParameterNodes. -// * After that, it creates a list of StatementNodes and adds a StatementNode to it by calling the getStatementNode method. -// * Finally, it creates a MethodNode using the provided AccessTypeNode, a BaseTypeNode representing the return type of the method, -// * the method name, the ParameterListNode, and the list of StatementNodes, and returns this MethodNode. -// * -// * @param accessTypeNode The AccessTypeNode representing the access type of the method. -// * @return The created MemberNode representing the method. -// */ -//private static MemberNode getMemberNode(AccessTypeNode accessTypeNode) { -// List parameterNodeList = new ArrayList<>(); -// ParameterNode parameterNode1 = new ParameterNode(new BaseTypeNode(EnumTypeNode.INT), "param1"); -// parameterNodeList.add(parameterNode1); -// ParameterListNode parameterListNode = new ParameterListNode(parameterNodeList); -// -// List statementNodeList = new ArrayList<>(); -// -// StatementNode statementNode1 = getStatementNode(); -// statementNodeList.add(statementNode1); -// -// return new MethodNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "testVar2", parameterListNode, statementNodeList); -//} -// -// /** -// * This method is used to create a StatementNode for an assignment operation. -// * It first creates two IdentifierExpressionNodes for 'this' and 'objectVar'. -// * Then, it creates a BinaryExpressionNode to represent the operation 'this.objectVar'. -// * After that, it creates a LiteralNode to represent the integer value 1. -// * Finally, it creates another BinaryExpressionNode to represent the assignment operation 'this.objectVar = 1', -// * and wraps this expression in an AssignmentStatementNode. -// * -// * @return The created AssignmentStatementNode representing the assignment operation 'this.objectVar = 1'. -// */ -//private static StatementNode getStatementNode() { -// ExpressionNode expressionNodeObjectVariableLeft = new IdentifierExpressionNode("this"); -// ExpressionNode expressionNodeObjectVariableRight = new IdentifierExpressionNode("objectVar"); -// -// ExpressionNode expressionNodeLeft = new BinaryExpressionNode(expressionNodeObjectVariableLeft, expressionNodeObjectVariableRight, ExpresssionOperator.DOT); -// -// ExpressionNode expressionNodeRight = new LiteralNode(1); -// -// BinaryExpressionNode expressionNode = new BinaryExpressionNode(expressionNodeLeft, expressionNodeRight, ExpresssionOperator.ASSIGNMENT); -// -// return new AssignmentStatementNode(expressionNode); -//} -} diff --git a/src/test/resources/semantic/correctRefType.json b/src/test/resources/semantic/correctRefType.json deleted file mode 100644 index 7e67bbc..0000000 --- a/src/test/resources/semantic/correctRefType.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "classes": [ - { - "identifier": "testClass1", - "accessType": { - "enumAccessTypeNode": "PUBLIC" - }, - "members": [ - { - "@type": "Field", - "accessTypeNode": { - "enumAccessTypeNode": "PUBLIC" - }, - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "testVar1" - }, - { - "@type": "Method", - "visibility": { - "enumAccessTypeNode": "PUBLIC" - }, - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "testMethod", - "parameters": { - "parameters": [ - { - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "param1" - } - ] - }, - "statements": [ - { - "@type": "Assignment", - "expressionLeft": { - "@type": "InstVar", - "identifier": "testVar1", - "expression": { - "@type": "This", - "type": { - "@type": "Reference", - "identifier": "testClass1" - } - }, - "type": null - }, - "expressionRight": { - "@type": "Literal", - "type": { - "@type": "Base", - "enumType": "INT" - } - } - } - ] - } - ], - "hasConstructor": false - } - ] -} \ No newline at end of file diff --git a/src/test/resources/semantic/refTypeMismatch.json b/src/test/resources/semantic/refTypeMismatch.json deleted file mode 100644 index e5ebcd3..0000000 --- a/src/test/resources/semantic/refTypeMismatch.json +++ /dev/null @@ -1,133 +0,0 @@ -{ - "classes": [ - { - "identifier": "testClass1", - "accessType": { - "enumAccessTypeNode": "PUBLIC" - }, - "members": [ - { - "@type": "Field", - "accessTypeNode": { - "enumAccessTypeNode": "PUBLIC" - }, - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "testVar1" - }, - { - "@type": "Method", - "visibility": { - "enumAccessTypeNode": "PUBLIC" - }, - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "testMethod", - "parameters": { - "parameters": [ - { - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "param1" - } - ] - }, - "statements": [ - { - "@type": "Assignment", - "expressionLeft": { - "@type": "InstVar", - "identifier": "testVar1", - "expression": { - "@type": "This", - "type": { - "@type": "Reference", - "identifier": "testClass1" - } - }, - "type": null - }, - "expressionRight": { - "@type": "Literal", - "type": { - "@type": "Base", - "enumType": "BOOLEAN" - } - } - } - ] - } - ], - "hasConstructor": false, - "methods": [ - { - "@type": "Method", - "visibility": { - "enumAccessTypeNode": "PUBLIC" - }, - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "testMethod", - "parameters": { - "parameters": [ - { - "type": { - "@type": "Base", - "enumType": "INT" - }, - "identifier": "param1" - } - ] - }, - "statements": [ - { - "@type": "Assignment", - "expressionLeft": { - "@type": "InstVar", - "identifier": "testVar", - "expression": { - "@type": "InstVar", - "identifier": "testVar", - "expression": { - "@type": "This", - "type": { - "@type": "Reference", - "identifier": "testClass2" - } - }, - "type": null - }, - "type": null - }, - "expressionRight": { - "@type": "Literal", - "type": null - }, - "type": null - }, - { - "@type": "VariableDeclaration", - "type": { - "@type": "Base", - "enumType": "CHAR" - }, - "identifier": "objectVar", - "expression": { - "@type": "Literal", - "type": null - } - } - ] - } - ] - } - ] -} \ No newline at end of file diff --git a/src/test/resources/semantic/test.json b/src/test/resources/semantic/test.json deleted file mode 100644 index 7acc30f..0000000 --- a/src/test/resources/semantic/test.json +++ /dev/null @@ -1 +0,0 @@ -{"classes":[{"identifier":"testClass","accessType":{"enumAccessTypeNode":"PUBLIC"},"members":[{"@type":"Field","accessTypeNode":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar1"},{"@type":"Field","accessTypeNode":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"objectVar"},{"@type":"Method","visibility":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar2","parameters":{"parameters":[{"type":{"@type":"Base","enumType":"INT"},"identifier":"param1"}]},"statements":[{"@type":"Assignment","expressionLeft":{"@type":"InstVar","identifier":"objectVar","expression":{"@type":"This","type":{"@type":"Reference","identifier":"testClass"}},"type":null},"expressionRight":{"@type":"Literal","type":{"@type":"Base","enumType":"INT"}}}]}],"hasConstructor":false,"methods":[{"@type":"Method","visibility":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar2","parameters":{"parameters":[{"type":{"@type":"Base","enumType":"INT"},"identifier":"param1"}]},"statements":[{"@type":"Assignment","expressionLeft":{"@type":"InstVar","identifier":"objectVar","expression":{"@type":"This","type":{"@type":"Reference","identifier":"testClass"}},"type":null},"expressionRight":{"@type":"Literal","type":{"@type":"Base","enumType":"INT"}}}]}]}]} \ No newline at end of file