Пример #1
0
        /// <summary>
        /// Evaluates a resolved entry that is not a Thunk
        /// </summary>
        internal bool TryResolveFunction(Context context, FilePosition filePosition, FullSymbol nameForDebuggingPurposes, out FunctionLikeExpression lambda, out FileModuleLiteral file)
        {
            if (TryResolveEntryByLocation(context, filePosition, nameForDebuggingPurposes, out var resolvedEntry, out file))
            {
                lambda = resolvedEntry.Function;
                return(true);
            }

            lambda = null;
            return(false);
        }
Пример #2
0
        /// <nodoc/>
        public ResolvedEntry(FullSymbol thunkContextName, Thunk thunk, QualifierSpaceId qualifierSpaceId, bool isVariableDeclaration)
            : this()
        {
            Contract.Requires(thunk != null);

            Thunk    = thunk;
            Location = thunk.Expression.Location;
            m_thunkContextNameOrSymbolName = thunkContextName;
            IsVariableDeclaration          = isVariableDeclaration;
            QualifierSpaceId = qualifierSpaceId;
        }
Пример #3
0
        public void RelocateForm2()
        {
            var        idt = new SymbolTable();
            FullSymbol d2  = FullSymbol.Create(idt, @"c.a.x");
            FullSymbol f1  = FullSymbol.Create(idt, @"C.a.b.c.d.cpp");

            XAssert.IsFalse(f1.IsWithin(idt, d2));
            FullSymbol f2 = f1.Relocate(idt, d2);

            XAssert.AreEqual(@"c.a.x.cpp", f2.ToString(idt));
        }
        /// <nodoc/>
        public LocationBasedSymbolReference(FilePosition filePosition, SymbolAtom symbolName, LineInfo location, SymbolTable symbolTable)
            : base(location)
        {
            Contract.Requires(filePosition.IsValid);
            Contract.Requires(symbolName.IsValid);

            FilePosition = filePosition;
            Name         = symbolName;

            m_fullSymbol = FullSymbol.Create(symbolTable, symbolName);
        }
Пример #5
0
        /// <summary>
        /// Constructs module literal for namespace.
        /// </summary>
        protected static TypeOrNamespaceModuleLiteral CreateTypeOrNamespaceModule(FullSymbol namespaceName, ModuleLiteral outerScope, LineInfo location)
        {
            Contract.Requires(namespaceName.IsValid);
            Contract.Requires(outerScope != null);
            Contract.Requires(outerScope.IsFileOrGlobal);

            ModuleLiteralId moduleId = outerScope.Id.WithName(namespaceName);

            return(new TypeOrNamespaceModuleLiteral(moduleId, qualifier: QualifierValue.Unqualified,
                                                    outerScope: outerScope, location: location));
        }
Пример #6
0
        /// <summary>
        /// Constructs a new Value pip
        /// </summary>
        public ValuePip(
            FullSymbol symbol,
            QualifierId qualifier,
            LocationData locationData)
        {
            Contract.Requires(symbol.IsValid);
            Contract.Requires(locationData.IsValid);

            Symbol       = symbol;
            Qualifier    = qualifier;
            LocationData = locationData;
        }
Пример #7
0
        public void GetParent()
        {
            var        idt    = new SymbolTable();
            FullSymbol da     = FullSymbol.Create(idt, @"c.a");
            FullSymbol parent = da.GetParent(idt);

            XAssert.AreEqual(@"c", parent.ToString(idt));

            da     = FullSymbol.Create(idt, @"c.a.b");
            parent = da.GetParent(idt);
            XAssert.AreEqual(@"c.a", parent.ToString(idt));
        }
Пример #8
0
        internal TValue this[FullSymbol key]
        {
            get
            {
                return(m_fullSymbolsToValues[key]);
            }

            set
            {
                m_fullSymbolsToValues[key] = value;
            }
        }
Пример #9
0
        public void IsInitialized()
        {
            FullSymbol p = default(FullSymbol);

            XAssert.IsFalse(p.IsValid);

            var idt = new SymbolTable();

            p = FullSymbol.Create(idt, @"C.AAA.CCC");
            XAssert.AreEqual(@"C.AAA.CCC", p.ToString(idt));
            XAssert.IsTrue(p.IsValid);
        }
Пример #10
0
        /// <summary>
        /// Gets module or namespace based on module id.
        /// </summary>
        public EvaluationResult GetNamespace(ImmutableContextBase context, FullSymbol fullName, bool recurs, ModuleLiteral origin, LineInfo location)
        {
            ModuleBinding binding = GetNamespaceBinding(context, fullName, recurs);

            if (binding == null)
            {
                context.Errors.ReportMissingNamespace(origin ?? this, fullName, this, location);
                return(EvaluationResult.Error);
            }

            return(EvaluationResult.Create(binding.Body));
        }
Пример #11
0
        /// <summary>
        /// Converts a string to a FullSymbol
        /// </summary>
        /// <param name="symbolTable">SymbolTable to use to convert the string</param>
        /// <param name="str">String to convert to FullSymbol</param>
        /// <returns>The result of converting the provided string to a FullSymbol</returns>
        public static FullSymbol StringToFullSymbol(this SymbolTable symbolTable, string str)
        {
            FullSymbol fullSymbol;

            if (FullSymbol.TryGet(symbolTable, str, out fullSymbol))
            {
                return(fullSymbol);
            }
            else
            {
                throw new ArgumentException("Unable to find FullSymbol for string: '" + str + "'");
            }
        }
Пример #12
0
        /// <summary>
        /// Deserializes
        /// </summary>
        public static ValuePathFileAccessAllowlistEntry Deserialize(BuildXLReader reader)
        {
            Contract.Requires(reader != null);

            var        state  = ReadState(reader);
            FullSymbol symbol = reader.ReadFullSymbol();

            return(new ValuePathFileAccessAllowlistEntry(
                       symbol,
                       state.PathRegex,
                       state.AllowsCaching,
                       state.Name));
        }
Пример #13
0
        /// <nodoc />
        protected void RegisterNamespaceDefinition(
            GlobalModuleLiteral globalModuleLiteral,
            AmbientNamespaceDefinition namespaceDefinition)
        {
            Contract.Requires(globalModuleLiteral != null);

            globalModuleLiteral.AddNamespace(
                FullSymbol.Create(globalModuleLiteral.SymbolTable, namespaceDefinition.Name),
                default(UniversalLocation),
                null,
                out TypeOrNamespaceModuleLiteral registeredModule);

            RegisterFunctionDefinitions(registeredModule, namespaceDefinition.FunctionDefinitions);
        }
Пример #14
0
        public bool Contains(KeyValuePair <string, TValue> item)
        {
            FullSymbol keyFullSymbol = m_symbolTable.StringToFullSymbol(item.Key);

            if (ContainsKey(keyFullSymbol))
            {
                if (this[keyFullSymbol].Equals(item.Value))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #15
0
        private void AddAllowListEntry(IFileAccessAllowlistEntry allowlistEntry, bool allowsCaching)
        {
            SerializableRegex pathRegex;
            string            regexError;

            if (string.IsNullOrEmpty(allowlistEntry.PathRegex))
            {
                if (!TryCreateAllowlistRegex(Regex.Escape(allowlistEntry.PathFragment), out pathRegex, out regexError))
                {
                    throw new BuildXLException("An allowlist regex should never fail to construct from an escaped pattern: " + regexError);
                }
            }
            else
            {
                if (!TryCreateAllowlistRegex(allowlistEntry.PathRegex, out pathRegex, out regexError))
                {
                    throw new BuildXLException("A regex should have already been validated when parsed: " + regexError);
                }
            }

            if (!string.IsNullOrEmpty(allowlistEntry.Value))
            {
                Add(
                    new ValuePathFileAccessAllowlistEntry(
                        outputValue: FullSymbol.Create(m_context.SymbolTable, allowlistEntry.Value),
                        pathRegex: pathRegex,
                        allowsCaching: allowsCaching,
                        name: allowlistEntry.Name));
            }
            else
            {
                object toolPath       = allowlistEntry.ToolPath.GetValue();
                var    executablePath =
                    toolPath switch
                {
                    FileArtifact file => new DiscriminatingUnion <AbsolutePath, PathAtom>(file.Path),
                    PathAtom toolName => new DiscriminatingUnion <AbsolutePath, PathAtom>(toolName),
                    _ => null,
                };

                Contract.RequiresNotNull(executablePath);

                Add(
                    new ExecutablePathAllowlistEntry(
                        executable: executablePath,
                        pathRegex: pathRegex,
                        allowsCaching: allowsCaching,
                        name: allowlistEntry.Name));
            }
        }
Пример #16
0
 /// <summary>
 /// Creates a ValueDependency
 /// </summary>
 public ValueDependency(
     FullSymbol parentIdentifier,
     QualifierId parentQualifier,
     LocationData parentLocation,
     FullSymbol childIdentifier,
     QualifierId childQualifier,
     LocationData childLocation)
 {
     ParentIdentifier = parentIdentifier;
     ParentQualifier  = parentQualifier;
     ChildIdentifier  = childIdentifier;
     ChildQualifier   = childQualifier;
     ParentLocation   = parentLocation;
     ChildLocation    = childLocation;
 }
Пример #17
0
        /// <summary>
        /// Evaluates a member using by resolving a symbol by a full name.
        /// </summary>
        /// <remarks>
        /// DScript V2 feature.
        /// </remarks>
        internal EvaluationResult EvaluateEntryByFullName(Context context, FullSymbol fullName, LineInfo location)
        {
            ResolvedEntry resolvedEntry = default(ResolvedEntry);

            if (CurrentFileModule?.TryGetResolvedEntryByFullName(fullName, out resolvedEntry) == true)
            {
                return(EvaluateResolvedSymbol(context, this, location, resolvedEntry));
            }

            // This is an assertion but not a graceful error, because resolution may fail only if something went wrong.
            string message = I($"Can't find resolved symbol by a full name '{fullName.ToString(context.FrontEndContext.SymbolTable)}'");

            Contract.Assert(false, message);

            return(EvaluationResult.Undefined);
        }
Пример #18
0
        public void IsValidIdChar()
        {
            XAssert.IsTrue(FullSymbol.IsValidAbsoluteIdChar('a'));
            XAssert.IsTrue(FullSymbol.IsValidAbsoluteIdChar('z'));
            XAssert.IsTrue(FullSymbol.IsValidAbsoluteIdChar('A'));
            XAssert.IsTrue(FullSymbol.IsValidAbsoluteIdChar('Z'));
            XAssert.IsTrue(FullSymbol.IsValidAbsoluteIdChar('0'));
            XAssert.IsTrue(FullSymbol.IsValidAbsoluteIdChar('9'));

            XAssert.IsFalse(FullSymbol.IsValidAbsoluteIdChar('\\'));
            XAssert.IsFalse(FullSymbol.IsValidAbsoluteIdChar('/'));
            XAssert.IsFalse(FullSymbol.IsValidAbsoluteIdChar(':'));

            XAssert.IsFalse(FullSymbol.IsValidAbsoluteIdChar('.'));
            XAssert.IsFalse(FullSymbol.IsValidAbsoluteIdChar('?'));
        }
Пример #19
0
        /// <inheritdoc />
        public override FullSymbol ReadFullSymbol()
        {
            var alternateSymbolSeparator = ReadChar();

            if (alternateSymbolSeparator == default)
            {
                return(FullSymbol.Create(m_pipExecutionContext.SymbolTable, ReadString()));
            }
            else
            {
                OptimizedSymbols++;
                var segments = ReadArray(r => r.ReadStringId());
                var id       = m_pipExecutionContext.SymbolTable.AddComponents(HierarchicalNameId.Invalid, segments);
                return(new FullSymbol(id, alternateSymbolSeparator));
            }
        }
Пример #20
0
        /// <nodoc />
        public void ReportMissingNamespace(ModuleLiteral env, FullSymbol name, ModuleLiteral relatedEnv, LineInfo lineInfo)
        {
            Contract.Requires(env != null);
            Contract.Requires(name.IsValid);
            Contract.Requires(relatedEnv != null);
            var relatedLocation = relatedEnv.Location.AsLoggingLocation(relatedEnv, Context).ToDisplayString();
            var relatedMessage  = env == relatedEnv ? string.Empty : I($", related location '{relatedLocation}'");

            var location = lineInfo.AsUniversalLocation(env, Context);

            Logger.ReportMissingNamespace(
                LoggingContext,
                location.AsLoggingLocation(),
                name.ToDisplayString(Context),
                relatedMessage,
                Context.GetStackTraceAsErrorMessage(location));
        }
Пример #21
0
 private CompositeGraphFingerprint CreateRandomWithModulesAndValues(string[] modules, string[] valueNames)
 {
     return(new CompositeGraphFingerprint()
     {
         OverallFingerprint = new ContentFingerprint(Fingerprint.Random(33)),
         FilterHash = Fingerprint.Random(33),
         EvaluationFilter = new EvaluationFilter(
             m_symbolTable,
             m_pathTable,
             valueNames.Select(vn => FullSymbol.Create(this.m_symbolTable, new StringSegment(vn))).ToArray(),
             new AbsolutePath[0],
             modules.Select(m => StringId.Create(this.m_pathTable.StringTable, m)).ToArray()),
         BuildEngineHash = FingerprintUtilities.ZeroFingerprint,
         ConfigFileHash = FingerprintUtilities.ZeroFingerprint,
         QualifierHash = FingerprintUtilities.ZeroFingerprint,
     });
 }
Пример #22
0
        /// <nodoc />
        public TopLevelValueInfo(
            Thunk activeThunk,
            FullSymbol valueName,
            AbsolutePath specFile,
            LineInfo valueDeclarationLineInfo,
            object templateValue)
        {
            Contract.Requires(activeThunk != null);
            Contract.Requires(valueName.IsValid);
            Contract.Requires(specFile.IsValid);

            ActiveThunk = activeThunk;
            ValueName   = valueName;
            SpecFile    = specFile;
            ValueDeclarationLineInfo = valueDeclarationLineInfo;
            CapturedTemplateValue    = templateValue;
        }
Пример #23
0
 /// <summary>
 /// Class constructor.
 /// </summary>
 public PipProvenance(
     long semiStableHash,
     ModuleId moduleId,
     StringId moduleName,
     FullSymbol outputValueSymbol,
     LocationData token,
     QualifierId qualifierId,
     PipData usage)
 {
     SemiStableHash    = semiStableHash;
     ModuleId          = moduleId;
     ModuleName        = moduleName;
     OutputValueSymbol = outputValueSymbol;
     Token             = token;
     QualifierId       = qualifierId;
     Usage             = usage;
 }
Пример #24
0
        /// <summary>
        /// Adds a callback for a particular symbol that will be called
        /// at evaluation time when that symbol is evaluated.
        /// </summary>
        /// <remarks>
        /// Useful for programmatically executing customized evaluation for non-DScript
        /// resolvers
        /// </remarks>
        public static void AddEvaluationCallbackToFileModule(
            FileModuleLiteral fileModule,
            Func <Context, ModuleLiteral, EvaluationStackFrame, Task <EvaluationResult> > evaluationCallback,
            FullSymbol symbol,
            int position)
        {
            var sourceFilePath = fileModule.Path;

            var outputResolvedEntry = new ResolvedEntry(
                symbol,
                (Context context, ModuleLiteral env, EvaluationStackFrame args) => evaluationCallback(context, env, args),
                // The following position is a contract right now with he generated ast in the workspace resolver
                // we have to find a nicer way to handle and register these.
                TypeScript.Net.Utilities.LineInfo.FromLineAndPosition(0, position)
                );

            fileModule.AddResolvedEntry(symbol, outputResolvedEntry);
            fileModule.AddResolvedEntry(new FilePosition(position, sourceFilePath), outputResolvedEntry);
        }
Пример #25
0
        /// <summary>
        /// Creates a mutable named child context.
        /// </summary>
        /// <remarks>
        /// Until all mutable child contexts have been disposed, no mutations are allowed on the current context.
        /// </remarks>
        public Context CreateWithName(Thunk activeThunk, FullSymbol name, ModuleLiteral module, object templateValue, LineInfo location)
        {
            Contract.Requires(name.IsValid);
            Contract.Requires(module != null);

            var topLevelValueState = new TopLevelValueInfo(
                activeThunk,
                name,
                module.Path,
                location,
                templateValue);

            return(new Context(
                       ContextTree,
                       this,
                       module,
                       topLevelValueState,
                       FileType,
                       EvaluatorConfiguration,
                       EvaluationScheduler));
        }
Пример #26
0
        internal static PipProvenance Deserialize(PipReader reader)
        {
            Contract.Requires(reader != null);

            long         semiStableHash  = reader.ReadInt64();
            ModuleId     moduleId        = reader.ReadModuleId();
            StringId     moduleName      = reader.ReadStringId();
            FullSymbol   outputValueName = reader.ReadFullSymbol();
            LocationData token           = reader.ReadLocationData();
            QualifierId  qualifierId     = new QualifierId(reader.ReadInt32Compact());
            PipData      usage           = reader.ReadPipData();

            return(new PipProvenance(
                       semiStableHash,
                       moduleId,
                       moduleName,
                       outputValueName,
                       token,
                       qualifierId,
                       usage));
        }
Пример #27
0
 /// <summary>
 /// Helper method with defaults for convenient creation from unit tests
 /// </summary>
 public static PipConstructionHelper CreateForTesting(
     PipExecutionContext context,
     AbsolutePath?objectRoot = null,
     AbsolutePath?tempRoot   = null,
     string moduleName       = null,
     string specRelativePath = null,
     string symbol           = null,
     AbsolutePath?specPath   = null,
     QualifierId?qualifierId = null)
 {
     return(Create(
                context,
                objectRoot ?? AbsolutePath.Create(context.PathTable, "d:\\test\\obj"),
                tempRoot ?? objectRoot ?? AbsolutePath.Create(context.PathTable, "d:\\test\\tmp"),
                new ModuleId(1),
                moduleName ?? "TestModule",
                RelativePath.Create(context.StringTable, specRelativePath ?? "spec"),
                FullSymbol.Create(context.SymbolTable, symbol ?? "testValue"),
                new LocationData(specPath ?? AbsolutePath.Create(context.PathTable, "d:\\src\\spec.dsc"), 0, 0),
                qualifierId ?? QualifierId.Unqualified));
 }
Пример #28
0
        public void Combine()
        {
            var        idt = new SymbolTable();
            FullSymbol a1  = FullSymbol.Create(idt, @"C");
            SymbolAtom p1  = SymbolAtom.Create(idt.StringTable, "A");
            FullSymbol a2  = a1.Combine(idt, p1);

            XAssert.AreEqual(@"C.A", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            p1 = SymbolAtom.Create(idt.StringTable, "A");
            a2 = a1.Combine(idt, p1);
            XAssert.AreEqual(@"C.X.A", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            p1 = SymbolAtom.Create(idt.StringTable, "A");
            SymbolAtom p2 = SymbolAtom.Create(idt.StringTable, "B");

            a2 = a1.Combine(idt, p1, p2);
            XAssert.AreEqual(@"C.X.A.B", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            p1 = SymbolAtom.Create(idt.StringTable, "A");
            p2 = SymbolAtom.Create(idt.StringTable, "B");
            SymbolAtom p3 = SymbolAtom.Create(idt.StringTable, "C");

            a2 = a1.Combine(idt, p1, p2, p3);
            XAssert.AreEqual(@"C.X.A.B.C", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C");
            PartialSymbol rp = PartialSymbol.Create(idt.StringTable, @"A.B");

            a2 = a1.Combine(idt, rp);
            XAssert.AreEqual(@"C.A.B", a2.ToString(idt));

            a1 = FullSymbol.Create(idt, @"C.X");
            rp = PartialSymbol.Create(idt.StringTable, @"A.B");
            a2 = a1.Combine(idt, rp);
            XAssert.AreEqual(@"C.X.A.B", a2.ToString(idt));
        }
Пример #29
0
        private void AddWhiteListEntry(IFileAccessWhitelistEntry whitelistEntry, bool allowsCaching)
        {
            SerializableRegex pathRegex;
            string            regexError;

            if (string.IsNullOrEmpty(whitelistEntry.PathRegex))
            {
                if (!TryCreateWhitelistRegex(Regex.Escape(whitelistEntry.PathFragment), out pathRegex, out regexError))
                {
                    throw new BuildXLException("A whitelist regex should never fail to construct from an escaped pattern: " + regexError);
                }
            }
            else
            {
                if (!TryCreateWhitelistRegex(whitelistEntry.PathRegex, out pathRegex, out regexError))
                {
                    throw new BuildXLException("A regex should have already been validated when parsed: " + regexError);
                }
            }

            if (!string.IsNullOrEmpty(whitelistEntry.Value))
            {
                Add(
                    new ValuePathFileAccessWhitelistEntry(
                        outputValue: FullSymbol.Create(m_context.SymbolTable, whitelistEntry.Value),
                        pathRegex: pathRegex,
                        allowsCaching: allowsCaching,
                        name: whitelistEntry.Name));
            }
            else
            {
                Add(
                    new ExecutablePathWhitelistEntry(
                        executablePath: whitelistEntry.ToolPath,
                        pathRegex: pathRegex,
                        allowsCaching: allowsCaching,
                        name: whitelistEntry.Name));
            }
        }
Пример #30
0
        public AstConversionContext(
            RuntimeModelContext runtimeModelContext,
            AbsolutePath currentSpecPath,
            ISourceFile currentSourceFile,
            FileModuleLiteral currentFileModule)
        {
            RuntimeModelContext = runtimeModelContext;
            CurrentSpecPath     = currentSpecPath;
            CurrentSourceFile   = currentSourceFile;
            CurrentFileModule   = currentFileModule;

            QualifierDeclarationKeyword = CreateSymbol(Constants.Names.CurrentQualifier);
            WithQualifierKeyword        = CreateSymbol(Constants.Names.WithQualifierFunction);
            UndefinedLiteral            = CreateSymbol(Constants.Names.Undefined);
            LegacyPackageKeyword        = CreateSymbol(Constants.Names.LegacyModuleConfigurationFunctionCall);
            ModuleKeyword              = CreateSymbol(Constants.Names.ModuleConfigurationFunctionCall);
            TemplateReference          = CreateSymbol(Constants.Names.TemplateReference);
            RuntimeRootNamespaceSymbol = CreateSymbol(Constants.Names.RuntimeRootNamespaceAlias);

            UnsafeNamespace         = CreateFullSymbol(Constants.Names.UnsafeNamespace);
            UnsafeOutputFile        = CreateSymbol(Constants.Names.UnsafeOutputFile);
            UnsafeExOutputDirectory = CreateSymbol(Constants.Names.UnsafeExOutputDirectory);
        }