Example #1
0
        /// <nodoc />
        public PredefinedTypes(PrimitiveTypes knownTypes)
        {
            Contract.Requires(knownTypes != null);

            AllAmbientDefinitions = new Dictionary <Type, AmbientDefinitionBase>
            {
                [typeof(ArrayLiteral)]      = AmbientArray = new AmbientArray(knownTypes),
                [typeof(DirectoryArtifact)] = m_ambientDirectory = new AmbientDirectory(knownTypes),
                [typeof(EnumValue)]         = m_ambientEnum = new AmbientEnum(knownTypes),
                [typeof(FileArtifact)]      = m_ambientFile = new AmbientFile(knownTypes),
                [typeof(ObjectLiteral)]     = AmbientObject = new AmbientObject(knownTypes),
                [typeof(ObjectLiteral0)]    = AmbientObject,
                [typeof(ObjectLiteralSlim)] = AmbientObject,
                [typeof(ObjectLiteralN)]    = AmbientObject,
                [typeof(AbsolutePath)]      = m_ambientPath = new AmbientPath(knownTypes),
                [typeof(StaticDirectory)]   = m_ambientStaticDirectory = new AmbientStaticDirectory(knownTypes),
                [typeof(string)]            = m_ambientString = new AmbientString(knownTypes),
                [typeof(AmbientStringBuilder.StringBuilderWrapper)] = m_ambientStringBuilder = new AmbientStringBuilder(knownTypes),
                [typeof(int)]          = m_ambientNumber = new AmbientNumber(knownTypes),
                [typeof(UnitValue)]    = m_ambientUnit = new AmbientUnit(knownTypes),
                [typeof(bool)]         = m_ambientBoolean = new AmbientBoolean(knownTypes),
                [typeof(OrderedMap)]   = m_ambientMap = new AmbientMap(knownTypes),
                [typeof(OrderedSet)]   = m_ambientSet = new AmbientSet(knownTypes),
                [typeof(MutableSet)]   = m_ambientMutableSet = new AmbientMutableSet(knownTypes),
                [typeof(PathAtom)]     = m_ambientPathAtom = new AmbientPathAtom(knownTypes),
                [typeof(RelativePath)] = m_ambientRelativePath = new AmbientRelativePath(knownTypes),

                // the ones below don't define any 'instance' methods, thus are not associated with a "real" object type,
                // i.e., a type that is going to be encountered during a DScript evaluation.
                [typeof(Dummy)] = m_ambientContext = new AmbientContext(knownTypes),
                [typeof(Dummy)] = m_ambientDebug = new AmbientDebug(knownTypes),
                [typeof(Dummy)] = m_ambientContract = new AmbientContract(knownTypes),
                [typeof(Dummy)] = m_ambientGlobal = new AmbientGlobal(knownTypes),
                [typeof(Dummy)] = m_ambientMath = new AmbientMath(knownTypes),
                [typeof(Dummy)] = m_ambientTransformerOriginal = new AmbientTransformerOriginal(knownTypes),
                [typeof(Dummy)] = m_ambientTransformerHack = new AmbientTransformerHack(knownTypes),
                [typeof(Dummy)] = m_ambientEnvironment = new AmbientEnvironment(knownTypes),
                [typeof(Dummy)] = m_ambientArgumentKind = new AmbientArgumentKind(knownTypes),
                [typeof(Dummy)] = m_ambientArtifactKind = new AmbientArtifactKind(knownTypes),
                [typeof(Dummy)] = m_ambientTextEncoding = new AmbientTextEncoding(knownTypes),
                [typeof(Dummy)] = m_ambientNameResolutionSemantics = new AmbientNameResolutionSemantics(knownTypes),
                [typeof(Dummy)] = m_ambientKeyForm = new AmbientKeyForm(knownTypes),
                [typeof(Dummy)] = m_ambientSealSourceDirectoryOption = new AmbientSealSourceDirectoryOption(knownTypes),
                [typeof(Dummy)] = m_ambientHashHelper = new AmbientHashing(knownTypes),
                [typeof(Dummy)] = m_ambientValueCacheHelper = new AmbientValueCache(knownTypes),
                [typeof(Dummy)] = m_ambientJsonHelper = new AmbientJson(knownTypes),
                [typeof(Dummy)] = m_ambientXmlHelper = new AmbientXml(knownTypes),
                [typeof(Dummy)] = m_ambientContainerIsolationLevel = new AmbientContainerIsolationLevel(knownTypes),
                [typeof(Dummy)] = m_ambientUnsafe = new AmbientUnsafe(knownTypes),
            };
        }
Example #2
0
        /// <summary>
        /// Replaces the name of each environment variable embedded in the specified path with the string equivalent of the value of the variable.
        /// Replacement only occurs for environment variables that are set. Unset environment variables are left unexpanded.
        /// </summary>
        private static EvaluationResult ExpandEnvironmentVariablesInPath(Context context, ModuleLiteral env, EvaluationStackFrame args)
        {
            var path         = Args.AsPath(args, 0);
            var pathAsString = path.ToString(context.PathTable);

            if (StringVariableExpander.TryExpandVariablesInString(pathAsString, context.FrontEndHost.Engine, out string expandedPath))
            {
                // The resulting expanded path may not be a valid one. Apply the same validations as when creating an absolute path from a literal
                return(AmbientPath.CreateFromAbsolutePathString(context, expandedPath));
            }

            // No expansion occurred
            return(EvaluationResult.Create(path));
        }