/// <summary>
 /// Add a <see cref="LocalDecl"/>.
 /// </summary>
 public void Add(LocalDecl localDecl)
 {
     // Set the Type and Modifiers to those of the parent multi
     localDecl.Type      = (Type != null ? (Expression)Type.Clone() : null);
     localDecl.Modifiers = _modifiers;
     AddInternal(localDecl);
 }
Beispiel #2
0
 /// <summary>
 /// Create a <see cref="For"/> with the specified <see cref="CodeObject"/> in the body.
 /// </summary>
 public For(LocalDecl initialization, Expression conditional, Expression iteration)
 {
     Initialization = initialization;
     Conditional    = conditional;
     if (iteration != null)
     {
         Iterations.Add(iteration);
     }
 }
        protected void AddInternal(LocalDecl localDecl)
        {
            // Override the default newlines to 0 if it hasn't been explicitly set
            if (!localDecl.IsNewLinesSet)
            {
                localDecl.SetNewLines(0);
            }

            _localDecls.Add(localDecl);
        }
Beispiel #4
0
 /// <summary>
 /// Create a <see cref="For"/> with the specified <see cref="CodeObject"/> in the body.
 /// </summary>
 public For(LocalDecl initialization, Expression conditional, Expression iteration, CodeObject body)
     : base(body, true)
 {
     Initialization = initialization;
     Conditional    = conditional;
     if (iteration != null)
     {
         Iterations.Add(iteration);
     }
 }
        protected ForEach(Parser parser, CodeObject parent)
            : base(parser, parent)
        {
            parser.NextToken();                                          // Move past 'foreach'
            ParseExpectedToken(parser, Expression.ParseTokenStartGroup); // Move past '('
            SetField(ref _iteration, LocalDecl.Parse(parser, this, false, false), false);
            ParseExpectedToken(parser, ParseTokenIn);
            SetField(ref _collection, Expression.Parse(parser, this, true, Expression.ParseTokenEndGroup), false);
            ParseExpectedToken(parser, Expression.ParseTokenEndGroup); // Move past ')'

            new Block(out _body, parser, this, false);                 // Parse the body
        }
        /// <summary>
        /// Parse a <see cref="LocalDecl"/>.
        /// </summary>
        public static LocalDecl Parse(Parser parser, CodeObject parent, bool standAlone, bool allowInitAndMulti)
        {
            // Parse the first LocalDecl
            LocalDecl localDecl = new LocalDecl(parser, parent, standAlone, allowInitAndMulti, true, false);

            // Handle additional LocalDecls after any commas
            if (!localDecl.HasTerminator && allowInitAndMulti && parser.TokenText == Expression.ParseTokenSeparator)
            {
                // If it's a multi, create one, and transfer the IsFirstOnLine setting
                MultiLocalDecl multiLocalDecl = new MultiLocalDecl(localDecl)
                {
                    NewLines = localDecl.NewLines, HasTerminator = false
                };
                multiLocalDecl.SetLineCol(localDecl);
                localDecl.NewLines = 0;
                do
                {
                    Token commaToken = parser.Token;
                    parser.NextToken();  // Move past ','

                    // Associate any EOL comment on the ',' to the last LocalDecl
                    localDecl.MoveEOLComment(commaToken, false, false);

                    localDecl = new LocalDecl(parser, null, false, true, false, true);

                    // Force the expression to first-on-line if the last comma was (handles special-case
                    // formatting where the commas preceed the list items instead of following them).
                    if (commaToken.IsFirstOnLine)
                    {
                        localDecl.IsFirstOnLine = true;
                    }

                    // Move any comments after the ',' to the current LocalDecl
                    localDecl.MoveComments(commaToken);

                    multiLocalDecl.Add(localDecl);
                }while (parser.TokenText == Expression.ParseTokenSeparator);
                localDecl = multiLocalDecl;

                if (standAlone)
                {
                    multiLocalDecl.ParseTerminator(parser);
                }
            }

            return(localDecl);
        }
Beispiel #7
0
        protected For(Parser parser, CodeObject parent)
            : base(parser, parent)
        {
            parser.NextToken();  // Move past 'for'
            ParseExpectedToken(parser, Expression.ParseTokenStartGroup);

            // Parse either LocalDecl or Expression List
            if (LocalDecl.PeekLocalDecl(parser))
            {
                _initializations = LocalDecl.Parse(parser, this, false, true);
            }
            else
            {
                _initializations = Expression.ParseList(parser, this, Expression.ParseTokenEndGroup);
            }
            if (_initializations == null)
            {
                MoveAllComments(parser.LastToken, false, false, AnnotationFlags.IsInfix1);
            }
            ParseExpectedToken(parser, Terminator);  // Move past ';'

            SetField(ref _conditional, Expression.Parse(parser, this, true, Terminator + Expression.ParseTokenEndGroup), false);
            if (_conditional == null)
            {
                MoveAllComments(parser.LastToken, false, false, AnnotationFlags.IsInfix2);
            }
            ParseExpectedToken(parser, Terminator);  // Move past ';'

            _iterations = Expression.ParseList(parser, this, Expression.ParseTokenEndGroup);
            if (_iterations == null)
            {
                MoveAllComments(parser.LastToken, false, false, AnnotationFlags.IsInfix3);
            }

            ParseExpectedToken(parser, Expression.ParseTokenEndGroup);

            if (parser.TokenText == Terminator && !parser.Token.IsFirstOnLine)
            {
                ParseTerminator(parser);  // Handle same-line ';' (null body)
            }
            else
            {
                new Block(out _body, parser, this, false);  // Parse the body
            }
        }
        protected Using(Parser parser, CodeObject parent)
            : base(parser, parent)
        {
            parser.NextToken();                                          // Move past 'using'
            ParseExpectedToken(parser, Expression.ParseTokenStartGroup); // Move past '('

            // Parse either LocalDecl or Expression (object)
            if (LocalDecl.PeekLocalDecl(parser))
            {
                SetField(ref _target, LocalDecl.Parse(parser, this, false, true), false);
            }
            else
            {
                SetField(ref _target, Expression.Parse(parser, this, true, Expression.ParseTokenEndGroup), false);
            }

            ParseExpectedToken(parser, Expression.ParseTokenEndGroup); // Move past ')'

            new Block(out _body, parser, this, false);                 // Parse the body
        }
        /// <summary>
        /// Create a multi local variable declaration from an array of LocalDecls.
        /// </summary>
        /// <param name="localDecls">An array of LocalDecls.</param>
        public MultiLocalDecl(params LocalDecl[] localDecls)
            : base(null, null)
        {
            _localDecls = new ChildList <LocalDecl>(this);
            if (localDecls.Length > 0)
            {
                // Acquire the Parent, Type, and Modifiers from the first LocalDecl
                LocalDecl localDecl1 = localDecls[0];
                Parent            = localDecl1.Parent;
                localDecl1.Parent = null;  // Break parent link to avoid clone on Add
                SetField(ref _type, (Expression)localDecl1.Type.Clone(), true);
                _modifiers = localDecl1.Modifiers;

                // Add with internal method to avoid changes to Type, etc.
                foreach (LocalDecl localDecl in localDecls)
                {
                    AddInternal(localDecl);
                }
            }
        }
        protected Catch(Parser parser, CodeObject parent)
            : base(parser, parent)
        {
            MoveComments(parser.LastToken);  // Get any comments before 'catch'
            parser.NextToken();              // Move past 'catch'

            // Check for compiler directives, storing them as infix annotations on the parent
            Block.ParseCompilerDirectives(parser, this, AnnotationFlags.IsInfix1);

            // Check if 'catch' has parens
            if (parser.TokenText == Expression.ParseTokenStartGroup)
            {
                parser.NextToken();  // Move past '('

                // Parse either LocalDecl or Expression (TypeRef)
                if (LocalDecl.PeekLocalDecl(parser))
                {
                    SetField(ref _target, LocalDecl.Parse(parser, this, false, false), false);
                }
                else
                {
                    SetField(ref _target, Expression.Parse(parser, this, true, Expression.ParseTokenEndGroup), false);
                }

                ParseExpectedToken(parser, Expression.ParseTokenEndGroup);  // Move past ')'
            }

            new Block(out _body, parser, this, true);    // Parse the body
            ParseUnusedAnnotations(parser, this, true);  // Parse any annotations from the Unused list

            // Remove any preceeding blank lines if auto-cleanup is on
            if (AutomaticFormattingCleanup && NewLines > 1)
            {
                NewLines = 1;
            }
        }
 /// <summary>
 /// Create a <see cref="Using"/>.
 /// </summary>
 public Using(LocalDecl localDecl)
     : base(null, false)
 {
     Target = localDecl;
 }
 /// <summary>
 /// Create a <see cref="Using"/>.
 /// </summary>
 public Using(LocalDecl localDecl, CodeObject body)
     : base(body, false)
 {
     Target = localDecl;
 }
 /// <summary>
 /// Create a <see cref="Catch"/>.
 /// </summary>
 public Catch(LocalDecl localDecl)
     : base(null, false)
 {
     Target = localDecl;
 }
 /// <summary>
 /// Create a <see cref="ForEach"/>.
 /// </summary>
 public ForEach(LocalDecl iteration, Expression collection)
     : base(null, false)
 {
     Iteration  = iteration;
     Collection = collection;
 }
 /// <summary>
 /// Create a <see cref="ForEach"/>.
 /// </summary>
 public ForEach(LocalDecl iteration, Expression collection, CodeObject body)
     : base(body, false)
 {
     Iteration  = iteration;
     Collection = collection;
 }