Example #1
0
 protected ClassSymbol(SymbolType type, string name, NamespaceSymbol parent)
     : base(type, name, parent)
 {
     _inheritanceDepth = -1;
     _minimizationDepth = -1;
     _transformationCookie = -1;
 }
Example #2
0
        protected TypeSymbol(SymbolType type, string name, NamespaceSymbol parent)
            : base(type, name, parent) {
            Debug.Assert(parent != null);

            _memberTable = new Dictionary<string, MemberSymbol>();
            _members = new List<MemberSymbol>();
            _applicationType = true;
        }
Example #3
0
        public SymbolSet() {
            _namespaces = new List<NamespaceSymbol>();
            _namespaceMap = new Dictionary<string, NamespaceSymbol>();

            _globalNamespace = new NamespaceSymbol(String.Empty, this);
            _globalNamespace.SetTransformedName(String.Empty);
            _namespaces.Add(_globalNamespace);
            _namespaceMap[String.Empty] = _globalNamespace;

            _systemNamespace = new NamespaceSymbol("System", this);
            _namespaces.Add(_systemNamespace);
            _namespaceMap["System"] = _systemNamespace;

            _resources = new Dictionary<string, Dictionary<string, ResXItem>>(StringComparer.OrdinalIgnoreCase);
        }
        public static void GenerateScript(ScriptGenerator generator, NamespaceSymbol namespaceSymbol, Dictionary<string,bool> generatedNamespaces)
        {
            Debug.Assert(generator != null);
            Debug.Assert(namespaceSymbol != null);
            Debug.Assert(namespaceSymbol.HasApplicationTypes);

            ScriptTextWriter writer = generator.Writer;

            // First generate enums and interfaces which do not have cross-dependencies
            // (Classes for example, might have dependencies on enums)

            foreach (TypeSymbol type in namespaceSymbol.Types) {
                if (type.IsApplicationType) {
                    if (type.IsTestType && (generator.Options.IncludeTests == false)) {
                        continue;
                    }

                    string namespaceName = type.GeneratedNamespace;
                    if ((namespaceName.Length != 0) &&
                        (generatedNamespaces.ContainsKey(namespaceName) == false)) {
                        writer.Write("Type.registerNamespace('");
                        writer.Write(namespaceName);
                        writer.Write("');");
                        writer.WriteNewLine();
                        writer.WriteNewLine();
                        generatedNamespaces[namespaceName] = true;
                    }
                }

                if (type.IsApplicationType &&
                    ((type.Type == SymbolType.Enumeration) ||
                     (type.Type == SymbolType.Interface) ||
                     (type.Type == SymbolType.Record) ||
                     (type.Type == SymbolType.Resources))) {
                    TypeGenerator.GenerateScript(generator, type);
                }
            }

            foreach (TypeSymbol type in namespaceSymbol.Types) {
                if (type.IsApplicationType && (type.Type == SymbolType.Class)) {
                    if (type.IsTestType && (generator.Options.IncludeTests == false)) {
                        continue;
                    }

                    TypeGenerator.GenerateScript(generator, type);
                }
            }
        }
Example #5
0
 public RecordSymbol(string name, NamespaceSymbol parent)
     : base(SymbolType.Record, name, parent) {
 }
 public GenericParameterSymbol(int index, string name, bool typeParameter, NamespaceSymbol parent)
     : base(SymbolType.GenericParameter, name, parent)
 {
     _index = index;
     _typeParameter = typeParameter;
 }
Example #7
0
        private void CreateNamespace(string namespaceName)
        {
            if (namespaceName.IndexOf('.') > 0) {
                NamespaceSymbol namespaceSymbol = new NamespaceSymbol(namespaceName, this);

                _namespaces.Add(namespaceSymbol);
                _namespaceMap[namespaceName] = namespaceSymbol;
            }
            else {
                // Split up the namespace into its individual parts, and then
                // create namespace symbols for each sub-namespace leading up
                // to the full specified namespace

                string[] namespaceParts = namespaceName.Split('.');

                for (int i = 0; i < namespaceParts.Length; i++) {
                    string partialNamespace;
                    if (i == 0) {
                        partialNamespace = namespaceParts[0];
                    }
                    else {
                        partialNamespace = String.Join(".", namespaceParts, 0, i + 1);
                    }

                    NamespaceSymbol namespaceSymbol = new NamespaceSymbol(partialNamespace, this);

                    _namespaces.Add(namespaceSymbol);
                    _namespaceMap[namespaceName] = namespaceSymbol;
                }
            }
        }
Example #8
0
 public RecordSymbol(string name, NamespaceSymbol parent)
     : base(SymbolType.Record, name, parent)
 {
 }
Example #9
0
 public GenericTypeSymbol(int genericArgumentIndex, NamespaceSymbol parent)
     : base(SymbolType.GenericParameter, "<T>", parent) {
     _genericArgumentIndex = genericArgumentIndex;
 }
 public EnumerationSymbol(string name, NamespaceSymbol parent, bool flags)
     : base(SymbolType.Enumeration, name, parent)
 {
     _flags = flags;
     _transformationCookie = -1;
 }
Example #11
0
 public GenericParameterSymbol(int index, string name, bool typeParameter, NamespaceSymbol parent)
     : base(SymbolType.GenericParameter, name, parent)
 {
     _index         = index;
     _typeParameter = typeParameter;
 }
Example #12
0
 public InterfaceSymbol(string name, NamespaceSymbol parent)
     : base(SymbolType.Interface, name, parent)
 {
 }
        Symbol ISymbolTable.FindSymbol(string name, Symbol context, SymbolFilter filter)
        {
            if ((filter & SymbolFilter.Types) == 0)
            {
                return(null);
            }

            Symbol symbol = null;

            if (name.IndexOf('.') > 0)
            {
                int nameIndex = name.LastIndexOf('.') + 1;
                Debug.Assert(nameIndex < name.Length);

                string namespaceName = name.Substring(0, nameIndex - 1);
                name = name.Substring(nameIndex);

                NamespaceSymbol namespaceSymbol;
                if (_namespaceMap.TryGetValue(namespaceName, out namespaceSymbol))
                {
                    symbol = ((ISymbolTable)namespaceSymbol).FindSymbol(name, /* context */ null, SymbolFilter.Types);
                }
            }
            else
            {
                Debug.Assert(context != null);

                TypeSymbol typeSymbol = context as TypeSymbol;
                if (typeSymbol == null)
                {
                    Symbol parentSymbol = context.Parent;
                    while (parentSymbol != null)
                    {
                        typeSymbol = parentSymbol as TypeSymbol;
                        if (typeSymbol != null)
                        {
                            break;
                        }

                        parentSymbol = parentSymbol.Parent;
                    }
                }

                Debug.Assert(typeSymbol != null);
                if (typeSymbol == null)
                {
                    return(null);
                }

                bool systemNamespaceChecked = false;

                NamespaceSymbol containerNamespace = (NamespaceSymbol)typeSymbol.Parent;
                Debug.Assert(containerNamespace != null);

                symbol = ((ISymbolTable)containerNamespace).FindSymbol(name, /* context */ null, SymbolFilter.Types);
                if (containerNamespace == _systemNamespace)
                {
                    systemNamespaceChecked = true;
                }
                if (symbol == null)
                {
                    if ((typeSymbol.Aliases != null) && typeSymbol.Aliases.ContainsKey(name))
                    {
                        string typeReference = typeSymbol.Aliases[name];
                        symbol = ((ISymbolTable)this).FindSymbol(typeReference, /* context */ null, SymbolFilter.Types);
                    }
                    else if (typeSymbol.Imports != null)
                    {
                        foreach (string importedNamespaceReference in typeSymbol.Imports)
                        {
                            if (_namespaceMap.ContainsKey(importedNamespaceReference) == false)
                            {
                                // Since we included all parent namespaces of the current type's
                                // namespace, we might run into a namespace that doesn't contain
                                // any defined types, i.e. doesn't exist.

                                continue;
                            }

                            NamespaceSymbol importedNamespace = _namespaceMap[importedNamespaceReference];
                            if (importedNamespace == containerNamespace)
                            {
                                continue;
                            }

                            symbol = ((ISymbolTable)importedNamespace).FindSymbol(name, /* context */ null, SymbolFilter.Types);
                            if (importedNamespace == _systemNamespace)
                            {
                                systemNamespaceChecked = true;
                            }
                            if (symbol != null)
                            {
                                break;
                            }
                        }
                    }
                }
                if ((symbol == null) && (systemNamespaceChecked == false))
                {
                    symbol = ((ISymbolTable)_systemNamespace).FindSymbol(name, /* context */ null, SymbolFilter.Types);
                }
                if (symbol == null)
                {
                    symbol = ((ISymbolTable)_globalNamespace).FindSymbol(name, /* context */ null, SymbolFilter.Types);
                }
            }

            return(symbol);
        }
        /// <summary>
        /// This maps C# intrinsic types (managed types that have an equivalent
        /// C# keyword)
        /// </summary>
        public TypeSymbol ResolveIntrinsicType(IntrinsicType type)
        {
            string mappedTypeName  = null;
            string mappedNamespace = null;

            switch (type)
            {
            case IntrinsicType.Object:
                mappedTypeName = "Object";
                break;

            case IntrinsicType.Boolean:
                mappedTypeName = "Boolean";
                break;

            case IntrinsicType.String:
                mappedTypeName = "String";
                break;

            case IntrinsicType.Integer:
                mappedTypeName = "Int32";
                break;

            case IntrinsicType.UnsignedInteger:
                mappedTypeName = "UInt32";
                break;

            case IntrinsicType.Long:
                mappedTypeName = "Int64";
                break;

            case IntrinsicType.UnsignedLong:
                mappedTypeName = "UInt64";
                break;

            case IntrinsicType.Short:
                mappedTypeName = "Int16";
                break;

            case IntrinsicType.UnsignedShort:
                mappedTypeName = "UInt16";
                break;

            case IntrinsicType.Byte:
                mappedTypeName = "Byte";
                break;

            case IntrinsicType.SignedByte:
                mappedTypeName = "SByte";
                break;

            case IntrinsicType.Single:
                mappedTypeName = "Single";
                break;

            case IntrinsicType.Decimal:
                mappedTypeName = "Decimal";
                break;

            case IntrinsicType.Double:
                mappedTypeName = "Double";
                break;

            case IntrinsicType.Delegate:
                mappedTypeName = "Delegate";
                break;

            case IntrinsicType.Function:
                mappedTypeName = "Function";
                break;

            case IntrinsicType.Void:
                mappedTypeName = "Void";
                break;

            case IntrinsicType.Array:
                mappedTypeName = "Array";
                break;

            case IntrinsicType.Dictionary:
                mappedTypeName  = "Dictionary";
                mappedNamespace = "System.Collections";
                break;

            case IntrinsicType.GenericList:
                mappedTypeName  = "List`1";
                mappedNamespace = "System.Collections.Generic";
                break;

            case IntrinsicType.GenericDictionary:
                mappedTypeName  = "Dictionary`2";
                mappedNamespace = "System.Collections.Generic";
                break;

            case IntrinsicType.Type:
                mappedTypeName = "Type";
                break;

            case IntrinsicType.IEnumerator:
                mappedTypeName  = "IEnumerator";
                mappedNamespace = "System.Collections";
                break;

            case IntrinsicType.Enum:
                mappedTypeName = "Enum";
                break;

            case IntrinsicType.Exception:
                mappedTypeName = "Exception";
                break;

            case IntrinsicType.Script:
                mappedTypeName = "Script";
                break;

            case IntrinsicType.Number:
                mappedTypeName = "Number";
                break;

            case IntrinsicType.Arguments:
                mappedTypeName = "Arguments";
                break;

            case IntrinsicType.Nullable:
                mappedTypeName = "Nullable`1";
                break;

            default:
                Debug.Fail("Unmapped intrinsic type " + type);
                break;
            }

            NamespaceSymbol ns = _systemNamespace;

            if (mappedNamespace != null)
            {
                ns = GetNamespace(mappedNamespace);
                Debug.Assert(ns != null);
            }

            if (mappedTypeName != null)
            {
                TypeSymbol typeSymbol = (TypeSymbol)((ISymbolTable)ns).FindSymbol(mappedTypeName, null, SymbolFilter.Types);
                Debug.Assert(typeSymbol != null);

                return(typeSymbol);
            }

            return(null);
        }
Example #15
0
        private void DumpNamespace(NamespaceSymbol namespaceSymbol)
        {
            _writer.Write("HasApplicationTypes: ");
            _writer.WriteLine(namespaceSymbol.HasApplicationTypes);
            _writer.WriteLine("Types:");
            _writer.Indent++;

            ArrayList types = new ArrayList(namespaceSymbol.Types.Count);
            foreach (TypeSymbol type in namespaceSymbol.Types) {
                types.Add(type);
            }
            types.Sort(new SymbolComparer());

            foreach (TypeSymbol type in types) {
                DumpSymbol(type);
            }
            _writer.Indent--;
        }
Example #16
0
 public ClassSymbol(string name, NamespaceSymbol parent)
     : this(SymbolType.Class, name, parent)
 {
 }
Example #17
0
 public InterfaceSymbol(string name, NamespaceSymbol parent)
     : base(SymbolType.Interface, name, parent)
 {
 }
Example #18
0
 public DelegateSymbol(string name, NamespaceSymbol parent)
     : base(SymbolType.Delegate, name, parent) {
 }
 public EnumerationSymbol(string name, NamespaceSymbol parent, bool flags)
     : base(SymbolType.Enumeration, name, parent)
 {
     _flags = flags;
     _transformationCookie = -1;
 }
Example #20
0
 public ResourcesSymbol(string name, NamespaceSymbol parent)
     : base(SymbolType.Resources, name, parent) {
 }
Example #21
0
        private TypeSymbol BuildType(UserTypeNode typeNode, NamespaceSymbol namespaceSymbol) {
            Debug.Assert(typeNode != null);
            Debug.Assert(namespaceSymbol != null);

            TypeSymbol typeSymbol = null;
            ParseNodeList attributes = typeNode.Attributes;

            if (typeNode.Type == TokenType.Class) {
                CustomTypeNode customTypeNode = (CustomTypeNode)typeNode;
                Debug.Assert(customTypeNode != null);

                NameNode baseTypeNameNode = null;
                if (customTypeNode.BaseTypes.Count != 0) {
                    baseTypeNameNode = customTypeNode.BaseTypes[0] as NameNode;
                }

                if ((baseTypeNameNode != null) && (String.CompareOrdinal(baseTypeNameNode.Name, "Record") == 0)) {
                    typeSymbol = new RecordSymbol(typeNode.Name, namespaceSymbol);
                }
                else {
                    AttributeNode resourcesAttribute = AttributeNode.FindAttribute(attributes, "Resources");
                    if (resourcesAttribute != null) {
                        typeSymbol = new ResourcesSymbol(typeNode.Name, namespaceSymbol);
                    }
                    else {
                        typeSymbol = new ClassSymbol(typeNode.Name, namespaceSymbol);

                        if ((baseTypeNameNode != null) &&
                            (String.CompareOrdinal(baseTypeNameNode.Name, "TestClass") == 0)) {
                            ((ClassSymbol)typeSymbol).SetTestClass();
                        }
                    }
                }
            }
            else if (typeNode.Type == TokenType.Interface) {
                typeSymbol = new InterfaceSymbol(typeNode.Name, namespaceSymbol);
            }
            else if (typeNode.Type == TokenType.Enum) {
                bool flags = false;

                AttributeNode flagsAttribute = AttributeNode.FindAttribute(typeNode.Attributes, "Flags");
                if (flagsAttribute != null) {
                    flags = true;
                }

                typeSymbol = new EnumerationSymbol(typeNode.Name, namespaceSymbol, flags);
            }
            else if (typeNode.Type == TokenType.Delegate) {
                typeSymbol = new DelegateSymbol(typeNode.Name, namespaceSymbol);
                typeSymbol.SetTransformedName("Function");
                typeSymbol.SetIgnoreNamespace();
            }

            Debug.Assert(typeSymbol != null, "Unexpected type node " + typeNode.Type);
            if (typeSymbol != null) {
                if ((typeNode.Modifiers & Modifiers.Public) != 0) {
                    typeSymbol.SetPublic();
                }

                BuildType(typeSymbol, typeNode);

                if (namespaceSymbol.Name.EndsWith(_options.TestsSubnamespace, StringComparison.Ordinal)) {
                    typeSymbol.SetTestType();
                }
            }

            return typeSymbol;
        }
Example #22
0
 public ResourcesSymbol(string name, NamespaceSymbol parent)
     : base(SymbolType.Resources, name, parent)
 {
 }