Exemplo n.º 1
0
        private string GetVariablePrototype(
            EnumMemberDeclarationSyntax node,
            IFieldSymbol symbol,
            PrototypeFlags flags
            )
        {
            if ((flags & PrototypeFlags.Signature) != 0)
            {
                if (flags != PrototypeFlags.Signature)
                {
                    // vsCMPrototypeUniqueSignature can't be combined with anything else.
                    throw Exceptions.ThrowEInvalidArg();
                }

                // The unique signature is simply the node key.
                return(GetNodeKey(node).Name);
            }

            var builder = new StringBuilder();

            AppendVariablePrototype(builder, symbol, flags, GetName(node));

            if (
                (flags & PrototypeFlags.Initializer) != 0 &&
                node.EqualsValue != null &&
                node.EqualsValue.Value != null &&
                !node.EqualsValue.Value.IsMissing
                )
            {
                builder.Append(" = ");
                builder.Append(node.EqualsValue.Value);
            }

            return(builder.ToString());
        }
        private void AppendParameterPrototype(StringBuilder builder, PrototypeFlags flags, IParameterSymbol parameter)
        {
            var addSpace = false;

            if ((flags & PrototypeFlags.ParameterTypes) != 0)
            {
                if (parameter.RefKind == RefKind.Ref)
                {
                    builder.Append("ref ");
                }
                else if (parameter.RefKind == RefKind.Out)
                {
                    builder.Append("out ");
                }
                else if (parameter.IsParams)
                {
                    builder.Append("params ");
                }

                builder.Append(GetAsStringForCodeTypeRef(parameter.Type));
                addSpace = true;
            }

            if ((flags & PrototypeFlags.ParameterNames) != 0)
            {
                if (addSpace)
                {
                    builder.Append(' ');
                }

                builder.Append(parameter.Name);
            }
        }
        public override string GetPrototype(SyntaxNode node, ISymbol symbol, PrototypeFlags flags)
        {
            Debug.Assert(symbol != null);

            if (node == null)
            {
                switch (symbol.Kind)
                {
                case SymbolKind.Field:
                    return(GetVariablePrototype((IFieldSymbol)symbol, flags));

                case SymbolKind.Method:
                    return(GetFunctionPrototype((IMethodSymbol)symbol, flags));

                case SymbolKind.Property:
                    return(GetPropertyPrototype((IPropertySymbol)symbol, flags));

                case SymbolKind.Event:
                    return(GetEventPrototype((IEventSymbol)symbol, flags));

                case SymbolKind.NamedType:
                    var namedType = (INamedTypeSymbol)symbol;
                    if (namedType.TypeKind == TypeKind.Delegate)
                    {
                        return(GetDelegatePrototype((INamedTypeSymbol)symbol, flags));
                    }

                    break;
                }

                Debug.Fail("Invalid symbol kind: " + symbol.Kind);
                throw Exceptions.ThrowEUnexpected();
            }
            else
            {
                switch (node)
                {
                case BaseMethodDeclarationSyntax methodDeclaration:
                    return(GetFunctionPrototype(methodDeclaration, (IMethodSymbol)symbol, flags));

                case BasePropertyDeclarationSyntax propertyDeclaration:
                    return(GetPropertyPrototype(propertyDeclaration, (IPropertySymbol)symbol, flags));

                case VariableDeclaratorSyntax variableDeclarator when symbol.Kind == SymbolKind.Field:
                    return(GetVariablePrototype(variableDeclarator, (IFieldSymbol)symbol, flags));

                case EnumMemberDeclarationSyntax enumMember:
                    return(GetVariablePrototype(enumMember, (IFieldSymbol)symbol, flags));

                case DelegateDeclarationSyntax delegateDeclaration:
                    return(GetDelegatePrototype(delegateDeclaration, (INamedTypeSymbol)symbol, flags));
                }

                // Crazily, events for source are not implemented by the legacy C#
                // code model implementation, but they are for metadata events.

                Debug.Fail(string.Format("Invalid node/symbol kind: {0}/{1}", node.Kind(), symbol.Kind));
                throw Exceptions.ThrowENotImpl();
            }
        }
Exemplo n.º 4
0
        private void AppendPropertyPrototype(
            StringBuilder builder,
            IPropertySymbol symbol,
            PrototypeFlags flags,
            string baseName
            )
        {
            if ((flags & PrototypeFlags.Type) != 0)
            {
                builder.Append(GetAsStringForCodeTypeRef(symbol.Type));

                if ((flags & PrototypeFlags.NameMask) != PrototypeFlags.NoName)
                {
                    builder.Append(' ');
                }
            }

            switch (flags & PrototypeFlags.NameMask)
            {
            case PrototypeFlags.FullName:
                AppendTypeNamePrototype(
                    builder,
                    includeNamespaces: true,
                    includeGenerics: false,
                    symbol: symbol.ContainingSymbol
                    );
                builder.Append('.');
                goto case PrototypeFlags.BaseName;

            case PrototypeFlags.TypeName:
                AppendTypeNamePrototype(
                    builder,
                    includeNamespaces: false,
                    includeGenerics: true,
                    symbol: symbol.ContainingSymbol
                    );
                builder.Append('.');
                goto case PrototypeFlags.BaseName;

            case PrototypeFlags.BaseName:
                if (symbol.IsIndexer)
                {
                    builder.Append("this[");
                    AppendParametersPrototype(
                        builder,
                        symbol.Parameters,
                        PrototypeFlags.ParameterTypes | PrototypeFlags.ParameterNames
                        );
                    builder.Append("]");
                }
                else
                {
                    builder.Append(baseName);
                }
                break;
            }
        }
Exemplo n.º 5
0
        private void AppendVariablePrototype(
            StringBuilder builder,
            IFieldSymbol symbol,
            PrototypeFlags flags,
            string baseName
            )
        {
            if ((flags & PrototypeFlags.Type) != 0)
            {
                builder.Append(GetAsStringForCodeTypeRef(symbol.Type));

                if ((flags & PrototypeFlags.NameMask) != PrototypeFlags.NoName)
                {
                    builder.Append(' ');
                }
            }

            switch (flags & PrototypeFlags.NameMask)
            {
            case PrototypeFlags.FullName:
                AppendTypeNamePrototype(
                    builder,
                    includeNamespaces: true,
                    includeGenerics: false,
                    symbol: symbol.ContainingSymbol
                    );
                builder.Append('.');
                goto case PrototypeFlags.BaseName;

            case PrototypeFlags.TypeName:
                AppendTypeNamePrototype(
                    builder,
                    includeNamespaces: false,
                    includeGenerics: true,
                    symbol: symbol.ContainingSymbol
                    );
                builder.Append('.');
                goto case PrototypeFlags.BaseName;

            case PrototypeFlags.BaseName:
                builder.Append(baseName);
                break;
            }
        }
Exemplo n.º 6
0
        private string GetVariablePrototype(IFieldSymbol symbol, PrototypeFlags flags)
        {
            if ((flags & PrototypeFlags.Signature) != 0)
            {
                if (flags != PrototypeFlags.Signature)
                {
                    // vsCMPrototypeUniqueSignature can't be combined with anything else.
                    throw Exceptions.ThrowEInvalidArg();
                }

                // The unique signature is simply the node key.
                flags = PrototypeFlags.FullName | PrototypeFlags.Type;
            }

            var builder = new StringBuilder();

            AppendVariablePrototype(builder, symbol, flags, symbol.Name);

            return(builder.ToString());
        }
Exemplo n.º 7
0
        private void AppendParametersPrototype(
            StringBuilder builder,
            ImmutableArray <IParameterSymbol> parameters,
            PrototypeFlags flags
            )
        {
            var first = true;

            foreach (var parameter in parameters)
            {
                if (!first)
                {
                    builder.Append(", ");
                }

                AppendParameterPrototype(builder, flags, parameter);

                first = false;
            }
        }
Exemplo n.º 8
0
        private string GetDelegatePrototype(INamedTypeSymbol symbol, PrototypeFlags flags)
        {
            if ((flags & PrototypeFlags.Signature) != 0)
            {
                if (flags != PrototypeFlags.Signature)
                {
                    // vsCMPrototypeUniqueSignature can't be combined with anything else.
                    // Note that we only throw E_FAIL in this case. All others throw E_INVALIDARG.
                    throw Exceptions.ThrowEFail();
                }

                // The unique signature is simply the node key.
                return(GetExternalSymbolFullName(symbol));
            }

            var builder = new StringBuilder();

            AppendDelegatePrototype(builder, symbol, flags, symbol.Name);

            return(builder.ToString());
        }
        private string GetDelegatePrototype(INamedTypeSymbol symbol, PrototypeFlags flags)
        {
            if ((flags & PrototypeFlags.Signature) != 0)
            {
                if (flags != PrototypeFlags.Signature)
                {
                    // vsCMPrototypeUniqueSignature can't be combined with anything else.
                    // Note that we only throw E_FAIL in this case. All others throw E_INVALIDARG.
                    throw Exceptions.ThrowEFail();
                }

                // The unique signature is simply the node key.
                return GetExternalSymbolFullName(symbol);
            }

            var builder = new StringBuilder();

            AppendDelegatePrototype(builder, symbol, flags, symbol.Name);

            return builder.ToString();
        }
Exemplo n.º 10
0
        private string GetPropertyPrototype(
            BasePropertyDeclarationSyntax node,
            IPropertySymbol symbol,
            PrototypeFlags flags
            )
        {
            if ((flags & PrototypeFlags.Signature) != 0)
            {
                if (flags != PrototypeFlags.Signature)
                {
                    // vsCMPrototypeUniqueSignature can't be combined with anything else.
                    throw Exceptions.ThrowEInvalidArg();
                }

                // The unique signature is simply the node key.
                return(GetNodeKey(node).Name);
            }

            var builder = new StringBuilder();

            AppendPropertyPrototype(builder, symbol, flags, GetName(node));

            return(builder.ToString());
        }
        private void AppendVariablePrototype(StringBuilder builder, IFieldSymbol symbol, PrototypeFlags flags, string baseName)
        {
            if ((flags & PrototypeFlags.Type) != 0)
            {
                builder.Append(GetAsStringForCodeTypeRef(symbol.Type));

                if ((flags & PrototypeFlags.NameMask) != PrototypeFlags.NoName)
                {
                    builder.Append(' ');
                }
            }

            switch (flags & PrototypeFlags.NameMask)
            {
                case PrototypeFlags.FullName:
                    AppendTypeNamePrototype(builder, includeNamespaces: true, includeGenerics: false, symbol: symbol.ContainingSymbol);
                    builder.Append('.');
                    goto case PrototypeFlags.BaseName;

                case PrototypeFlags.TypeName:
                    AppendTypeNamePrototype(builder, includeNamespaces: false, includeGenerics: true, symbol: symbol.ContainingSymbol);
                    builder.Append('.');
                    goto case PrototypeFlags.BaseName;

                case PrototypeFlags.BaseName:
                    builder.Append(baseName);
                    break;
            }
        }
        public override string GetPrototype(SyntaxNode node, ISymbol symbol, PrototypeFlags flags)
        {
            Debug.Assert(symbol != null);

            if (node == null)
            {
                switch (symbol.Kind)
                {
                    case SymbolKind.Field:
                        return GetVariablePrototype((IFieldSymbol)symbol, flags);
                    case SymbolKind.Method:
                        return GetFunctionPrototype((IMethodSymbol)symbol, flags);
                    case SymbolKind.Property:
                        return GetPropertyPrototype((IPropertySymbol)symbol, flags);
                    case SymbolKind.Event:
                        return GetEventPrototype((IEventSymbol)symbol, flags);
                    case SymbolKind.NamedType:
                        var namedType = (INamedTypeSymbol)symbol;
                        if (namedType.TypeKind == TypeKind.Delegate)
                        {
                            return GetDelegatePrototype((INamedTypeSymbol)symbol, flags);
                        }

                        break;
                }

                Debug.Fail("Invalid symbol kind: " + symbol.Kind);
                throw Exceptions.ThrowEUnexpected();
            }
            else
            {
                var methodDeclaration = node as BaseMethodDeclarationSyntax;
                if (methodDeclaration != null)
                {
                    return GetFunctionPrototype(methodDeclaration, (IMethodSymbol)symbol, flags);
                }

                var propertyDeclaration = node as BasePropertyDeclarationSyntax;
                if (propertyDeclaration != null)
                {
                    return GetPropertyPrototype(propertyDeclaration, (IPropertySymbol)symbol, flags);
                }

                var variableDeclarator = node as VariableDeclaratorSyntax;
                if (variableDeclarator != null && symbol.Kind == SymbolKind.Field)
                {
                    return GetVariablePrototype(variableDeclarator, (IFieldSymbol)symbol, flags);
                }

                var enumMember = node as EnumMemberDeclarationSyntax;
                if (enumMember != null)
                {
                    return GetVariablePrototype(enumMember, (IFieldSymbol)symbol, flags);
                }

                var delegateDeclaration = node as DelegateDeclarationSyntax;
                if (delegateDeclaration != null)
                {
                    return GetDelegatePrototype(delegateDeclaration, (INamedTypeSymbol)symbol, flags);
                }

                // Crazily, events for source are not implemented by the legacy C#
                // code model implementation, but they are for metadata events.

                Debug.Fail(string.Format("Invalid node/symbol kind: {0}/{1}", node.Kind(), symbol.Kind));
                throw Exceptions.ThrowENotImpl();
            }
        }
Exemplo n.º 13
0
        private void AppendFunctionPrototype(
            StringBuilder builder,
            IMethodSymbol symbol,
            PrototypeFlags flags,
            string baseName
            )
        {
            if ((flags & PrototypeFlags.Type) != 0)
            {
                builder.Append(GetAsStringForCodeTypeRef(symbol.ReturnType));

                if ((flags & PrototypeFlags.NameMask) != PrototypeFlags.NoName)
                {
                    builder.Append(' ');
                }
            }

            var addSpace = true;

            switch (flags & PrototypeFlags.NameMask)
            {
            case PrototypeFlags.FullName:
                AppendTypeNamePrototype(
                    builder,
                    includeNamespaces: true,
                    includeGenerics: false,
                    symbol: symbol.ContainingSymbol
                    );
                builder.Append('.');
                goto case PrototypeFlags.BaseName;

            case PrototypeFlags.TypeName:
                AppendTypeNamePrototype(
                    builder,
                    includeNamespaces: false,
                    includeGenerics: true,
                    symbol: symbol.ContainingSymbol
                    );
                builder.Append('.');
                goto case PrototypeFlags.BaseName;

            case PrototypeFlags.BaseName:
                builder.Append(baseName);
                break;

            case PrototypeFlags.NoName:
                addSpace = false;
                break;
            }

            if ((flags & (PrototypeFlags.ParameterNames | PrototypeFlags.ParameterTypes)) != 0)
            {
                if (addSpace)
                {
                    builder.Append(' ');
                }

                builder.Append('(');

                AppendParametersPrototype(builder, symbol.Parameters, flags);

                builder.Append(')');
            }
        }
        private string GetPropertyPrototype(BasePropertyDeclarationSyntax node, IPropertySymbol symbol, PrototypeFlags flags)
        {
            if ((flags & PrototypeFlags.Signature) != 0)
            {
                if (flags != PrototypeFlags.Signature)
                {
                    // vsCMPrototypeUniqueSignature can't be combined with anything else.
                    throw Exceptions.ThrowEInvalidArg();
                }

                // The unique signature is simply the node key.
                return GetNodeKey(node).Name;
            }

            var builder = new StringBuilder();

            AppendPropertyPrototype(builder, symbol, flags, GetName(node));

            return builder.ToString();
        }
        private string GetVariablePrototype(IFieldSymbol symbol, PrototypeFlags flags)
        {
            if ((flags & PrototypeFlags.Signature) != 0)
            {
                if (flags != PrototypeFlags.Signature)
                {
                    // vsCMPrototypeUniqueSignature can't be combined with anything else.
                    throw Exceptions.ThrowEInvalidArg();
                }

                // The unique signature is simply the node key.
                flags = PrototypeFlags.FullName | PrototypeFlags.Type;
            }

            var builder = new StringBuilder();

            AppendVariablePrototype(builder, symbol, flags, symbol.Name);

            return builder.ToString();
        }
        private void AppendParameterPrototype(StringBuilder builder, PrototypeFlags flags, IParameterSymbol parameter)
        {
            var addSpace = false;
            if ((flags & PrototypeFlags.ParameterTypes) != 0)
            {
                if (parameter.RefKind == RefKind.Ref)
                {
                    builder.Append("ref ");
                }
                else if (parameter.RefKind == RefKind.Out)
                {
                    builder.Append("out ");
                }
                else if (parameter.IsParams)
                {
                    builder.Append("params ");
                }

                builder.Append(GetAsStringForCodeTypeRef(parameter.Type));
                addSpace = true;
            }

            if ((flags & PrototypeFlags.ParameterNames) != 0)
            {
                if (addSpace)
                {
                    builder.Append(' ');
                }

                builder.Append(parameter.Name);
            }
        }
 public PrototypeFlags <T> Copy(ISerializationManager serializationManager, PrototypeFlags <T> source, PrototypeFlags <T> target,
                                bool skipHook, ISerializationContext?context = null)
 {
     return(new PrototypeFlags <T>(source));
 }
        private string GetVariablePrototype(EnumMemberDeclarationSyntax node, IFieldSymbol symbol, PrototypeFlags flags)
        {
            if ((flags & PrototypeFlags.Signature) != 0)
            {
                if (flags != PrototypeFlags.Signature)
                {
                    // vsCMPrototypeUniqueSignature can't be combined with anything else.
                    throw Exceptions.ThrowEInvalidArg();
                }

                // The unique signature is simply the node key.
                return GetNodeKey(node).Name;
            }

            var builder = new StringBuilder();

            AppendVariablePrototype(builder, symbol, flags, GetName(node));

            if ((flags & PrototypeFlags.Initializer) != 0 &&
                node.EqualsValue != null &&
                node.EqualsValue.Value != null &&
                !node.EqualsValue.Value.IsMissing)
            {
                builder.Append(" = ");
                builder.Append(node.EqualsValue.Value);
            }

            return builder.ToString();
        }
        private void AppendPropertyPrototype(StringBuilder builder, IPropertySymbol symbol, PrototypeFlags flags, string baseName)
        {
            if ((flags & PrototypeFlags.Type) != 0)
            {
                builder.Append(GetAsStringForCodeTypeRef(symbol.Type));

                if ((flags & PrototypeFlags.NameMask) != PrototypeFlags.NoName)
                {
                    builder.Append(' ');
                }
            }

            switch (flags & PrototypeFlags.NameMask)
            {
                case PrototypeFlags.FullName:
                    AppendTypeNamePrototype(builder, includeNamespaces: true, includeGenerics: false, symbol: symbol.ContainingSymbol);
                    builder.Append('.');
                    goto case PrototypeFlags.BaseName;

                case PrototypeFlags.TypeName:
                    AppendTypeNamePrototype(builder, includeNamespaces: false, includeGenerics: true, symbol: symbol.ContainingSymbol);
                    builder.Append('.');
                    goto case PrototypeFlags.BaseName;

                case PrototypeFlags.BaseName:
                    if (symbol.IsIndexer)
                    {
                        builder.Append("this[");
                        AppendParametersPrototype(builder, symbol.Parameters, PrototypeFlags.ParameterTypes | PrototypeFlags.ParameterNames);
                        builder.Append("]");
                    }
                    else
                    {
                        builder.Append(baseName);
                    }

                    break;
            }
        }
        private void AppendFunctionPrototype(StringBuilder builder, IMethodSymbol symbol, PrototypeFlags flags, string baseName)
        {
            if ((flags & PrototypeFlags.Type) != 0)
            {
                builder.Append(GetAsStringForCodeTypeRef(symbol.ReturnType));

                if ((flags & PrototypeFlags.NameMask) != PrototypeFlags.NoName)
                {
                    builder.Append(' ');
                }
            }

            var addSpace = true;

            switch (flags & PrototypeFlags.NameMask)
            {
                case PrototypeFlags.FullName:
                    AppendTypeNamePrototype(builder, includeNamespaces: true, includeGenerics: false, symbol: symbol.ContainingSymbol);
                    builder.Append('.');
                    goto case PrototypeFlags.BaseName;

                case PrototypeFlags.TypeName:
                    AppendTypeNamePrototype(builder, includeNamespaces: false, includeGenerics: true, symbol: symbol.ContainingSymbol);
                    builder.Append('.');
                    goto case PrototypeFlags.BaseName;

                case PrototypeFlags.BaseName:
                    builder.Append(baseName);
                    break;

                case PrototypeFlags.NoName:
                    addSpace = false;
                    break;
            }

            if ((flags & (PrototypeFlags.ParameterNames | PrototypeFlags.ParameterTypes)) != 0)
            {
                if (addSpace)
                {
                    builder.Append(' ');
                }

                builder.Append('(');

                AppendParametersPrototype(builder, symbol.Parameters, flags);

                builder.Append(')');
            }
        }
        private void AppendParametersPrototype(StringBuilder builder, ImmutableArray<IParameterSymbol> parameters, PrototypeFlags flags)
        {
            var first = true;
            foreach (var parameter in parameters)
            {
                if (!first)
                {
                    builder.Append(", ");
                }

                AppendParameterPrototype(builder, flags, parameter);

                first = false;
            }
        }
 public DataNode Write(ISerializationManager serializationManager, PrototypeFlags <T> value, bool alwaysWrite = false,
                       ISerializationContext?context = null)
 {
     return(new SequenceDataNode(value.ToArray()));
 }