Beispiel #1
0
        static Expression GetDeclarationExpression(this NewObjectNode non, Context ctx)
        {
            var typeName  = non.DataType.GetTypeName();
            var arguments = non.ConstructorArguments().GetExpressions(ctx);

            return(Instantiate(typeName, arguments, ctx, ctx.TryGetTagHash(non)));
        }
Beispiel #2
0
        public static IEnumerable <ValueSource> ConstructorArguments(this NewObjectNode self)
        {
            var args = self.DataType.Properties.Where(x => x.IsConstructorArgument);

            foreach (var arg in args)
            {
                var p = self.Properties.FirstOrDefault(a => a.Facet == arg);
                if (p is AtomicProperty)
                {
                    var ap = (AtomicProperty)p;
                    if (ap.Value != null)
                    {
                        yield return(new AtomicValueSource(ap.Value));
                    }
                }
                else if (p is ReferenceProperty)
                {
                    var rp = (ReferenceProperty)p;
                    if (rp.Source != null)
                    {
                        yield return(rp.Source);
                    }
                }
                else
                {
                    throw new Exception("Unhandled constructor argument type: " + p.GetType().FullName);
                }
            }
        }
Beispiel #3
0
 public bool ApplyBehaviour(List <ASTNode> nodes, int opIndex, OrderMethod caller)
 {
     if (this.m_isObj)
     {
         if (this.m_matchReqParenthesis)   // sizeof operator or something
         {
             throw new NotImplementedException();
         }
         else
         {
             nodes[opIndex] = new NewObjectNode((nodes[opIndex + 1] as IdentifierNode).ToTypeIdentifier(), nodes[opIndex + 2] as ExpressionNode, nodes[opIndex].Pos);
             nodes.RemoveRange(opIndex + 1, 2);
             return(true);
         }
     }
     else
     {
         var look = nodes[opIndex + 1] as LookupNode;
         nodes[opIndex] = new NewArrayNode(look.ToTypeIdentifier(), look.Index, nodes[opIndex].Pos);
         nodes.RemoveAt(opIndex + 1);
     }
     return(true);
 }
Beispiel #4
0
        /// <summary>
        /// new_object_line                             = type invoke_line_args
        /// </summary>
        private NewObjectNode parseNewObjectLine()
        {
            var type = attempt(parseType);
            if (type == null)
                return null;

            var args = parseInvokeLineArgs().ToList();
            if (args.Count == 0)
                return null;

            var node = new NewObjectNode();
            node.TypeSignature = type;
            node.Arguments = args;
            return node;
        }