Beispiel #1
0
        CSNode VisitSelectors(CSScriptParser.SelectorContext[] selectors, int line, int col)
        {
            int selectorLen = selectors.Length;

            string firstName = selectors[0].NAME().GetText();

            if (_state.HasVariable(firstName))
            {
                CSLocalVariableNode node = new CSLocalVariableNode(line, col);
                node._declaration  = false;
                node._variableName = firstName;
                if (selectorLen == 1)
                {
                    return(node);
                }
                else
                {
                    CSSelectorNode selectorNode = new CSSelectorNode(line, col);
                    selectorNode._selectors = GetSelectorStrings(selectors, 1);
                    CSOPDotNode dotNode = new CSOPDotNode(line, col);
                    dotNode._children    = new CSNode[2];
                    dotNode._children[0] = node;
                    dotNode._children[1] = selectorNode;
                    return(dotNode);
                }
            }

            string currentTypeString = null;

            System.Type currentType = null;
            int         typeStart   = -1;
            int         typeEnd     = 0;

            for (int i = 0; i < selectorLen; ++i)
            {
                CSScriptParser.SelectorContext next = selectors[i];
                string name = next.NAME().GetText();
                currentTypeString = GetTypeString(selectors, i + 1, typeStart);
                System.Type nextType = ReflectionUtil.GetType(currentTypeString);

                if (typeStart == -1 && nextType != null)
                {
                    typeStart = i;
                }

                if (currentType != null && nextType == null)
                {
                    typeEnd = i;
                    break;
                }
                currentType = nextType;
            }

            if (currentType != null)
            {
                if (typeEnd == 0)
                {
                    CSTypeNode node = new CSTypeNode(line, col);
                    node._typeString   = currentTypeString;
                    node._type         = currentType;
                    node._assemblyName = currentType.Assembly.GetCleanName();
                    return(node);
                }
                else
                {
                    CSStaticVariableNode node = new CSStaticVariableNode(line, col);
                    string varName            = selectors[typeEnd].NAME().GetText();
                    node._variableName = varName;
                    node._staticType   = currentType;
                    node._type         = ReflectionUtil.GetFieldType(currentType, varName);

                    if (node._type == null)
                    {
                        CSLog.E(node, "type: " + currentType.FullName + " doesn't have: " + varName);
                    }

                    if (selectorLen == typeEnd + 1)
                    {
                        return(node);
                    }
                    else
                    {
                        CSSelectorNode selectorNode = new CSSelectorNode(line, col);
                        selectorNode._selectors = GetSelectorStrings(selectors, typeEnd + 1);
                        CSOPDotNode dotNode = new CSOPDotNode(line, col);
                        dotNode._children    = new CSNode[2];
                        dotNode._children[0] = node;
                        dotNode._children[1] = selectorNode;
                        return(dotNode);
                    }
                }
            }
            else
            {
                CSSelectorNode node = new CSSelectorNode(line, col);
                node._selectors = GetSelectorStrings(selectors, 0);
                return(node);
            }
        }
 /// <summary>
 /// Visit a parse tree produced by <see cref="CSScriptParser.selector"/>.
 /// <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 VisitSelector([NotNull] CSScriptParser.SelectorContext context)
 {
     return(VisitChildren(context));
 }