Пример #1
0
        public static void AsTextPropertyInfo(CodeWriter writer, PropertyInfo propertyInfo, RenderFlags flags)
        {
            RenderFlags passFlags = flags & ~RenderFlags.Description;

            if (!flags.HasFlag(RenderFlags.NoPreAnnotations))
            {
                Attribute.AsTextAttributes(writer, propertyInfo);
            }
            writer.Write(ModifiersHelpers.AsString(GetPropertyModifiers(propertyInfo)));
            Type propertyType = propertyInfo.PropertyType;

            TypeRefBase.AsTextType(writer, propertyType, passFlags);
            writer.Write(" ");
            TypeRefBase.AsTextType(writer, propertyInfo.DeclaringType, passFlags);
            Dot.AsTextDot(writer);

            if (PropertyInfoUtil.IsIndexed(propertyInfo))
            {
                // Display the actual name instead of 'this' - it will usually be 'Item', but not always,
                // plus it might have a prefix (if it's an explicit interface implementation).
                writer.Write(propertyInfo.Name + IndexerDecl.ParseTokenStart);
                MethodRef.AsTextParameters(writer, propertyInfo.GetIndexParameters(), flags);
                writer.Write(IndexerDecl.ParseTokenEnd);
            }
            else
            {
                writer.Write(propertyInfo.Name);
            }
        }
 protected override void AsTextPrefix(CodeWriter writer, RenderFlags flags)
 {
     // If in Description mode, use NoEOLComments to determine if we're being rendered as part of a MultiLocalDecl or not
     if (!(_parent is MultiLocalDecl) || (flags.HasFlag(RenderFlags.Description) && !flags.HasFlag(RenderFlags.NoEOLComments)))
     {
         ModifiersHelpers.AsText(_modifiers, writer);
     }
 }
Пример #3
0
 /// <summary>
 /// This method is used when we must parse backwards through the Unused list to get a type.
 /// </summary>
 protected void ParseUnusedType(Parser parser, ref Expression type)
 {
     if (!ModifiersHelpers.IsModifier(parser.LastUnusedTokenText))
     {
         Expression expression = parser.RemoveLastUnusedExpression();
         MoveFormatting(expression);
         SetField(ref type, expression, false);
     }
 }
Пример #4
0
 /// <summary>
 /// Parse an <see cref="OperatorDecl"/>.
 /// </summary>
 public static new OperatorDecl Parse(Parser parser, CodeObject parent, ParseFlags flags)
 {
     // Handle conversion operators
     if (ModifiersHelpers.IsModifier(parser.LastUnusedTokenText))
     {
         return(new ConversionOperatorDecl(parser, parent, flags));
     }
     // Handle other operators
     return(new OperatorDecl(parser, parent, true, flags));
 }
 /// <summary>
 /// Parse a <see cref="ConversionOperatorDecl"/>.
 /// </summary>
 public ConversionOperatorDecl(Parser parser, CodeObject parent, ParseFlags flags)
     : base(parser, parent, false, flags)
 {
     parser.NextToken();                                 // Move past 'operator'
     _modifiers = ModifiersHelpers.Parse(parser, this);  // Parse any modifiers in reverse from the Unused list
     _name      = GetInternalName(_modifiers);           // Get the name
     ParseUnusedAnnotations(parser, this, false);        // Parse attributes and/or doc comments from the Unused list
     SetField(ref _returnType, Expression.Parse(parser, this, true, Expression.ParseTokenStartGroup), false);
     ParseParameters(parser);
     ParseTerminatorOrBody(parser, flags);
 }
        /// <summary>
        /// Parse a <see cref="LocalDecl"/>.
        /// </summary>
        public LocalDecl(Parser parser, CodeObject parent, bool standAlone, bool allowInit, bool hasType, bool isMulti)
            : base(parser, parent)
        {
            if (isMulti)
            {
                ParseName(parser, parent);  // Parse the name
                if (allowInit)
                {
                    ParseInitialization(parser, parent);  // Parse the initialization (if any)
                }
            }
            else
            {
                if (standAlone)
                {
                    // Parse the name from the Unused list
                    Token token = parser.RemoveLastUnusedToken();
                    _name = token.NonVerbatimText;
                    MoveLocationAndComment(token);

                    ParseUnusedType(parser, ref _type);  // Parse the type from the Unused list

                    // Parse any modifiers in reverse from the Unused list.
                    // NOTE: Only 'const' is valid for LocalDecls.
                    _modifiers = ModifiersHelpers.Parse(parser, this);

                    if (allowInit)
                    {
                        ParseInitialization(parser, parent);  // Parse the initialization (if any)
                    }
                }
                else
                {
                    if (hasType)
                    {
                        ParseType(parser);     // Parse the type
                    }
                    ParseName(parser, parent); // Parse the name
                    if (allowInit)
                    {
                        ParseInitialization(parser, parent);  // Parse the initialization (if any)
                    }
                }

                if (standAlone && parser.TokenText != Expression.ParseTokenSeparator)
                {
                    ParseTerminator(parser);
                }
            }
        }
        public static void AsTextEventInfo(CodeWriter writer, EventInfo eventInfo, RenderFlags flags)
        {
            RenderFlags passFlags = flags & ~RenderFlags.Description;

            if (!flags.HasFlag(RenderFlags.NoPreAnnotations))
            {
                Attribute.AsTextAttributes(writer, eventInfo);
            }
            writer.Write(ModifiersHelpers.AsString(GetEventModifiers(eventInfo)));
            TypeRefBase.AsTextType(writer, eventInfo.EventHandlerType, passFlags);
            writer.Write(" ");
            TypeRefBase.AsTextType(writer, eventInfo.DeclaringType, passFlags);
            writer.Write(Dot.ParseToken + eventInfo.Name);
        }
Пример #8
0
 /// <summary>
 /// Parse a <see cref="PropertyDecl"/> or <see cref="EventDecl"/>.
 /// </summary>
 public static PropertyDeclBase Parse(Parser parser, CodeObject parent, ParseFlags flags)
 {
     // If our parent is a TypeDecl, verify that we have an unused Expression (it can be either an
     // identifier or a Dot operator for explicit interface implementations).  Otherwise, require a
     // possible type in addition to the Expression.
     // If it doesn't seem to match the proper pattern, abort so that other types can try parsing it.
     if ((parent is TypeDecl && parser.HasUnusedExpression) || parser.HasUnusedTypeRefAndExpression)
     {
         // If we have an unused 'event' modifier, it's an event, otherwise treat it as a property
         string eventModifier = ModifiersHelpers.AsString(Modifiers.Event).Trim();
         bool   isEvent       = (Enumerable.Any(parser.Unused, delegate(ParsedObject parsedObject) { return(parsedObject is Token && ((Token)parsedObject).Text == eventModifier); }));
         return(isEvent ? (PropertyDeclBase) new EventDecl(parser, parent) : new PropertyDecl(parser, parent));
     }
     return(null);
 }
        public static void AsTextConstructorInfo(CodeWriter writer, ConstructorInfo constructorInfo, RenderFlags flags)
        {
            RenderFlags passFlags = flags & ~RenderFlags.Description;

            if (!flags.HasFlag(RenderFlags.NoPreAnnotations))
            {
                Attribute.AsTextAttributes(writer, constructorInfo);
            }
            writer.Write(ModifiersHelpers.AsString(GetMethodModifiers(constructorInfo)));
            Type declaringType = constructorInfo.DeclaringType;

            AsTextType(writer, declaringType, passFlags);
            Dot.AsTextDot(writer);
            if (declaringType != null)
            {
                writer.WriteName(declaringType.IsGenericType ? TypeUtil.NonGenericName(declaringType) : declaringType.Name, passFlags);
            }
            AsTextMethodParameters(writer, constructorInfo, flags);
        }
Пример #10
0
        public static void AsTextFieldInfo(CodeWriter writer, FieldInfo fieldInfo, RenderFlags flags)
        {
            RenderFlags passFlags = flags & ~RenderFlags.Description;

            // Skip all details for enum members, including the declaring type since it will always be on the left of the dot
            if (!(fieldInfo.IsLiteral && fieldInfo.FieldType.IsEnum))
            {
                if (!flags.HasFlag(RenderFlags.NoPreAnnotations))
                {
                    Attribute.AsTextAttributes(writer, fieldInfo);
                }
                writer.Write(ModifiersHelpers.AsString(GetFieldModifiers(fieldInfo)));
                Type fieldType = fieldInfo.FieldType;
                TypeRefBase.AsTextType(writer, fieldType, passFlags);
                writer.Write(" ");
                TypeRefBase.AsTextType(writer, fieldInfo.DeclaringType, passFlags);
                Dot.AsTextDot(writer);
            }
            writer.Write(fieldInfo.Name);
        }
        protected FieldDecl(Parser parser, CodeObject parent, bool isMulti)
            : base(parser, parent)
        {
            // Ignore for derived types (FixedSizeBufferDecl)
            if (GetType() != typeof(FieldDecl))
            {
                return;
            }

            if (isMulti)
            {
                // Parse the name
                _name = parser.GetIdentifierText();
                MoveLocationAndComment(parser.LastToken);

                ParseInitialization(parser, parent);  // Parse the initialization (if any)
            }
            else
            {
                // Parse the name from the Unused list
                Token token = parser.RemoveLastUnusedToken();
                _name = token.NonVerbatimText;
                MoveLocationAndComment(token);

                ParseUnusedType(parser, ref _type);                // Parse the type from the Unused list
                _modifiers = ModifiersHelpers.Parse(parser, this); // Parse any modifiers in reverse from the Unused list
                ParseUnusedAnnotations(parser, this, false);       // Parse attributes and/or doc comments from the Unused list

                ParseInitialization(parser, parent);               // Parse the initialization (if any)
                if (parser.TokenText != Expression.ParseTokenSeparator)
                {
                    ParseTerminator(parser);
                }

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

                // Force field decls to always start on a new line
                IsFirstOnLine = true;
            }
        }
 protected override void AsTextPrefix(CodeWriter writer, RenderFlags flags)
 {
     ModifiersHelpers.AsText(_modifiers, writer);
 }
 protected void ParseModifiersAndAnnotations(Parser parser)
 {
     _modifiers = ModifiersHelpers.Parse(parser, this);  // Parse any modifiers in reverse from the Unused list
     ParseUnusedAnnotations(parser, this, false);        // Parse attributes and/or doc comments from the Unused list
 }