Beispiel #1
0
        private static PastelContext GetContextForConfigImpl(
            ProjectConfig config,
            Dictionary <string, PastelContext> contexts,
            HashSet <string> recursionCheck)
        {
            if (contexts.ContainsKey(config.Path))
            {
                return(contexts[config.Path]);
            }
            if (recursionCheck.Contains(config.Path))
            {
                throw new InvalidOperationException("Project config dependencies have a cycle involving: " + config.Path);
            }

            recursionCheck.Add(config.Path);

            ProjectConfig[] requiredScopes = config.DependenciesByPrefix.Values.ToArray();
            for (int i = 0; i < requiredScopes.Length; ++i)
            {
                string path = requiredScopes[i].Path;
                if (!contexts.ContainsKey(path))
                {
                    throw new Exception(); // This shouldn't happen. These are run in dependency order.
                }
            }

            string        sourceRootDir = System.IO.Path.GetDirectoryName(config.Source);
            PastelContext context       = new PastelContext(sourceRootDir, config.Language, new CodeLoader(sourceRootDir));

            foreach (string prefix in config.DependenciesByPrefix.Keys)
            {
                ProjectConfig depConfig = config.DependenciesByPrefix[prefix];

                // TODO: make this a little more generic for other possible languages
                string funcNs       = depConfig.NamespaceForFunctions;
                string classWrapper = depConfig.WrappingClassNameForFunctions;
                string outputPrefix = "";
                if (funcNs != null)
                {
                    outputPrefix = funcNs + ".";
                }
                if (classWrapper != null)
                {
                    outputPrefix += classWrapper + ".";
                }

                context.AddDependency(contexts[depConfig.Path], prefix, outputPrefix);
            }
            context.MarkDependenciesAsFinalized();

            foreach (string constantName in config.Flags.Keys)
            {
                context.SetConstant(constantName, config.Flags[constantName]);
            }

            foreach (ExtensibleFunction exFn in config.GetExtensibleFunctions())
            {
                // TODO(pastel-split): Translation is already set on the extensible function in the
                // new codepath, so the 2nd parameter here ought to be removed.
                context.AddExtensibleFunction(exFn, exFn.Translation);
            }

            contexts[config.Path] = context;
            recursionCheck.Remove(config.Path);
            return(context);
        }