Package gw.internal.gosu.ir.transform
Class GosuClassTransformer
- java.lang.Object
-
- gw.internal.gosu.ir.transform.AbstractElementTransformer<ClassStatement>
-
- gw.internal.gosu.ir.transform.GosuClassTransformer
-
public class GosuClassTransformer extends AbstractElementTransformer<ClassStatement>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classGosuClassTransformer.EnumOrdinalCounter
-
Field Summary
Fields Modifier and Type Field Description private boolean_bHasAssertsprivate GosuClassTransformationContext_contextprivate GosuClassTransformer.EnumOrdinalCounter_enumCounterprivate IGosuClassInternal_gsClassprivate IRClass_irClass(package private) java.util.Set<java.lang.String>bridgesGenerates a synthetic method if: - method overrides with covariant return type - for each in ancestry e.g., Square f() -> Rectangle f() -> Shape f().static java.lang.StringENHANCED_TYPE_FIELDstatic java.lang.StringENUM_VALUES_FIELD-
Fields inherited from class gw.internal.gosu.ir.transform.AbstractElementTransformer
CAPTURED_VAR_PREFIX, CTX_SYMBOL, CTX_SYMBOL_SUFFIX, CUSTOM_RUNTIMES, EMPTY_CLASS_ARRAY, ENHANCEMENT_THIS_REF, ENHANCEMENT_TYPE_PARAM_PREFIX, ENUM_PARAM_PREFIX, OBJECT_TYPE, OUTER_ACCESS, TYPE_PARAM_PREFIX
-
-
Constructor Summary
Constructors Modifier Constructor Description privateGosuClassTransformer(IGosuClassInternal gsClass)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddAnnotations()private voidaddCapturedSymbolFields()private booleanaddCovarientProxyBridgeMethods(DynamicFunctionSymbol dfs)Add a bridge method for a Java interface method that is not only implemented by a method in this Gosu class, but is also itself a covariant "override" of its super interface E.g.,private voidaddGosuMarker(java.util.List<IRAnnotation> annotations)private voidaddInstanceFields()private voidaddOuterThisField()private voidaddSourceFileRef()private voidaddStaticFields()private voidaddTypeParamDescriptor(java.util.List<IRSymbol> parameters, java.util.List<IGenericTypeVariable> genTypeVars)private voidaddTypeParamFields()private voidappendTypeVarsFromEnclosingFunctions(java.util.List<IRSymbol> parameters, IGosuClassInternal gsClass)private IRClasscompile()static IRClasscompile(IGosuClassInternal gsClass)private voidcompileBridgeMethods(DynamicFunctionSymbol dfs)private voidcompileClassHeader()private voidcompileConstructors()private IRStatementcompileDefaultCtorBody()private voidcompileEnumAllValuesPropertyGetter()private voidcompileEnumCodePropertyGetter()private voidcompileEnumDisplayNamePropertyGetter()private voidcompileEnumNamePropertyGetter()private voidcompileEnumOrdinalPropertyGetter()private voidcompileEnumValueOfMethod()private voidcompileEnumValuePropertyGetter()private voidcompileEnumValuesFieldInitializer(java.util.List<IRStatement> statements)private voidcompileEnumValuesMethod()private voidcompileFields()private voidcompileInnerClasses()private voidcompileIntrinsicTypePropertyGetter()private voidcompileJavaInteropBridgeConstructor(DynamicFunctionSymbol dfs)Add constructor so Java can use the Gosu generic class without explicitly passing in type arguments.private voidcompileMainMethod()private voidcompileMethod(DynamicFunctionSymbol dfs)private voidcompileMethods()private voidcompileOuterAccessMethod()private voidcompileStaticInitializer()private booleangenBridgeMethod(IJavaClassMethod bridge, IJavaClassMethod m)private booleangenInterfaceProxyBridgeMethod(IJavaClassMethod m, IJavaClassInfo iJavaClassInfo)private booleangenProxyCovariantBridgeMethod(DynamicFunctionSymbol dfs, DynamicFunctionSymbol superDfs)##hack: Potentially generates a bridge method for an overridden method where the super method is in a proxy and the proxy is for a Java interface having param types that are transformed to non-bytecode types in the type system.private intgetClassModifiers()private intgetClassModifiers(IGosuClass gsClass, boolean bForInnerClass)private IRTypegetDescriptorNoStructures(IType type)IGosuEnhancementInternalgetGosuEnhancement()private IGosuClassInternalgetGosuObjectInterface()private IRType[]getInterfaceNames()private java.util.List<IRAnnotation>getIRAnnotations(java.util.List<? extends IAnnotationInfo> gosuAnnotations)private IJavaClassMethodgetMethodOverridableFromDfs(DynamicFunctionSymbol dfs, IJavaClassInfo declaringClass)private java.util.List<IVarStatement>getOrderedFields()java.lang.StringgetOuterThisFieldName()private java.lang.StringgetParameterDescriptors(IType[] types)private java.lang.StringgetParameterDescriptors(IJavaClassInfo[] iJavaClassInfos)private IType[]getParamsIncludingTypeParams(DynamicFunctionSymbol dfs)private DynamicFunctionSymbolgetSuperDfs(DynamicFunctionSymbol dfs, IType gsClass, IType superType)private IRTypegetSuperSlashName()private booleanhasRetentionPolicy(IAnnotationInfo annotation, java.lang.annotation.RetentionPolicy policy)voidinitCapturedSymbolFields(java.util.List<IRStatement> statements)private IRStatementinitializeAssertionsDisabledField()voidinitializeInstanceFields(java.util.List<IRStatement> statements)voidinitializeStaticFields(java.util.List<IRStatement> statements)voidinitTypeVarFields(java.util.List<IRStatement> statements)booleanisBlockInvoke(DynamicFunctionSymbol dfs)private booleanisGosuObjectMethod(DynamicFunctionSymbol dfs)booleanisNonStaticInnerClass()private booleanisOverrideForSuperClass(DynamicFunctionSymbol dfs)private booleanisStaticEnumMethod(DynamicFunctionSymbol dfs)private IRExpressionmakeArrayOfTypeParameters()private voidmakeCovariantParamBridgeMethod(DynamicFunctionSymbol dfs, DynamicFunctionSymbol superDfs, IJavaClassMethod method)private intmakeModifiersForBridgeMethod(int modifiers)(package private) IRSymbolmakeParamSymbol(DynamicFunctionSymbol dfs, ISymbol param)private voidmaybeAddEnhancedTypeMarkerField()If this is an enhancement, add a (hacky) marker field to indicate the enhanced type for tooling.private voidmaybeAddImplicitEnhancementParameters(DynamicFunctionSymbol dfs, java.util.List<IRSymbol> parameters)private voidmaybeAddImplicitExternalSymbolsParameter(DynamicFunctionSymbol dfs, java.util.List<IRSymbol> parameters)voidmaybeAssignOuterRef(java.util.List<IRStatement> statements)private voidmaybeGetCapturedSymbolTypes(java.util.List<IRSymbol> parameters)private voidmaybeGetEnumSuperConstructorSymbols(java.util.List<IRSymbol> parameters)private voidmaybeGetOuterThisParamType(java.util.List<IRSymbol> parameters)private java.util.List<DynamicFunctionSymbol>maybeGetSuperDfs(DynamicFunctionSymbol dfs)private voidmaybeGetTypeVarSymbolTypes(DynamicFunctionSymbol dfs, java.util.List<IRSymbol> parameters)private voidmaybeGetTypeVarSymbolTypesForConstructor(java.util.List<IRSymbol> parameters)private voidmaybePassTypeParams(DynamicFunctionSymbol dfs, java.util.List<IRExpression> args)voidmaybePushSupersEnclosingThisRef(java.util.List<IRExpression> arguments)private IRStatementmaybeWrapProgramEvaluateForManangedProgram(DynamicFunctionSymbol dfs, IRStatement methodBody)If this is: a Gosu program and it has a superclass that implements IManagedProgramInstance and this method isevaluate( IExternalSymbolMap )Generate the evaluate() method like so:voidpushEnumNameAndOrdinal(IType type, java.util.List<IRExpression> args)voidsetHasAsserts()private voidsetUpFunctionContext(boolean instanceMethod, java.util.List<IRSymbol> params)private voidsetUpFunctionContext(DynamicFunctionSymbol dfs, boolean instanceMethod, java.util.List<IRSymbol> params)java.lang.StringtoString()private voidvisitInnerClass(IGosuClass innerClass)-
Methods inherited from class gw.internal.gosu.ir.transform.AbstractElementTransformer
_cc, assignStructuralTypeOwner, avoidVerifyError, booleanLiteral, boxValue, boxValue, boxValueToType, buildAddition, buildArithmetic, buildArrayLength, buildArrayLoad, buildArrayLoad, buildArrayStore, buildAssignment, buildCast, buildComposite, buildComposite, buildEquals, buildFieldGet, buildFieldSet, buildGreaterThan, buildIf, buildIfElse, buildInitializedArray, buildMethodCall, buildMethodCall, buildMethodCall, buildNegation, buildNewExpression, buildNewExpression, buildNewExpression, buildNotEquals, buildNullCheckTernary, buildReturn, buildSubtraction, buildTernary, buildThrow, callMethod, callMethod, callMethod, callMethod, callMethod, callSpecialMethod, callSpecialMethod, callSpecialMethod, callStaticMethod, castResultingTypeIfNecessary, charLiteral, checkCast, checkCast, checkCast, classLiteral, classLiteral, classLiteral, clearCustomRuntimes, collectArgsIntoObjArray, convertBoxedNullToPrimitive, convertNullToPrimitive, convertOperandToBig, convertOperandToPrimitive, convertOperandToRational, exprList, fastStringCoercion, findComparableParamType, findDimensionType, getActualPropertyInfo, getCapturedSymbolParameterName, getClassInfos, getConcreteType, getConstructorParamTypes, getCustomRuntime, getDeclaredField, getDeclaredFieldImpl, getDeclaredMethod, getDeclaredMethod, getDefaultConstIns, getDescriptor, getDescriptor, getDescriptor, getDescriptor, getEnclosingDFS, getField, getField_new, getGosuClass, getInstanceField, getIRTypes, getIRTypes, getModifiers, getParsedElement, getRuntimeEnclosingType, getStaticField, getTypes, getTypeVarParamName, getTypeVarsForDFS, handleCustomExpressionRuntime, handleNamedArgs, identifier, initLocalVar, initLocalVarWithDefault, initMultiArray, inStaticContext, isBigType, isBoxedIntType, isBytecodeType, isBytecodeType, isCheckedArithmeticEnabled, isCompilingEnhancement, isEnhancementType, isEvalProgram, isExecuteMethod, isHandledByCustomCoercion, isIntType, isMemberOnEnclosingType, isMemberOnEnhancementOfEnclosingType, isNonBigBoxedNumberType, isNonStaticInnerClass, isNumberType, isPrimitiveNumberType, isProgram, isProgramOrEnclosedInProgram, makeAnnotationInfos, makeArrayViaTypeInfo, makeEmptyArrayViaTypeInfo, makeIRSymbol, maybeUnwrapMetaType, newArray, nullCheckVar, nullLiteral, numberConvert, numberConvert, numericLiteral, pushArrayOfDefValueExpr, pushArrayOfString, pushArrayOfTypes, pushCapturedSymbols, pushConstant, pushEnumSuperConstructorArguments, pushExternalSymbolsMap, pushLazyType, pushLazyType, pushNull, pushOuter, pushOuter, pushOuter, pushParamTypes, pushRuntimeTypeOfTypeVar, pushString, pushThis, pushThisOrOuter, pushType, pushType, pushTypeParametersForConstructor, requiresExternalSymbolCapture, requiresImplicitEnhancementArg, requiresImplicitEnhancementArg, setCc, setField, setField, setInstanceField, setStaticField, stringLiteral, unboxValueFromType, unboxValueToType, unboxValueToType, valueOf
-
-
-
-
Field Detail
-
ENUM_VALUES_FIELD
public static final java.lang.String ENUM_VALUES_FIELD
- See Also:
- Constant Field Values
-
ENHANCED_TYPE_FIELD
public static final java.lang.String ENHANCED_TYPE_FIELD
- See Also:
- Constant Field Values
-
_gsClass
private IGosuClassInternal _gsClass
-
_enumCounter
private GosuClassTransformer.EnumOrdinalCounter _enumCounter
-
_irClass
private IRClass _irClass
-
_context
private GosuClassTransformationContext _context
-
_bHasAsserts
private boolean _bHasAsserts
-
bridges
java.util.Set<java.lang.String> bridges
Generates a synthetic method if: - method overrides with covariant return type - for each in ancestry e.g., Square f() -> Rectangle f() -> Shape f(). - method overrides and specifies a concrete type for a parameter that is a type variable in the super e.g., B extends Awhere B#foo( o: String ) -> A#foo( o: T )
-
-
Constructor Detail
-
GosuClassTransformer
private GosuClassTransformer(IGosuClassInternal gsClass)
-
-
Method Detail
-
compile
public static IRClass compile(IGosuClassInternal gsClass)
-
compile
private IRClass compile()
-
addAnnotations
private void addAnnotations()
-
addGosuMarker
private void addGosuMarker(java.util.List<IRAnnotation> annotations)
-
getIRAnnotations
private java.util.List<IRAnnotation> getIRAnnotations(java.util.List<? extends IAnnotationInfo> gosuAnnotations)
-
hasRetentionPolicy
private boolean hasRetentionPolicy(IAnnotationInfo annotation, java.lang.annotation.RetentionPolicy policy)
-
compileInnerClasses
private void compileInnerClasses()
-
visitInnerClass
private void visitInnerClass(IGosuClass innerClass)
-
compileStaticInitializer
private void compileStaticInitializer()
-
compileFields
private void compileFields()
-
addInstanceFields
private void addInstanceFields()
-
maybeAddEnhancedTypeMarkerField
private void maybeAddEnhancedTypeMarkerField()
If this is an enhancement, add a (hacky) marker field to indicate the enhanced type for tooling. E.g., private static finalENHNANCED$TYPE;
-
addStaticFields
private void addStaticFields()
-
addOuterThisField
private void addOuterThisField()
-
addCapturedSymbolFields
private void addCapturedSymbolFields()
-
addTypeParamFields
private void addTypeParamFields()
-
isNonStaticInnerClass
public boolean isNonStaticInnerClass()
-
getOuterThisFieldName
public java.lang.String getOuterThisFieldName()
-
compileConstructors
private void compileConstructors()
-
compileJavaInteropBridgeConstructor
private void compileJavaInteropBridgeConstructor(DynamicFunctionSymbol dfs)
Add constructor so Java can use the Gosu generic class without explicitly passing in type arguments. Note this constructor forwards to the given constructor with default type arguments.
-
makeParamSymbol
IRSymbol makeParamSymbol(DynamicFunctionSymbol dfs, ISymbol param)
-
maybeGetTypeVarSymbolTypesForConstructor
private void maybeGetTypeVarSymbolTypesForConstructor(java.util.List<IRSymbol> parameters)
-
maybeGetEnumSuperConstructorSymbols
private void maybeGetEnumSuperConstructorSymbols(java.util.List<IRSymbol> parameters)
-
maybeAddImplicitEnhancementParameters
private void maybeAddImplicitEnhancementParameters(DynamicFunctionSymbol dfs, java.util.List<IRSymbol> parameters)
-
maybeAddImplicitExternalSymbolsParameter
private void maybeAddImplicitExternalSymbolsParameter(DynamicFunctionSymbol dfs, java.util.List<IRSymbol> parameters)
-
isOverrideForSuperClass
private boolean isOverrideForSuperClass(DynamicFunctionSymbol dfs)
-
maybeGetTypeVarSymbolTypes
private void maybeGetTypeVarSymbolTypes(DynamicFunctionSymbol dfs, java.util.List<IRSymbol> parameters)
-
addTypeParamDescriptor
private void addTypeParamDescriptor(java.util.List<IRSymbol> parameters, java.util.List<IGenericTypeVariable> genTypeVars)
-
appendTypeVarsFromEnclosingFunctions
private void appendTypeVarsFromEnclosingFunctions(java.util.List<IRSymbol> parameters, IGosuClassInternal gsClass)
-
maybeGetCapturedSymbolTypes
private void maybeGetCapturedSymbolTypes(java.util.List<IRSymbol> parameters)
-
maybeGetOuterThisParamType
private void maybeGetOuterThisParamType(java.util.List<IRSymbol> parameters)
-
compileDefaultCtorBody
private IRStatement compileDefaultCtorBody()
-
maybeAssignOuterRef
public void maybeAssignOuterRef(java.util.List<IRStatement> statements)
-
maybePushSupersEnclosingThisRef
public void maybePushSupersEnclosingThisRef(java.util.List<IRExpression> arguments)
-
compileMethods
private void compileMethods()
-
compileBridgeMethods
private void compileBridgeMethods(DynamicFunctionSymbol dfs)
-
maybeGetSuperDfs
private java.util.List<DynamicFunctionSymbol> maybeGetSuperDfs(DynamicFunctionSymbol dfs)
-
getSuperDfs
private DynamicFunctionSymbol getSuperDfs(DynamicFunctionSymbol dfs, IType gsClass, IType superType)
-
makeModifiersForBridgeMethod
private int makeModifiersForBridgeMethod(int modifiers)
-
addCovarientProxyBridgeMethods
private boolean addCovarientProxyBridgeMethods(DynamicFunctionSymbol dfs)
Add a bridge method for a Java interface method that is not only implemented by a method in this Gosu class, but is also itself a covariant "override" of its super interface E.g.,interface JavaBase { public CharSequence makeText(); } interface JavaSub extends JavaBase { public String makeText(); } class GosuSub extends JavaSub { function makeText() : String ... }Here we need for this class to define a bridge method implementing JavaBase#makeText() : CharSequence
-
getMethodOverridableFromDfs
private IJavaClassMethod getMethodOverridableFromDfs(DynamicFunctionSymbol dfs, IJavaClassInfo declaringClass)
-
genInterfaceProxyBridgeMethod
private boolean genInterfaceProxyBridgeMethod(IJavaClassMethod m, IJavaClassInfo iJavaClassInfo)
-
genBridgeMethod
private boolean genBridgeMethod(IJavaClassMethod bridge, IJavaClassMethod m)
-
genProxyCovariantBridgeMethod
private boolean genProxyCovariantBridgeMethod(DynamicFunctionSymbol dfs, DynamicFunctionSymbol superDfs)
##hack: Potentially generates a bridge method for an overridden method where the super method is in a proxy and the proxy is for a Java interface having param types that are transformed to non-bytecode types in the type system. E.g., A guidewire platform plugin interface may declare UserBase or the like as a parameter type, which is always represented as the corresponding app derivative: UserBase -> CC's User. Essentially, we need to generate a bridge method to make the otherwise unsavory covariant parameter types work in method overrides.
-
makeCovariantParamBridgeMethod
private void makeCovariantParamBridgeMethod(DynamicFunctionSymbol dfs, DynamicFunctionSymbol superDfs, IJavaClassMethod method)
-
getParamsIncludingTypeParams
private IType[] getParamsIncludingTypeParams(DynamicFunctionSymbol dfs)
-
maybePassTypeParams
private void maybePassTypeParams(DynamicFunctionSymbol dfs, java.util.List<IRExpression> args)
-
compileOuterAccessMethod
private void compileOuterAccessMethod()
-
compileMethod
private void compileMethod(DynamicFunctionSymbol dfs)
-
maybeWrapProgramEvaluateForManangedProgram
private IRStatement maybeWrapProgramEvaluateForManangedProgram(DynamicFunctionSymbol dfs, IRStatement methodBody)
If this is:- a Gosu program and
- it has a superclass that implements IManagedProgramInstance and
- this method is
evaluate( IExternalSymbolMap )
function evaluate( map: IExternalSymbolMap ) : Object { var $failure : Throwable if( this.beforeExecution() ) { try { [method-body] // returns result } catch( $catchFailure: Throwable ) { $failure = $catchFailure } finally { this.afterExecution( $failure ) } } return null // only get here if exception not rethrown in afterExecution() }
-
isStaticEnumMethod
private boolean isStaticEnumMethod(DynamicFunctionSymbol dfs)
-
isGosuObjectMethod
private boolean isGosuObjectMethod(DynamicFunctionSymbol dfs)
-
getGosuObjectInterface
private IGosuClassInternal getGosuObjectInterface()
-
compileIntrinsicTypePropertyGetter
private void compileIntrinsicTypePropertyGetter()
-
compileMainMethod
private void compileMainMethod()
-
compileEnumValuesMethod
private void compileEnumValuesMethod()
-
compileEnumAllValuesPropertyGetter
private void compileEnumAllValuesPropertyGetter()
-
compileEnumValueOfMethod
private void compileEnumValueOfMethod()
-
compileEnumValuePropertyGetter
private void compileEnumValuePropertyGetter()
-
compileEnumCodePropertyGetter
private void compileEnumCodePropertyGetter()
-
compileEnumOrdinalPropertyGetter
private void compileEnumOrdinalPropertyGetter()
-
compileEnumNamePropertyGetter
private void compileEnumNamePropertyGetter()
-
compileEnumDisplayNamePropertyGetter
private void compileEnumDisplayNamePropertyGetter()
-
makeArrayOfTypeParameters
private IRExpression makeArrayOfTypeParameters()
-
initializeInstanceFields
public void initializeInstanceFields(java.util.List<IRStatement> statements)
-
initTypeVarFields
public void initTypeVarFields(java.util.List<IRStatement> statements)
-
initCapturedSymbolFields
public void initCapturedSymbolFields(java.util.List<IRStatement> statements)
-
initializeStaticFields
public void initializeStaticFields(java.util.List<IRStatement> statements)
-
initializeAssertionsDisabledField
private IRStatement initializeAssertionsDisabledField()
-
compileEnumValuesFieldInitializer
private void compileEnumValuesFieldInitializer(java.util.List<IRStatement> statements)
-
getOrderedFields
private java.util.List<IVarStatement> getOrderedFields()
-
getParameterDescriptors
private java.lang.String getParameterDescriptors(IType[] types)
-
getParameterDescriptors
private java.lang.String getParameterDescriptors(IJavaClassInfo[] iJavaClassInfos)
-
compileClassHeader
private void compileClassHeader()
-
getSuperSlashName
private IRType getSuperSlashName()
-
addSourceFileRef
private void addSourceFileRef()
-
getClassModifiers
private int getClassModifiers()
-
getClassModifiers
private int getClassModifiers(IGosuClass gsClass, boolean bForInnerClass)
-
getInterfaceNames
private IRType[] getInterfaceNames()
-
getGosuEnhancement
public IGosuEnhancementInternal getGosuEnhancement()
-
pushEnumNameAndOrdinal
public void pushEnumNameAndOrdinal(IType type, java.util.List<IRExpression> args)
-
setHasAsserts
public void setHasAsserts()
-
isBlockInvoke
public boolean isBlockInvoke(DynamicFunctionSymbol dfs)
-
setUpFunctionContext
private void setUpFunctionContext(boolean instanceMethod, java.util.List<IRSymbol> params)
-
setUpFunctionContext
private void setUpFunctionContext(DynamicFunctionSymbol dfs, boolean instanceMethod, java.util.List<IRSymbol> params)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-