SyntaxTreeNode angefügt. SourceFile steht nun nur noch für eine Java-Datei nicht mehr für mehrere.
This commit is contained in:
parent
31473630f8
commit
8cbd22f562
@ -41,6 +41,7 @@ import mycompiler.mytypereconstruction.TypeinferenceResultSet;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.xml.DOMConfigurator;
|
||||
|
||||
import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;
|
||||
import com.sun.org.apache.xerces.internal.impl.xs.identity.Field;
|
||||
|
||||
import typinferenz.TypinferenzException;
|
||||
@ -97,7 +98,7 @@ public class MyCompiler implements MyCompilerAPI
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.m_AbstractSyntaxTree.21280.declaration
|
||||
private SourceFile m_AbstractSyntaxTree;
|
||||
private Vector<SourceFile> m_AbstractSyntaxTree = new Vector<SourceFile>();
|
||||
// ino.end
|
||||
|
||||
// ino.method.MyCompiler.21283.defdescription type=javadoc
|
||||
@ -248,11 +249,12 @@ public class MyCompiler implements MyCompilerAPI
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.parse.21292.definition
|
||||
private void parse(Reader reader)
|
||||
private void parse_backup(Reader reader)
|
||||
throws IOException, JavaParser.yyException
|
||||
// ino.end
|
||||
// ino.method.parse.21292.body
|
||||
{
|
||||
/*
|
||||
parserlog.info("#########################################");
|
||||
parserlog.info("# Parsen - START #");
|
||||
parserlog.info("#########################################\n");
|
||||
@ -459,6 +461,7 @@ public class MyCompiler implements MyCompilerAPI
|
||||
parserlog.info("#########################################");
|
||||
parserlog.info("# Parsen - ENDE #");
|
||||
parserlog.info("#########################################\n");
|
||||
*/
|
||||
} // end Methode parse()
|
||||
// ino.end
|
||||
|
||||
@ -501,32 +504,11 @@ public class MyCompiler implements MyCompilerAPI
|
||||
// ino.method.parse.21298.body
|
||||
{
|
||||
FileReader fr = new FileReader(file);
|
||||
this.parse(fr);
|
||||
this.m_AbstractSyntaxTree.add(this.parse2SyntaxTree(file.getName(), fr));
|
||||
fr.close();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.parse.21301.defdescription type=javadoc
|
||||
/**
|
||||
* Author: J�rg B�uerle<br/>
|
||||
* Ruft die Parse-Methode.
|
||||
* @param srcCode Der zu parsende Quellcode
|
||||
* @throws IOException Wenn was schief l�uft.
|
||||
* @throws JavaParser.yyException Wenn ein Fehler beim Parsen auftritt.
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.parse.21301.definition
|
||||
public void parse(String srcCode)
|
||||
throws IOException, yyException
|
||||
// ino.end
|
||||
// ino.method.parse.21301.body
|
||||
{
|
||||
StringReader sr = new StringReader(srcCode);
|
||||
this.parse(sr);
|
||||
sr.close();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
// ino.method.typeReconstruction.21304.defdescription type=javadoc
|
||||
/**
|
||||
* Author: J�rg B�uerle<br/>
|
||||
@ -550,10 +532,13 @@ public class MyCompiler implements MyCompilerAPI
|
||||
inferencelog.info("# TypeReconstruction-Algorithmus - START #");
|
||||
inferencelog.info("##########################################\n");
|
||||
|
||||
TypeAssumptions globalAssumptions = m_AbstractSyntaxTree.makeBasicAssumptions();
|
||||
TypeAssumptions globalAssumptions = m_AbstractSyntaxTree.elementAt(0).makeBasicAssumptions();
|
||||
Vector<TypeinferenceResultSet> result = new Vector<TypeinferenceResultSet>();
|
||||
for(SourceFile srcFile : m_AbstractSyntaxTree){
|
||||
result.addAll(srcFile.typeReconstruction(globalAssumptions));
|
||||
|
||||
}
|
||||
|
||||
Vector<TypeinferenceResultSet> result = m_AbstractSyntaxTree.typeReconstruction(globalAssumptions);
|
||||
|
||||
inferencelog.info("#########################################");
|
||||
inferencelog.info("# TypeReconstruction-Algorithmus - ENDE #");
|
||||
inferencelog.info("#########################################\n");
|
||||
@ -562,23 +547,7 @@ public class MyCompiler implements MyCompilerAPI
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.getSyntaxTree.21307.defdescription type=javadoc
|
||||
/**
|
||||
* Author: J�rg B�uerle<br/>
|
||||
* Liefert den geparsten Syntaxbaume zur�ck.
|
||||
* @return Die Syntaxb�ume
|
||||
* @throws NullPointerException Wenn noch keine Syntaxb�ume berechnet worden sind.
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.getSyntaxTree.21307.definition
|
||||
public SourceFile getSyntaxTree()
|
||||
throws NullPointerException
|
||||
// ino.end
|
||||
// ino.method.getSyntaxTree.21307.body
|
||||
{
|
||||
return m_AbstractSyntaxTree;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
// ino.method.codeGeneration.21310.defdescription type=javadoc
|
||||
/**
|
||||
@ -599,7 +568,7 @@ public class MyCompiler implements MyCompilerAPI
|
||||
}
|
||||
codegenlog.info("Beginn der Codegenerierung ...");
|
||||
|
||||
m_AbstractSyntaxTree.codegen();
|
||||
//m_AbstractSyntaxTree.codegen();
|
||||
|
||||
codegenlog.info("Codegenerierung beendet!");
|
||||
}
|
||||
@ -778,9 +747,69 @@ public class MyCompiler implements MyCompilerAPI
|
||||
}
|
||||
|
||||
/**
|
||||
* Alle übergebenen Dateien werden zu einem String zusammengefügt und gemeinsam in einer SourceFile geparst.
|
||||
* Parst den Inhalt einer Datei zu einem Syntaxbaum.
|
||||
*/
|
||||
private SourceFile parse2SyntaxTree(String filename, Reader fileContent){
|
||||
|
||||
//StringReader reader = new StringReader(fileContent);
|
||||
//////////////////////////////////////
|
||||
// Scanner und Parser erzeugen:
|
||||
//////////////////////////////////////
|
||||
Scanner scanner = new Scanner(fileContent);
|
||||
JavaParser parser = new JavaParser();
|
||||
|
||||
//////////////////////////////////////
|
||||
// Parsen ==> Ergebnis: srcFile
|
||||
//////////////////////////////////////
|
||||
SourceFile srcFile = null;
|
||||
try {
|
||||
srcFile = (SourceFile) parser.yyparse( scanner );
|
||||
} catch (IOException | yyException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
//////////////////////////////////////
|
||||
// Postprocessing:
|
||||
//////////////////////////////////////
|
||||
srcFile.setFileName(filename);
|
||||
srcFile.parserPostProcessing(null); //Muss mit null aufgerufen werden.
|
||||
//Fertig:
|
||||
return srcFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Diese Funktion nimmt einen Vector von Dateinamen. Alle diese Dateien werden zu einem SyntaxBaum geparst.
|
||||
*/
|
||||
public void parse(Vector<String> filenames) {
|
||||
|
||||
for(String filename : filenames){
|
||||
StringBuffer fileData = new StringBuffer();
|
||||
BufferedReader reader;
|
||||
try {
|
||||
reader = new BufferedReader(
|
||||
new FileReader(filename));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new TypinferenzException("Die Datei "+ filename+" konnte nicht gelesen werden.");
|
||||
}
|
||||
char[] buf = new char[1024];
|
||||
int numRead=0;
|
||||
try {
|
||||
while((numRead=reader.read(buf)) != -1){
|
||||
String readData = String.valueOf(buf, 0, numRead);
|
||||
fileData.append(readData);
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
StringReader srcreader = new StringReader(fileData.toString());
|
||||
//Den aus der Datei ausgelesenen Quellcode zu einem Syntaxbaum parsen:
|
||||
this.m_AbstractSyntaxTree.add(parse2SyntaxTree(filename,srcreader)); // Alle Dateien nacheinander hintereinander anhängen...
|
||||
|
||||
}
|
||||
/*
|
||||
String gesamterSrc = "";
|
||||
//Hier werden alle übergebenen Dateinamen abgearbeitet:
|
||||
for(String filename : filenames){
|
||||
@ -811,7 +840,7 @@ public class MyCompiler implements MyCompilerAPI
|
||||
//throw new TypinferenzException("Fehler beim Parsen");
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -61,13 +61,14 @@ public interface MyCompilerAPI
|
||||
* @param srcCode Der zu parsende Quellcode
|
||||
* @throws IOException Wenn was schief läuft.
|
||||
* @throws JavaParser.yyException Wenn ein Fehler beim Parsen auftritt.
|
||||
*/
|
||||
|
||||
// ino.end
|
||||
// ino.method.parse.21337.declaration
|
||||
public void parse(String srcCode)
|
||||
throws IOException, JavaParser.yyException;
|
||||
// ino.end
|
||||
|
||||
*/
|
||||
|
||||
// ino.method.typeReconstruction.21340.decldescription type=javadoc
|
||||
/**
|
||||
* Author: Jörg Bäuerle<br/>
|
||||
@ -83,19 +84,6 @@ public interface MyCompilerAPI
|
||||
throws NullPointerException, CTypeReconstructionException;
|
||||
// ino.end
|
||||
|
||||
// ino.method.getSyntaxTree.21343.decldescription type=javadoc
|
||||
/**
|
||||
* Author: Jörg Bäuerle<br/>
|
||||
* Liefert den geparsten Syntaxbaum zurück.
|
||||
* @return Die Syntaxbäume
|
||||
* @throws NullPointerException Wenn noch kein Syntaxbaum berechnet worden ist.
|
||||
*/
|
||||
// ino.end
|
||||
// ino.method.getSyntaxTree.21343.declaration
|
||||
public SourceFile getSyntaxTree()
|
||||
throws NullPointerException;
|
||||
// ino.end
|
||||
|
||||
// ino.method.codeGeneration.21346.decldescription type=javadoc
|
||||
/**
|
||||
* Author: Jörg Bäuerle<br/>
|
||||
|
@ -42,6 +42,7 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import sun.reflect.generics.reflectiveObjects.TypeVariableImpl;
|
||||
import typinferenz.ConstraintsSet;
|
||||
import typinferenz.FunN;
|
||||
import typinferenz.TypinferenzException;
|
||||
import typinferenz.UndConstraint;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
|
||||
@ -50,6 +51,7 @@ import typinferenz.assumptions.TypeAssumptions;
|
||||
|
||||
// ino.class.SourceFile.21355.declaration
|
||||
public class SourceFile
|
||||
implements SyntaxTreeNode
|
||||
// ino.end
|
||||
// ino.class.SourceFile.21355.body
|
||||
{
|
||||
@ -121,37 +123,13 @@ public class SourceFile
|
||||
// ino.attribute.InterfaceVektor.21379.declaration
|
||||
public Vector<Interface> InterfaceVektor = new Vector<Interface>();
|
||||
// ino.end
|
||||
|
||||
// ino.attribute.imports.21382.decldescription type=javadoc
|
||||
private String filename;
|
||||
/**
|
||||
* HOTI 4.5.06
|
||||
* Beinhaltet alle Imports des aktuell geparsten Files
|
||||
* in Form einer UsedId
|
||||
* Die SourceFile repräsntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
|
||||
* SourceFile stellt dabei den Wurzelknoten des Syntaxbaumes dar.
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.imports.21382.declaration
|
||||
private ImportDeclarations imports=new ImportDeclarations();
|
||||
// ino.end
|
||||
// ino.attribute.baseTypeTranslationTable.21385.decldescription type=javadoc
|
||||
/**
|
||||
* Table zum Übersetzen der nicht implementierten Base-Types:
|
||||
* Überall im Compiler wird statt bspw. int Integer verwendet
|
||||
* d.h. 1+2 liefert ein Integer
|
||||
* Deshalb benötigen wir hier eine Tabelle, mit der man die von
|
||||
* der JRE gelieferten Base-Typen (int,char, etc) und die Objekt-
|
||||
* Typen umwandeln können
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.baseTypeTranslationTable.21385.declaration
|
||||
private Hashtable<String,String> baseTypeTranslationTable;
|
||||
// ino.end
|
||||
|
||||
// ino.method.SourceFile.21388.definition
|
||||
public SourceFile()
|
||||
// ino.end
|
||||
// ino.method.SourceFile.21388.body
|
||||
{
|
||||
// HOTI 4.5.06
|
||||
public SourceFile(){
|
||||
// HOTI 4.5.06
|
||||
// Base-Type-Translations anlegen (siehe kommentar BaseTypeTranslationTable)
|
||||
baseTypeTranslationTable=new Hashtable<String,String>();
|
||||
baseTypeTranslationTable.put("int","java.lang.Integer");
|
||||
@ -180,7 +158,32 @@ public class SourceFile
|
||||
this.imports.add(UsedId.createFromQualifiedName("java.lang.Object",-1));
|
||||
}
|
||||
}
|
||||
|
||||
// ino.attribute.imports.21382.decldescription type=javadoc
|
||||
/**
|
||||
* HOTI 4.5.06
|
||||
* Beinhaltet alle Imports des aktuell geparsten Files
|
||||
* in Form einer UsedId
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.imports.21382.declaration
|
||||
private ImportDeclarations imports=new ImportDeclarations();
|
||||
// ino.end
|
||||
// ino.attribute.baseTypeTranslationTable.21385.decldescription type=javadoc
|
||||
/**
|
||||
* Table zum Übersetzen der nicht implementierten Base-Types:
|
||||
* Überall im Compiler wird statt bspw. int Integer verwendet
|
||||
* d.h. 1+2 liefert ein Integer
|
||||
* Deshalb benötigen wir hier eine Tabelle, mit der man die von
|
||||
* der JRE gelieferten Base-Typen (int,char, etc) und die Objekt-
|
||||
* Typen umwandeln können
|
||||
*/
|
||||
// ino.end
|
||||
// ino.attribute.baseTypeTranslationTable.21385.declaration
|
||||
private Hashtable<String,String> baseTypeTranslationTable;
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
|
||||
// ino.method.addElement.21394.defdescription type=javadoc
|
||||
@ -1498,5 +1501,34 @@ public class SourceFile
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
if(parent!=null)throw new TypinferenzException("Eine SourceFile hat keine Elternelement im Syntaxbaum");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SyntaxTreeNode getParent() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vector<SyntaxTreeNode> getChildren() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SourceFile stellt eine geparste Java-Datei dar. Mit dieser Methode wird der Name der eingelesenen Datei gesetzt.
|
||||
* @param filename - Der Name der eingelesenen JavaDatei
|
||||
*/
|
||||
public void setFileName(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -1,5 +1,18 @@
|
||||
package mycompiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public interface SyntaxTreeNode {
|
||||
|
||||
/**
|
||||
* Wird nach dem Parsen aufgerufen.
|
||||
* Erfüllt folgenden Aufgaben:
|
||||
* 1. Füllt fehlende Typangaben mit TPHs auf.
|
||||
* 2. Verknüpft die Knoten des Syntaxbaums. (setzt Parent)
|
||||
*
|
||||
*/
|
||||
public void parserPostProcessing(SyntaxTreeNode parent);
|
||||
|
||||
public SyntaxTreeNode getParent();
|
||||
public Vector<SyntaxTreeNode> getChildren();
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ public class Class extends AClassOrInterface implements SyntaxTreeNode
|
||||
protected Logger parselog = Logger.getLogger("parser");
|
||||
// ino.end
|
||||
protected Logger typinferenzLog = Logger.getLogger("Typeinference");
|
||||
private SyntaxTreeNode parent;
|
||||
|
||||
|
||||
// ino.method.Class.23041.definition
|
||||
@ -1129,6 +1130,22 @@ public class Class extends AClassOrInterface implements SyntaxTreeNode
|
||||
TypeAssumptions ret = this.getTypeAssumptions();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parserPostProcessing(SyntaxTreeNode parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SyntaxTreeNode getParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector<SyntaxTreeNode> getChildren() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -2,28 +2,29 @@ package mycompiler.myclass;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.myexception.JVMCodeException;
|
||||
import mycompiler.mytype.Type;
|
||||
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.Typable;
|
||||
import typinferenz.Typeable;
|
||||
import typinferenz.TypeInsertable;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
|
||||
public abstract class Field implements TypeInsertable, Typable{
|
||||
public abstract class Field implements TypeInsertable, Typeable, SyntaxTreeNode{
|
||||
// ino.attribute.declid.23370.declaration
|
||||
protected Vector<DeclId> declid = new Vector<DeclId>(); // Vector, da 'int a, b, c, ...' auch eingeparst werden muss
|
||||
|
||||
private Type typ;
|
||||
|
||||
@Override
|
||||
public void setTypeVariable(Type typ) {
|
||||
public void setType(Type typ) {
|
||||
this.typ = typ;
|
||||
}
|
||||
@Override
|
||||
public Type getTypeVariable() {
|
||||
public Type getType() {
|
||||
return typ;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import java.util.Vector;
|
||||
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.Typable;
|
||||
import typinferenz.Typeable;
|
||||
import typinferenz.TypeInsertable;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
|
@ -16,11 +16,11 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.Typable;
|
||||
import typinferenz.Typeable;
|
||||
import typinferenz.TypeInsertable;
|
||||
|
||||
// ino.class.FormalParameter.23391.declaration
|
||||
public class FormalParameter implements ITypeReplacementListener, Typable, TypeInsertable
|
||||
public class FormalParameter implements ITypeReplacementListener, Typeable, TypeInsertable
|
||||
// ino.end
|
||||
// ino.class.FormalParameter.23391.body
|
||||
{
|
||||
@ -180,21 +180,14 @@ public class FormalParameter implements ITypeReplacementListener, Typable, TypeI
|
||||
|
||||
//private Type typeVariable;
|
||||
|
||||
public void setTypeVariable(Type typ) {
|
||||
this.setType(typ);
|
||||
}
|
||||
public Type getTypeVariable() {
|
||||
return this.getType();
|
||||
}
|
||||
|
||||
public String getTypeInformation() {
|
||||
return getTypeVariable().toString() + " " +this.get_Name();
|
||||
return getType().toString() + " " +this.get_Name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
String ret = "";
|
||||
if(this.getTypeVariable() != null)ret += this.getTypeVariable().toString();
|
||||
if(this.getType() != null)ret += this.getType().toString();
|
||||
if(this.get_Name() != null)ret += " "+get_Name();
|
||||
return ret;
|
||||
}
|
||||
@ -202,7 +195,7 @@ public class FormalParameter implements ITypeReplacementListener, Typable, TypeI
|
||||
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
JavaCodeResult ret = new JavaCodeResult();
|
||||
if(this.getTypeVariable() != null)ret.attach(this.getTypeVariable().printJavaCode(resultSet));
|
||||
if(this.getType() != null)ret.attach(this.getType().printJavaCode(resultSet));
|
||||
if(this.get_Name() != null)ret.attach(" "+get_Name());
|
||||
|
||||
return ret;
|
||||
|
@ -197,7 +197,7 @@ public class Method extends Field implements ITypeReplacementListener, IItemWith
|
||||
// this.returntype = type; //auskommentiert von Andreas Stadelmeier (a10023)
|
||||
//Der ReturnType der Methode ist der Returntype des Methodenblocks:
|
||||
if(block!=null)
|
||||
this.block.setTypeVariable(type);
|
||||
this.block.setType(type);
|
||||
this.returntype = type;
|
||||
}
|
||||
// ino.end
|
||||
@ -207,7 +207,7 @@ public class Method extends Field implements ITypeReplacementListener, IItemWith
|
||||
// ino.end
|
||||
// ino.method.set_Block.23542.body
|
||||
{
|
||||
if(blo.getTypeVariable() == null)blo.setTypeVariable(this.returntype);
|
||||
if(blo.getType() == null)blo.setType(this.returntype);
|
||||
this.block = blo;
|
||||
}
|
||||
// ino.end
|
||||
@ -306,7 +306,7 @@ public class Method extends Field implements ITypeReplacementListener, IItemWith
|
||||
// ino.end
|
||||
// ino.method.getReturnType.23569.body
|
||||
{
|
||||
return this.block.getTypeVariable();
|
||||
return this.block.getType();
|
||||
//return this.returntype; //auskommentiert von Andreas Stadelmeier (a10023)
|
||||
}
|
||||
// ino.end
|
||||
@ -549,7 +549,7 @@ public class Method extends Field implements ITypeReplacementListener, IItemWith
|
||||
|
||||
ret.add(this.block.TYPEStmt(ass));
|
||||
//eine Verknüpfung mit der Type Assumption aus dem Assumption Set und dem ermittelten Typ der Methode:
|
||||
ret.add(new SingleConstraint(this.block.getTypeVariable(), assumedType));
|
||||
ret.add(new SingleConstraint(this.block.getType(), assumedType));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1383,7 +1383,7 @@ case 79:
|
||||
case 80:
|
||||
// line 884 "./../src/mycompiler/myparser/JavaParser.jay"
|
||||
{
|
||||
((FieldDeclaration)yyVals[0+yyTop]).setTypeVariable(((Type)yyVals[-1+yyTop]));
|
||||
((FieldDeclaration)yyVals[0+yyTop]).setType(((Type)yyVals[-1+yyTop]));
|
||||
yyVal=((FieldDeclaration)yyVals[0+yyTop]);
|
||||
}
|
||||
break;
|
||||
|
@ -196,9 +196,9 @@ public class Assign extends Expr
|
||||
ret.add(expr1.TYPEExpr(assumptions));
|
||||
ret.add(expr2.TYPEExpr(assumptions));
|
||||
//this.setTypeVariable( TypePlaceholder.fresh(this));
|
||||
this.setTypeVariable(TypePlaceholder.fresh(this));
|
||||
ret.add(new SingleConstraint(expr2.getTypeVariable(), expr1.getTypeVariable())); //expr1.type < expr2.type
|
||||
ret.add(new SingleConstraint(expr1.getTypeVariable(), this.getTypeVariable()));
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
ret.add(new SingleConstraint(expr2.getType(), expr1.getType())); //expr1.type < expr2.type
|
||||
ret.add(new SingleConstraint(expr1.getType(), this.getType()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -211,7 +211,7 @@ public class Assign extends Expr
|
||||
@Override
|
||||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){
|
||||
ConstraintsSet ret = this.TYPEExpr(assumptions); //TypeExpr aufrufen
|
||||
this.setTypeVariable(new Void(0)); //Typ des Statments auf Void setzen.
|
||||
this.setType(new Void(0)); //Typ des Statments auf Void setzen.
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -228,8 +228,8 @@ public class Assign extends Expr
|
||||
// ino.end
|
||||
// ino.method.toString.24960.body
|
||||
{
|
||||
if(getTypeVariable() == null)return "(" + expr1.toString() + " = " + expr2.toString() + ")";
|
||||
return getTypeVariable().toString() + "(" + expr1.toString() + " = " + expr2.toString() + ")";
|
||||
if(getType() == null)return "(" + expr1.toString() + " = " + expr2.toString() + ")";
|
||||
return getType().toString() + "(" + expr1.toString() + " = " + expr2.toString() + ")";
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@ -250,7 +250,7 @@ public class Assign extends Expr
|
||||
|
||||
@Override
|
||||
public String getTypeInformation(){
|
||||
return "(" + expr1.getTypeInformation() + " = " + expr2.getTypeInformation() + ") : "+this.getTypeVariable();
|
||||
return "(" + expr1.getTypeInformation() + " = " + expr2.getTypeInformation() + ") : "+this.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -233,20 +233,20 @@ public class Block extends Statement
|
||||
if(statements.size()>0){
|
||||
Statement stmt = statements.elementAt(statements.size()-1);
|
||||
typinferenceLog.debug("Prozessing statement: "+stmt);
|
||||
this.setTypeVariable(stmt.getTypeVariable());
|
||||
this.setType(stmt.getType());
|
||||
for(int i= statements.size()-2; i >= 0; i--) {
|
||||
stmt = statements.elementAt(i);
|
||||
typinferenceLog.debug("Prozessing statement: "+stmt);
|
||||
if (!(stmt.getTypeVariable() instanceof Void))
|
||||
if (this.getTypeVariable() instanceof Void) {
|
||||
if (!(stmt.getType() instanceof Void))
|
||||
if (this.getType() instanceof Void) {
|
||||
//this.setTypeVariable(stmt.getTypeVariable());
|
||||
throw new TypinferenzException("Falscher Return Type");
|
||||
}
|
||||
else {
|
||||
TypePlaceholder tph = TypePlaceholder.fresh(this);
|
||||
ret.add(new SingleConstraint(this.getTypeVariable(), tph));
|
||||
ret.add(new SingleConstraint(stmt.getTypeVariable(), tph));
|
||||
this.setTypeVariable(tph);
|
||||
ret.add(new SingleConstraint(this.getType(), tph));
|
||||
ret.add(new SingleConstraint(stmt.getType(), tph));
|
||||
this.setType(tph);
|
||||
}
|
||||
}
|
||||
if (this.type instanceof TypePlaceholder) {
|
||||
|
@ -46,22 +46,13 @@ public abstract class ExprStmt extends Statement implements ITypeReplacementList
|
||||
// ino.end
|
||||
// ino.method.getTypeName.25279.body
|
||||
{
|
||||
if (getTypeVariable()!=null)
|
||||
return getTypeVariable().getName();
|
||||
if (getType()!=null)
|
||||
return getType().getName();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
// ino.end
|
||||
|
||||
// ino.method.getType.25282.definition
|
||||
public Type getType()
|
||||
// ino.end
|
||||
// ino.method.getType.25282.body
|
||||
{
|
||||
return getTypeVariable();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
||||
|
||||
// ino.method.getTypeLineNumber.25291.defdescription type=javadoc
|
||||
|
@ -379,18 +379,18 @@ public class IfStmt extends Statement
|
||||
@Override
|
||||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
this.setTypeVariable(TypePlaceholder.fresh(this));
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
|
||||
ret.add(expr.TYPEExpr(assumptions)); // die Constraints für (expressionDesIfStmt)
|
||||
ret.add(this.then_block.TYPEStmt(assumptions));
|
||||
if(else_block!=null){
|
||||
ret.add(this.else_block.TYPEStmt(assumptions));
|
||||
if(!(else_block.getTypeVariable() instanceof Void))ret.add(new SingleConstraint(else_block.getTypeVariable(),this.getTypeVariable()));
|
||||
if(!(else_block.getType() instanceof Void))ret.add(new SingleConstraint(else_block.getType(),this.getType()));
|
||||
}
|
||||
ret.add(new SingleConstraint(expr.getTypeVariable(),new RefType("boolean",0))); //(expressionDesIfStmt)<.boolean
|
||||
if(!(then_block.getTypeVariable() instanceof Void))ret.add(new SingleConstraint(then_block.getTypeVariable(),this.getTypeVariable()));
|
||||
if(then_block.getTypeVariable() instanceof Void &&
|
||||
(else_block == null || else_block.getTypeVariable() instanceof Void))this.setTypeVariable(new Void(this.getOffset()));
|
||||
ret.add(new SingleConstraint(expr.getType(),new RefType("boolean",0))); //(expressionDesIfStmt)<.boolean
|
||||
if(!(then_block.getType() instanceof Void))ret.add(new SingleConstraint(then_block.getType(),this.getType()));
|
||||
if(then_block.getType() instanceof Void &&
|
||||
(else_block == null || else_block.getType() instanceof Void))this.setType(new Void(this.getOffset()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -266,7 +266,7 @@ public class InstVar extends Expr
|
||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
ret.add(expr.TYPEExpr(assumptions));
|
||||
this.setTypeVariable(TypePlaceholder.fresh(this));
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ public class IntLiteral extends Literal
|
||||
// ino.end
|
||||
// ino.method.toString.25484.body
|
||||
{
|
||||
return getTypeVariable().toString() + " " + Int;
|
||||
return getType().toString() + " " + Int;
|
||||
}
|
||||
// ino.end
|
||||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25487.definition
|
||||
@ -204,7 +204,7 @@ public class IntLiteral extends Literal
|
||||
@Override
|
||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
this.setTypeVariable(new IntegerType());
|
||||
this.setType(new IntegerType());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import typinferenz.ConstraintsSet;
|
||||
import typinferenz.FreshTypeVariable;
|
||||
import typinferenz.FunN;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.Typable;
|
||||
import typinferenz.Typeable;
|
||||
import typinferenz.TypinferenzException;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
@ -126,16 +126,16 @@ public class LambdaExpression extends Expr{
|
||||
Vector<Type> paramTypes = new Vector<Type>();
|
||||
|
||||
for(FormalParameter param : params.formalparameter){
|
||||
if(param.getTypeVariable()==null)param.setTypeVariable(TypePlaceholder.fresh(this));
|
||||
if(param.getType()==null)param.setType(TypePlaceholder.fresh(this));
|
||||
int offset = 0;
|
||||
//Jeder Parameter der LambdaExpression wird als CParaTypeAssumption der Assumption liste hinzugefügt:
|
||||
ArgumentAssumptions.add(new CParaTypeAssumption("", "", offset, offset, param.get_Name(), param.getTypeVariable(), offset, offset, null));
|
||||
paramTypes.add(param.getTypeVariable());
|
||||
ArgumentAssumptions.add(new CParaTypeAssumption("", "", offset, offset, param.get_Name(), param.getType(), offset, offset, null));
|
||||
paramTypes.add(param.getType());
|
||||
}
|
||||
this.setTypeVariable(TypePlaceholder.fresh(this));
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
//ArgumentAssumptions + assumptions ergeben die Assumptions für die Statements innerhalb des Lambda-Bodys:
|
||||
ret.add(method_body.TYPEStmt(ArgumentAssumptions.add(assumptions))); //Es gibt die LambdaExpression nur mit einem Block als Method Body, nicht mit einer einzelnen Expression
|
||||
ret.add(new SingleConstraint(new FunN(method_body.getTypeVariable(), paramTypes),this.getTypeVariable()));
|
||||
ret.add(new SingleConstraint(new FunN(method_body.getType(), paramTypes),this.getType()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ public class LambdaExpression extends Expr{
|
||||
|
||||
@Override
|
||||
public String getTypeInformation(){
|
||||
return this.getTypeVariable().toString()+" :: ("+this.params.getTypeInformation()+ ") -> " +this.method_body.getTypeInformation();
|
||||
return this.getType().toString()+" :: ("+this.params.getTypeInformation()+ ") -> " +this.method_body.getTypeInformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -145,8 +145,8 @@ public class LocalOrFieldVar extends Expr
|
||||
}
|
||||
|
||||
// Falls noetig, Unboxing auf primitiven Typ!
|
||||
if (this.getTypeVariable() instanceof RefType) {
|
||||
RefType rt = (RefType) this.getTypeVariable();
|
||||
if (this.getType() instanceof RefType) {
|
||||
RefType rt = (RefType) this.getType();
|
||||
if (! rt.getPrimitiveFlag()) return;
|
||||
|
||||
if (rt.getName().equalsIgnoreCase("java.lang.Integer")) { // Int Unboxen
|
||||
@ -178,8 +178,8 @@ public class LocalOrFieldVar extends Expr
|
||||
// ino.end
|
||||
// ino.method.toString.25534.body
|
||||
{
|
||||
if(getTypeVariable()==null)return usedid.toString();
|
||||
return usedid.toString() + ": " + getTypeVariable().toString();
|
||||
if(getType()==null)return usedid.toString();
|
||||
return usedid.toString() + ": " + getType().toString();
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@ -205,13 +205,13 @@ 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.setTypeVariable(thisTypeAssumption);
|
||||
this.setType(thisTypeAssumption);
|
||||
//ret.add(new Constraint(thisTypeAssumption, this.getTypeVariable()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getTypeInformation(){
|
||||
return this.getTypeVariable()+" "+this.get_Name();
|
||||
return this.getType()+" "+this.get_Name();
|
||||
|
||||
}
|
||||
|
||||
|
@ -362,12 +362,12 @@ public class LocalVarDecl extends Statement implements ITypeReplacementListener
|
||||
// ino.end
|
||||
// ino.method.replaceType.25608.body
|
||||
{
|
||||
if(e.getOldType().equals(this.getTypeVariable())){
|
||||
if(e.getOldType().equals(this.getType())){
|
||||
inferencelog.debug("Ersetze Typ in LocalVarDecl \""+this.get_Name()+"\"\n");
|
||||
if(getTypeVariable() instanceof TypePlaceholder){
|
||||
((TypePlaceholder)getTypeVariable()).removeReplacementListener(this);
|
||||
if(getType() instanceof TypePlaceholder){
|
||||
((TypePlaceholder)getType()).removeReplacementListener(this);
|
||||
}
|
||||
this.setTypeVariable(e.getNewType());
|
||||
this.setType(e.getNewType());
|
||||
}
|
||||
if(e.getOldType().equals(this.getDeclType())){
|
||||
inferencelog.debug("Ersetze Typ in LocalVarDecl \""+this.get_Name()+"\"\n");
|
||||
@ -484,7 +484,7 @@ public class LocalVarDecl extends Statement implements ITypeReplacementListener
|
||||
if(this.getDeclType()==null || this.getDeclType() instanceof TypePlaceholder)this.setDeclType(TypePlaceholder.fresh(this));
|
||||
assumptions.addInstVarAssumption(assumptions.getThisValue().getName(), this.get_Name(), this.getDeclType());
|
||||
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
|
||||
this.setTypeVariable(new Void(0)); //Return typ einer Variablendeklaration ist Void
|
||||
this.setType(new Void(0)); //Return typ einer Variablendeklaration ist Void
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ public class LongLiteral extends Literal
|
||||
// ino.end
|
||||
// ino.method.toString.25484.body
|
||||
{
|
||||
return getTypeVariable().toString() + " " + Long;
|
||||
return getType().toString() + " " + Long;
|
||||
}
|
||||
// ino.end
|
||||
// ino.method.wandleRefTypeAttributes2GenericAttributes.25487.definition
|
||||
|
@ -259,13 +259,13 @@ public class MethodCall extends Expr
|
||||
// Auf eine TypePlaceholders-Variable (=> nichterkannte) kann kein Methodenaufruf ausgeführt werden
|
||||
// Es muss sich also um einen RefType handeln. Ansonsten gibt es einen Fehler
|
||||
|
||||
if(!(receiver.get_Expr().getTypeVariable() instanceof RefType)){
|
||||
throw new JVMCodeException("Es kann nur auf ein RefType ein Methodenaufruf ausgeführt werden ("+receiver+"["+receiver.get_Expr().getTypeVariable()+"])");
|
||||
if(!(receiver.get_Expr().getType() instanceof RefType)){
|
||||
throw new JVMCodeException("Es kann nur auf ein RefType ein Methodenaufruf ausgeführt werden ("+receiver+"["+receiver.get_Expr().getType()+"])");
|
||||
}
|
||||
|
||||
// HOTI 4.5.06
|
||||
// Es handelt sich also um einen RefType. Der Klassenname wird nun bezogen
|
||||
String receiverClassName=((RefType)receiver.get_Expr().getTypeVariable()).getTypeName();
|
||||
String receiverClassName=((RefType)receiver.get_Expr().getType()).getTypeName();
|
||||
|
||||
// Die richtige Methode wird gesucht und gesetzt
|
||||
called_method=getMethodFittingMethodCallAndClassname(receiverClassName);
|
||||
@ -668,7 +668,7 @@ public class MethodCall extends Expr
|
||||
//Hier der Ablauf für einen Methodenaufruf:
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
//Der Return-Type des MEthodenaufrufs ist zunächst unbekannt:
|
||||
this.setTypeVariable(TypePlaceholder.fresh(this));
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
//Berechne die Constraints des Receivers
|
||||
if(receiver == null){
|
||||
receiver = new Receiver(new This(0,0));
|
||||
@ -681,7 +681,7 @@ public class MethodCall extends Expr
|
||||
}
|
||||
|
||||
//Noch das Overloading-Constraint anhängen:
|
||||
ret.add(new Overloading(assumptions, this, this.getTypeVariable()).generateConsstraints());
|
||||
ret.add(new Overloading(assumptions, this, this.getType()).generateConsstraints());
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -695,7 +695,7 @@ public class MethodCall extends Expr
|
||||
@Override
|
||||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){
|
||||
ConstraintsSet ret = this.TYPEExpr(assumptions); //TypeExpr aufrufen
|
||||
this.setTypeVariable(new Void(0)); //Typ des Statments auf Void setzen, da als alleinstehendes Statement
|
||||
this.setType(new Void(0)); //Typ des Statments auf Void setzen, da als alleinstehendes Statement
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ public class NewClass extends Expr
|
||||
// ino.method.toString.25867.body
|
||||
{
|
||||
String ret = "NEW ";
|
||||
Type thisType = getTypeVariable();
|
||||
Type thisType = getType();
|
||||
if(thisType != null)ret += thisType.toString();
|
||||
else ret += this.get_Name();
|
||||
return ret;
|
||||
@ -241,11 +241,11 @@ public class NewClass extends Expr
|
||||
|
||||
//Ein new-Aufruf ist nichts anderes als ein MethodCall der Methode <init>
|
||||
MethodCall newAufruf = new MethodCall(0,0);
|
||||
this.setTypeVariable(new RefType(this.get_Name(),0));
|
||||
this.setType(new RefType(this.get_Name(),0));
|
||||
newAufruf.type = new RefType(this.get_Name(),0);
|
||||
newAufruf.set_Name("<init>");
|
||||
newAufruf.set_Receiver(null);
|
||||
ret.add(new Overloading(assumptions, newAufruf, this.getTypeVariable()).generateConsstraints());
|
||||
ret.add(new Overloading(assumptions, newAufruf, this.getType()).generateConsstraints());
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -266,7 +266,7 @@ public class NewClass extends Expr
|
||||
@Override
|
||||
public JavaCodeResult printJavaCode(ResultSet resultSet) {
|
||||
JavaCodeResult ret = new JavaCodeResult("new ");
|
||||
ret.attach(this.getTypeVariable().printJavaCode(resultSet));
|
||||
ret.attach(this.getType().printJavaCode(resultSet));
|
||||
ret.attach("(");
|
||||
if(this.arglist!=null && this.arglist.expr != null){
|
||||
Iterator<Expr> it = this.arglist.expr.iterator();
|
||||
|
@ -117,8 +117,8 @@ public class Return extends Statement
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
ret.add(this.retexpr.TYPEExpr(assumptions));
|
||||
//this.setTypeVariable(TypePlaceholder.fresh("Return Type"));
|
||||
this.setTypeVariable(TypePlaceholder.fresh(this));
|
||||
ret.add(new SingleConstraint(retexpr.getTypeVariable(), this.getTypeVariable()));
|
||||
this.setType(TypePlaceholder.fresh(this));
|
||||
ret.add(new SingleConstraint(retexpr.getType(), this.getType()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ public class Return extends Statement
|
||||
|
||||
@Override
|
||||
public String getTypeInformation(){
|
||||
String ret = this.getTypeVariable()+" :: (Return "+this.retexpr.getTypeInformation()+")";
|
||||
String ret = this.getType()+" :: (Return "+this.retexpr.getTypeInformation()+")";
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,10 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import typinferenz.ConstraintsSet;
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.Typable;
|
||||
import typinferenz.Typeable;
|
||||
import typinferenz.assumptions.TypeAssumptions;
|
||||
import mycompiler.IItemWithOffset;
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mybytecode.ClassFile;
|
||||
import mycompiler.mybytecode.CodeAttribute;
|
||||
import mycompiler.myclass.Class;
|
||||
@ -36,7 +37,7 @@ import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption;
|
||||
|
||||
|
||||
// ino.class.Statement.26184.declaration
|
||||
public abstract class Statement implements IItemWithOffset, Typable, ITypeReplacementListener
|
||||
public abstract class Statement implements IItemWithOffset, Typeable, ITypeReplacementListener, SyntaxTreeNode
|
||||
// ino.end
|
||||
// ino.class.Statement.26184.body
|
||||
{
|
||||
@ -99,15 +100,9 @@ public abstract class Statement implements IItemWithOffset, Typable, ITypeReplac
|
||||
*/
|
||||
public abstract ConstraintsSet TYPEStmt(TypeAssumptions assumptions);
|
||||
|
||||
/**
|
||||
* @author AI10023 - Andreas Stadelmeier
|
||||
* Jedem Statement und jeder Expression wird im Zuge des Typinferenzalgorithmus eine Typvariable zugewiesen.
|
||||
* Daher müssen alle Statements und Expressions die Methoden setTypeVariable und getTypeVariable implementieren.
|
||||
*/
|
||||
public void setTypeVariable(Type typ){
|
||||
this.setType(typ);
|
||||
}
|
||||
public Type getTypeVariable(){
|
||||
|
||||
|
||||
public Type getType(){
|
||||
return type;
|
||||
}
|
||||
|
||||
@ -123,14 +118,14 @@ public abstract class Statement implements IItemWithOffset, Typable, ITypeReplac
|
||||
|
||||
|
||||
/**
|
||||
* <br/>Author: J�rg B�uerle
|
||||
* Verschoben aus ExprStmt von Andreas Stadelmeier, a10023
|
||||
* @param t
|
||||
* @author AI10023 - Andreas Stadelmeier
|
||||
* Jedem Statement und jeder Expression wird im Zuge des Typinferenzalgorithmus eine Typvariable zugewiesen.
|
||||
* Daher müssen alle Statements und Expressions die Methoden setTypeVariable und getTypeVariable implementieren.
|
||||
*/
|
||||
public void setType(Type t)
|
||||
{
|
||||
if(this.getTypeVariable() instanceof TypePlaceholder){
|
||||
((TypePlaceholder)this.getTypeVariable()).removeReplacementListener(this);
|
||||
if(this.getType() instanceof TypePlaceholder){
|
||||
((TypePlaceholder)this.getType()).removeReplacementListener(this);
|
||||
}
|
||||
if(t instanceof TypePlaceholder){
|
||||
((TypePlaceholder)t).addReplacementListener(this);
|
||||
@ -140,8 +135,8 @@ public abstract class Statement implements IItemWithOffset, Typable, ITypeReplac
|
||||
|
||||
public void replaceType(CReplaceTypeEvent e)
|
||||
{
|
||||
if(getTypeVariable() instanceof TypePlaceholder){
|
||||
((TypePlaceholder)getTypeVariable()).removeReplacementListener(this);
|
||||
if(getType() instanceof TypePlaceholder){
|
||||
((TypePlaceholder)getType()).removeReplacementListener(this);
|
||||
}
|
||||
this.setType(e.getNewType());
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ public class This extends Expr
|
||||
public ConstraintsSet TYPEExpr(TypeAssumptions assumptions) {
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
//this.set_Type(new);
|
||||
this.setTypeVariable(assumptions.getThisValue());//Die Assumption für this als TypeVariable setzen.
|
||||
this.setType(assumptions.getThisValue());//Die Assumption für this als TypeVariable setzen.
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -180,10 +180,10 @@ public class WhileStmt extends Statement
|
||||
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
|
||||
ConstraintsSet ret = new ConstraintsSet();
|
||||
ret.add(expr.TYPEExpr(assumptions));
|
||||
SingleConstraint exprMustBeBool = new SingleConstraint(expr.getTypeVariable(), new RefType("boolean", 0)); // while(expr){}; expr <. boolean
|
||||
SingleConstraint exprMustBeBool = new SingleConstraint(expr.getType(), new RefType("boolean", 0)); // while(expr){}; expr <. boolean
|
||||
ret.add(exprMustBeBool);
|
||||
ret.add(this.loop_block.TYPEStmt(assumptions));
|
||||
this.setTypeVariable(loop_block.getTypeVariable());
|
||||
this.setType(loop_block.getType());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class Overloading{
|
||||
for(int i=0; i<assumption.getParaCount();i++){
|
||||
CParaTypeAssumption pAss = assumption.getParaAssumption(i);
|
||||
//Type der Argument Expressions <. AssumedType der Parameter
|
||||
methodConstraint.addConstraint( methodCall.getArgumentList().argumentAt(i).getTypeVariable(), pAss.getAssumedType());
|
||||
methodConstraint.addConstraint( methodCall.getArgumentList().argumentAt(i).getType(), pAss.getAssumedType());
|
||||
}
|
||||
Vector<Type> parameterAssumptions = new Vector<Type>();
|
||||
parameterAssumptions.add(assumption.getAssumedType());
|
||||
@ -73,7 +73,7 @@ public class Overloading{
|
||||
//Ein Constraint für den Receiver der Methode (falls vorhanden)...
|
||||
//ret.add(new Constraint(methodCall.get_Receiver().get_Expr().getTypeVariable(), new RefType(assumption.getClassName(), null, 0)));
|
||||
if(methodCall.get_Receiver() != null && methodCall.get_Receiver().get_Expr() != null)
|
||||
methodConstraint.addConstraint(methodCall.get_Receiver().get_Expr().getTypeVariable(), assumption.getClassType());
|
||||
methodConstraint.addConstraint(methodCall.get_Receiver().get_Expr().getType(), assumption.getClassType());
|
||||
//ret.add(new Constraint(methodCall.get_Receiver().get_Expr().getTypeVariable(), new RefType(assumption.getClassName(), parameterAssumptions, 0)));
|
||||
|
||||
//return ret; //Bereits nach der ersten Assumption abbrechen...
|
||||
|
@ -3,7 +3,7 @@ package typinferenz;
|
||||
import mycompiler.mytype.Type;
|
||||
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
|
||||
|
||||
public interface Typable {
|
||||
public interface Typeable {
|
||||
/**
|
||||
* @author Andreas Stadelmeier, a10023
|
||||
* Jede Expression und jedes Statement muss im Zuge des Typinferenzalgorithmus das Interfece Typable einbinden.
|
||||
@ -11,6 +11,6 @@ public interface Typable {
|
||||
* Dabei kann auch eine FreshTypeVariable als Typ vergeben werden.
|
||||
* @param typ Der Typ der Typable-Expression/Statement
|
||||
*/
|
||||
void setTypeVariable(Type typ);
|
||||
Type getTypeVariable();
|
||||
void setType(Type typ);
|
||||
Type getType();
|
||||
}
|
Loading…
Reference in New Issue
Block a user