Пример #1
0
        private void TransformSymbols()
        {
            ISymbolTransformer transformer;

            if (options.Minimize)
            {
                transformer = new SymbolObfuscator();
            }
            else
            {
                transformer = new SymbolInternalizer();
            }

            SymbolSetTransformer symbolSetTransformer = new SymbolSetTransformer(transformer);

            symbolSetTransformer.TransformSymbolSet(symbols, useInheritanceOrder: true);
        }
Пример #2
0
        private void BuildMetadata()
        {
            if ((_options.Resources != null) && (_options.Resources.Count != 0))
            {
                ResourcesBuilder resourcesBuilder = new ResourcesBuilder(_symbols);
                resourcesBuilder.BuildResources(_options.Resources);
            }

            MetadataBuilder mdBuilder = new MetadataBuilder(this);

            _appSymbols = mdBuilder.BuildMetadata(_compilationUnitList, _symbols, _options);

            // Check if any of the types defined in this assembly conflict against types in
            // imported assemblies.

            Dictionary <string, TypeSymbol> types = new Dictionary <string, TypeSymbol>();

            foreach (TypeSymbol importedType in _importedSymbols)
            {
                types[importedType.FullGeneratedName] = importedType;
            }

            foreach (TypeSymbol appType in _appSymbols)
            {
                if ((appType.IsApplicationType == false) || (appType.Type == SymbolType.Delegate))
                {
                    // Skip the check for types that are marked as imported, as they
                    // aren't going to be generated into the script.
                    // Delegates are implicitly imported types, as they're never generated into
                    // the script.
                    continue;
                }

                if ((appType.Type == SymbolType.Class) &&
                    (((ClassSymbol)appType).PrimaryPartialClass != appType))
                {
                    // Skip the check for partial types, since they should only be
                    // checked once.
                    continue;
                }

                string name = appType.FullGeneratedName;
                if (types.ContainsKey(name))
                {
                    string error = "The type '" + name + "' conflicts with another existing type with the same full name. This might be because a referenced assembly uses the same type, or you have multiple types with the same name across namespaces mapped to the same script namespace.";
                    ((IErrorHandler)this).ReportError(error, null);
                }
                else
                {
                    types[name] = appType;
                }
            }

            // Capture whether there are any test types in the project
            // when not compiling the test flavor script. This is used to determine
            // if the test flavor script should be compiled in the build task.

            if (_options.IncludeTests == false)
            {
                foreach (TypeSymbol appType in _appSymbols)
                {
                    if (appType.IsApplicationType && appType.IsTestType)
                    {
                        _options.HasTestTypes = true;
                    }
                }
            }

#if DEBUG
            if (_options.InternalTestType == "metadata")
            {
                StringWriter testWriter = new StringWriter();

                testWriter.WriteLine("Metadata");
                testWriter.WriteLine("================================================================");

                SymbolSetDumper symbolDumper = new SymbolSetDumper(testWriter);
                symbolDumper.DumpSymbols(_symbols);

                testWriter.WriteLine();
                testWriter.WriteLine();

                _testOutput = testWriter.ToString();
            }
#endif // DEBUG

            if (_options.Minimize)
            {
                SymbolObfuscator     obfuscator             = new SymbolObfuscator();
                SymbolSetTransformer obfuscationTransformer = new SymbolSetTransformer(obfuscator);

                ICollection <Symbol> obfuscatedSymbols = obfuscationTransformer.TransformSymbolSet(_symbols, /* useInheritanceOrder */ true);

#if DEBUG
                if (_options.InternalTestType == "minimizationMap")
                {
                    StringWriter testWriter = new StringWriter();

                    testWriter.WriteLine("Minimization Map");
                    testWriter.WriteLine("================================================================");

                    List <Symbol> sortedObfuscatedSymbols = new List <Symbol>(obfuscatedSymbols);
                    sortedObfuscatedSymbols.Sort(delegate(Symbol s1, Symbol s2) {
                        return(String.Compare(s1.Name, s2.Name));
                    });

                    foreach (Symbol obfuscatedSymbol in sortedObfuscatedSymbols)
                    {
                        if (obfuscatedSymbol is TypeSymbol)
                        {
                            TypeSymbol typeSymbol = (TypeSymbol)obfuscatedSymbol;

                            testWriter.WriteLine("Type '" + typeSymbol.FullName + "' renamed to '" + typeSymbol.GeneratedName + "'");
                        }
                        else
                        {
                            Debug.Assert(obfuscatedSymbol is MemberSymbol);
                            testWriter.WriteLine("    Member '" + obfuscatedSymbol.Name + "' renamed to '" + obfuscatedSymbol.GeneratedName + "'");
                        }
                    }

                    testWriter.WriteLine();
                    testWriter.WriteLine();

                    _testOutput = testWriter.ToString();
                }
#endif // DEBUG
            }
            else
            {
                if (_options.DebugFlavor)
                {
                    SymbolInternalizer   internalizer             = new SymbolInternalizer();
                    SymbolSetTransformer internalizingTransformer = new SymbolSetTransformer(internalizer);

                    internalizingTransformer.TransformSymbolSet(_symbols, /* useInheritanceOrder */ true);
                }
            }
        }
Пример #3
0
        private void BuildMetadata() {
            if ((_options.Resources != null) && (_options.Resources.Count != 0)) {
                ResourcesBuilder resourcesBuilder = new ResourcesBuilder(_symbols);
                resourcesBuilder.BuildResources(_options.Resources);
            }

            MetadataBuilder mdBuilder = new MetadataBuilder(this);
            _appSymbols = mdBuilder.BuildMetadata(_compilationUnitList, _symbols, _options);

            // Check if any of the types defined in this assembly conflict against types in
            // imported assemblies.

            Dictionary<string, TypeSymbol> types = new Dictionary<string, TypeSymbol>();
            foreach (TypeSymbol importedType in _importedSymbols) {
                types[importedType.FullGeneratedName] = importedType;
            }

            foreach (TypeSymbol appType in _appSymbols) {
                if ((appType.IsApplicationType == false) || (appType.Type == SymbolType.Delegate)) {
                    // Skip the check for types that are marked as imported, as they
                    // aren't going to be generated into the script.
                    // Delegates are implicitly imported types, as they're never generated into
                    // the script.
                    continue;
                }

                if ((appType.Type == SymbolType.Class) &&
                    (((ClassSymbol)appType).PrimaryPartialClass != appType)) {
                    // Skip the check for partial types, since they should only be
                    // checked once.
                    continue;
                }

                string name = appType.FullGeneratedName;
                if (types.ContainsKey(name)) {
                    string error = "The type '" + name + "' conflicts with another existing type with the same full name. This might be because a referenced assembly uses the same type, or you have multiple types with the same name across namespaces mapped to the same script namespace.";
                    ((IErrorHandler)this).ReportError(error, null);
                }
                else {
                    types[name] = appType;
                }
            }

            // Capture whether there are any test types in the project
            // when not compiling the test flavor script. This is used to determine
            // if the test flavor script should be compiled in the build task.

            if (_options.IncludeTests == false) {
                foreach (TypeSymbol appType in _appSymbols) {
                    if (appType.IsApplicationType && appType.IsTestType) {
                        _options.HasTestTypes = true;
                    }
                }
            }

#if DEBUG
            if (_options.InternalTestType == "metadata") {
                StringWriter testWriter = new StringWriter();

                testWriter.WriteLine("Metadata");
                testWriter.WriteLine("================================================================");

                SymbolSetDumper symbolDumper = new SymbolSetDumper(testWriter);
                symbolDumper.DumpSymbols(_symbols);

                testWriter.WriteLine();
                testWriter.WriteLine();

                _testOutput = testWriter.ToString();
            }
#endif // DEBUG

            if (_options.Minimize) {
                SymbolObfuscator obfuscator = new SymbolObfuscator();
                SymbolSetTransformer obfuscationTransformer = new SymbolSetTransformer(obfuscator);

                ICollection<Symbol> obfuscatedSymbols = obfuscationTransformer.TransformSymbolSet(_symbols, /* useInheritanceOrder */ true);

#if DEBUG
                if (_options.InternalTestType == "minimizationMap") {
                    StringWriter testWriter = new StringWriter();

                    testWriter.WriteLine("Minimization Map");
                    testWriter.WriteLine("================================================================");

                    List<Symbol> sortedObfuscatedSymbols = new List<Symbol>(obfuscatedSymbols);
                    sortedObfuscatedSymbols.Sort(delegate(Symbol s1, Symbol s2) {
                        return String.Compare(s1.Name, s2.Name);
                    });

                    foreach (Symbol obfuscatedSymbol in sortedObfuscatedSymbols) {
                        if (obfuscatedSymbol is TypeSymbol) {
                            TypeSymbol typeSymbol = (TypeSymbol)obfuscatedSymbol;

                            testWriter.WriteLine("Type '" + typeSymbol.FullName + "' renamed to '" + typeSymbol.GeneratedName + "'");
                        }
                        else {
                            Debug.Assert(obfuscatedSymbol is MemberSymbol);
                            testWriter.WriteLine("    Member '" + obfuscatedSymbol.Name + "' renamed to '" + obfuscatedSymbol.GeneratedName + "'");
                        }
                    }

                    testWriter.WriteLine();
                    testWriter.WriteLine();

                    _testOutput = testWriter.ToString();
                }
#endif // DEBUG
            }
            else {
                if (_options.DebugFlavor) {
                    SymbolInternalizer internalizer = new SymbolInternalizer();
                    SymbolSetTransformer internalizingTransformer = new SymbolSetTransformer(internalizer);

                    internalizingTransformer.TransformSymbolSet(_symbols, /* useInheritanceOrder */ true);
                }
            }
        }
Пример #4
0
        //TODO: Look at removing the internal testing type mechanism in favour of testing the compiler correctly.
        private void BuildMetadata()
        {
            if (options.Resources != null && options.Resources.Count != 0)
            {
                ResourcesBuilder resourcesBuilder = new ResourcesBuilder(symbols);
                resourcesBuilder.BuildResources(options.Resources);
            }

            MetadataBuilder mdBuilder = new MetadataBuilder(this);

            appSymbols = mdBuilder.BuildMetadata(compilationUnitList, symbols, options);

            // Check if any of the types defined in this assembly conflict.
            Dictionary <string, TypeSymbol> types = new Dictionary <string, TypeSymbol>();

            foreach (TypeSymbol appType in appSymbols)
            {
                if (appType.IsApplicationType == false || appType.Type == SymbolType.Delegate)
                {
                    // Skip the check for types that are marked as imported, as they
                    // aren't going to be generated into the script.
                    // Delegates are implicitly imported types, as they're never generated into
                    // the script.
                    continue;
                }

                if (appType.Type == SymbolType.Class &&
                    ((ClassSymbol)appType).PrimaryPartialClass != appType)
                {
                    // Skip the check for partial types, since they should only be
                    // checked once.
                    continue;
                }

                // TODO: We could allow conflicting types as long as both aren't public
                //       since they won't be on the exported types list. Internal types that
                //       conflict could be generated using full name.

                string name = appType.GeneratedName;

                if (types.ContainsKey(name))
                {
                    ((IErrorHandler)this).ReportGeneralError(string.Format(DSharpStringResources.CONFLICTING_TYPE_NAME_ERROR_FORMAT, appType.FullName, types[name].FullName));
                }
                else
                {
                    types[name] = appType;
                }
            }

            ISymbolTransformer transformer = null;

            if (options.Minimize)
            {
                transformer = new SymbolObfuscator();
            }
            else
            {
                transformer = new SymbolInternalizer();
            }

            if (transformer != null)
            {
                SymbolSetTransformer symbolSetTransformer = new SymbolSetTransformer(transformer);
                ICollection <Symbol> transformedSymbols   =
                    symbolSetTransformer.TransformSymbolSet(symbols, /* useInheritanceOrder */ true);
            }
        }