Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the PreprocessorDirective class.
        /// </summary>
        /// <param name="proxy">Proxy object for the directive.</param>
        /// <param name="preprocessorType">The type of the preprocessor.</param>
        internal PreprocessorDirective(CodeUnitProxy proxy, PreprocessorType preprocessorType)
            : base(proxy, (int)preprocessorType)
        {
            Param.AssertNotNull(proxy, "proxy");
            Param.Ignore(preprocessorType);

            CsLanguageService.Debug.Assert(System.Enum.IsDefined(typeof(PreprocessorType), this.PreprocessorType), "The type is invalid.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the PreprocessorDirective class.
        /// </summary>
        /// <param name="proxy">Proxy object for the directive.</param>
        /// <param name="preprocessorType">The type of the preprocessor.</param>
        internal PreprocessorDirective(CodeUnitProxy proxy, PreprocessorType preprocessorType)
            : base(proxy, (int)preprocessorType)
        {
            Param.AssertNotNull(proxy, "proxy");
            Param.Ignore(preprocessorType);

            CsLanguageService.Debug.Assert(System.Enum.IsDefined(typeof(PreprocessorType), this.PreprocessorType), "The type is invalid.");
        }
 public void Clear()
 {
     preprocessor    = PreprocessorType.None;
     attributes      = null;
     values          = null;
     childrenDict    = null;
     childrenList    = null;
     isChildrenDirty = true;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the SimplePreprocessorDirective class.
        /// </summary>
        /// <param name="document">The parent document.</param>
        /// <param name="text">The preprocessor directive text.</param>
        /// <param name="preprocessorDirectiveType">The preprocessor directive type.</param>
        /// <param name="location">The location of the directive within the code document.</param>
        /// <param name="generated">True if the directive is inside of a block of generated code.</param>
        internal SimplePreprocessorDirective(CsDocument document, string text, PreprocessorType preprocessorDirectiveType, CodeLocation location, bool generated)
            : base(new CodeUnitProxy(document), preprocessorDirectiveType, location)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertValidString(text, "text");
            Param.Ignore(preprocessorDirectiveType);
            Param.AssertNotNull(location, "location");
            Param.Ignore(generated);

            this.Text      = text;
            this.Generated = generated;
        }
        /// <summary>
        /// Initializes a new instance of the SimplePreprocessorDirective class.
        /// </summary>
        /// <param name="document">The parent document.</param>
        /// <param name="text">The preprocessor directive text.</param>
        /// <param name="preprocessorDirectiveType">The preprocessor directive type.</param>
        /// <param name="location">The location of the directive within the code document.</param>
        /// <param name="generated">True if the directive is inside of a block of generated code.</param>
        internal SimplePreprocessorDirective(CsDocument document, string text, PreprocessorType preprocessorDirectiveType, CodeLocation location, bool generated)
            : base(new CodeUnitProxy(document), preprocessorDirectiveType, location)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertValidString(text, "text");
            Param.Ignore(preprocessorDirectiveType);
            Param.AssertNotNull(location, "location");
            Param.Ignore(generated);

            this.Text = text;
            this.Generated = generated;
        }
        /// <summary>
        /// Initializes a new instance of the ConditionalCompilationDirective class.
        /// </summary>
        /// <param name="text">The line text.</param>
        /// <param name="proxy">Proxy object for the directive.</param>
        /// <param name="type">The type of the directive.</param>
        /// <param name="body">The expression that makes up the body of the directive.</param>
        internal ConditionalCompilationDirective(
            string text, CodeUnitProxy proxy, PreprocessorType type, Expression body)
            : base(proxy, type)
        {
            Param.AssertValidString(text, "text");
            Param.Ignore(proxy);
            Param.Ignore(type);
            Param.Ignore(body);

            CsLanguageService.Debug.Assert(
                type == PreprocessorType.If ||
                type == PreprocessorType.Elif ||
                type == PreprocessorType.Else ||
                type == PreprocessorType.Endif,
                "The type must be one of the conditional compilation directive types.");

            this.Text = text;
            this.body.Value = body;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the ConditionalCompilationDirective class.
        /// </summary>
        /// <param name="text">The line text.</param>
        /// <param name="proxy">Proxy object for the directive.</param>
        /// <param name="type">The type of the directive.</param>
        /// <param name="body">The expression that makes up the body of the directive.</param>
        internal ConditionalCompilationDirective(
            string text, CodeUnitProxy proxy, PreprocessorType type, Expression body)
            : base(proxy, type)
        {
            Param.AssertValidString(text, "text");
            Param.Ignore(proxy);
            Param.Ignore(type);
            Param.Ignore(body);

            CsLanguageService.Debug.Assert(
                type == PreprocessorType.If ||
                type == PreprocessorType.Elif ||
                type == PreprocessorType.Else ||
                type == PreprocessorType.Endif,
                "The type must be one of the conditional compilation directive types.");

            this.Text       = text;
            this.body.Value = body;
        }
        public Table(Table table)
        {
            name            = table.name;
            parent          = table.parent;
            scope           = table.scope;
            preprocessor    = table.preprocessor;
            isChildrenDirty = table.isChildrenDirty;

            if (table.attributes != null && table.attributes.Count != 0)
            {
                attributes = new List <TableAttribute>();

                for (int i = 0; i < table.attributes.Count; i++)
                {
                    attributes.Add(new TableAttribute(table.attributes[i].name, table.attributes[i].value));
                }
            }

            if (table.values != null && table.values.Count != 0)
            {
                values = new List <object>();

                for (int i = 0; i < table.values.Count; i++)
                {
                    values.Add(table.values[i]);
                }
            }

            if (table.childrenCount != 0)
            {
                childrenDict = new Dictionary <string, Table>();
                childrenList = new List <Table>();

                for (int i = 0; i < table.childrenCount; i++)
                {
                    AppendChild(new Table(table[i]));
                }
            }
        }
 public PreprocessorDirective(PreprocessorType type, int line, int column, long position)
     : base(column, line, position)
 {
     this.type = type;
 }
 public Table(string name, PreprocessorType preprocessor)
 {
     this.name         = name;
     this.preprocessor = preprocessor;
 }
        //Parse
        private static bool Parse(ref TableInfo tableInfo)
        {
            source                  = tableInfo.content;
            curSourceIndex          = 0;
            curWord                 = null;
            curWordIndentationCount = 0;

            errorCount = 0;

            Table parent           = new Table();
            Table table            = parent;//Just in case the first loop has a bigger scope than 0
            int   scopeIndentation = 0;

            tableInfo.root = parent;

            while ((curWord = StringUtils.ReadNextWord(source, ref curSourceIndex, ref curWordIndentationCount)) != null)
            {
                if (curWord == "\n")
                {
                    continue;
                }

                if (curWordIndentationCount < scopeIndentation)
                {
                    if (parent.preprocessor == PreprocessorType.SortChildrenByValueAscending)
                    {
                        parent.SortChildrenByValueAscending();
                    }
                    else if (parent.preprocessor == PreprocessorType.SortChildrenByValueDescending)
                    {
                        parent.SortChildrenByValueDescending();
                    }

                    Table curTable = table;

                    while (scopeIndentation >= curWordIndentationCount)
                    {
                        parent   = curTable.parent;
                        curTable = parent;

                        scopeIndentation--;
                    }

                    scopeIndentation++;

                    if (scopeIndentation < 0)
                    {
                        scopeIndentation = 0;
                    }
                }
                else if (curWordIndentationCount > scopeIndentation)
                {
                    parent           = table;
                    scopeIndentation = curWordIndentationCount;
                }

                curWord = StringUtils.RemoveQuotes(curWord);

                PreprocessorType preprocessor = PreprocessorType.None;

                for (int i = 0; i < (int)PreprocessorType.Count; i++)
                {
                    if (curWord == PREPROCESSOR_SYMBOL[i])
                    {
                        preprocessor = (PreprocessorType)i;

                        break;
                    }
                }

                if (preprocessor != PreprocessorType.None)
                {
                    curWord = StringUtils.ReadNextWord(source, ref curSourceIndex, ref curWordIndentationCount);

                    if (string.IsNullOrEmpty(curWord) || curWord == "\n")
                    {
                        LogParseError("Invalid key.");

                        return(false);
                    }

                    curWord = StringUtils.RemoveQuotes(curWord);

                    if (preprocessor == PreprocessorType.LoadTemplate || preprocessor == PreprocessorType.LoadTemplateWithoutParent)
                    {
                        if (!templates.ContainsKey(curWord))
                        {
                            LogParseError("The template '" + curWord + "' does not exist.");

                            return(false);
                        }

                        if (preprocessor == PreprocessorType.LoadTemplate)
                        {
                            parent.AppendChild(new Table(templates[curWord]));
                        }
                        else if (preprocessor == PreprocessorType.LoadTemplateWithoutParent)
                        {
                            Table template = templates[curWord];

                            for (int i = 0; i < template.childrenCount; i++)
                            {
                                parent.AppendChild(new Table(template[i]));
                            }
                        }

                        continue;
                    }
                }

                table = new Table(curWord, preprocessor);

                if (parent.preprocessor == PreprocessorType.EnumerateChildren)
                {
                    table.name += parent.childrenCount;
                }
                else if (preprocessor == PreprocessorType.CreateTemplate)
                {
                    if (templates.ContainsKey(table.name))
                    {
                        LogParseError("The template '" + table.name + "' already exists.");

                        return(false);
                    }

                    templates.Add(table.name, table);
                }

                if (!parent.AppendChild(table))
                {
                    LogParseError("The table '" + parent.name + "' already contains a child with name '" + curWord + "'.");

                    return(false);
                }

                while ((curWord = StringUtils.ReadNextWord(source, ref curSourceIndex, ref curWordIndentationCount)) != null)
                {
                    if (curWord == "\n")
                    {
                        break;
                    }

                    //if(curWord == "-")
                    //{
                    //    curWord += StringUtils.ReadNextWord(source, ref curSourceIndex);
                    //}

                    if (curWord == "[")
                    {
                        while ((curWord = StringUtils.ReadNextWord(source, ref curSourceIndex)) != null)
                        {
                            if (curWord == "\n")
                            {
                                LogParseError("Broken attribute declaration.");

                                return(false);
                            }

                            if (curWord == "]")
                            {
                                break;
                            }

                            if (curWord == ",")
                            {
                                continue;
                            }

                            string attribute = StringUtils.RemoveQuotes(curWord);

                            curWord = StringUtils.ReadNextWord(source, ref curSourceIndex);

                            if (curWord != "=")
                            {
                                LogParseError("Missing '=' on attribute '" + attribute + "'.");

                                return(false);
                            }

                            curWord = StringUtils.ReadNextWord(source, ref curSourceIndex);

                            object value = ParseValue(curWord);

                            if (value == null)
                            {
                                LogParseError("Missing value for attribute '" + attribute + "'.");

                                return(false);
                            }

                            if (!table.AddAttribute(attribute, value))
                            {
                                LogParseError("The table '" + table.name + "' already contains a attribute with name '" + attribute + "'.");

                                return(false);
                            }
                        }
                    }
                    else
                    {
                        object value = ParseValue(curWord);

                        if (value == null)
                        {
                            break;
                        }

                        table.AddValue(value);
                    }
                }
            }

            tableInfo.content = null;

            return(true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the next conditional compilation directive from the code.
        /// </summary>
        /// <param name="preprocessorSymbol">The symbol representing the directive.</param>
        /// <param name="type">The type of the conditional compilation directive.</param>
        /// <param name="startIndex">The start index of the body of the directive.</param>
        /// <returns>Returns the directive.</returns>
        private ConditionalCompilationDirective GetConditionalCompilationDirective(Symbol preprocessorSymbol, PreprocessorType type, int startIndex)
        {
            Param.AssertNotNull(preprocessorSymbol, "preprocessorSymbol");
            Param.Ignore(type);
            Param.AssertGreaterThanOrEqualToZero(startIndex, "startIndex");

            Expression body = null;

            var directiveProxy = new CodeUnitProxy(this.document);

            // Extract the body of the directive if necessary.
            if (type != PreprocessorType.Endif && startIndex < preprocessorSymbol.Text.Length)
            {
                body = CodeParser.GetConditionalPreprocessorBodyExpression(
                    this.document, this.lexer.SourceCode, directiveProxy, this.languageService, this.preprocessorDefinitions, preprocessorSymbol, startIndex);
            }

            // Create and return the directive.
            switch (type)
            {
                case PreprocessorType.If:
                    return new IfDirective(preprocessorSymbol.Text, directiveProxy, body);
                case PreprocessorType.Elif:
                    return new ElifDirective(preprocessorSymbol.Text, directiveProxy, body);
                case PreprocessorType.Else:
                    return new ElseDirective(preprocessorSymbol.Text, directiveProxy, body);
                case PreprocessorType.Endif:
                    return new EndifDirective(preprocessorSymbol.Text, directiveProxy, body);
                default:
                    CsLanguageService.Debug.Fail("Not a conditional preprocessor type.");
                    return null;
            }
        }