public void GetName() { var st = new StringTable(0); PartialSymbol rp = PartialSymbol.Create(st, @"AAA"); SymbolAtom atom = rp.GetName(); XAssert.AreEqual(@"AAA", atom.ToString(st)); rp = PartialSymbol.Create(st, @"AAA.BBB"); atom = rp.GetName(); XAssert.AreEqual(@"BBB", atom.ToString(st)); }
/// <nodoc /> public PackageDeclaration( SymbolAtom packageKeyword, IReadOnlyList <Expression> packageExpressions, LineInfo location) : base(DeclarationFlags.None, location) { Contract.Requires(packageKeyword.IsValid); Contract.Requires(packageExpressions != null); Contract.RequiresForAll(packageExpressions, p => p != null); PackageKeyword = packageKeyword; PackageExpressions = packageExpressions; }
/// <summary> /// Resolves and returns a bound member for receiver and a specified name. /// </summary> public CallableValue <T> ResolveMember(T receiver, SymbolAtom name) { Contract.Requires(receiver != null); Contract.Requires(name.IsValid); if (m_callableMembersFast.TryGetValue(name.StringId.Value, out CallableMember <T> result)) { return(result.Bind(receiver)); } // Member is not found! return(null); }
/// <nodoc /> protected CallableMember(FunctionStatistic statistic, SymbolAtom name, short minArity, short maxArity, bool rest) : base(location: default(LineInfo)) { Contract.Requires(minArity >= 0); Contract.Requires(maxArity >= 0); Contract.Requires(minArity <= maxArity); Name = name; MinArity = minArity; MaxArity = maxArity; Rest = rest; Statistic = statistic; }
private CommandLineArgumentsConverter(StringTable stringTable) { Contract.Requires(stringTable != null); m_stringTable = stringTable; m_argumentNameField = Create("name"); m_argumentValueField = Create("value"); m_artifactPathField = Create("path"); m_artifactKindField = Create("kind"); m_artifactOriginalField = Create("original"); m_primitiveArgumentValueField = Create("value"); m_primitiveArgumentKindField = Create("kind"); m_listArgumentValuesField = Create("values"); m_listArgumentSeparatorField = Create("separator"); }
/// <nodoc /> public void ReportMissingProperty(ModuleLiteral env, SymbolAtom selector, object receiver, LineInfo lineInfo) { Contract.Requires(env != null); Contract.Requires(receiver != null); var locationForLogging = lineInfo.AsUniversalLocation(env, Context); Logger.ReportMissingInstanceMember( LoggingContext, locationForLogging.AsLoggingLocation(), selector.ToDisplayString(Context), receiver.GetType().ToDisplayString(Context), Context.GetStackTraceAsString(locationForLogging)); }
/// <summary> /// Tries to project this expression based on the given name. /// </summary> /// <remarks> /// This method returns true if the kind of expression is eligible for projection. /// The returned value can be undefined though. /// </remarks> public virtual bool TryProject( Context context, SymbolAtom name, ModuleLiteral origin, out EvaluationResult result, LineInfo location) { Contract.Requires(context != null); Contract.Requires(name.IsValid); Contract.Requires(origin != null); result = EvaluationResult.Error; return(false); }
/// <nodoc /> public VarDeclaration( SymbolAtom name, Type type, Expression initializer, DeclarationFlags modifier, LineInfo location) : base(modifier, location) { Contract.Requires(name.IsValid); Name = name; Type = type; Initializer = initializer; }
/// <inheritdoc /> protected override bool IsQualifierDeclaration(IStatement statement) { return(statement.IsQualifierDeclaration(GetQualifierNameAsAtom(), Names.CurrentQualifier)); SymbolAtom GetQualifierNameAsAtom() { if (!m_qualifierNameAsAtom.IsValid) { m_qualifierNameAsAtom = SymbolAtom.Create(m_pathTable.StringTable, Names.CurrentQualifier); } return(m_qualifierNameAsAtom); } }
public static PipProvenance CreateDummy(PipExecutionContext context) { Contract.Requires(context != null); Contract.Requires(context.StringTable != null); return(new PipProvenance( new System.Random().Next(), ModuleId.Invalid, StringId.Invalid, FullSymbol.Invalid.Combine(context.SymbolTable, SymbolAtom.CreateUnchecked(context.StringTable, "<Unknown Pip>")), LocationData.Invalid, QualifierId.Unqualified, PipData.Invalid)); }
/// <summary> /// Gets the field body if exists. /// </summary> /// <remarks> /// This method does not evaluate the body of the field if exists, and moreover, does not recurs to the parent. /// </remarks> public bool TryGetField(SymbolAtom name, out object body) { ModuleBinding binding = null; // TODO:ST: sounds reasonable to add "warning" if name was resolved but it is not exposed! if (m_bindings?.TryGetValue(name, out binding) == true && binding.IsExported) { body = binding.Body; return(true); } body = null; return(false); }
/// <nodoc /> public static List <SymbolAtom> GetFullName(SymbolAtom @namespace, SymbolAtom name) { var result = new List <SymbolAtom>(); // Namespace is optional (for instance, for globR from the prelude). if (@namespace.IsValid) { result.Add(@namespace); } Contract.Assert(name.IsValid); result.Add(name); return(result); }
internal static SymbolAtom GetDelimiterSymbol(string name, SourceSpan source) { if (name == null) { return(null); } var result = SymbolAtom.GetAtom(name, source); if (!result.IsDelimeter) { return(null); } return(result); }
private void InitializeSealDirectoryNames() { m_sealRoot = Symbol("root"); m_sealFiles = Symbol("files"); m_sealTags = Symbol("tags"); m_sealDescription = Symbol("description"); m_sealInclude = Symbol("include"); m_sealPatterns = Symbol("patterns"); m_sealScrub = Symbol("scrub"); m_sealOutputDirectories = Symbol("outputDirectories"); m_sealDirectories = Symbol("directories"); m_sealDirectoryContentFilter = Symbol("contentFilter"); m_sealDirectoryContentFilterRegex = Symbol("regex"); m_sealDirectoryContentFilterKind = Symbol("kind"); }
public OverUnderDelimiter( SourceSpan source, Atom baseAtom, Atom script, SymbolAtom symbol, TexUnit kernUnit, double kern, bool over) : base(source) { this.BaseAtom = baseAtom; this.Script = script; this.Symbol = symbol; this.Kern = new SpaceAtom(null, kernUnit, 0, kern, 0); this.Over = over; }
/// <nodoc /> public VarStatement( SymbolAtom name, int index, Type type, Expression initializer, LineInfo location) : base(location) { Contract.Requires(name.IsValid); Contract.Requires(index >= 0); Name = name; Type = type; Initializer = initializer; Index = index; }
/// <summary> /// Tries to find the object literal associated to the configuration. /// Since we actually support two config keywords (the legacy one is there for compat reasons), we need to check both cases /// Returns null if the result cannot be casted to an object literal. /// </summary> private ObjectLiteral ResolveConfigObjectLiteral(ModuleLiteral instantiatedModule, Context context) { var bindings = instantiatedModule.GetAllBindings(context).ToList(); Contract.Assert(bindings.Count == 1, "Expected AstConverter to produce exactly one binding in the resulting ModuleLiteral when converting a config file"); var binding = bindings.Single(); return(instantiatedModule .GetOrEvalFieldBinding( context, SymbolAtom.Create(context.StringTable, Script.Constants.Names.ConfigurationFunctionCall), binding.Value, instantiatedModule.Location) .Value as ObjectLiteral); }
private void IntializeIpcNames() { m_ipcSendMoniker = Symbol("moniker"); m_ipcSendMessageBody = Symbol("messageBody"); m_ipcSendTargetServicePip = Symbol("targetService"); m_ipcSendOutputFile = Symbol("outputFile"); m_ipcSendDependencies = Symbol("fileDependencies"); m_ipcSendMaxConnectRetries = Symbol("maxConnectRetries"); m_ipcSendConnectRetryDelayMillis = Symbol("connectRetryDelayMillis"); m_ipcSendLazilyMaterializedDependencies = Symbol("lazilyMaterializedDependencies"); m_ipcSendMustRunOnMaster = Symbol("mustRunOnMaster"); // IpcSendResult m_ipcSendResultOutputFile = Symbol("outputFile"); m_ipcObjectFolderName = PathAtom.Create(StringTable, "ipc"); m_ipcOutputFileName = PathAtom.Create(StringTable, "results.txt"); }
/// <summary> /// Resolves a variable name by following the parent chain. /// </summary> public bool TryResolveRecursively(SymbolAtom name, out VariableDefinition definition) { definition = default(VariableDefinition); var current = this; while (current != null) { if (current.m_scope.TryGetValue(name, out definition)) { return(true); } current = current.m_parent; } return(false); }
public void PutDelimiterOver( TexDelimiter delimiter, TexFormula superscriptFormula, TexUnit kernUnit, double kern) { var name = TexFormulaParser.DelimiterNames[(int)delimiter][(int)TexDelimeterType.Over]; this.Formula.RootAtom = new OverUnderDelimiter( this.source, this.Formula.RootAtom, superscriptFormula?.RootAtom, SymbolAtom.GetAtom(name, null), kernUnit, kern, true); }
/// <inheritdoc /> public override bool TryProject(Context context, SymbolAtom name, ModuleLiteral origin, out EvaluationResult result, LineInfo location) { var value = this[name.StringId]; if (value.IsUndefined) { // TODO: Optimize this for look-up miss cases (there can be tons of them). var resolvedMember = ((ModuleRegistry)context.FrontEndHost.ModuleRegistry).PredefinedTypes.AmbientObject.ResolveMember(this, name) ?? (object)UndefinedValue.Instance; result = EvaluationResult.Create(resolvedMember); } else { result = value; } return(true); }
/// <nodoc /> public void ReportMissingMember(ModuleLiteral env, SymbolAtom name, ModuleLiteral relatedEnv, LineInfo lineInfo) { Contract.Requires(env != null); Contract.Requires(name.IsValid); 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.ReportMissingNamespaceMember( LoggingContext, location.AsLoggingLocation(), name.ToDisplayString(Context), relatedMessage, Context.GetStackTraceAsErrorMessage(location)); }
/// <summary> /// Parses, validates, and converts a given configuration file for the purpose of getting the configuration object. /// </summary> public async Task <ConfigConversionResult> ParseValidateAndConvertConfigFileAsync(AbsolutePath configPath) { var configStatistics = FrontEndStatistics.LoadConfigStatistics; using (configStatistics.TotalDuration.Start()) { Workspace workspace; using (configStatistics.ParseDuration.Start()) { workspace = await ParseAndValidateConfigFileAsync(configPath, typecheck : true); if (workspace == null) { return(new ConfigConversionResult(Logger.ErrorCount)); } } if (!workspace.Succeeded) { ReportErrorDiagnostics(workspace.GetAllParsingAndBindingErrors()); ReportErrorDiagnostics(workspace.GetSemanticModel()?.GetAllSemanticDiagnostics()); ReportConfigParsingFailed(workspace.Failures.Select(f => f.Describe())); return(new ConfigConversionResult(workspace.Failures.Count)); } // convert every spec in the workspace IReadOnlyCollection <FileModuleLiteral> convertedModules; using (configStatistics.ConversionDuration.Start()) { convertedModules = ConvertWorkspaceInParallel(workspace, configPath); if (Logger.HasErrors) { return(new ConfigConversionResult(Logger.ErrorCount)); } } configStatistics.FileCountCounter.Increment(workspace.AllSpecCount); FileModuleLiteral configModule = convertedModules.First(m => m.Path == configPath); SymbolAtom configKeyword = GetConfigKeyword(workspace.ConfigurationModule.Specs[configPath].SourceFile); return(new ConfigConversionResult(configModule, configKeyword)); } }
/// <nodoc /> public EnumDeclaration( SymbolAtom name, IReadOnlyList <EnumMemberDeclaration> enumMemberDeclarations, IReadOnlyList <Expression> decorators, DeclarationFlags modifier, LineInfo location) : base(modifier, location) { Contract.Requires(name.IsValid); Contract.Requires(enumMemberDeclarations != null); Contract.RequiresForAll(enumMemberDeclarations, e => e != null); Contract.Requires(decorators != null); Contract.RequiresForAll(decorators, e => e != null); Name = name; EnumMemberDeclarations = enumMemberDeclarations; Decorators = decorators; }
/// <summary> /// Adds a binding. /// </summary> public bool AddBinding(SymbolAtom name, ModuleBinding binding) { Contract.Requires(name.IsValid); Contract.Requires(Qualifier == QualifierValue.Unqualified); Contract.Requires(binding != null); lock (m_syncRoot) { m_bindings = m_bindings ?? new BindingDictionary(); if (m_bindings.ContainsKey(name)) { return(false); } m_bindings.Add(name, binding); } return(true); }
/// <summary> /// Evaluates given <paramref name="binding"/> that corresponds to field <paramref name="name"/> /// (<seealso cref="GetOrEvalField(Context, SymbolAtom, bool, ModuleLiteral, LineInfo)"/>) /// </summary> public EvaluationResult GetOrEvalFieldBinding(Context context, SymbolAtom name, ModuleBinding binding, LineInfo callingLocation) { object o = binding.Body; if (o is Thunk thunk) { return(GetOrEvalFieldBindingThunk(context, name, binding, thunk)); } if (o is Expression expr) { using (var frame = EvaluationStackFrame.Empty()) { return(expr.Eval(context, this, frame)); } } return(EvaluationResult.Create(o)); }
/// <nodoc /> public AmbientTesting(TestEngineAbstraction engineAbstraction, Func <IEnumerable <Diagnostic> > getDiagnostics, PrimitiveTypes knownTypes) : base("Testing", knownTypes) { Contract.Requires(engineAbstraction != null); m_engineAbstraction = engineAbstraction; m_getDiagnostics = getDiagnostics; m_testingSetMountPointName = Symbol("name"); m_testingSetMountPointPath = Symbol("path"); m_testingSetMountPointTrackSourceFileChanges = Symbol("trackSourceFileChanges"); m_testingSetMountPointIsWritable = Symbol("isWritable"); m_testingSetMountPointIsReadable = Symbol("isReadable"); m_testingSetMountPointIsSystem = Symbol("isSystem"); m_testingSetMountPointIsScrubbable = Symbol("isScrubbable"); m_testingExpectedMessageCode = Symbol("code"); m_testingExpectedMessageContent = Symbol("content"); m_testingExpectedMessageLevel = Symbol("level"); }
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); }
private static EvaluationResult MapWithState(Context context, ArrayLiteral receiver, EvaluationResult arg0, EvaluationResult arg1, EvaluationStackFrame captures) { var closure = Converter.ExpectClosure(arg0); int paramsCount = closure.Function.Params; var state = arg1; var arrays = new EvaluationResult[receiver.Length]; using (var frame = EvaluationStackFrame.Create(closure.Function, captures.Frame)) { var entry = context.TopStack; var stateName = SymbolAtom.Create(context.FrontEndContext.StringTable, "state"); var elemsName = SymbolAtom.Create(context.FrontEndContext.StringTable, "elems"); var elemName = SymbolAtom.Create(context.FrontEndContext.StringTable, "elem"); for (int i = 0; i < receiver.Length; ++i) { frame.TrySetArguments(paramsCount, state, receiver[i], i, EvaluationResult.Create(receiver)); EvaluationResult mapResult = context.InvokeClosure(closure, frame); if (mapResult.IsErrorValue) { return(EvaluationResult.Error); } if (!(mapResult.Value is ObjectLiteral objectResult)) { throw Converter.CreateException <ObjectLiteral>(mapResult, default(ConversionContext)); } arrays[i] = objectResult[elemName]; state = objectResult[stateName]; } var bindings = new List <Binding> { new Binding(elemsName, ArrayLiteral.CreateWithoutCopy(arrays, entry.InvocationLocation, entry.Path), location: default(LineInfo)), new Binding(stateName, state, location: default(LineInfo)), }; return(EvaluationResult.Create(ObjectLiteral.Create(bindings, entry.InvocationLocation, entry.Path))); } }
/// <summary> /// Creates a simulation of a local scope such that passed local variable indexes match /// </summary> private static FunctionScope BuildLocalScopeForLocalVars(Context context, StackEntry stackEntry) { var stringTable = context.StringTable; var localScope = new FunctionScope(); var localVariables = DebugInfo.ComputeCurrentLocals(stackEntry); if (localVariables.Count == 0) { return(localScope); } // Sort variables by index var localsByIndex = new SortedDictionary <int, ILocalVar>(); foreach (var localVar in localVariables) { localsByIndex[localVar.Index] = localVar; } // Construct a local scope where variable indexes are respected, filling with dummy variables if there are holes in the index range int currentIndex = 0; foreach (int index in localsByIndex.Keys) { Contract.Assert(currentIndex <= index); while (index != currentIndex) { var dummyIndex = localScope.AddVariable(SymbolAtom.Create(stringTable, "__dummy_var__" + currentIndex), default(UniversalLocation), isConstant: false); Contract.Assert(dummyIndex != null); currentIndex++; } var indexResult = localScope.AddVariable(localsByIndex[index].Name, default(UniversalLocation), isConstant: false); Contract.Assert(indexResult == index); currentIndex++; } return(localScope); }