Umbau des StatementGenerators fortgeführt

This commit is contained in:
luca9913 2023-03-01 06:49:59 +01:00
parent c118c05bb2
commit d362858184
3 changed files with 489 additions and 527 deletions

View File

@ -620,7 +620,7 @@ expression
| SUPER superSuffix
| explicitGenericInvocation
) # dottedexpression
| expression '[' expression ']' #arrayexpression
| expression '[' expression ']' #arrayaccessexpression
| methodCall #methodcallexpression
| NEW creator #newinstanceexpression
| '(' annotation* typeType ('&' typeType)* ')' expression #castexpression
@ -628,10 +628,10 @@ expression
| prefix=('+'|'-'|'++'|'--'|'~'|'!') expression #prefixexpression
| expression bop=('*'|'/'|'%') expression #mathmuldivmodexpression
| expression bop=('+'|'-') expression #mathaddsubexpression
| expression ('<' '<' | '>' '>' '>' | '>' '>') expression #shifexpression
| expression bop=('<=' | '>=' | '>' | '<') expression #compareexpression
| expression ('<' '<' | '>' '>' '>' | '>' '>') expression #shiftexpression
| expression bop=('<=' | '>=' | '>' | '<') expression #relationalexpression
| expression bop=INSTANCEOF (typeType | pattern) #instanceofexpression
| expression bop=('==' | '!=') expression #compareequalityexpression
| expression bop=('==' | '!=') expression #equalityexpression
| expression bop='&' expression #bitwiseandexpression
| expression bop='^' expression #bitwisexorexpression
| expression bop='|' expression #bitwiseorexpression

View File

@ -177,7 +177,7 @@ public class TypeGenerator {
public static RefTypeOrTPHOrWildcardOrGeneric convertTypeName(String name, Token offset, JavaClassRegistry reg,
GenericsRegistry generics) {
return convertTypeName(name, null, offset, reg, generics);
return convertTypeName(name, (Java17Parser.TypeArgumentsContext) null, offset, reg, generics);
}
public static RefTypeOrTPHOrWildcardOrGeneric convertTypeName(
@ -207,6 +207,34 @@ public class TypeGenerator {
}
}
public static RefTypeOrTPHOrWildcardOrGeneric convertTypeName(
String name, Java17Parser.NonWildcardTypeArgumentsContext typeArguments, Token offset,
JavaClassRegistry reg,
GenericsRegistry generics) {
if (!reg.contains(name)) { // Dann könnte es ein generischer Type oder ein FunN$$-Type sein
if (generics.contains(name)) {
return new GenericRefType(name, offset);
} else {
Pattern p = Pattern.compile("Fun(\\d+)[$][$]");
Matcher m = p.matcher(name);
if (m.matches()) {// es ist FunN$$-Type
return new RefType(new JavaClassName(name), convert(typeArguments, reg, generics), offset);
} else {
throw new TypeinferenceException("Der Typ " + name + " ist nicht vorhanden", offset);
}
}
}
if (typeArguments == null) {
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
for (int i = 0; i < reg.getNumberOfGenerics(name); i++) {
params.add(TypePlaceholder.fresh(offset));
}
return new RefType(reg.getName(name), params, offset);
} else {
return new RefType(reg.getName(name), convert(typeArguments, reg, generics), offset);
}
}
public static List<RefTypeOrTPHOrWildcardOrGeneric> convert(Java17Parser.TypeArgumentsContext typeArguments,
JavaClassRegistry reg, GenericsRegistry generics) {
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
@ -220,4 +248,14 @@ public class TypeGenerator {
}
return ret;
}
public static List<RefTypeOrTPHOrWildcardOrGeneric> convert(
Java17Parser.NonWildcardTypeArgumentsContext typeArguments,
JavaClassRegistry reg, GenericsRegistry generics) {
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
for (Java17Parser.TypeTypeContext arg : typeArguments.typeList().typeType()) {
ret.add(convert(arg, reg, generics));
}
return ret;
}
}