Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
Added the ability to recieve a stackOverflowError, if any recursion does not have an intact recursion anchor.
  • Loading branch information
Christian-2003 authored Apr 12, 2021
1 parent 64a3aea commit 77a5699
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 5 additions & 0 deletions errorHandling/ReturnValueTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,9 @@ public class ReturnValueTypes {
* werden soll.
*/
public static int ERROR_UNKNOWN_CLASS = 21;

/**
* Speichert die Fehlermeldung fuer einen Stackoverflowerror.
*/
public static int ERROR_STACK_OVERFLOW = 22;
}
3 changes: 2 additions & 1 deletion interpreter/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public Class(LinkedList<Token> plTokensObj) {
lPrivateFunctionsObj = new LinkedList<Function>();
lPublicAttributesObj = new LinkedList<Atom>();
lPublicFunctionsObj = new LinkedList<Function>();
lTokensObj = new LinkedList<Token>(plTokensObj);
lTokensObj = new LinkedList<Token>();
lTokensObj.addAll(plTokensObj);

//Den Bezeichner der Klasse identifizieren:
sName = plTokensObj.poll().getValue();
Expand Down
26 changes: 23 additions & 3 deletions interpreter/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,15 @@ else if (currentToken.getType().equals(TokenTypes.TOKEN_BRACKET_OPENED)) {
}
}
ReturnValue<Object> ifReturn = new ReturnValue<Object>(); //Speichert den Rueckgabewert der if-Verzweigung.
ifReturn = ifStatement(lConditionObj, lExpressionObj);

//Zum Vorbeugen eines Stackoverflowerrors:
try {
ifReturn = ifStatement(lConditionObj, lExpressionObj);
}
catch (StackOverflowError exception) {
return new ReturnValue<Object>(null, ReturnValueTypes.ERROR_STACK_OVERFLOW);
}

if (ifReturn.getExecutionInformation() != ReturnValueTypes.SUCCESS) {
//Es ist ein Fehler aufgetreten:
return new ReturnValue<Object>(null, ifReturn.getExecutionInformation());
Expand Down Expand Up @@ -767,11 +775,11 @@ else if (currentTokenObj.getType().equals(TokenTypes.TOKEN_BRACKET_OPENED)) {
return new ReturnValue<Object>(null, ReturnValueTypes.ERROR_UNKNOWN_CLASS);
}
else {
//Obejkt "muss" instanziiert werden, da der JAVA-Compiler sonst einen Fehler ausgibt, wenn das Objekt der Lisp-Klasse
//Objekt "muss" instanziiert werden, da der JAVA-Compiler sonst einen Fehler ausgibt, wenn das Objekt der Lisp-Klasse
//instanziiert wird. Eigentlich, sollte es dazu aber nicht kommen, da das Objekt classTypeObj instanziiert wird, wenn
//der Klassentyp gefunden wird...
//Machste nix nh... \(*_*)/
classTypeObj = new Class();
classTypeObj = new Class(lClassesObj.peek().getClassTokens());
}

//Herausfinden, ob Instanzbezeichner verfuegbar ist:
Expand Down Expand Up @@ -1264,6 +1272,18 @@ else if (pnErrorMessage == ReturnValueTypes.ERROR_INCORRECT_PARAMETER_NUMBER) {
else if (pnErrorMessage == ReturnValueTypes.ERROR_NO_RETURN_VALUE) {
System.out.print("non-existing return value was expected.");
}
else if (pnErrorMessage == ReturnValueTypes.ERROR_INSTANCE_NAME_DOES_EXIST) {
System.out.print("the name of an instance is already used.");
}
else if (pnErrorMessage == ReturnValueTypes.ERROR_INSTANCE_NAME_CANNOT_BE_CLASS_NAME) {
System.out.print("instance name cannot be class name.");
}
else if (pnErrorMessage == ReturnValueTypes.ERROR_UNKNOWN_CLASS) {
System.out.print("unknown class type.");
}
else if (pnErrorMessage == ReturnValueTypes.ERROR_STACK_OVERFLOW) {
System.out.print("stackOverflowError.");
}
else {
System.out.print("unknwon error occured. Error message: " + pnErrorMessage);
}
Expand Down

0 comments on commit 77a5699

Please sign in to comment.