forked from JavaTX/JavaCompilerCore
TypeinferenceException überarbeitet
This commit is contained in:
parent
0345dceb8e
commit
87e4f2fd36
@ -46,8 +46,9 @@ import typinferenz.FunNInterface;
|
||||
import typinferenz.ResultSet;
|
||||
// ino.end
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.ParserException;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.DebugException;
|
||||
import typinferenz.exceptions.ParserError;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
|
||||
|
||||
|
||||
@ -756,7 +757,7 @@ public class MyCompiler implements MyCompilerAPI
|
||||
/**
|
||||
* Parst den Inhalt einer Datei zu einem Syntaxbaum.
|
||||
*/
|
||||
private SourceFile parse2SyntaxTree(Reader fileContent){
|
||||
private SourceFile parse2SyntaxTree(Reader fileContent) throws ParserError{
|
||||
|
||||
//StringReader reader = new StringReader(fileContent);
|
||||
//////////////////////////////////////
|
||||
@ -773,7 +774,7 @@ public class MyCompiler implements MyCompilerAPI
|
||||
srcFile = (SourceFile) parser.yyparse( scanner );
|
||||
} catch (IOException | yyException e) {
|
||||
e.printStackTrace();
|
||||
if(e instanceof yyException)throw new ParserException((yyException)e);
|
||||
if(e instanceof yyException)throw new ParserError((yyException)e);
|
||||
}
|
||||
//////////////////////////////////////
|
||||
// Postprocessing:
|
||||
@ -786,7 +787,7 @@ public class MyCompiler implements MyCompilerAPI
|
||||
/**
|
||||
* Diese Funktion nimmt einen Vector von Dateinamen. Alle diese Dateien werden zu einem SyntaxBaum geparst.
|
||||
*/
|
||||
public void parse(Vector<String> filenames) {
|
||||
public void parse(Vector<String> filenames) throws ParserError {
|
||||
|
||||
for(String filename : filenames){
|
||||
StringBuffer fileData = new StringBuffer();
|
||||
@ -795,7 +796,7 @@ public class MyCompiler implements MyCompilerAPI
|
||||
reader = new BufferedReader(
|
||||
new FileReader(filename));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new TypinferenzException("Die Datei "+ filename+" konnte nicht gelesen werden.");
|
||||
throw new DebugException("Die Datei "+ filename+" konnte nicht gelesen werden.");
|
||||
}
|
||||
char[] buf = new char[1024];
|
||||
int numRead=0;
|
||||
|
@ -9,6 +9,8 @@ import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.exceptions.ParserError;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.myexception.CTypeReconstructionException;
|
||||
import mycompiler.myexception.JVMCodeException;
|
||||
@ -84,7 +86,7 @@ public interface MyCompilerAPI
|
||||
// ino.end
|
||||
// ino.method.typeReconstruction.21340.declaration
|
||||
public Vector<TypeinferenceResultSet> typeReconstruction()
|
||||
throws NullPointerException, CTypeReconstructionException;
|
||||
throws NullPointerException, TypeinferenceException;
|
||||
// ino.end
|
||||
|
||||
// ino.method.codeGeneration.21346.decldescription type=javadoc
|
||||
@ -125,14 +127,14 @@ public interface MyCompilerAPI
|
||||
* Parst zusammenhängende JavaKlassen in verschiedenen Dateien.
|
||||
* @param filenames - Eine Liste von Quellcodedateien, welche gseparst werden sollen
|
||||
*/
|
||||
public void parse(Vector<String> filenames);
|
||||
public void parse(Vector<String> filenames) throws ParserError;
|
||||
|
||||
/**
|
||||
* Parst den SourceCode einer Datei.
|
||||
* @param sourceCode - SourceCode einer Java-Quellcodedatei
|
||||
* @return den aus dem sourceCode generierten Syntaxbaum
|
||||
*/
|
||||
public SourceFile parse(String sourceCode);
|
||||
public SourceFile parse(String sourceCode) throws ParserError;
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -58,7 +58,8 @@ import typinferenz.assumptions.ClassAssumption;
|
||||
import typinferenz.assumptions.MethodAssumption;
|
||||
import typinferenz.assumptions.ParameterAssumption;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.DebugException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
|
||||
|
||||
|
||||
@ -1584,7 +1585,7 @@ public class SourceFile
|
||||
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
if(parent!=null)throw new TypinferenzException("Eine SourceFile hat keine Elternelement im Syntaxbaum");
|
||||
if(parent!=null)throw new DebugException("Eine SourceFile hat kein Elternelement im Syntaxbaum");
|
||||
super.parserPostProcessing(parent);
|
||||
//for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
|
||||
}
|
||||
|
@ -2,7 +2,8 @@ package mycompiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.DebugException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import mycompiler.myclass.Class;
|
||||
import mycompiler.mytype.GenericTypeVar;
|
||||
|
||||
@ -33,7 +34,7 @@ public abstract class SyntaxTreeNode {
|
||||
public Class getParentClass(){
|
||||
SyntaxTreeNode parent = this.getParent();
|
||||
if(parent instanceof Class)return (Class)parent;
|
||||
if(parent == null)throw new TypinferenzException("Das Wurzelelement eines Syntaxbaumes muss Class sein");
|
||||
if(parent == null)throw new DebugException("Das Wurzelelement eines Syntaxbaumes muss Class sein");
|
||||
return parent.getParentClass();
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ import typinferenz.UndConstraint;
|
||||
import typinferenz.FunN;
|
||||
import typinferenz.assumptions.ClassAssumption;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import typinferenz.*;
|
||||
|
||||
|
||||
@ -407,7 +407,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface
|
||||
* -Rückgabetyp der Methode/Konstruktors ist der Typ der Klasse
|
||||
* -Ein Konstruktor kann nicht aufgerufen werden (nur mit new)
|
||||
*/
|
||||
if(m.get_Method_Name().equals("<init>"))throw new TypinferenzException("<init> ist kein gültiger Methodenname");
|
||||
if(m.get_Method_Name().equals("<init>"))throw new TypeinferenceException("<init> ist kein gültiger Methodenname", m);
|
||||
if((m.get_Method_Name().equals(this.getName()))) {
|
||||
Constructor constructor = new Constructor(m);
|
||||
tempFields.add(constructor); //Den Konstruktor anstatt der Methode anfügen
|
||||
|
@ -18,7 +18,7 @@ import typinferenz.SingleConstraint;
|
||||
import typinferenz.assumptions.ConstructorAssumption;
|
||||
import typinferenz.assumptions.MethodAssumption;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
|
||||
public class Constructor extends Method {
|
||||
private Method methode;
|
||||
@ -265,7 +265,7 @@ public class Constructor extends Method {
|
||||
|
||||
@Override
|
||||
public void setType(Type t) {
|
||||
throw new TypinferenzException("Einem Konstruktor kann kein Typ zugewiesen werden");
|
||||
throw new TypeinferenceException("Einem Konstruktor kann kein Typ zugewiesen werden", this);
|
||||
//this.methode.setType(t);
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import typinferenz.ResultSet;
|
||||
import typinferenz.SingleConstraint;
|
||||
import typinferenz.assumptions.FieldAssumption;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.myexception.JVMCodeException;
|
||||
@ -90,7 +90,7 @@ public class FieldDeclaration extends Field{
|
||||
* Der Feld-Assumption muss ein TPH als Typ hinzugefügt werden, falls er Typlos initialisiert wurde. Dies kann auch der Type-Algorithmus der Inst/FieldVar - Klasse machen.
|
||||
* Wird das Feld mit einem Typ initialisiert so muss dieser auch in die Assumptions.
|
||||
*/
|
||||
if(this.getType() == null)throw new TypinferenzException("Der Typ eines Feldes darf nicht null sein");
|
||||
if(this.getType() == null)throw new TypeinferenceException("Der Typ eines Feldes darf nicht null sein", this);
|
||||
//assumptions.add(TypeAssumptions.createFieldVarAssumption(classmember.getName(), this.getName(), this.getType()));
|
||||
assumptions.addAssumption(new FieldAssumption(this,classmember));
|
||||
return assumptions;
|
||||
@ -134,7 +134,15 @@ public class FieldDeclaration extends Field{
|
||||
GenericTypeVar gtv = (GenericTypeVar) this.getType();
|
||||
}
|
||||
*/
|
||||
if(this.getType()!=null && (this.getType() instanceof RefType))this.setType(publicAssumptions.getTypeFor((RefType)this.getType()));
|
||||
|
||||
//TypeCheck, falls es sich um einen RefType handelt:
|
||||
if(this.getType()!=null && (this.getType() instanceof RefType)){
|
||||
Type replaceType = null;
|
||||
replaceType = publicAssumptions.getTypeFor((RefType)this.getType());
|
||||
if(replaceType == null)throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this);
|
||||
this.setType(replaceType);
|
||||
}
|
||||
|
||||
SingleConstraint c1 = new SingleConstraint(this.getType(), this.getType());
|
||||
ret.add(c1); //Damit die TypVariable des Felds in den Constraints auftaucht
|
||||
|
||||
|
@ -32,7 +32,7 @@ import typinferenz.ResultSet;
|
||||
import typinferenz.TypeInsertPoint;
|
||||
import typinferenz.Typeable;
|
||||
import typinferenz.TypeInsertable;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
|
||||
// ino.class.FormalParameter.23391.declaration
|
||||
public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementListener, Typeable, TypeInsertable
|
||||
@ -127,7 +127,7 @@ public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementL
|
||||
public String getTypeName()
|
||||
// ino.end
|
||||
// ino.method.getTypeName.23416.body
|
||||
{
|
||||
{ if(this.getType() == null)return "";
|
||||
return this.getType().getName();
|
||||
}
|
||||
// ino.end
|
||||
@ -263,5 +263,14 @@ public class FormalParameter extends SyntaxTreeNode implements ITypeReplacementL
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getVariableLength() {
|
||||
int ret = 0;
|
||||
ret += this.getTypeName().length();
|
||||
ret +=this.getIdentifier().length();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -41,6 +41,7 @@ import typinferenz.TypeInsertable;
|
||||
import typinferenz.assumptions.MethodAssumption;
|
||||
import typinferenz.assumptions.ParameterAssumption;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
|
||||
|
||||
|
||||
@ -541,15 +542,30 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
|
||||
|
||||
public ConstraintsSet TYPE(TypeAssumptions ass) {
|
||||
if((this.returntype instanceof RefType) &&
|
||||
!(this.returntype instanceof mycompiler.mytype.Void))//Sonderfall der Methode: Ihr Typ darf Void definiert werden.
|
||||
this.returntype = ass.getTypeFor((RefType)this.returntype);
|
||||
//TypeCheck, falls es sich um einen RefType handelt:
|
||||
if(this.returntype!=null && (this.returntype instanceof RefType)&&
|
||||
!(this.returntype instanceof mycompiler.mytype.Void)){//Sonderfall der Methode: Ihr Typ darf Void definiert werden.
|
||||
Type replaceType = null;
|
||||
replaceType = ass.getTypeFor((RefType)this.returntype);
|
||||
if(replaceType == null)throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this);
|
||||
this.returntype = replaceType;
|
||||
}
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
TypeAssumptions localAss = new TypeAssumptions();
|
||||
localAss.add(ass); //Die globalen Assumptions anhängen
|
||||
//Die Parameter zu den Assumptions hinzufügen:
|
||||
if(this.parameterlist!=null)for(FormalParameter param : this.parameterlist){
|
||||
if(param.getType() instanceof RefType)param.setType(ass.getTypeFor((RefType)param.getType()));
|
||||
|
||||
|
||||
if(param.getType() instanceof RefType)
|
||||
{
|
||||
Type replaceType = null;
|
||||
replaceType = ass.getTypeFor((RefType)param.getType());
|
||||
if(replaceType == null)throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",param);
|
||||
param.setType(replaceType);
|
||||
}
|
||||
|
||||
|
||||
localAss.addAssumption(new ParameterAssumption(param));
|
||||
}
|
||||
ret.add(this.block.TYPEStmt(localAss));
|
||||
|
@ -7,7 +7,7 @@ import java.util.Vector;
|
||||
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import mycompiler.IItemWithOffset;
|
||||
import mycompiler.mybytecode.JVMCode;
|
||||
import mycompiler.mytype.Type;
|
||||
@ -312,7 +312,7 @@ public class UsedId implements IItemWithOffset
|
||||
// ino.end
|
||||
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
if(this.name.size()>1)throw new TypinferenzException("Es kann maximal nur eine Superklasse pro Klasse geben");
|
||||
if(this.name.size()>1)throw new TypeinferenceException("Es kann maximal nur eine Superklasse pro Klasse geben", this);
|
||||
JavaCodeResult ret = new JavaCodeResult(this.getQualifiedName());
|
||||
if(this.paralist != null){
|
||||
ret.attach( "<" );
|
||||
|
@ -40,7 +40,7 @@ import typinferenz.ConstraintsSet;
|
||||
import typinferenz.FreshTypeVariable;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
|
||||
|
||||
|
||||
@ -236,7 +236,7 @@ public class Block extends Statement
|
||||
if (!(stmt.getType() instanceof Void))
|
||||
if (this.getType() instanceof Void) {
|
||||
//this.setTypeVariable(stmt.getTypeVariable());
|
||||
throw new TypinferenzException("Falscher Return Type");
|
||||
throw new TypeinferenceException("Block besitzt falschen Rückgabetyp (fehlendes return-stmt)", this);
|
||||
}
|
||||
else {
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(this);
|
||||
|
@ -12,7 +12,7 @@ import typinferenz.ResultSet;
|
||||
import typinferenz.Typeable;
|
||||
import typinferenz.assumptions.ParameterAssumption;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.mybytecode.CodeAttribute;
|
||||
@ -171,7 +171,7 @@ public class LambdaExpression extends Expr{
|
||||
|
||||
@Override
|
||||
public ConstraintsSet TYPEStmt(TypeAssumptions ass){
|
||||
throw new TypinferenzException("Eine LambdaExpression darf nicht als Statement verwendet werden.");
|
||||
throw new TypeinferenceException("Eine LambdaExpression darf nicht als Statement verwendet werden.", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,6 +34,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.SingleConstraint;
|
||||
@ -41,6 +42,7 @@ import typinferenz.ConstraintsSet;
|
||||
import typinferenz.FreshTypeVariable;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
|
||||
|
||||
|
||||
@ -207,6 +209,7 @@ public class LocalOrFieldVar extends Expr
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
//gibt es eine Assumption für den die LocalOrFieldVar-Variablen, dann folgendes ausführen:
|
||||
Type thisTypeAssumption = assumptions.getVarType(this.get_Name(), this.getParentClass());
|
||||
if(thisTypeAssumption == null)throw new TypeinferenceException("Eine Variable "+this.get_Name()+" ist in den Assumptions nicht vorhanden",this);
|
||||
this.setType(thisTypeAssumption);
|
||||
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
|
||||
return ret;
|
||||
|
@ -40,6 +40,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
import typinferenz.ConstraintsSet;
|
||||
import typinferenz.FreshTypeVariable;
|
||||
import typinferenz.JavaCodeResult;
|
||||
@ -48,6 +49,7 @@ import typinferenz.TypeInsertPoint;
|
||||
import typinferenz.TypeInsertable;
|
||||
import typinferenz.assumptions.LocalVarAssumption;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
|
||||
|
||||
|
||||
@ -463,7 +465,12 @@ public class LocalVarDecl extends Statement implements TypeInsertable
|
||||
@Override
|
||||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
if((this.getType() instanceof RefType))this.setType(assumptions.getTypeFor((RefType)this.getType()));
|
||||
if((this.getType() instanceof RefType)){
|
||||
Type replaceType = null;
|
||||
replaceType = assumptions.getTypeFor((RefType)this.getType());
|
||||
if(replaceType == null)throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this);
|
||||
this.setType(replaceType);
|
||||
}
|
||||
assumptions.addAssumption(new LocalVarAssumption(this));
|
||||
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
|
||||
this.setType(new Void(0)); //Return typ einer Variablendeklaration ist Void
|
||||
|
@ -27,10 +27,12 @@ import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
import typinferenz.ConstraintsSet;
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
|
||||
|
||||
|
||||
@ -138,6 +140,7 @@ public class StringLiteral extends Literal
|
||||
@Override
|
||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||
this.set_Type(assumptions.getTypeFor(new RefType("String",0)));
|
||||
if(this.getType() == null)throw new TypeinferenceException("java.lang.String nicht importiert",this);
|
||||
return new ConstraintsSet();
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ import org.apache.log4j.PatternLayout;
|
||||
import org.apache.log4j.SimpleLayout;
|
||||
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import mycompiler.MyCompiler;
|
||||
import mycompiler.MyCompilerAPI;
|
||||
import mycompiler.mytype.Type;
|
||||
@ -145,7 +145,7 @@ public class LambdaTest {
|
||||
/////////////////////////
|
||||
try{
|
||||
resultSet = compiler.typeReconstruction();
|
||||
}catch(TypinferenzException texc){
|
||||
}catch(TypeinferenceException texc){
|
||||
texc.printStackTrace();
|
||||
fail("Fehler bei Typinferenzalgorithmus. Message: "+texc.getMessage());
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import typinferenz.ResultSet;
|
||||
import typinferenz.TypeInsertPoint;
|
||||
import typinferenz.TypeInsertSet;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import mycompiler.mytype.GenericTypeVar;
|
||||
import mycompiler.mytype.Pair;
|
||||
import mycompiler.mytype.RefType;
|
||||
|
@ -4,6 +4,7 @@ import java.util.Vector;
|
||||
|
||||
import typinferenz.assumptions.MethodAssumption;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import mycompiler.mystatement.Expr;
|
||||
import mycompiler.mystatement.MethodCall;
|
||||
import mycompiler.mytype.RefType;
|
||||
@ -60,7 +61,9 @@ public class Overloading{
|
||||
for(Expr argument : methodCall.getArgumentList().expr){
|
||||
parameterList.add(argument.getType());
|
||||
}
|
||||
for(MethodAssumption methodAssumption : assumptions.getMethodAssumptions(methodCall.getName(), parameterList)){
|
||||
Vector<MethodAssumption> methodAssumptions = assumptions.getMethodAssumptions(methodCall.getName(), parameterList);
|
||||
if(methodAssumptions.size()==0)throw new TypeinferenceException("Eine Methode "+methodCall.get_Name()+" ist in den Assumptions nicht vorhanden", methodCall);
|
||||
for(MethodAssumption methodAssumption : methodAssumptions){
|
||||
if(!(this.type instanceof TypePlaceholder) && !this.type.equals(methodAssumption.getAssumedType()))break;
|
||||
UndConstraint methodConstraint = new UndConstraint();
|
||||
//Ein Constraint für den ReturnType der Methode...
|
||||
|
@ -2,7 +2,8 @@ package typinferenz;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.DebugException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import mycompiler.mytype.GenericTypeVar;
|
||||
import mycompiler.mytype.Pair;
|
||||
import mycompiler.mytype.RefType;
|
||||
@ -43,7 +44,7 @@ public class SingleConstraint extends UndConstraint{
|
||||
}
|
||||
|
||||
public void addConstraint(Pair toAdd){
|
||||
if(constraintPair != null)throw new TypinferenzException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich.");
|
||||
if(constraintPair != null)throw new DebugException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich.");
|
||||
|
||||
Type p1 = toAdd.TA1;
|
||||
Type p2 = toAdd.TA2;
|
||||
|
@ -1,9 +1,10 @@
|
||||
package typinferenz;
|
||||
|
||||
import mycompiler.IItemWithOffset;
|
||||
import mycompiler.mytype.TypePlaceholder;
|
||||
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
|
||||
|
||||
public interface TypeInsertable extends ITypeReplacementListener, Typeable {
|
||||
public interface TypeInsertable extends ITypeReplacementListener, Typeable, IItemWithOffset {
|
||||
|
||||
public int getOffset();
|
||||
public void setOffset(int offset);
|
||||
|
@ -10,7 +10,7 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import typinferenz.FunN;
|
||||
import typinferenz.FunNInterface;
|
||||
import typinferenz.FunNMethod;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import mycompiler.mytype.GenericTypeVar;
|
||||
import mycompiler.mytype.RefType;
|
||||
import mycompiler.mytype.Type;
|
||||
@ -81,11 +81,18 @@ public class TypeAssumptions {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert den Typ einer Feldvariable der Klasse inClass
|
||||
* @param withName
|
||||
* @param inClass
|
||||
* @return null, falls die Klasse kein zugängliches Feld enthält
|
||||
*/
|
||||
public Type getTypeOfFieldVar(String withName, Class inClass){
|
||||
for(FieldAssumption fa : this.getFieldVars(withName)){
|
||||
if(fa.getParentClass().equals(inClass))return fa.getAssumedType();
|
||||
}
|
||||
throw new TypinferenzException("Das Feld "+withName+" ist in der Klasse "+inClass.getName()+" nicht vorhanden.");
|
||||
//throw new TypeinferenceException("Das Feld "+withName+" ist in der Klasse "+inClass.getName()+" nicht vorhanden.");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,7 +144,7 @@ public class TypeAssumptions {
|
||||
// MethodAssumption funNAssumption = new MethodAssumption(new FunNMethod(parameterCount), new FunNInterface(parameter));
|
||||
// ret.add(funNAssumption);
|
||||
//}
|
||||
if(ret.size()==0)throw new TypinferenzException("Eine Methode "+methodName+" ist in den Assumptions nicht vorhanden");
|
||||
//if(ret.size()==0)throw new TypeinferenceException("Eine Methode "+methodName+" ist in den Assumptions nicht vorhanden");
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -147,7 +154,7 @@ public class TypeAssumptions {
|
||||
* In den Assumptions wird dann in der Reihenfolge LocalVarAssumptions, FieldAssumption nach dem übergebenen Variablennamen gesucht.
|
||||
* @param variableName - der Identifier der gesuchten Variablen
|
||||
* @param inScope - Sucht auch die Felder der übergebenen Klasse ab. Hier kann auch null übergeben werden, dann werden nur die Lokalen Variablen dieser TypeAssumption durchsucht.
|
||||
* @return - Der Typ für diesen Identifier
|
||||
* @return - Der Typ für diesen Identifier, oder null, falls kein Typ vorliegt.
|
||||
*/
|
||||
public Type getVarType(String variableName, Class inScope){
|
||||
//Zuerst die Parameter durchsuchen
|
||||
@ -166,7 +173,8 @@ public class TypeAssumptions {
|
||||
}
|
||||
}
|
||||
//Wird keine Assumption gefunden, muss ein Fehler vorliegen:
|
||||
throw new TypinferenzException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden");
|
||||
//throw new TypeinferenceException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,20 +279,14 @@ public class TypeAssumptions {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Type getThisValue2() {
|
||||
if(thisClassName == null)throw new TypinferenzException("Kein Wert für this vorhanden, in diesem Kontext");
|
||||
return new RefType(thisClassName, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kontrolliert den vom Parser gesetzten Typ.
|
||||
* Erweitert dessen Bezeichnung, wenn nötig.
|
||||
* @param t
|
||||
* @return
|
||||
* @throws TypinferenzException
|
||||
* @return null, falls der Typ nicht vorhanden ist.
|
||||
*/
|
||||
public Type getTypeFor(RefType t) throws TypinferenzException{
|
||||
public Type getTypeFor(RefType t){
|
||||
//TODO: Die Parameterliste noch kontrollieren: (hier könnte es Constraints geben: "? extends String")
|
||||
//Alle bekannten Klassen nach diesem Typ durchsuchen:
|
||||
String typName = t.getName();
|
||||
@ -306,7 +308,7 @@ public class TypeAssumptions {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
throw new TypinferenzException("Der Typ "+t.getName()+" ist nicht korrekt");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
12
src/typinferenz/exceptions/ParserError.java
Normal file
12
src/typinferenz/exceptions/ParserError.java
Normal file
@ -0,0 +1,12 @@
|
||||
package typinferenz.exceptions;
|
||||
|
||||
import mycompiler.myparser.JavaParser.yyException;
|
||||
|
||||
|
||||
public class ParserError extends TypeinferenceException{
|
||||
|
||||
public ParserError(yyException exc){
|
||||
super(exc.getMessage(), exc.token.getOffset());
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package typinferenz.exceptions;
|
||||
|
||||
import mycompiler.myparser.JavaParser.yyException;
|
||||
|
||||
|
||||
public class ParserException extends TypinferenzException {
|
||||
|
||||
public ParserException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ParserException(yyException exc){
|
||||
super("Parserfehler");
|
||||
}
|
||||
|
||||
}
|
31
src/typinferenz/exceptions/TypeinferenceException.java
Executable file
31
src/typinferenz/exceptions/TypeinferenceException.java
Executable file
@ -0,0 +1,31 @@
|
||||
package typinferenz.exceptions;
|
||||
|
||||
import mycompiler.IItemWithOffset;
|
||||
|
||||
/**
|
||||
* Eine RuntimeException, welche bei einem Fehler während des Typinferenzalgorithmus ausgelöst wird.
|
||||
* Dies wird zum Beispiel durch Programmierfehler in der Java-Eingabedatei ausgelöst.
|
||||
* @author Andreas Stadelmeier, a10023
|
||||
*
|
||||
*/
|
||||
//TODO: Diese Klasse muss von Exception erben
|
||||
public class TypeinferenceException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Das Offset im Quelltext bei dem das Problem aufgetaucht ist
|
||||
*/
|
||||
private int offset;
|
||||
private String message;
|
||||
|
||||
public TypeinferenceException(String message, IItemWithOffset problemSource)
|
||||
{
|
||||
super(message);
|
||||
this.message=message;
|
||||
this.offset=problemSource.getOffset();
|
||||
}
|
||||
|
||||
public TypeinferenceException(String message, int offset){
|
||||
this.message=message;
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package typinferenz.exceptions;
|
||||
|
||||
/**
|
||||
* Eine RuntimeException, welche bei einem Fehler während des Typinferenzalgorithmus ausgelöst wird.
|
||||
* Dies wird zum Beispiel durch Programmierfehler in der Java-Eingabedatei ausgelöst.
|
||||
* @author Andreas Stadelmeier, a10023
|
||||
*
|
||||
*/
|
||||
public class TypinferenzException extends RuntimeException {
|
||||
public TypinferenzException(String message){
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ import java.util.Vector;
|
||||
import mycompiler.MyCompiler;
|
||||
import mycompiler.MyCompilerAPI;
|
||||
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
|
||||
import typinferenz.exceptions.TypinferenzException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -45,7 +45,7 @@ public class ConsoleInterface {
|
||||
/////////////////////////
|
||||
try{
|
||||
resultSet = compiler.typeReconstruction();
|
||||
}catch(TypinferenzException texc){
|
||||
}catch(TypeinferenceException texc){
|
||||
texc.printStackTrace();
|
||||
fail("Fehler bei Typinferenzalgorithmus. Message: "+texc.getMessage());
|
||||
}
|
||||
|
@ -110,6 +110,12 @@ class TestNode implements TypeInsertable{
|
||||
ResultSet resultSet) {
|
||||
return new TypeInsertPoint(tph, this, resultSet.getTypeEqualTo(tph), resultSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVariableLength() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user