private static IPhpValue _AddFilter(IExternalTranslationContext ctx, CsharpMethodCallExpression src) { var methodName = src.MethodInfo.Name; WpTags tag; if (Enum.TryParse(methodName, out tag)) { var tt = typeof(WpTags); var methodCallExpression = new PhpMethodCallExpression("add_filter"); var fi = tt.GetField(methodName); var sss = new ClassFieldAccessExpression(fi, fi.IsStatic); var sss1 = ctx.TranslateValue(sss); IValue v = new ConstValue(tag); var gg = ctx.TranslateValue(v); methodCallExpression.Arguments.Add(new PhpMethodInvokeValue(sss1)); foreach (var argument in src.Arguments) { var phpValue = ctx.TranslateValue(argument.MyValue); methodCallExpression.Arguments.Add(new PhpMethodInvokeValue(phpValue)); } return(methodCallExpression); } throw new NotImplementedException(); }
protected override IValue VisitIdentifierName(IdentifierNameSyntax node) { // var tt = context.Roslyn_GetNamedTypeSymbols(null); var sInfo = ModelExtensions.GetSymbolInfo(context.RoslynModel, node); var tInfo2 = context.RoslynModel.GetTypeInfo2(node); var tInfo = tInfo2.TypeInfo; //var sInfo = sInfo2.ty Type type = tInfo.Type == null ? null : context.Roslyn_ResolveType(tInfo.Type); switch (sInfo.Symbol.Kind) { case SymbolKind.Local: //var symbolLocal = info.Symbol as CSharp.SourceLocalSymbol; IValue tmp = new LocalVariableExpression(sInfo.Symbol.Name, new LangType(type)); tmp = ImplicitConvert(tmp, tInfo2); return(Simplify(tmp)); case SymbolKind.NamedType: // var a = sInfo.Symbol.ToDisplayString(); var b = sInfo.Symbol.OriginalDefinition as INamedTypeSymbol; if (b != null) { var c = context.Roslyn_ResolveType(b); return(new TypeValue(c)); } throw new NotSupportedException(); case SymbolKind.Parameter: #warning 'Formalnie to nie jest zmienna lokalna !!'; tmp = new LocalVariableExpression(sInfo.Symbol.Name, new LangType(type)); return(Simplify(tmp)); case SymbolKind.Field: var ax = context.Roslyn_ResolveField(sInfo.Symbol as IFieldSymbol); if (ax.IsStatic) { // throw new NotSupportedException(); var fieldSymbol = sInfo.Symbol as IFieldSymbol; tmp = new ClassFieldAccessExpression(ax, fieldSymbol != null && fieldSymbol.IsConst); return(Simplify(tmp)); } tmp = new InstanceFieldAccessExpression(ax, new ThisExpression(state.CurrentType)); // niczego nie wiem o kontekście -> domyślam się, że this return(Simplify(tmp)); case SymbolKind.Method: { var methodBaseInfo = context.Roslyn_ResolveMethod(sInfo.Symbol as IMethodSymbol); var methodInfo = methodBaseInfo as MethodInfo; if (methodInfo == null) { throw new NotSupportedException(); } var result = new MethodExpression(methodInfo); return(Simplify(result)); } case SymbolKind.Property: { var pi = context.Roslyn_ResolveProperty(sInfo.Symbol as IPropertySymbol); var targetObject = new ThisExpression(state.CurrentType); var result = new CsharpInstancePropertyAccessExpression(pi, targetObject); return(result); } default: throw new NotSupportedException(); } //throw new NotSupportedException(); //var m = info.Symbol; //var info2 = context.RoslynModel.AnalyzeDataFlow(node); ////var info3 = context.RoslynModel.GetDeclaredSymbol(node); //var mg = context.RoslynModel.GetMemberGroup(node); //string identifier = node.Identifier.ValueText.Trim(); // return InternalVisitTextIdentifier(identifier); }
protected override IPhpValue VisitClassFieldAccessExpression(ClassFieldAccessExpression src) { var tmp = state.Principles.NodeTranslators.Translate(state, src); if (tmp != null) { return(SimplifyPhpExpression(tmp)); } var isStatic = src.IsStatic; var member = src.Member; var memberName = member.Name; var memberDeclaringType = member.DeclaringType; { var tInfo = state.Principles.GetOrMakeTranslationInfo(src.Member); if (tInfo.IsDefinedInNonincludableModule) { var b = state.Principles.GetTi(state.Principles.CurrentType, true); if (tInfo.IncludeModule != b.ModuleName) { throw new Exception( string.Format( "Unable to reference to field {1}.{0} from {2}.{3}. Containing module is page and cannot be included.", memberName, memberDeclaringType == null ? "?" : (memberDeclaringType.FullName ?? memberDeclaringType.Name), state.Principles.CurrentType.FullName, state.Principles.CurrentMethod )); } } var fieldDeclaringType = memberDeclaringType; if (fieldDeclaringType == null) { throw new Exception("fieldDeclaringType"); } state.Principles.GetTi(fieldDeclaringType, false); { if (fieldDeclaringType.IsEnum) { if (!isStatic) { throw new NotSupportedException(); } var asDefinedConstAttribute = member.GetCustomAttribute <AsDefinedConstAttribute>(); if (asDefinedConstAttribute != null) { var definedExpression = new PhpDefinedConstExpression(asDefinedConstAttribute.DefinedConstName, tInfo.IncludeModule); return(SimplifyPhpExpression(definedExpression)); } var renderValueAttribute = member.GetCustomAttribute <RenderValueAttribute>(); if (renderValueAttribute != null) { if (PhpValues.TryGetPhpStringValue(renderValueAttribute.Name, out var strCandidate)) { var valueExpression = new PhpConstValue(strCandidate); #if DEBUG { var a1 = renderValueAttribute.Name.Trim(); var a2 = valueExpression.ToString(); if (a1 != a2) { throw new InvalidOperationException(); } } #endif return(SimplifyPhpExpression(valueExpression)); } else { var valueExpression = new PhpFreeExpression(renderValueAttribute.Name); return(SimplifyPhpExpression(valueExpression)); } } { // object v1 = ReadEnumValueAndProcessForPhp(member); var v1 = member.GetValue(null); var g = new PhpConstValue(v1); return(SimplifyPhpExpression(g)); } //throw new NotSupportedException(); } } var principles = state.Principles; switch (tInfo.Destination) { case FieldTranslationDestionations.DefinedConst: if (!member.IsStatic) { throw new NotSupportedException("Unable to convert instance field into PHP defined const"); } if (tInfo.IsScriptNamePhpEncoded) { throw new Exception("Encoded php values are not supported"); } var definedExpression = new PhpDefinedConstExpression(tInfo.ScriptName, tInfo.IncludeModule); return(SimplifyPhpExpression(definedExpression)); case FieldTranslationDestionations.GlobalVariable: if (!member.IsStatic) { throw new NotSupportedException( "Unable to convert instance field into PHP global variable"); } if (tInfo.IsScriptNamePhpEncoded) { throw new Exception("Encoded php values are not supported"); } var globalVariable = PhpVariableExpression.MakeGlobal(tInfo.ScriptName); return(SimplifyPhpExpression(globalVariable)); case FieldTranslationDestionations.JustValue: if (!member.IsStatic) { throw new NotSupportedException("Unable to convert instance field into compile-time value"); } var constValue = member.GetValue(null); var phpConstValue = new PhpConstValue(constValue, tInfo.UsGlueForValue); return(SimplifyPhpExpression(phpConstValue)); case FieldTranslationDestionations.NormalField: if (tInfo.IsScriptNamePhpEncoded) { throw new Exception("Encoded php values are not supported"); } var rr = new PhpClassFieldAccessExpression { FieldName = tInfo.ScriptName, IsConst = tInfo.Destination == FieldTranslationDestionations.ClassConst }; rr.SetClassName( principles.GetPhpType(memberDeclaringType, true, principles.CurrentType), principles.GetOrMakeTranslationInfo(memberDeclaringType) ); return(SimplifyPhpExpression(rr)); case FieldTranslationDestionations.ClassConst: if (tInfo.IsScriptNamePhpEncoded) { throw new Exception("Encoded php values are not supported"); } rr = new PhpClassFieldAccessExpression { FieldName = tInfo.ScriptName, IsConst = true }; rr.SetClassName( principles.GetPhpType(memberDeclaringType, true, principles.CurrentType), principles.GetOrMakeTranslationInfo(memberDeclaringType)); return(SimplifyPhpExpression(rr)); default: throw new NotSupportedException(string.Format( "Unable to translate class field with destination option equal {0}", tInfo.Destination)); } } }