示例#1
0
        public static TNode WithAdditionalAnnotationsGreen <TNode>(this TNode node, IEnumerable <SyntaxAnnotation> annotations) where TNode : GreenNode
        {
            SyntaxAnnotation[] existingAnnotations = node.GetAnnotations();

            if (annotations == null)
            {
                return(node);
            }

            ArrayBuilder <SyntaxAnnotation> newAnnotations = ArrayBuilder <SyntaxAnnotation> .GetInstance();

            newAnnotations.AddRange(existingAnnotations);

            foreach (SyntaxAnnotation candidate in annotations)
            {
                if (!newAnnotations.Contains(candidate))
                {
                    newAnnotations.Add(candidate);
                }
            }

            if (newAnnotations.Count == existingAnnotations.Length)
            {
                newAnnotations.Free();
                return(node);
            }
            else
            {
                return((TNode)node.SetAnnotations(newAnnotations.ToArrayAndFree()));
            }
        }
示例#2
0
        internal object GetValidTargetsErrorArgument()
        {
            int validTargetsInt = (int)ValidTargets;

            if (!HasValidAttributeTargets)
            {
                return(string.Empty);
            }

            ArrayBuilder <string> builder = ArrayBuilder <string> .GetInstance();

            int flag = 0;

            while (validTargetsInt > 0)
            {
                if ((validTargetsInt & 1) != 0)
                {
                    builder.Add(GetErrorDisplayNameResourceId((AttributeTargets)(1 << flag)));
                }

                validTargetsInt >>= 1;
                flag++;
            }

            return(new ValidTargetsStringLocalizableErrorArgument(builder.ToArrayAndFree()));
        }
            private AssemblyQualifiedTypeName[] DecodeTypeArguments()
            {
                if (EndOfInput)
                {
                    return(null);
                }

                ArrayBuilder <AssemblyQualifiedTypeName> typeBuilder = ArrayBuilder <AssemblyQualifiedTypeName> .GetInstance();

                while (!EndOfInput)
                {
                    typeBuilder.Add(DecodeTypeArgument());

                    if (!EndOfInput)
                    {
                        switch (Current)
                        {
                        case ',':
                            // More type arguments follow
                            Advance();
                            if (!EndOfInput && Char.IsWhiteSpace(Current))
                            {
                                Advance();
                            }
                            break;

                        case ']':
                            // End of type arguments
                            Advance();
                            return(typeBuilder.ToArrayAndFree());

                        default:
                            throw ExceptionUtilities.UnexpectedValue(EndOfInput);
                        }
                    }
                }

                return(typeBuilder.ToArrayAndFree());
            }
示例#4
0
        public static TNode WithoutAnnotationsGreen <TNode>(this TNode node, IEnumerable <SyntaxAnnotation> annotations) where TNode : GreenNode
        {
            SyntaxAnnotation[] existingAnnotations = node.GetAnnotations();

            if (annotations == null || existingAnnotations.Length == 0)
            {
                return(node);
            }

            ArrayBuilder <SyntaxAnnotation> removalAnnotations = ArrayBuilder <SyntaxAnnotation> .GetInstance();

            removalAnnotations.AddRange(annotations);
            try
            {
                if (removalAnnotations.Count == 0)
                {
                    return(node);
                }

                ArrayBuilder <SyntaxAnnotation> newAnnotations = ArrayBuilder <SyntaxAnnotation> .GetInstance();

                foreach (SyntaxAnnotation candidate in existingAnnotations)
                {
                    if (!removalAnnotations.Contains(candidate))
                    {
                        newAnnotations.Add(candidate);
                    }
                }

                return((TNode)node.SetAnnotations(newAnnotations.ToArrayAndFree()));
            }
            finally
            {
                removalAnnotations.Free();
            }
        }
        private LocalizableResourceString(ObjectReader reader)
        {
            _resourceSource            = reader.ReadType();
            _nameOfLocalizableResource = reader.ReadString();
            _resourceManager           = new ResourceManager(_resourceSource);

            int length = reader.ReadInt32();

            if (length == 0)
            {
                _formatArguments = Array.Empty <string>();
            }
            else
            {
                ArrayBuilder <string> argumentsBuilder = ArrayBuilder <string> .GetInstance(length);

                for (int i = 0; i < length; i++)
                {
                    argumentsBuilder.Add(reader.ReadString());
                }

                _formatArguments = argumentsBuilder.ToArrayAndFree();
            }
        }
示例#6
0
            /// <summary>
            /// Decodes a type name.  A type name is a string which is terminated by the end of the string or one of the
            /// delimiters '+', ',', '[', ']'. '+' separates nested classes. '[' and ']'
            /// enclosed generic type arguments.  ',' separates types.
            /// </summary>
            internal AssemblyQualifiedTypeName DecodeTypeName(bool isTypeArgument = false, bool isTypeArgumentWithAssemblyName = false)
            {
                Debug.Assert(!isTypeArgumentWithAssemblyName || isTypeArgument);

                string topLevelType = null;
                ArrayBuilder <string> nestedTypesBuilder = null;

                AssemblyQualifiedTypeName[] typeArguments = null;
                int pointerCount = 0;
                ArrayBuilder <int> arrayRanksBuilder = null;
                string             assemblyName      = null;
                bool decodingTopLevelType            = true;
                bool isGenericTypeName = false;

                var           pooledStrBuilder = PooledStringBuilder.GetInstance();
                StringBuilder typeNameBuilder  = pooledStrBuilder.Builder;

                while (!EndOfInput)
                {
                    int i = _input.IndexOfAny(s_typeNameDelimiters, _offset);
                    if (i >= 0)
                    {
                        char c = _input[i];

                        // Found name, which could be a generic name with arity.
                        // Generic type parameter count, if any, are handled in DecodeGenericName.
                        string decodedString = DecodeGenericName(i);
                        Debug.Assert(decodedString != null);

                        // Type name is generic if the decoded name of the top level type OR any of the outer types of a nested type had the '`' character.
                        isGenericTypeName = isGenericTypeName || decodedString.IndexOf(GenericTypeNameManglingChar) >= 0;
                        typeNameBuilder.Append(decodedString);

                        switch (c)
                        {
                        case '*':
                            if (arrayRanksBuilder != null)
                            {
                                // Error case, array shape must be specified at the end of the type name.
                                // Process as a regular character and continue.
                                typeNameBuilder.Append(c);
                            }
                            else
                            {
                                pointerCount++;
                            }

                            Advance();
                            break;

                        case '+':
                            if (arrayRanksBuilder != null || pointerCount > 0)
                            {
                                // Error case, array shape must be specified at the end of the type name.
                                // Process as a regular character and continue.
                                typeNameBuilder.Append(c);
                            }
                            else
                            {
                                // Type followed by nested type. Handle nested class separator and collect the nested types.
                                HandleDecodedTypeName(typeNameBuilder.ToString(), decodingTopLevelType, ref topLevelType, ref nestedTypesBuilder);
                                typeNameBuilder.Clear();
                                decodingTopLevelType = false;
                            }

                            Advance();
                            break;

                        case '[':
                            // Is type followed by generic type arguments?
                            if (isGenericTypeName && typeArguments == null)
                            {
                                Advance();
                                if (arrayRanksBuilder != null || pointerCount > 0)
                                {
                                    // Error case, array shape must be specified at the end of the type name.
                                    // Process as a regular character and continue.
                                    typeNameBuilder.Append(c);
                                }
                                else
                                {
                                    // Decode type arguments.
                                    typeArguments = DecodeTypeArguments();
                                }
                            }
                            else
                            {
                                // Decode array shape.
                                DecodeArrayShape(typeNameBuilder, ref arrayRanksBuilder);
                            }

                            break;

                        case ']':
                            if (isTypeArgument)
                            {
                                // End of type arguments.  This occurs when the last type argument is a type in the
                                // current assembly.
                                goto ExitDecodeTypeName;
                            }
                            else
                            {
                                // Error case, process as a regular character and continue.
                                typeNameBuilder.Append(c);
                                Advance();
                                break;
                            }

                        case ',':
                            // A comma may separate a type name from its assembly name or a type argument from
                            // another type argument.
                            // If processing non-type argument or a type argument with assembly name,
                            // process the characters after the comma as an assembly name.
                            if (!isTypeArgument || isTypeArgumentWithAssemblyName)
                            {
                                Advance();
                                if (!EndOfInput && Char.IsWhiteSpace(Current))
                                {
                                    Advance();
                                }

                                assemblyName = DecodeAssemblyName(isTypeArgumentWithAssemblyName);
                            }
                            goto ExitDecodeTypeName;

                        default:
                            throw ExceptionUtilities.UnexpectedValue(c);
                        }
                    }
                    else
                    {
                        typeNameBuilder.Append(DecodeGenericName(_input.Length));
                        goto ExitDecodeTypeName;
                    }
                }

ExitDecodeTypeName:
                HandleDecodedTypeName(typeNameBuilder.ToString(), decodingTopLevelType, ref topLevelType, ref nestedTypesBuilder);
                pooledStrBuilder.Free();

                return(new AssemblyQualifiedTypeName(
                           topLevelType,
                           nestedTypesBuilder?.ToArrayAndFree(),
                           typeArguments,
                           pointerCount,
                           arrayRanksBuilder?.ToArrayAndFree(),
                           assemblyName));
            }