Exemplo n.º 1
0
 public override void OnMethodInvocationExpression(MethodInvocationExpression node)
 {
     if (node.Arguments.Count > 0 && node.Arguments[0].NodeType == NodeType.MethodInvocationExpression)
     {
         var evalTargetInvocation = (MethodInvocationExpression)node.Arguments[0];
         if (evalTargetInvocation.Target.Entity == BuiltinFunction.InitValueType)
         {
             var typeBeingInitialized = ((ITypedEntity)evalTargetInvocation.Arguments[0].Entity).Type;
             var found = typeBeingInitialized.GetConstructors().FirstOrDefault();
             if (found != null) // Use any available ctor reference.
             {
                 ReplaceCurrentNode(CodeBuilder.CreateConstructorInvocation(LexicalInfo.Empty, found, evalTargetInvocation.Arguments.Skip(1).ToArray()));
             }
             else
             {
                 var replacement = new ReferenceExpression(typeBeingInitialized.Name)
                 {
                     Entity = typeBeingInitialized, ExpressionType = typeBeingInitialized.Type
                 };
                 replacement.Annotate("VALUE_TYPE_INITIALIZATON_MARKER");
                 ReplaceCurrentNode(replacement);
             }
         }
     }
     base.OnMethodInvocationExpression(node);
 }
Exemplo n.º 2
0
 public override void OnReferenceExpression(ReferenceExpression node)
 {
     if (AstUtil.IsStandaloneReference(node) && node.ParentNode.NodeType != NodeType.TypeofExpression && !AstUtil.IsTargetOfMethodInvocation(node))
     {
         Node node2 = new ReferenceFinder(_inferredUnit).Resolve(node) as Node;
         if (node2 != null)
         {
             if (node2.Entity is IType)
             {
                 node.Annotate(TypeInference.TypeLiteral);
             }
         }
     }
 }