public override void VisitCastExpression (CastExpression castExpression) { base.VisitCastExpression (castExpression); VisitTypeCastExpression (castExpression, ctx.Resolve (castExpression.Expression).Type, ctx.ResolveType (castExpression.Type)); }
public override void VisitCastExpression (CastExpression castExpression) { base.VisitCastExpression (castExpression); CheckTypeCast (castExpression, castExpression.Expression, castExpression.StartLocation, castExpression.Expression.StartLocation); }
public ISymbolValue Visit(CastExpression ce) { var toCast = ce.UnaryExpression != null ? ce.UnaryExpression.Accept (this) : null; var targetType = ce.Type != null ? TypeDeclarationResolver.ResolveSingle(ce.Type, ctxt) : null; var pv = toCast as PrimitiveValue; var pt = targetType as PrimitiveType; if (pv != null && pt != null) { //TODO: Truncate value bytes if required and/or treat Value/ImaginaryPart in any way! return new PrimitiveValue(pt.TypeToken, pv.Value, pv.ImaginaryPart, pt.Modifier); } // TODO: Convert actual object return null; }
public override void VisitCastExpression(CastExpression castExpression) { base.VisitCastExpression(castExpression); var expression = castExpression.Expression; if (expression is ParenthesizedExpression) expression = (expression as ParenthesizedExpression).Expression; object value = null; if (expression is PrimitiveExpression) value = (expression as PrimitiveExpression).Value; else if (expression is UnaryOperatorExpression && (expression as UnaryOperatorExpression).Expression is PrimitiveExpression) { var primitive = (expression as UnaryOperatorExpression).Expression as PrimitiveExpression; value = primitive.Value; } if (value != null) { var type = (castExpression.Type as PrimitiveType).KnownTypeCode; if ((type == KnownTypeCode.Int16 && value is short) || (type == KnownTypeCode.Int32 && value is int) || (type == KnownTypeCode.Int64 && value is long) || (type == KnownTypeCode.UInt16 && value is ushort) || (type == KnownTypeCode.UInt32 && value is uint) || (type == KnownTypeCode.UInt64 && value is ulong) || (type == KnownTypeCode.Double && value is double) || (type == KnownTypeCode.Single && value is float) || (type == KnownTypeCode.String && value is string) || (type == KnownTypeCode.Boolean && value is bool) || (type == KnownTypeCode.Char && value is char) || (type == KnownTypeCode.Byte && value is byte) || (type == KnownTypeCode.SByte && value is sbyte) || (type == KnownTypeCode.Decimal && value is decimal)) { castExpression.ReplaceWith(expression); } } }
public override object Visit (Cast castExpression) { var result = new CastExpression (); var location = LocationsBag.GetLocations (castExpression); result.AddChild (new CSharpTokenNode (Convert (castExpression.Location), 1), CastExpression.Roles.LPar); if (castExpression.TargetType != null) result.AddChild ((INode)castExpression.TargetType.Accept (this), CastExpression.Roles.ReturnType); if (location != null) result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CastExpression.Roles.RPar); if (castExpression.Expr != null) result.AddChild ((INode)castExpression.Expr.Accept (this), CastExpression.Roles.Expression); return result; }
public virtual void VisitCastExpression (CastExpression castExpression) { VisitChildren (castExpression); }
public virtual void VisitCastExpression(CastExpression castExpression) { if (this.ThrowException) { throw (Exception)this.CreateException(castExpression); } }
public override void VisitCastExpression(CastExpression castExpression) { if (castExpression.RParToken != null) { ForceSpacesAfter(castExpression.LParToken, policy.SpacesWithinCastParentheses); ForceSpacesBefore(castExpression.RParToken, policy.SpacesWithinCastParentheses); ForceSpacesAfter(castExpression.RParToken, policy.SpaceAfterTypecast); } base.VisitCastExpression(castExpression); }
public void Visit(CastExpression x) { }
IExpression UnaryExpression(IBlockNode Scope = null) { switch (laKind) { // Note: PowExpressions are handled in PowExpression() case BitwiseAnd: case Increment: case Decrement: case Times: case Minus: case Plus: case Not: case Tilde: Step(); SimpleUnaryExpression sue; switch (t.Kind) { case BitwiseAnd: sue = new UnaryExpression_And(); break; case Increment: sue = new UnaryExpression_Increment(); break; case Decrement: sue = new UnaryExpression_Decrement(); break; case Times: sue = new UnaryExpression_Mul(); break; case Minus: sue = new UnaryExpression_Sub(); break; case Plus: sue = new UnaryExpression_Add(); break; case Tilde: sue = new UnaryExpression_Cat(); break; case Not: sue = new UnaryExpression_Not(); break; default: SynErr(t.Kind, "Illegal token for unary expressions"); return null; } sue.Location = t.Location; sue.UnaryExpression = UnaryExpression(Scope); return sue; // CastExpression case Cast: Step(); var ce = new CastExpression { Location= t.Location }; if (Expect(OpenParenthesis)) { if (laKind != CloseParenthesis) // Yes, it is possible that a cast() can contain an empty type! ce.Type = Type(); Expect(CloseParenthesis); } ce.UnaryExpression = UnaryExpression(Scope); ce.EndLocation = t.EndLocation; return ce; // DeleteExpression case Delete: Step(); return new DeleteExpression() { UnaryExpression = UnaryExpression(Scope) }; // PowExpression default: var left = PostfixExpression(Scope); if (laKind != Pow) return left; Step(); var pe = new PowExpression(); pe.LeftOperand = left; pe.RightOperand = UnaryExpression(Scope); return pe; } }
public override void VisitCXXMethodDecl(CXXMethodDecl decl, VisitKind visitKind) { if (!MethodIsBindable (decl, visitKind)) return; var cmethodBuilder = new StringBuilder(); AstType pinvokeReturn, methodReturn; WrapKind returnIsWrapped; ICSharpCode.NRefactory.CSharp.ParameterModifier pinvokeMod, methodMod; LookupMarshalTypes(decl.ReturnQualType, out pinvokeReturn, out pinvokeMod, out methodReturn, out methodMod, out returnIsWrapped, isReturn: true); var methodReturn2 = methodReturn.Clone(); var propertyInfo = ScanBaseTypes.GetPropertyInfo(decl); if (propertyInfo != null) { propertyInfo.HostType = currentType; if (decl.Name.StartsWith("Get") || decl.Name.StartsWith("Is")) propertyInfo.MethodReturn = methodReturn.Clone(); } var methodName = decl.Name; if (currentTypeNames.Contains(methodName)) methodName += (uniqueMethodName++).ToString(); currentTypeNames.Add(methodName); // // PInvoke declaration + C counterpart declaration // string pinvoke_name = currentType.Name + "_" + methodName; var isConstructor = decl is CXXConstructorDecl; if (isConstructor) { pinvokeReturn = new SimpleType ("IntPtr"); // Do not bind a default constructor for Skeleton if (currentType.Name == "Skeleton") return; } var pinvoke = new MethodDeclaration { Name = pinvoke_name, ReturnType = pinvokeReturn, Modifiers = Modifiers.Extern | Modifiers.Static | Modifiers.Internal }; if (!decl.IsStatic && !isConstructor) pinvoke.Parameters.Add(new ParameterDeclaration(new SimpleType("IntPtr"), "handle")); var dllImport = new Attribute { Type = new SimpleType("DllImport") }; dllImport.Arguments.Add (new PrimitiveExpression ("mono-urho")); dllImport.Arguments.Add (new AssignmentExpression (new IdentifierExpression ("CallingConvention"), csParser.ParseExpression ("CallingConvention.Cdecl"))); pinvoke.Attributes.Add(new AttributeSection(dllImport)); // The C counterpart var cinvoke = new StringBuilder(); string marshalReturn = "{0}"; string creturnType = CleanTypeCplusplus(decl.ReturnQualType); switch (creturnType) { case "bool": creturnType = "int"; break; case "Urho3D::StringHash": creturnType = "int"; marshalReturn = "({0}).Value ()"; break; case "Urho3D::String": case "const Urho3D::String &": case "const class Urho3D::String &": creturnType = "const char *"; marshalReturn = "strdup(({0}).CString ())"; break; case "const struct Urho3D::TileMapInfo2D &": creturnType = "Urho3D::TileMapInfo2D"; break; case "const struct Urho3D::CrowdObstacleAvoidanceParams &": creturnType = "Urho3D::CrowdObstacleAvoidanceParams"; break; case "const class Urho3D::Vector3 &": case "const class Urho3D::Vector2 &": case "const class Urho3D::Vector4 &": case "const class Urho3D::IntVector2 &": case "const class Urho3D::Quaternion &": case "const class Urho3D::Plane &": case "const class Urho3D::BoundingBox &": case "const class Urho3D::Color &": case "Urho3D::Vector3": case "Urho3D::Vector2": case "Urho3D::Vector4": case "Urho3D::IntVector2": case "Urho3D::Quaternion": case "Urho3D::Plane": case "Urho3D::BoundingBox": case "Urho3D::Color": var nsIndex = creturnType.IndexOf ("Urho3D::") + "Urho3D".Length; creturnType = "Interop" + creturnType.Remove (0, nsIndex).Trim ('&', ' ') + " "; marshalReturn = "*((" + creturnType + " *) &({0}))"; break; } if (creturnType.StartsWith("SharedPtr<")) { creturnType = creturnType.ExtractGenericParameter().DropClassOrStructPrefix() + " *"; marshalReturn = "auto copy = {0};\n" + "\tauto plain = copy.Get();\n" + "\tcopy.Detach();\n" + "\tdelete copy;\n" + "\treturn plain;"; } const string methodNameSuffix = "%MethodSuffix%"; const string variantConverterMask = "%VariantConvertor%"; if (isConstructor) cmethodBuilder.Append($"DllExport void *\n{pinvoke_name}{methodNameSuffix} ("); else cmethodBuilder.Append($"DllExport {creturnType}\n{pinvoke_name}{methodNameSuffix} ("); if (decl.IsStatic) { cinvoke.Append($"{decl.Parent.Name}::{decl.Name} ("); } else if (isConstructor) { cinvoke.Append($"new {decl.Name}("); } else { cmethodBuilder.Append($"Urho3D::{decl.Parent.Name} *_target"); if (decl.Parameters.Any()) cmethodBuilder.Append(", "); cinvoke.Append($"_target->{decl.Name} ("); } // // Method declaration // MethodDeclaration method = null; ConstructorDeclaration constructor = null; if (isConstructor) { constructor = new ConstructorDeclaration { Name = RemapMemberName(decl.Parent.Name, decl.Name), Modifiers = (decl.IsStatic ? Modifiers.Static : 0) | (propertyInfo != null ? Modifiers.Private : Modifiers.Public) | (decl.Name == "ToString" ? Modifiers.Override : 0) }; constructor.Body = new BlockStatement(); } else { method = new MethodDeclaration { Name = RemapMemberName(decl.Parent.Name, decl.Name), ReturnType = methodReturn, Modifiers = (decl.IsStatic ? Modifiers.Static : 0) | (propertyInfo != null ? Modifiers.Private : Modifiers.Public) }; method.Body = new BlockStatement(); } // // Marshal from C# to C and the C support to call into C++ // var invoke = new InvocationExpression(new IdentifierExpression(pinvoke_name)); if (!decl.IsStatic && !isConstructor) invoke.Arguments.Add(new IdentifierExpression("handle")); bool first = true; int anonymousParameterNameCount = 1; int currentParamCount = -1; foreach (var param in decl.Parameters) { currentParamCount++; AstType pinvokeParameter, parameter; WrapKind wrapKind; if (!first) { cinvoke.Append(", "); cmethodBuilder.Append(", "); } else first = false; LookupMarshalTypes(param.QualType, out pinvokeParameter, out pinvokeMod, out parameter, out methodMod, out wrapKind); string paramName = param.Name; if (string.IsNullOrEmpty(paramName)) paramName = "param" + (anonymousParameterNameCount++); Expression parameterReference = new IdentifierExpression (paramName); switch (currentType.Name) { case "Input": switch (decl.Name) { case "GetMouseButtonDown": case "GetMouseButtonPress": parameter = new SimpleType ("MouseButton"); parameterReference = new CastExpression (new PrimitiveType ("int"), parameterReference); break; case "GetKeyPress": case "GetKeyDown": case "GetScancodeFromKey": case "GetKeyName": if (currentParamCount == 0 && paramName == "key") { parameter = new SimpleType ("Key"); parameterReference = new CastExpression (new PrimitiveType ("int"), parameterReference); } break; } break; case "VertexBuffer": switch (decl.Name) { case "SetSize": if (currentParamCount == 1 && paramName == "elementMask") { parameter = new SimpleType ("ElementMask"); parameterReference = new CastExpression (new PrimitiveType ("uint"), parameterReference); } break; case "GetVertexSize": if (currentParamCount == 0 && paramName == "elementMask") { parameter = new SimpleType ("ElementMask"); parameterReference = new CastExpression (new PrimitiveType ("uint"), parameterReference); } break; case "GetElementOffset": if (currentParamCount == 0 && paramName == "elementMask") { parameter = new SimpleType ("ElementMask"); parameterReference = new CastExpression (new PrimitiveType ("uint"), parameterReference); } break; } break; case "Log": switch (decl.Name) { case "Write": if (currentParamCount == 0 && paramName == "level") { parameter = new SimpleType ("LogLevel"); parameterReference = new CastExpression (new PrimitiveType ("int"), parameterReference); } break; } break; } if (constructor == null) method.Parameters.Add(new ParameterDeclaration(parameter, paramName, methodMod)); else constructor.Parameters.Add(new ParameterDeclaration(parameter, paramName, methodMod)); pinvoke.Parameters.Add(new ParameterDeclaration(pinvokeParameter, paramName, pinvokeMod)); switch (wrapKind) { case WrapKind.None: invoke.Arguments.Add(parameterReference); break; case WrapKind.HandleMember: case WrapKind.UrhoObject: var cond = new ConditionalExpression (new BinaryOperatorExpression (new CastExpression (new PrimitiveType ("object"), parameterReference), BinaryOperatorType.Equality, new PrimitiveExpression (null)), csParser.ParseExpression ("IntPtr.Zero"), csParser.ParseExpression (paramName + ".Handle")); invoke.Arguments.Add (cond); break; case WrapKind.EventHandler: invoke.Arguments.Add(parameterReference); break; case WrapKind.StringHash: invoke.Arguments.Add (csParser.ParseExpression (paramName + ".Code")); break; case WrapKind.RefBlittable: invoke.Arguments.Add (new DirectionExpression (FieldDirection.Ref, parameterReference)); break; case WrapKind.VectorSharedPtr: throw new NotImplementedException ("Vector marshaling not supported for parameters yet"); } var ctype = CleanTypeCplusplus (param.QualType); string paramInvoke = paramName; switch (ctype) { case "bool": ctype = "int"; break; case "Urho3D::Deserializer &": case "Urho3D::Serializer &": ctype = "File *"; paramInvoke = $"*{paramInvoke}"; break; case "const class Urho3D::String &": ctype = "const char *"; paramInvoke = $"Urho3D::String({paramInvoke})"; break; case "Urho3D::StringHash": ctype = "int"; paramInvoke = $"Urho3D::StringHash({paramInvoke})"; break; case "const class Urho3D::Variant &": paramInvoke = $"{variantConverterMask}({paramInvoke})"; break; } cmethodBuilder.Append($"{ctype} {paramName}"); cinvoke.Append($"{paramInvoke}"); } cinvoke.Append(")"); cmethodBuilder.Append(")\n{\n\t"); // if the type has a ctor accepting Context - add a parameterless one that will use "this(Application.CurrentContext)" if (isConstructor && decl.Parameters.Count() == 1 && decl.Parameters.ElementAt(0).QualType.ToString() == "class Urho3D::Context *") { var ctor = new ConstructorDeclaration { Modifiers = Modifiers.Public, Body = new BlockStatement(), Initializer = new ConstructorInitializer { ConstructorInitializerType = ConstructorInitializerType.This } }; ctor.Initializer.Arguments.Add(csParser.ParseExpression("Application.CurrentContext")); currentType.Members.Add(ctor); } if (method != null && methodReturn is Sharpie.Bind.Types.VoidType) { method.Body.Add(invoke); // pn ($"fprintf (stderr,\"DEBUG {creturnType} {pinvoke_name} (...)\\n\");"); cmethodBuilder.AppendLine($"{cinvoke.ToString()};"); } else { ReturnStatement ret = null; Expression returnExpression; if (!isConstructor) ret = new ReturnStatement(); switch (returnIsWrapped) { case WrapKind.HandleMember: returnExpression = new InvocationExpression (new MemberReferenceExpression (new IdentifierExpression ("Runtime"), "LookupRefCounted", methodReturn2), invoke); break; case WrapKind.UrhoObject: returnExpression = new InvocationExpression (new MemberReferenceExpression (new IdentifierExpression ("Runtime"), "LookupObject", methodReturn2), invoke); break; case WrapKind.EventHandler: returnExpression = invoke; break; case WrapKind.StringHash: returnExpression = new ObjectCreateExpression (new SimpleType ("StringHash"), invoke); break; case WrapKind.MarshalPtrToString: returnExpression = new InvocationExpression(new MemberReferenceExpression(new IdentifierExpression("Marshal"), "PtrToStringAnsi"), invoke); break; case WrapKind.MarshalPtrToStruct: returnExpression = new InvocationExpression(new MemberReferenceExpression(new IdentifierExpression("Marshal"), "PtrToStructure"), invoke, new TypeOfExpression(methodReturn2)); returnExpression = new CastExpression(methodReturn2.Clone(), returnExpression); break; case WrapKind.VectorSharedPtr: var cacheName = "_" + method.Name + "_cache"; var f = new FieldDeclaration () { ReturnType = method.ReturnType.Clone (), Modifiers = Modifiers.Private | (method.Modifiers & Modifiers.Static) }; f.Variables.Add (new VariableInitializer (cacheName, null)); currentType.Members.Add (f); var sharedPtrType = (methodReturn as SimpleType).TypeArguments.First ().Clone (); //TODO: check if UrhoObject var create = (sharedPtrType.ToString() == "AnimationState") ? "CreateVectorSharedPtrRefcountedProxy" : "CreateVectorSharedPtrProxy"; returnExpression = new ConditionalExpression ( new BinaryOperatorExpression (new IdentifierExpression (cacheName), BinaryOperatorType.InEquality, new PrimitiveExpression (null)), new IdentifierExpression (cacheName), new AssignmentExpression ( new IdentifierExpression (cacheName), new InvocationExpression ( new MemberReferenceExpression ( new IdentifierExpression ("Runtime"), create, sharedPtrType), invoke))); break; default: returnExpression = invoke; break; } if (ret != null) { ret.Expression = returnExpression; method.Body.Add(ret); } else { if (currentType.ClassType == ClassType.Class){ //usually, the Context is the first object user creates so let's add additional check if engine is inited if (currentType.Name == "Context") { constructor.Body.Add (new InvocationExpression (new IdentifierExpression ("CheckEngine"), null)); } bool hasBaseTypes = currentType.BaseTypes.Count != 0; if (hasBaseTypes) { constructor.Initializer = new ConstructorInitializer { ConstructorInitializerType = ConstructorInitializerType.Base, }; constructor.Initializer.Arguments.Add(csParser.ParseExpression("UrhoObjectFlag.Empty")); } var ctorAssign = new AssignmentExpression(new IdentifierExpression("handle"), returnExpression); constructor.Body.Add(new ExpressionStatement(ctorAssign)); if (hasBaseTypes) { constructor.Body.Add (new InvocationExpression (new MemberReferenceExpression (new IdentifierExpression ("Runtime"), "RegisterObject"), new ThisReferenceExpression ())); } } } var rstr = String.Format(marshalReturn, cinvoke.ToString()); CXXRecordDecl returnType; //Wrap with WeakPtr all RefCounted subclasses constructors if (isConstructor) { if (ScanBaseTypes.nameToDecl.TryGetValue(decl.Parent.QualifiedName, out returnType) && returnType.IsDerivedFrom(ScanBaseTypes.UrhoRefCounted)) rstr = $"WeakPtr<{decl.Name}>({rstr})"; } cmethodBuilder.AppendLine(!rstr.Contains("\treturn ") ? $"return {rstr};" : rstr); } cmethodBuilder.AppendLine("}\n"); var code = cmethodBuilder.ToString(); const string variantArgDef = "const class Urho3D::Variant &"; //if methods contains Variant argument -- replace it with overloads if (code.Contains(variantArgDef)) { var variantSupportedTypes = new Dictionary<string, string> { //C++ - C# types map {"const class Urho3D::Vector3 &", "Vector3"}, {"const class Urho3D::IntRect &", "IntRect"}, {"const class Urho3D::Color &", "Color"}, {"const class Urho3D::Vector2 &", "Vector2"}, {"const class Urho3D::Vector4 &", "Vector4"}, {"const class Urho3D::IntVector2 &", "IntVector2"}, {"const class Urho3D::Quaternion &", "Quaternion"}, {"int", "int"}, {"float", "float"}, {"const char *", "string"}, //TODO: Matrix, StringHash? }; var primitiveTypes = new[] { "int", "float", "string" }; pn("// Urho3D::Variant overloads begin:"); int index = 0; foreach (var item in variantSupportedTypes) { //C: p(code .Replace(variantArgDef, item.Key) .Replace(methodNameSuffix, index.ToString()) .Replace(variantConverterMask, item.Key == "const char *" ? "Urho3D::String" : string.Empty)); //methodNameSuffix to avoid error: // error C2733: second C linkage of overloaded function 'function name' not allowed. //C#: var isPrimitive = primitiveTypes.Contains(item.Value); AstType argumentType; var argumentModifier = ICSharpCode.NRefactory.CSharp.ParameterModifier.None; if (!isPrimitive) { argumentType = new SimpleType(item.Value); argumentModifier = ICSharpCode.NRefactory.CSharp.ParameterModifier.Ref; } else { argumentType = new PrimitiveType(item.Value); } var dllImportItem = (MethodDeclaration)pinvoke.Clone(); var originalEntryPointName = dllImportItem.Name; dllImportItem.Name += index; var variantParam = dllImportItem.Parameters.First(p => p.ToString().Contains(variantArgDef)); variantParam.Type = argumentType.Clone(); variantParam.ParameterModifier = argumentModifier; currentType.Members.Add(dllImportItem); var clonedMethod = (MethodDeclaration)method.Clone(); variantParam = clonedMethod.Parameters.First(p => p.ToString().Contains(variantArgDef)); variantParam.Type = argumentType.Clone(); //add 'index' to all EntryPoint invocations inside the method (no mater how complex method body is): //and 'ref' keyword for the argument clonedMethod.Body.Descendants .OfType<InvocationExpression>() .Where(ie => ie.Target is IdentifierExpression && ((IdentifierExpression)ie.Target).Identifier == originalEntryPointName) .ToList() .ForEach(ie => { if (!isPrimitive) { //non-primitive types should be marked with 'ref' keyword var argument = ie.Arguments.OfType<IdentifierExpression>().First(arg => arg.Identifier == variantParam.Name); ie.Arguments.Remove(argument); ie.Arguments.Add(new DirectionExpression(FieldDirection.Ref, argument)); } var exp = (IdentifierExpression)ie.Target; exp.Identifier += index; }); currentType.Members.Add(clonedMethod); InsertSummaryComments(clonedMethod, StringUtil.GetMethodComments(decl)); index++; } pn("// Urho3D::Variant overloads end."); } //method does not have "Variant" arguments else { //C: pn(code .Replace(methodNameSuffix, string.Empty) .Replace(variantConverterMask, string.Empty)); //C#: currentType.Members.Add(pinvoke); if (method == null) currentType.Members.Add(constructor); else { currentType.Members.Add(method); InsertSummaryComments(method, StringUtil.GetMethodComments(decl)); } } }
public ISymbolValue Visit(CastExpression ce) { // TODO: Convert actual object return null; }
public override void VisitCastExpression(CastExpression castExpression) { new CastBlock(this, castExpression).Emit(); }
IExpression UnaryExpression(IBlockNode Scope = null) { // Note: PowExpressions are handled in PowExpression() if (laKind == (BitwiseAnd) || laKind == (Increment) || laKind == (Decrement) || laKind == (Times) || laKind == (Minus) || laKind == (Plus) || laKind == (Not) || laKind == (Tilde)) { Step(); SimpleUnaryExpression ae = null; switch (t.Kind) { case BitwiseAnd: ae = new UnaryExpression_And(); break; case Increment: ae = new UnaryExpression_Increment(); break; case Decrement: ae = new UnaryExpression_Decrement(); break; case Times: ae = new UnaryExpression_Mul(); break; case Minus: ae = new UnaryExpression_Sub(); break; case Plus: ae = new UnaryExpression_Add(); break; case Tilde: ae = new UnaryExpression_Cat(); break; case Not: ae = new UnaryExpression_Not(); break; } LastParsedObject = ae; ae.Location = t.Location; ae.UnaryExpression = UnaryExpression(Scope); return ae; } // ( Type ) . Identifier if (laKind == OpenParenthesis) { var wkParsing = AllowWeakTypeParsing; AllowWeakTypeParsing = true; var curLA = la; Step(); var td = Type(); AllowWeakTypeParsing = wkParsing; if (td!=null && ((t.Kind!=OpenParenthesis && laKind == CloseParenthesis && Peek(1).Kind == Dot && Peek(2).Kind == Identifier) || (IsEOF || Peek(1).Kind==EOF || Peek(2).Kind==EOF))) // Also take it as a type declaration if there's nothing following (see Expression Resolving) { Step(); // Skip to ) Step(); // Skip to . Step(); // Skip to identifier var accExpr = new UnaryExpression_Type() { Type=td, AccessIdentifier=t.Value }; accExpr.Location = curLA.Location; accExpr.EndLocation = t.EndLocation; return accExpr; } else { // Reset the current token with the earlier one to enable Expression parsing la = curLA; Peek(1); } } // CastExpression if (laKind == (Cast)) { Step(); var ae = new CastExpression { Location= t.Location }; if (Expect(OpenParenthesis)) { if (laKind != CloseParenthesis) // Yes, it is possible that a cast() can contain an empty type! ae.Type = Type(); Expect(CloseParenthesis); } ae.UnaryExpression = UnaryExpression(Scope); ae.EndLocation = t.EndLocation; return ae; } // NewExpression if (laKind == (New)) return NewExpression(Scope); // DeleteExpression if (laKind == (Delete)) { Step(); return new DeleteExpression() { UnaryExpression = UnaryExpression(Scope) }; } // PowExpression var left = PostfixExpression(Scope); if (laKind != Pow) return left; Step(); var pe = new PowExpression(); pe.LeftOperand = left; pe.RightOperand = UnaryExpression(Scope); return pe; }
void SimpleNonInvocationExpression( #line 1645 "VBNET.ATG" out Expression pexpr) { #line 1647 "VBNET.ATG" Expression expr; TypeReference type = null; string name = String.Empty; pexpr = null; if (StartOf(32)) { switch (la.kind) { case 3: { lexer.NextToken(); #line 1655 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 4: { lexer.NextToken(); #line 1656 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 7: { lexer.NextToken(); #line 1657 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 6: { lexer.NextToken(); #line 1658 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 5: { lexer.NextToken(); #line 1659 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 9: { lexer.NextToken(); #line 1660 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 8: { lexer.NextToken(); #line 1661 "VBNET.ATG" pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat }; break; } case 202: { lexer.NextToken(); #line 1663 "VBNET.ATG" pexpr = new PrimitiveExpression(true, "true"); break; } case 109: { lexer.NextToken(); #line 1664 "VBNET.ATG" pexpr = new PrimitiveExpression(false, "false"); break; } case 151: { lexer.NextToken(); #line 1665 "VBNET.ATG" pexpr = new PrimitiveExpression(null, "null"); break; } case 25: { lexer.NextToken(); Expr( #line 1666 "VBNET.ATG" out expr); Expect(26); #line 1666 "VBNET.ATG" pexpr = new ParenthesizedExpression(expr); break; } case 2: case 45: case 49: case 51: case 52: case 53: case 54: case 57: case 74: case 85: case 91: case 94: case 103: case 108: case 113: case 120: case 126: case 130: case 133: case 156: case 162: case 169: case 188: case 197: case 198: case 208: case 209: case 215: { Identifier(); #line 1668 "VBNET.ATG" pexpr = new IdentifierExpression(t.val); pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; if ( #line 1671 "VBNET.ATG" la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { lexer.NextToken(); Expect(155); TypeArgumentList( #line 1672 "VBNET.ATG" ((IdentifierExpression)pexpr).TypeArguments); Expect(26); } break; } case 55: case 58: case 69: case 86: case 87: case 96: case 128: case 137: case 154: case 181: case 186: case 187: case 193: case 206: case 207: case 210: { #line 1674 "VBNET.ATG" string val = String.Empty; if (StartOf(11)) { PrimitiveTypeName( #line 1675 "VBNET.ATG" out val); } else if (la.kind == 154) { lexer.NextToken(); #line 1675 "VBNET.ATG" val = "System.Object"; } else SynErr(257); #line 1676 "VBNET.ATG" pexpr = new TypeReferenceExpression(new TypeReference(val, true)); break; } case 139: { lexer.NextToken(); #line 1677 "VBNET.ATG" pexpr = new ThisReferenceExpression(); break; } case 144: case 145: { #line 1678 "VBNET.ATG" Expression retExpr = null; if (la.kind == 144) { lexer.NextToken(); #line 1679 "VBNET.ATG" retExpr = new BaseReferenceExpression(); } else if (la.kind == 145) { lexer.NextToken(); #line 1680 "VBNET.ATG" retExpr = new ClassReferenceExpression(); } else SynErr(258); Expect(16); IdentifierOrKeyword( #line 1682 "VBNET.ATG" out name); #line 1682 "VBNET.ATG" pexpr = new MemberReferenceExpression(retExpr, name); break; } case 117: { lexer.NextToken(); Expect(16); Identifier(); #line 1684 "VBNET.ATG" type = new TypeReference(t.val ?? ""); #line 1686 "VBNET.ATG" type.IsGlobal = true; #line 1687 "VBNET.ATG" pexpr = new TypeReferenceExpression(type); break; } case 148: { ObjectCreateExpression( #line 1688 "VBNET.ATG" out expr); #line 1688 "VBNET.ATG" pexpr = expr; break; } case 81: case 93: case 204: { #line 1690 "VBNET.ATG" CastType castType = CastType.Cast; if (la.kind == 93) { lexer.NextToken(); } else if (la.kind == 81) { lexer.NextToken(); #line 1692 "VBNET.ATG" castType = CastType.Conversion; } else if (la.kind == 204) { lexer.NextToken(); #line 1693 "VBNET.ATG" castType = CastType.TryCast; } else SynErr(259); Expect(25); Expr( #line 1695 "VBNET.ATG" out expr); Expect(12); TypeName( #line 1695 "VBNET.ATG" out type); Expect(26); #line 1696 "VBNET.ATG" pexpr = new CastExpression(type, expr, castType); break; } case 63: case 64: case 65: case 66: case 67: case 68: case 70: case 72: case 73: case 77: case 78: case 79: case 80: case 82: case 83: case 84: { CastTarget( #line 1697 "VBNET.ATG" out type); Expect(25); Expr( #line 1697 "VBNET.ATG" out expr); Expect(26); #line 1697 "VBNET.ATG" pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); break; } case 44: { lexer.NextToken(); Expr( #line 1698 "VBNET.ATG" out expr); #line 1698 "VBNET.ATG" pexpr = new AddressOfExpression(expr); break; } case 116: { lexer.NextToken(); Expect(25); GetTypeTypeName( #line 1699 "VBNET.ATG" out type); Expect(26); #line 1699 "VBNET.ATG" pexpr = new TypeOfExpression(type); break; } case 205: { lexer.NextToken(); SimpleExpr( #line 1700 "VBNET.ATG" out expr); Expect(131); TypeName( #line 1700 "VBNET.ATG" out type); #line 1700 "VBNET.ATG" pexpr = new TypeOfIsExpression(expr, type); break; } case 122: { ConditionalExpression( #line 1701 "VBNET.ATG" out pexpr); break; } } } else if (la.kind == 16) { lexer.NextToken(); IdentifierOrKeyword( #line 1705 "VBNET.ATG" out name); #line 1705 "VBNET.ATG" pexpr = new MemberReferenceExpression(null, name); } else SynErr(260); }
public void VisitCastExpression(CastExpression castExpr) { throw new NotImplementedException(); }
public abstract StringBuilder VisitCastExpression(CastExpression castExpression, int data);
public void GenerateProperties() { foreach (var typeKV in ScanBaseTypes.allProperties) { foreach (var propNameKV in typeKV.Value) { foreach (var gs in propNameKV.Value.Values) { Expression valueReference = new IdentifierExpression ("value"); Expression invokeGetter = new InvocationExpression (new IdentifierExpression (RemapMemberName (gs.Getter.Parent.Name, gs.Getter.Name))); string pname = gs.Name; Modifiers mods = 0; switch (typeKV.Key) { case "UIElement": if (pname == "BringToFront") pname = "BringToFrontOnFocus"; if (pname == "BringToBack") pname = "BringToBackOnFocus"; if (pname == "SortChildren") pname = "ShouldSortChildren"; break; case "Menu": if (pname == "ShowPopup") pname = "IsPopupShown"; break; case "File": if (pname == "Handle") pname = "FileHandle"; break; case "Text": if (pname == "Text") pname = "Value"; break; case "Sprite": switch (pname) { case "Position": pname = "PositionFloat"; break; default: break; } break; case "View": #if false // if false -> temporarily moved the apis to Application, not RefCounted, so there is currently // no conflict // View.Graphics is the Urho C++ strong type to GetSubssytem(Graphics) if (pname == "Graphics" || pname == "Renderer") mods = Modifiers.New; #endif break; case "Camera": switch (pname) { case "ViewOverrideFlags": gs.MethodReturn = new SimpleType ("ViewOverrideFlags"); valueReference = new CastExpression (new PrimitiveType ("uint"), valueReference); invokeGetter = new CastExpression (new SimpleType ("ViewOverrideFlags"), invokeGetter); break; } break; case "VertexBuffer": switch (pname) { case "ElementMask": gs.MethodReturn = new SimpleType ("ElementMask"); valueReference = new CastExpression (new PrimitiveType ("uint"), valueReference); invokeGetter = new CastExpression (new SimpleType ("ElementMask"), invokeGetter); break; } break; } var p = new PropertyDeclaration() { Name = pname, ReturnType = gs.MethodReturn, Modifiers = Modifiers.Public | (gs.Getter.IsStatic ? Modifiers.Static : 0) | mods }; p.Getter = new Accessor() { Body = new BlockStatement() { new ReturnStatement (invokeGetter) } }; if (gs.Setter != null) { p.Setter = new Accessor() { Body = new BlockStatement() { new InvocationExpression (new IdentifierExpression (gs.Setter.Name), valueReference) } }; } // We are unable to bind if (gs.HostType == null) continue; gs.HostType.Members.Add(p); var comments = StringUtil.GetMethodComments(gs.Getter); if (gs.Setter != null) { var setterComments = StringUtil.GetMethodComments(gs.Setter).ToList(); if (setterComments.Count > 0) { setterComments.Insert(0, "Or"); } comments = comments.Concat(setterComments); } InsertSummaryComments(p, comments); } } } }
public void VisitCastExpression(CastExpression castExpression) { StartNode(castExpression); WriteToken ("<", Roles.LPar); Space(policy.SpacesWithinCastParentheses); castExpression.Type.AcceptVisitor(this); Space(policy.SpacesWithinCastParentheses); WriteToken (">", Roles.LPar); Space(policy.SpaceAfterTypecast); castExpression.Expression.AcceptVisitor(this); EndNode(castExpression); }
public override StringBuilder VisitCastExpression(CastExpression castExpression, int data) { // TODO: validate the cast operation, this unfortunateley needs a way to evalulate // the cast expressions type, which we still cant do properly with IC#.. // unlike c/c++ GLSL uses constructor syntax as float(intExpression) rather than // a cast like expression as (float)intExpression. var s = castExpression.Type.AcceptVisitor(this, data); return s.Append("(").Append(castExpression.Expression.AcceptVisitor(this, data)).Append(")"); }
public CastBlock(IEmitter emitter, CastExpression castExpression) : base(emitter, castExpression) { this.Emitter = emitter; this.CastExpression = castExpression; }
ISemantic E(CastExpression ce) { AbstractType castedType = null; if (ce.Type != null) { var castedTypes = TypeDeclarationResolver.Resolve(ce.Type, ctxt); ctxt.CheckForSingleResult(castedTypes, ce.Type); if (castedTypes != null && castedTypes.Length != 0) castedType = castedTypes[0]; } else { castedType = AbstractType.Get(E(ce.UnaryExpression)); if (castedType != null && ce.CastParamTokens != null && ce.CastParamTokens.Length > 0) { //TODO: Wrap resolved type with member function attributes } } return castedType; }
public ExplicitConversion_In_BinaryOperator_NavigatorImpl(CastExpression castExpression) { this.castExpression = castExpression; }
public override void VisitCastExpression(CastExpression castExpression) { ParenthesizeIfRequired(castExpression.Expression, InsertParenthesesForReadability ? Primary : Unary); // There's a nasty issue in the C# grammar: cast expressions including certain operators are ambiguous in some cases // "(int)-1" is fine, but "(A)-b" is not a cast. UnaryOperatorExpression uoe = castExpression.Expression as UnaryOperatorExpression; if (uoe != null && !(uoe.Operator == UnaryOperatorType.BitNot || uoe.Operator == UnaryOperatorType.Not)) { if (TypeCanBeMisinterpretedAsExpression(castExpression.Type)) { Parenthesize(castExpression.Expression); } } // The above issue can also happen with PrimitiveExpressions representing negative values: PrimitiveExpression pe = castExpression.Expression as PrimitiveExpression; if (pe != null && pe.Value != null && TypeCanBeMisinterpretedAsExpression(castExpression.Type)) { TypeCode typeCode = Type.GetTypeCode(pe.Value.GetType()); switch (typeCode) { case TypeCode.SByte: if ((sbyte)pe.Value < 0) Parenthesize(castExpression.Expression); break; case TypeCode.Int16: if ((short)pe.Value < 0) Parenthesize(castExpression.Expression); break; case TypeCode.Int32: if ((int)pe.Value < 0) Parenthesize(castExpression.Expression); break; case TypeCode.Int64: if ((long)pe.Value < 0) Parenthesize(castExpression.Expression); break; case TypeCode.Single: if ((float)pe.Value < 0) Parenthesize(castExpression.Expression); break; case TypeCode.Double: if ((double)pe.Value < 0) Parenthesize(castExpression.Expression); break; case TypeCode.Decimal: if ((decimal)pe.Value < 0) Parenthesize(castExpression.Expression); break; } } base.VisitCastExpression(castExpression); }
public override object VisitCastExpression(CastExpression castExpression, object data) { UnlockWith(castExpression); return base.VisitCastExpression(castExpression, data); }
public override StringBuilder VisitCastExpression(CastExpression castExpression, int data) { // TODO: implement throw new NotImplementedException(); }
public override object Visit(CastExpression castExpression, object data) { return new ReturnType(castExpression.CastTo.Type); }
public void VisitCastExpression(CastExpression castExpr) { castExpr.Target.AcceptWalker(this); castExpr.ToExpression.AcceptWalker(this); }
IExpression UnaryExpression(IBlockNode Scope = null) { // Note: PowExpressions are handled in PowExpression() if (laKind == (BitwiseAnd) || laKind == (Increment) || laKind == (Decrement) || laKind == (Times) || laKind == (Minus) || laKind == (Plus) || laKind == (Not) || laKind == (Tilde)) { Step(); SimpleUnaryExpression ae; switch (t.Kind) { case BitwiseAnd: ae = new UnaryExpression_And(); break; case Increment: ae = new UnaryExpression_Increment(); break; case Decrement: ae = new UnaryExpression_Decrement(); break; case Times: ae = new UnaryExpression_Mul(); break; case Minus: ae = new UnaryExpression_Sub(); break; case Plus: ae = new UnaryExpression_Add(); break; case Tilde: ae = new UnaryExpression_Cat(); break; case Not: ae = new UnaryExpression_Not(); break; default: SynErr(t.Kind, "Illegal token for unary expressions"); return null; } LastParsedObject = ae; ae.Location = t.Location; ae.UnaryExpression = UnaryExpression(Scope); return ae; } // CastExpression if (laKind == (Cast)) { Step(); var ae = new CastExpression { Location= t.Location }; if (Expect(OpenParenthesis)) { if (laKind != CloseParenthesis) // Yes, it is possible that a cast() can contain an empty type! ae.Type = Type(); Expect(CloseParenthesis); } ae.UnaryExpression = UnaryExpression(Scope); ae.EndLocation = t.EndLocation; return ae; } // DeleteExpression if (laKind == (Delete)) { Step(); return new DeleteExpression() { UnaryExpression = UnaryExpression(Scope) }; } // PowExpression var left = PostfixExpression(Scope); if (laKind != Pow) return left; Step(); var pe = new PowExpression(); pe.LeftOperand = left; pe.RightOperand = UnaryExpression(Scope); return pe; }
public void VisitCastExpression(CastExpression castExpression) { StartNode(castExpression); LPar(); Space(policy.SpacesWithinCastParentheses); castExpression.Type.AcceptVisitor(this); Space(policy.SpacesWithinCastParentheses); RPar(); Space(policy.SpaceAfterTypecast); castExpression.Expression.AcceptVisitor(this); EndNode(castExpression); }
public ISymbolValue Visit(CastExpression ce) { // TODO: Convert actual object return(null); }