コード例 #1
0
        private void BuildType(TypeSymbol typeSymbol, UserTypeNode typeNode)
        {
            Debug.Assert(typeSymbol != null);
            Debug.Assert(typeNode != null);

            ParseNodeList attributes = typeNode.Attributes;

            if (AttributeNode.FindAttribute(attributes, "Imported") != null)
            {
                typeSymbol.SetImported(/* dependencyName */ null);
            }

            if (AttributeNode.FindAttribute(attributes, "IgnoreNamespace") != null)
            {
                typeSymbol.SetIgnoreNamespace();
            }

            if (AttributeNode.FindAttribute(attributes, "PreserveName") != null)
            {
                typeSymbol.DisableNameTransformation();
            }

            string scriptName = GetAttributeValue(attributes, "ScriptName");

            if (scriptName != null)
            {
                typeSymbol.SetTransformedName(scriptName);
            }

            if (typeNode.Type == TokenType.Class)
            {
                bool   globalizeMembers = false;
                string mixinRoot        = null;

                AttributeNode globalMethodsAttribute = AttributeNode.FindAttribute(attributes, "GlobalMethods");
                if (globalMethodsAttribute != null)
                {
                    globalizeMembers = true;
                }
                else
                {
                    AttributeNode mixinAttribute = AttributeNode.FindAttribute(attributes, "Mixin");
                    if (mixinAttribute != null)
                    {
                        Debug.Assert(mixinAttribute.Arguments[0] is LiteralNode);
                        Debug.Assert(((LiteralNode)mixinAttribute.Arguments[0]).Value is string);

                        mixinRoot        = (string)((LiteralNode)mixinAttribute.Arguments[0]).Value;
                        globalizeMembers = true;
                    }
                }

                if (globalizeMembers)
                {
                    ((ClassSymbol)typeSymbol).SetGlobalMethods(mixinRoot);
                }
            }

            if (typeNode.Type == TokenType.Enum)
            {
                if (AttributeNode.FindAttribute(attributes, "NamedValues") != null)
                {
                    ((EnumerationSymbol)typeSymbol).SetNamedValues();
                }
                else if (AttributeNode.FindAttribute(attributes, "NumericValues") != null)
                {
                    ((EnumerationSymbol)typeSymbol).SetNumericValues();
                }
            }
        }