コード例 #1
0
        public override CSNode VisitNewExp(CSScriptParser.NewExpContext context)
        {
            CSOPNewNode node = new CSOPNewNode(context.Start.Line, context.Start.Column);

            node._children = new CSNode[6];

            CSScriptParser.ParametersContext  parameters = context.parameters();
            CSScriptParser.Array_indexContext arrayIndex = context.array_index();

            System.Type currentType;
            string      currentTypeString = VisitTypeElements(context.type_elements(), out currentType);

            if (arrayIndex != null)
            {
                currentTypeString = currentTypeString + "[]";
                currentType       = ReflectionUtil.GetType(currentTypeString);
            }

            if (currentType == null)
            {
                CSLog.E(node, "unknown type: " + currentTypeString);
                return(null);
            }

            CSTypeNode typeNode = new CSTypeNode(context.Start.Line, context.Start.Column);

            typeNode._type         = currentType;
            typeNode._typeString   = currentTypeString;
            typeNode._assemblyName = currentType.Assembly.GetCleanName();

            node._children[0] = typeNode;

            if (parameters != null)
            {
                node._children[1] = Visit(parameters);
            }

            if (arrayIndex != null)
            {
                node._children[2] = Visit(arrayIndex);
            }

            CSScriptParser.InitializerContext initializer = context.initializer();
            if (initializer != null)
            {
                CSScriptParser.Array_initializerContext arrayInitializer = initializer.array_initializer();
                if (arrayInitializer != null)
                {
                    node._children[3] = Visit(arrayInitializer);
                }

                CSScriptParser.Dictionary_initializerContext dictionaryInitializer = initializer.dictionary_initializer();
                if (dictionaryInitializer != null)
                {
                    node._children[4] = Visit(dictionaryInitializer);
                }

                CSScriptParser.Class_initializerContext classInitializer = initializer.class_initializer();
                if (classInitializer != null)
                {
                    node._children[5] = Visit(classInitializer);
                }
            }
            return(node);
        }
コード例 #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="CSScriptParser.newExp"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitNewExp([NotNull] CSScriptParser.NewExpContext context)
 {
     return(VisitChildren(context));
 }