ANTLR Parser erweitert

This commit is contained in:
JanUlrich 2017-02-10 17:37:42 +01:00
parent 8d0f24f2f8
commit 60a304667a
38 changed files with 175 additions and 201 deletions

View File

@ -109,7 +109,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/type/ObjectType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.ObjectType</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.type.RefType</li>
<li>de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH</li>
</ul>
</li>
</ul>

View File

@ -109,7 +109,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/type/ObjectType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.ObjectType</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/type/RefType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.RefType</a></li>
<li><a href="../../../../de/dhbwstuttgart/syntaxtree/type/RefType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.syntaxtree.type.Void</li>
@ -219,7 +219,7 @@ extends <a href="../../../../de/dhbwstuttgart/syntaxtree/type/RefType.html" titl
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.type.RefType">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;de.dhbwstuttgart.syntaxtree.type.<a href="../../../../de/dhbwstuttgart/syntaxtree/type/RefType.html" title="class in de.dhbwstuttgart.syntaxtree.type">RefType</a></h3>

View File

@ -3,7 +3,7 @@
<html lang="de">
<head>
<!-- Generated by javadoc (1.8.0_05) on Tue May 12 19:56:24 CEST 2015 -->
<title>Uses of Class de.dhbwstuttgart.syntaxtree.type.RefType</title>
<title>Uses of Class de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH</title>
<meta name="date" content="2015-05-12">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
@ -70,7 +70,7 @@
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.type.RefType" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.type.RefType</h2>
<h2 title="Uses of Class de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH" class="title">Uses of Class<br>de.dhbwstuttgart.syntaxtree.type.RefType</h2>
</div>
<div class="classUseContainer">
<ul class="blockList">

View File

@ -109,7 +109,7 @@ var activeTableTab = "activeTableTab";
<li><a href="../../../de/dhbwstuttgart/syntaxtree/type/ObjectType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.ObjectType</a></li>
<li>
<ul class="inheritance">
<li><a href="../../../de/dhbwstuttgart/syntaxtree/type/RefType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.RefType</a></li>
<li><a href="../../../de/dhbwstuttgart/syntaxtree/type/RefType.html" title="class in de.dhbwstuttgart.syntaxtree.type">de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH</a></li>
<li>
<ul class="inheritance">
<li>de.dhbwstuttgart.typeinference.FunN</li>
@ -245,7 +245,7 @@ extends <a href="../../../de/dhbwstuttgart/syntaxtree/type/RefType.html" title="
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.type.RefType">
<li class="blockList"><a name="methods.inherited.from.class.de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;de.dhbwstuttgart.syntaxtree.type.<a href="../../../de/dhbwstuttgart/syntaxtree/type/RefType.html" title="class in de.dhbwstuttgart.syntaxtree.type">RefType</a></h3>

View File

@ -10,16 +10,35 @@ import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class JavaTXParser {
public SourceFile parse(File sourceFile) throws IOException {
InputStream stream = new FileInputStream(sourceFile);
ANTLRInputStream input = new ANTLRInputStream(stream);
Java8Lexer lexer = new Java8Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Java8Parser parser = new Java8Parser(tokens);
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(new JavaClassRegistry());
return generator.convert(tree);
InputStream stream = new FileInputStream(sourceFile);
ANTLRInputStream input = new ANTLRInputStream(stream);
Java8Lexer lexer = new Java8Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
Java8Parser parser = new Java8Parser(tokens);
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(new JavaClassRegistry(generateJavaLangNames()));
return generator.convert(tree);
}
private List<String> generateJavaLangNames(){
List<String> ret = new ArrayList<>();
//TODO: Eigentlich sind es noch viele mehr:
ret.add("java.lang.String");
ret.add("java.lang.Boolean");
ret.add("java.lang.Integer");
ret.add("java.lang.Double");
ret.add("java.lang.Float");
ret.add("java.lang.Long");
ret.add("java.lang.Byte");
return ret;
}
}

View File

@ -7,6 +7,7 @@ import org.antlr.v4.runtime.CommonTokenStream;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.modifier.*;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
@ -24,7 +25,7 @@ public class RunParser{
CommonTokenStream tokens = new CommonTokenStream(lexer);
Java8Parser parser = new Java8Parser(tokens);
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(new JavaClassRegistry());
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(new JavaClassRegistry(new ArrayList<>()));
SourceFile f = generator.convert((Java8Parser.CompilationUnitContext) tree);
String pkgName = f.getPkgName();
System.out.println(pkgName);

View File

@ -7,14 +7,16 @@ import de.dhbwstuttgart.syntaxtree.modifier.fieldModifier.FieldModifier;
import de.dhbwstuttgart.syntaxtree.modifier.methodModifier.MethodModifier;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typecheck.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.TerminalNode;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
public class SyntaxTreeGenerator{
private JavaClassRegistry reg;
private String pkgName = "";
@ -44,6 +46,12 @@ public class SyntaxTreeGenerator{
else{
nameString = typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString();
}
//Die Generic TypeParameter Definitionen ebenfalls an die JavaClassName-Registry anfügen:
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
this.reg.add(tp.Identifier().toString());
}
}
this.reg.add(nameString);
}
}
@ -55,12 +63,18 @@ public class SyntaxTreeGenerator{
else{
nameString = typeDecl.classDeclaration().normalClassDeclaration().Identifier().toString();
}
//Die Generic TypeParameter Definitionen ebenfalls an die JavaClassName-Registry anfügen:
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
this.reg.add(tp.Identifier().toString());
}
}
this.reg.add(nameString);
}
}
}
}
public JavaClassRegistry getReg(){
return this.reg;
}
@ -82,7 +96,7 @@ public class SyntaxTreeGenerator{
}
private ClassOrInterface convertClass(Java8Parser.ClassDeclarationContext ctx) {
ClassOrInterface newClass = null;
ClassOrInterface newClass;
if(ctx.normalClassDeclaration() != null){
newClass = convertNormal(ctx.normalClassDeclaration());
}
@ -107,9 +121,9 @@ public class SyntaxTreeGenerator{
List<Field> fielddecl = convertFields(ctx.classBody());
GenericDeclarationList genericClassParameters = null;
Token offset = ctx.getStart();
RefType superClass = null;
RefTypeOrTPH superClass = null;
Boolean isInterface = false;
List<RefType> implementedInterfaces = null;
List<RefTypeOrTPH> implementedInterfaces = null;
return new ClassOrInterface(modifiers, name, fielddecl, genericClassParameters, superClass, isInterface, implementedInterfaces, offset);
}
@ -132,7 +146,7 @@ public class SyntaxTreeGenerator{
Java8Parser.MethodHeaderContext header = methodDeclarationContext.methodHeader();
String name = header.methodDeclarator().Identifier().getText();
RefType retType;
RefTypeOrTPH retType;
if(header.result() != null){
if(header.result().unannType() != null)
retType = convert(header.result().unannType());
@ -184,7 +198,7 @@ public class SyntaxTreeGenerator{
for(Java8Parser.FieldModifierContext fieldModifierContext : fieldDeclarationContext.fieldModifier()){
//TODO
}
RefType fieldType = convert(fieldDeclarationContext.unannType());
RefTypeOrTPH fieldType = convert(fieldDeclarationContext.unannType());
for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){
String fieldName = varCtx.variableDeclaratorId().getText();
if(varCtx.variableInitializer() != null){
@ -198,11 +212,27 @@ public class SyntaxTreeGenerator{
return ret;
}
private RefType convert(Java8Parser.UnannTypeContext unannTypeContext) {
//TODO
return null;
private RefTypeOrTPH convert(Java8Parser.UnannTypeContext unannTypeContext) {
if(unannTypeContext.unannPrimitiveType()!=null){
throw new NotImplementedException();
}else
if(unannTypeContext.unannReferenceType().unannArrayType()!=null){
throw new NotImplementedException();
}else
if(unannTypeContext.unannReferenceType().unannTypeVariable()!=null){
JavaClassName name = reg.getName(unannTypeContext.unannReferenceType().unannTypeVariable().Identifier().toString());
return new RefType(name, unannTypeContext.getStart());
}
return convert(unannTypeContext.unannReferenceType().unannClassOrInterfaceType());
}
private RefTypeOrTPH convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext) {
String name = unannClassOrInterfaceTypeContext.getText();
return new RefType(reg.getName(name), unannClassOrInterfaceTypeContext.getStart());
}
private Modifier convert(Java8Parser.ClassModifierContext ctx){
Modifier newModifier = null;
if(ctx.annotation() == null){

View File

@ -3,9 +3,7 @@ package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.typecheck.JavaClassName;
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
@ -20,12 +18,12 @@ public class ClassOrInterface extends GTVDeclarationContext implements IItemWith
private List<Field> fielddecl = new ArrayList<>();
private GenericDeclarationList genericClassParameters;
private Token offset;
private RefType superClass;
private RefTypeOrTPH superClass;
protected boolean isInterface;
private List<RefType> implementedInterfaces;
private List<RefTypeOrTPH> implementedInterfaces;
public ClassOrInterface(Modifiers modifiers, JavaClassName name, List<Field> fielddecl, GenericDeclarationList genericClassParameters,
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
public ClassOrInterface(Modifiers modifiers, JavaClassName name, List<Field> fielddecl, GenericDeclarationList genericClassParameters,
RefTypeOrTPH superClass, Boolean isInterface, List<RefTypeOrTPH> implementedInterfaces, Token offset){
if(modifiers != null){
this.modifiers = modifiers;
}

View File

@ -1,12 +1,9 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.syntaxtree.modifier.methodModifier.MethodModifier;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import org.antlr.v4.runtime.Token;
import org.apache.bcel.Constants;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typecheck.JavaClassName;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import java.util.List;
@ -14,7 +11,7 @@ import java.util.List;
public class Constructor extends Method {
public Constructor(String name, RefType returnType, List<MethodModifier> modifiers, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, Token offset) {
public Constructor(String name, RefTypeOrTPH returnType, List<MethodModifier> modifiers, ParameterList parameterList, Block block, GenericDeclarationList gtvDeclarations, Token offset) {
super(name, returnType, modifiers, parameterList, block, gtvDeclarations, offset);
}
}

View File

@ -1,14 +1,14 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import java.util.List;
public class ExceptionList
{
private List<RefType> exceptions;
private List<RefTypeOrTPH> exceptions;
public ExceptionList(List<RefType> exceptions){
public ExceptionList(List<RefTypeOrTPH> exceptions){
this.exceptions = exceptions;
}
}

View File

@ -1,7 +1,7 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.syntaxtree.modifier.fieldModifier.FieldModifier;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import org.antlr.v4.runtime.Token;
import java.util.List;
@ -9,12 +9,14 @@ import java.util.List;
public class Field extends GTVDeclarationContext implements Generic {
private String name;
private RefTypeOrTPH type;
private GenericDeclarationList genericParameters;
public Field(String name, RefType type, List<? extends FieldModifier> modifier, Token offset){
public Field(String name, RefTypeOrTPH type, List<? extends FieldModifier> modifier, Token offset){
this.name = name;
this.type = type;
}

View File

@ -1,17 +1,10 @@
package de.dhbwstuttgart.syntaxtree;
import com.sun.org.apache.xpath.internal.operations.Mod;
import de.dhbwstuttgart.syntaxtree.modifier.fieldModifier.FieldModifier;
import org.antlr.v4.runtime.Token;
import org.apache.bcel.generic.FieldGen;
import org.apache.bcel.generic.FieldInstruction;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.ObjectType;
import org.apache.bcel.Const;
import org.apache.bcel.generic.ClassGen;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import java.util.List;
@ -29,7 +22,7 @@ public class FieldDeclaration extends Field{
* Dieser Konstruktor der FieldDeclaration erstellt den Syntaxknoten vollständig.
* Kein nachträgliches hinzfügen von Informationen oder aufrufen von parserPostProcessing ist notwendig.
*/
public FieldDeclaration(String name, RefType typ, List<FieldModifier> modifier, Expr value, Token offset){
public FieldDeclaration(String name, RefTypeOrTPH typ, List<FieldModifier> modifier, Expr value, Token offset){
super(name, typ, modifier, offset);//Dieser Deklarator wird nicht vom Parser aufgerufen. Dadurch gibt es auch keinen Offset
this.wert = value;
}

View File

@ -1,13 +1,13 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
public class FormalParameter extends SyntaxTreeNode
{
private RefType type;
private RefTypeOrTPH type;
private String name;
public FormalParameter(String name, RefType type, int offset){
public FormalParameter(String name, RefTypeOrTPH type, int offset){
this.name = name;
this.type = type;
}

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import java.util.ArrayList;
import java.util.List;
@ -20,14 +20,14 @@ public class GenericTypeVar extends SyntaxTreeNode
/**
* Hier sind die Bounds in Form von Type-Objekten abgespeichert
*/
List<RefType> bounds=new ArrayList<RefType>();
List<RefTypeOrTPH> bounds=new ArrayList<RefTypeOrTPH>();
private int endOffset;
private String name;
public GenericTypeVar(String s, List<RefType> bounds, int offset, int endOffset)
public GenericTypeVar(String s, List<RefTypeOrTPH> bounds, int offset, int endOffset)
{
name = s;
if(bounds != null)for(RefType t : bounds){
if(bounds != null)for(RefTypeOrTPH t : bounds){
//if(t!=null)this.extendVars.add(t);
}
//this.genericTypeVar = new RefType(s,offset);
@ -39,7 +39,7 @@ public class GenericTypeVar extends SyntaxTreeNode
return this.endOffset;
}
public List<RefType> getBounds()
public List<RefTypeOrTPH> getBounds()
{
return bounds;
}

View File

@ -3,17 +3,12 @@ package de.dhbwstuttgart.syntaxtree;
import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.syntaxtree.modifier.fieldModifier.FieldModifier;
import de.dhbwstuttgart.syntaxtree.modifier.methodModifier.MethodModifier;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import org.antlr.v4.runtime.Token;
import org.apache.bcel.Constants;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.typecheck.JavaClassName;
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.modifier.Static;
import de.dhbwstuttgart.syntaxtree.statement.Block;
/**
@ -34,7 +29,7 @@ public class Method extends Field implements IItemWithOffset
private List<String> types_in_parameterlist = new ArrayList<>();
private Modifiers modifiers;
public Method(String name, RefType returnType, List<MethodModifier> modifiers, ParameterList parameterList, Block block,
public Method(String name, RefTypeOrTPH returnType, List<MethodModifier> modifiers, ParameterList parameterList, Block block,
GenericDeclarationList gtvDeclarations, Token offset) {
super(name, returnType, modifiers, offset);
this.name = name;

View File

@ -1,14 +1,13 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
public class Assign extends ExprStmt
{
public Assign(RefType type, int offset) {
public Assign(RefTypeOrTPH type, int offset) {
super(type, offset);
}

View File

@ -1,16 +1,11 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
public class CastExpr extends Expr
{
public CastExpr(RefType castType, Expr expr, int offset)
public CastExpr(RefTypeOrTPH castType, Expr expr, int offset)
{
super(null, 0);
}

View File

@ -1,17 +1,4 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.bcel.generic.BIPUSH;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.LDC;
import org.apache.bcel.generic.LDC2_W;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.RefType;
public class DoubleLiteral extends Literal

View File

@ -1,17 +1,14 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Iterator;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
public abstract class Executeable extends SyntaxTreeNode
{
private RefType type;
private RefTypeOrTPH type;
public Executeable(RefType type, int offset) {
public Executeable(RefTypeOrTPH type, int offset) {
this.type = type;
}

View File

@ -1,19 +1,13 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
public abstract class Expr extends Executeable
{
public Expr(RefType type, int offset) {
public Expr(RefTypeOrTPH type, int offset) {
super(type, offset);
}

View File

@ -1,10 +1,10 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
public abstract class ExprStmt extends Executeable{
public ExprStmt(RefType type, int offset) {
public ExprStmt(RefTypeOrTPH type, int offset) {
super(type, offset);
}
}

View File

@ -1,18 +1,13 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
public class InstanceOf extends BinaryExpr
{
public Expr expr;
private RefType reftype;
private RefTypeOrTPH reftype;
// private boolean is_instance = false;
@ -27,7 +22,7 @@ public class InstanceOf extends BinaryExpr
this.expr = exp;
}
public void set_Type(RefType typ)
public void set_Type(RefTypeOrTPH typ)
{
this.reftype = typ;
}

View File

@ -1,23 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.ArrayList;
import org.apache.bcel.Const;
import org.apache.bcel.classfile.BootstrapMethod;
import org.apache.bcel.classfile.ConstantMethodHandle;
import org.apache.bcel.classfile.ConstantMethodType;
import org.apache.bcel.classfile.InnerClass;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typecheck.JavaClassName;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.FunN;
import de.dhbwstuttgart.syntaxtree.type.FunVoidN;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
/**
* @author A10023 - Andreas Stadelmeier

View File

@ -1,7 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
public abstract class Literal extends Expr
{
@ -11,7 +11,7 @@ public abstract class Literal extends Expr
private boolean primitiveFlag=true;
public Literal(RefType o, int i) {
public Literal(RefTypeOrTPH o, int i) {
super(null, i);
}

View File

@ -1,14 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.List;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
public class NewArray extends Expr
@ -17,7 +10,7 @@ public class NewArray extends Expr
{
super(null,variableLength);
}
private RefType type;
private RefTypeOrTPH type;
public List<Expr> expr;

View File

@ -1,16 +1,8 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import org.apache.bcel.Constants;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionConstants;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
@ -24,7 +16,7 @@ public class NewClass extends Expr
private ArgumentList arglist;
private boolean isStatement = false;
private List<RefType> parameterList = new ArrayList<>();
private List<RefTypeOrTPH> parameterList = new ArrayList<>();
public ArgumentList getArgumentList()

View File

@ -1,22 +1,13 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Enumeration;
import java.util.Hashtable;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
public abstract class Statement extends Executeable
{
public Statement(RefType type, int offset)
public Statement(RefTypeOrTPH type, int offset)
{
super(type,offset);
}

View File

@ -17,7 +17,7 @@ public class ExtendsWildcardType extends WildcardType{
* Author: Arne ¼dtke<br/>
* Standard Konstruktor ¼r eine ExtendsWildcard
*/
public ExtendsWildcardType ( RefType extendsType,Token offset)
public ExtendsWildcardType (RefType extendsType, Token offset)
{
super(extendsType, offset);
}

View File

@ -1,11 +1,8 @@
package de.dhbwstuttgart.syntaxtree.type;
import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.typecheck.JavaClassName;
/**
* @see Spezifikation "Complete Typeinference in Java 8" von Martin Plümicke
* "interface FunN<R,T1, T2, ... ,TN> { R apply(T1 arg1, T2 arg2, ... , TN argN); }"
@ -17,8 +14,8 @@ import de.dhbwstuttgart.typecheck.JavaClassName;
*/
public class FunN extends RefType {
private RefType R;
private List<? extends RefType> T;
private RefTypeOrTPH R;
private List<? extends RefTypeOrTPH> T;
/**
* @author Andreas Stadelmeier, a10023
@ -28,7 +25,7 @@ public class FunN extends RefType {
* @param T
* @return
*/
public FunN(RefType R, List<? extends RefType> T) {
public FunN(RefTypeOrTPH R, List<? extends RefTypeOrTPH> T) {
super(null,null);
}

View File

@ -4,8 +4,6 @@ package de.dhbwstuttgart.syntaxtree.type;
import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.typecheck.JavaClassName;
/**
* FunVoid<T1,...,TN> {
* void apply(T1 arg1, ... TN argN);
@ -15,8 +13,8 @@ import de.dhbwstuttgart.typecheck.JavaClassName;
*/
public class FunVoidN extends FunN {
private RefType R;
private List<RefType> T;
private RefTypeOrTPH R;
private List<RefTypeOrTPH> T;
/**
* @author Andreas Stadelmeier, a10023
@ -25,7 +23,7 @@ public class FunVoidN extends FunN {
* @param T
* @return
*/
public FunVoidN(List<RefType> T) {
public FunVoidN(List<RefTypeOrTPH> T) {
super(null,T);
}
@ -36,7 +34,7 @@ public class FunVoidN extends FunN {
* Dabei werden bestimmte, von RefType geerbte, Parameter angepasst. Dies ist wichtig ¼r den Typinferenzalgorithmus.
*/
private void calculateNewParalist(){
List<RefType> t = new ArrayList<>();
List<RefTypeOrTPH> t = new ArrayList<>();
if(T!=null)t.addAll(T);
this.parameter = t;
}

View File

@ -1,27 +1,28 @@
package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typecheck.JavaClassName;
import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.typecheck.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import org.antlr.v4.runtime.Token;
public class RefType extends SyntaxTreeNode
{
public class RefType extends RefTypeOrTPH
{
/**
* Ist IsArray auf true, muss beim Codegen ein Zeichen [ gesetzt werden
* Ist IsArray auf true, muss beim Codegen ein Zeichen [ gesetzt werden
* Bsp.: 15| tag = CONSTANT_Utf8, length = 22, ([Ljava/lang/String;)V
* Ist IsArray auf false, muss beim Codegen ein Zeichen [ gesetzt werden
* Ist IsArray auf false, muss beim Codegen ein Zeichen [ gesetzt werden
* Bsp.: 9| tag = CONSTANT_Utf8, length = 21, (Ljava/lang/String;)V
*/
private boolean IsArray = false;
protected JavaClassName name;
protected List<RefType> parameter = null;
protected List<RefTypeOrTPH> parameter = null;
/**
* Ist primitiveFlag auf true, muss beim Codegen dieser Reftype durch
* den primitiven Datentyp ersetzt werden
*
*
* Bsp: java.lang.Integer mit Flag wird dann zu [int]
*/
private boolean primitiveFlag=false;
@ -30,7 +31,7 @@ public class RefType extends SyntaxTreeNode
{
this.name = (fullyQualifiedName);
}
@Override
public int hashCode() {
int hash = 0;
@ -39,7 +40,7 @@ public class RefType extends SyntaxTreeNode
return hash;
}
public RefType(JavaClassName fullyQualifiedName, List<RefType> parameter, Token offset)
public RefType(JavaClassName fullyQualifiedName, List<RefTypeOrTPH> parameter, Token offset)
{
this(fullyQualifiedName, offset);
if(parameter != null && parameter.size()>0)this.parameter = parameter;
@ -50,7 +51,7 @@ public class RefType extends SyntaxTreeNode
return name;
}
public List<RefType> getParaList(){
public List<RefTypeOrTPH> getParaList(){
if(this.parameter==null)return new ArrayList<>();
return this.parameter;
}
@ -93,5 +94,6 @@ public class RefType extends SyntaxTreeNode
}
}
}

View File

@ -0,0 +1,12 @@
package de.dhbwstuttgart.syntaxtree.type;
import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.typecheck.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import org.antlr.v4.runtime.Token;
public abstract class RefTypeOrTPH extends SyntaxTreeNode
{ }

View File

@ -28,7 +28,7 @@ public class SuperWildcardType extends WildcardType{
* Beispiel: ? super Integer.
* Integer wird zurückgegeben.
*/
public RefType get_SuperType()
public RefTypeOrTPH get_SuperType()
{
return this.innerType;
}

View File

@ -12,7 +12,7 @@ import org.antlr.v4.runtime.Token;
* @author ¯Â¿Â½rg ¯Â¿Â½uerle
* @version $Date: 2013/06/19 12:45:37 $
*/
public class TypePlaceholder extends RefType
public class TypePlaceholder extends RefTypeOrTPH
{
private static Hashtable<String, TypePlaceholder> m_TypePlaceholdersRegistry = new Hashtable<String, TypePlaceholder>();
@ -25,11 +25,9 @@ public class TypePlaceholder extends RefType
* Privater Konstruktor - Eine TypePlaceholder-Variable wird �ber die
* Factory-Methode <code>fresh()</code> erzeugt.
* <br>Author: ¯Â¿Â½rg ¯Â¿Â½uerle
* @param typeName Der Name der TypePlaceholder-Variablen
*/
private TypePlaceholder(String name)
{
super(null,null);
this.name = name;
}
@ -61,7 +59,6 @@ public class TypePlaceholder extends RefType
* @author Andreas Stadelmeier, a10023
* Ruft die TypePlaceholder.fresh()-Methode auf.
* ¼gt zusätzlich einen Replacementlistener hinzu.
* @param listener
* @return
*/
public static TypePlaceholder fresh(Token position){
@ -71,7 +68,6 @@ public class TypePlaceholder extends RefType
/**
* Author: ¯Â¿Â½rg ¯Â¿Â½uerle<br/>
* @param Object
* @return
*/
public boolean equals(Object obj)

View File

@ -1,12 +1,8 @@
package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typecheck.JavaClassName;
import org.antlr.v4.runtime.Token;
import java.util.ArrayList;
import java.util.List;
public class Void extends RefType
{

View File

@ -9,9 +9,9 @@ import org.antlr.v4.runtime.Token;
*
*/
public abstract class WildcardType extends RefType{
public abstract class WildcardType extends RefType {
protected RefType innerType = null;
protected RefTypeOrTPH innerType = null;
/**
* Author: Arne ¼dtke<br/>
@ -37,7 +37,7 @@ public abstract class WildcardType extends RefType{
* Author: Arne ¼dtke<br/>
* Die Allgemeine Wildcard enthält keinen Typen.
*/
public RefType GetWildcardType()
public RefTypeOrTPH GetWildcardType()
{
return null;
}

View File

@ -9,6 +9,12 @@ import java.util.List;
public class JavaClassRegistry {
public List<JavaClassName> existingClasses = new ArrayList<>();
public JavaClassRegistry(List<String> initialNames){
for(String name : initialNames){
existingClasses.add(new JavaClassName(name));
}
}
public void add(String className){
existingClasses.add(new JavaClassName(className));
}

View File

@ -0,0 +1,5 @@
class A {
mt(x, y, z) { return x.sub(y).add(z); }
}