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;
|
||||
|
||||
import ast.type.type.*;
|
||||
import semantic.exceptions.AlreadyDeclearedException;
|
||||
import semantic.exceptions.AlreadyDeclaredException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Stack;
|
||||
@ -16,7 +16,7 @@ public class Scope {
|
||||
|
||||
public void addLocalVar(String name, ITypeNode type) {
|
||||
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);
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
if (Objects.equals(otherMethod, methodNode))
|
||||
break;
|
||||
if (otherMethod.isSame(methodNode)) {
|
||||
errors.add(new AlreadyDeclearedException(
|
||||
errors.add(new AlreadyDeclaredException(
|
||||
"Method " + methodNode.getIdentifier() + " is already defined in class "
|
||||
+ currentClass.identifier));
|
||||
valid = false;
|
||||
@ -130,8 +130,8 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
valid = valid && result.isValid();
|
||||
try {
|
||||
currentScope.addLocalVar(parameter.identifier, parameter.type);
|
||||
} catch (AlreadyDeclearedException e) {
|
||||
errors.add(new AlreadyDeclearedException(parameter.identifier));
|
||||
} catch (AlreadyDeclaredException e) {
|
||||
errors.add(new AlreadyDeclaredException(parameter.identifier));
|
||||
}
|
||||
|
||||
}
|
||||
@ -165,7 +165,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
@Override
|
||||
public TypeCheckResult analyze(FieldNode toCheck) {
|
||||
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);
|
||||
} else {
|
||||
currentFields.put(toCheck.identifier, toCheck.type);
|
||||
@ -362,7 +362,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
} else if(currentFields.get(unary.identifier) != null) {
|
||||
return new TypeCheckResult(valid, currentFields.get(unary.identifier));
|
||||
} else {
|
||||
errors.add(new NotDeclearedException("Var is not Decleared"));
|
||||
errors.add(new NotDeclaredException("Var is not Declared"));
|
||||
}
|
||||
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);
|
||||
//
|
||||
// assertEquals(1, SemanticAnalyzer.errors.size());
|
||||
// assertInstanceOf(AlreadyDeclearedException.class, SemanticAnalyzer.errors.getFirst());
|
||||
// assertInstanceOf(AlreadyDeclaredException.class, SemanticAnalyzer.errors.getFirst());
|
||||
// assertNull(typedAst);
|
||||
// }
|
||||
//
|
||||
|
@ -1,4 +1,4 @@
|
||||
// @expected: AlreadyDeclearedException
|
||||
// @expected: AlreadyDeclaredException
|
||||
public class Example {
|
||||
|
||||
public int a;
|
@ -1,4 +1,4 @@
|
||||
// @expected: NotDeclearedException
|
||||
// @expected: NotDeclaredException
|
||||
public class Test {
|
||||
public static int testMethod(int x){
|
||||
int a = b;
|
@ -1,4 +1,4 @@
|
||||
// @expected: AlreadyDeclearedException
|
||||
// @expected: AlreadyDeclaredException
|
||||
public class Example {
|
||||
|
||||
public static int testMethod(char a, int a){
|
Loading…
Reference in New Issue
Block a user