Old spelling mistake in semantic fixed
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
parent
347bdcbd94
commit
4e56760dd6
@ -1,7 +1,7 @@
|
|||||||
package semantic;
|
package semantic;
|
||||||
|
|
||||||
import ast.type.type.*;
|
import ast.type.type.*;
|
||||||
import semantic.exceptions.AlreadyDeclearedException;
|
import semantic.exceptions.AlreadyDeclaredException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
@ -16,7 +16,7 @@ public class Scope {
|
|||||||
|
|
||||||
public void addLocalVar(String name, ITypeNode type) {
|
public void addLocalVar(String name, ITypeNode type) {
|
||||||
if (this.contains(name)) {
|
if (this.contains(name)) {
|
||||||
throw new AlreadyDeclearedException("Variable " + name + " already exists in this scope");
|
throw new AlreadyDeclaredException("Variable " + name + " already exists in this scope");
|
||||||
}
|
}
|
||||||
localVars.peek().put(name, type);
|
localVars.peek().put(name, type);
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
if (Objects.equals(otherMethod, methodNode))
|
if (Objects.equals(otherMethod, methodNode))
|
||||||
break;
|
break;
|
||||||
if (otherMethod.isSame(methodNode)) {
|
if (otherMethod.isSame(methodNode)) {
|
||||||
errors.add(new AlreadyDeclearedException(
|
errors.add(new AlreadyDeclaredException(
|
||||||
"Method " + methodNode.getIdentifier() + " is already defined in class "
|
"Method " + methodNode.getIdentifier() + " is already defined in class "
|
||||||
+ currentClass.identifier));
|
+ currentClass.identifier));
|
||||||
valid = false;
|
valid = false;
|
||||||
@ -130,8 +130,8 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
valid = valid && result.isValid();
|
valid = valid && result.isValid();
|
||||||
try {
|
try {
|
||||||
currentScope.addLocalVar(parameter.identifier, parameter.type);
|
currentScope.addLocalVar(parameter.identifier, parameter.type);
|
||||||
} catch (AlreadyDeclearedException e) {
|
} catch (AlreadyDeclaredException e) {
|
||||||
errors.add(new AlreadyDeclearedException(parameter.identifier));
|
errors.add(new AlreadyDeclaredException(parameter.identifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public TypeCheckResult analyze(FieldNode toCheck) {
|
public TypeCheckResult analyze(FieldNode toCheck) {
|
||||||
if (currentFields.get(toCheck.identifier) != null) {
|
if (currentFields.get(toCheck.identifier) != null) {
|
||||||
errors.add(new AlreadyDeclearedException("Already declared " + toCheck.identifier));
|
errors.add(new AlreadyDeclaredException("Already declared " + toCheck.identifier));
|
||||||
return new TypeCheckResult(false, null);
|
return new TypeCheckResult(false, null);
|
||||||
} else {
|
} else {
|
||||||
currentFields.put(toCheck.identifier, toCheck.type);
|
currentFields.put(toCheck.identifier, toCheck.type);
|
||||||
@ -362,7 +362,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
} else if(currentFields.get(unary.identifier) != null) {
|
} else if(currentFields.get(unary.identifier) != null) {
|
||||||
return new TypeCheckResult(valid, currentFields.get(unary.identifier));
|
return new TypeCheckResult(valid, currentFields.get(unary.identifier));
|
||||||
} else {
|
} else {
|
||||||
errors.add(new NotDeclearedException("Var is not Decleared"));
|
errors.add(new NotDeclaredException("Var is not Declared"));
|
||||||
}
|
}
|
||||||
return new TypeCheckResult(valid, null);
|
return new TypeCheckResult(valid, null);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package semantic.exceptions;
|
||||||
|
|
||||||
|
public class AlreadyDeclaredException extends RuntimeException {
|
||||||
|
|
||||||
|
public AlreadyDeclaredException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
package semantic.exceptions;
|
|
||||||
|
|
||||||
public class AlreadyDeclearedException extends RuntimeException {
|
|
||||||
|
|
||||||
public AlreadyDeclearedException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,9 @@
|
|||||||
|
package semantic.exceptions;
|
||||||
|
|
||||||
|
public class NotDeclaredException extends RuntimeException {
|
||||||
|
|
||||||
|
public NotDeclaredException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
package semantic.exceptions;
|
|
||||||
|
|
||||||
public class NotDeclearedException extends RuntimeException {
|
|
||||||
|
|
||||||
public NotDeclearedException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -22,7 +22,7 @@ public class SemanticTest {
|
|||||||
// ASTNode typedAst = SemanticAnalyzer.generateTast(programNode);
|
// ASTNode typedAst = SemanticAnalyzer.generateTast(programNode);
|
||||||
//
|
//
|
||||||
// assertEquals(1, SemanticAnalyzer.errors.size());
|
// assertEquals(1, SemanticAnalyzer.errors.size());
|
||||||
// assertInstanceOf(AlreadyDeclearedException.class, SemanticAnalyzer.errors.getFirst());
|
// assertInstanceOf(AlreadyDeclaredException.class, SemanticAnalyzer.errors.getFirst());
|
||||||
// assertNull(typedAst);
|
// assertNull(typedAst);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// @expected: AlreadyDeclearedException
|
// @expected: AlreadyDeclaredException
|
||||||
public class Example {
|
public class Example {
|
||||||
|
|
||||||
public int a;
|
public int a;
|
@ -1,4 +1,4 @@
|
|||||||
// @expected: NotDeclearedException
|
// @expected: NotDeclaredException
|
||||||
public class Test {
|
public class Test {
|
||||||
public static int testMethod(int x){
|
public static int testMethod(int x){
|
||||||
int a = b;
|
int a = b;
|
@ -1,4 +1,4 @@
|
|||||||
// @expected: AlreadyDeclearedException
|
// @expected: AlreadyDeclaredException
|
||||||
public class Example {
|
public class Example {
|
||||||
|
|
||||||
public static int testMethod(char a, int a){
|
public static int testMethod(char a, int a){
|
Loading…
Reference in New Issue
Block a user