예제 #1
0
        private void BuildImplementation() {
            CodeBuilder codeBuilder = new CodeBuilder(_options, this);
            ICollection<SymbolImplementation> implementations = codeBuilder.BuildCode(_symbols);

            if (_options.Minimize) {
                foreach (SymbolImplementation impl in implementations) {
                    if (impl.Scope == null) {
                        continue;
                    }

                    SymbolObfuscator obfuscator = new SymbolObfuscator();
                    SymbolImplementationTransformer transformer = new SymbolImplementationTransformer(obfuscator);

                    transformer.TransformSymbolImplementation(impl);
                }
            }
        }
예제 #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);
                }
            }
        }