public CodegenExpression UnderlyingGetCodegen( CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { CodegenMethod method = codegenMethodScope .MakeChild(typeof(object), GetType(), codegenClassScope) .AddParam(typeof(object), "und"); // TBD - fix this, this type is not right... below if (wrapperEventType.UnderlyingType == typeof(Pair<object, object>)) { method .Block .DeclareVarWCast(typeof(Pair<object, object>), "pair", "und") .DeclareVar<IDictionary<string, object>>("wrapped", ExprDotName(Ref("pair"), "Second")) .MethodReturn(mapGetter.UnderlyingGetCodegen(Ref("wrapped"), codegenMethodScope, codegenClassScope)); } else { method.Block.MethodReturn(ConstantNull()); } return LocalMethod(method, Ref("und")); }
private CodegenMethod GetCodegen( CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { return codegenMethodScope.MakeChild(typeof(object), GetType(), codegenClassScope) .AddParam(typeof(XmlNode), "node") .Block .DeclareVar<object>( "value", getter.UnderlyingGetCodegen(Ref("node"), codegenMethodScope, codegenClassScope)) .MethodReturn(StaticMethod(GetType(), "GetXPathNodeListWCheck", Ref("value"), Constant(index))); }
public CodegenExpression UnderlyingGetCodegen( CodegenExpression underlyingExpression, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { var method = codegenMethodScope .MakeChild(typeof(object), GetType(), codegenClassScope) .AddParam(typeof(object), "und"); var undType = wrapperEventType.UnderlyingEventType.UnderlyingType; if (IsGenericPair(wrapperEventType.UnderlyingType)) { method.Block .DeclareVarWCast(wrapperEventType.UnderlyingType, "pair", "und") .DeclareVar(undType, "wrapped", Cast(undType, ExprDotName(Ref("pair"), "First"))) .MethodReturn(underlyingGetter.UnderlyingGetCodegen(Ref("wrapped"), codegenMethodScope, codegenClassScope)); return LocalMethod(method, Ref("und")); } else { method.Block .DeclareVar(undType, "wrapped", Cast(undType, Ref("und"))) .MethodReturn(underlyingGetter.UnderlyingGetCodegen(Ref("wrapped"), codegenMethodScope, codegenClassScope)); return LocalMethod(method, Ref("und")); } }
private CodegenExpression CodegenGet( Type requiredType, CodegenMethodScope codegenMethodScope, ExprForgeCodegenSymbol exprSymbol, CodegenClassScope codegenClassScope) { if (returnType == null) { return ConstantNull(); } var castTargetType = GetCodegenReturnType(requiredType); var useUnderlying = exprSymbol.IsAllowUnderlyingReferences && !identNode.ResolvedPropertyName.Contains("?") && !(eventType is WrapperEventType) && !(eventType is VariantEventType); if (useUnderlying && !optionalEvent) { var underlying = exprSymbol.GetAddRequiredUnderlying( codegenMethodScope, streamNum, eventType, false); var property = propertyGetter.UnderlyingGetCodegen(underlying, codegenMethodScope, codegenClassScope); return CodegenLegoCast.CastSafeFromObjectType(castTargetType, property); } var method = codegenMethodScope.MakeChild( castTargetType, this.GetType(), codegenClassScope); var block = method.Block; if (useUnderlying) { var underlying = exprSymbol.GetAddRequiredUnderlying( method, streamNum, eventType, true); if (castTargetType.CanNotBeNull()) { #if THROW_VALUE_ON_NULL block.IfRefNullThrowException(underlying); #else block .IfRefNull(underlying) .BlockReturn(new CodegenExpressionDefault(castTargetType)); #endif } else { block.IfRefNullReturnNull(underlying); } block.MethodReturn( CodegenLegoCast.CastSafeFromObjectType( castTargetType, propertyGetter.UnderlyingGetCodegen(underlying, method, codegenClassScope))); } else { var refEPS = exprSymbol.GetAddEPS(method); method.Block.DeclareVar<EventBean>("@event", ArrayAtIndex(refEPS, Constant(streamNum))); if (optionalEvent) { if (castTargetType.CanNotBeNull()) { #if THROW_VALUE_ON_NULL block.IfRefNullThrowException(Ref("@event")); #else block .IfRefNull(Ref("@event")) .BlockReturn(new CodegenExpressionDefault(castTargetType)); #endif } else { block.IfRefNullReturnNull(Ref("@event")); } } block.MethodReturn( CodegenLegoCast.CastSafeFromObjectType( castTargetType, propertyGetter.EventBeanGetCodegen(Ref("@event"), method, codegenClassScope))); } return LocalMethod(method); }
public static CodegenMethod From( CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope, Type expectedUnderlyingType, EventPropertyGetterSPI innerGetter, AccessType accessType, Type generator) { var methodNode = codegenMethodScope.MakeChild( accessType == AccessType.EXISTS ? typeof(bool) : typeof(object), generator, codegenClassScope) .AddParam(typeof(object), "value"); var block = methodNode.Block .IfInstanceOf("value", typeof(EventBean)) .DeclareVarWCast(typeof(EventBean), "bean", "value"); if (accessType == AccessType.GET) { block = block.BlockReturn( innerGetter.EventBeanGetCodegen(Ref("bean"), codegenMethodScope, codegenClassScope)); } else if (accessType == AccessType.EXISTS) { block = block.BlockReturn( innerGetter.EventBeanExistsCodegen(Ref("bean"), codegenMethodScope, codegenClassScope)); } else if (accessType == AccessType.FRAGMENT) { block = block.BlockReturn( innerGetter.EventBeanFragmentCodegen(Ref("bean"), codegenMethodScope, codegenClassScope)); } else { throw new UnsupportedOperationException("Invalid access type " + accessType); } block = block .IfNotInstanceOf("value", expectedUnderlyingType) .BlockReturn( accessType == AccessType.EXISTS ? Constant(false) : ConstantNull()); CodegenExpression expression; if (accessType == AccessType.GET) { expression = innerGetter.UnderlyingGetCodegen( Cast(expectedUnderlyingType, Ref("value")), codegenMethodScope, codegenClassScope); } else if (accessType == AccessType.EXISTS) { expression = innerGetter.UnderlyingExistsCodegen( Cast(expectedUnderlyingType, Ref("value")), codegenMethodScope, codegenClassScope); } else if (accessType == AccessType.FRAGMENT) { expression = innerGetter.UnderlyingFragmentCodegen( Cast(expectedUnderlyingType, Ref("value")), codegenMethodScope, codegenClassScope); } else { throw new UnsupportedOperationException("Invalid access type " + accessType); } block.MethodReturn(expression); return(methodNode); }