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)); }
public void GetName() { var idt = new SymbolTable(); FullSymbol da = FullSymbol.Create(idt, @"c.a"); SymbolAtom atom = da.GetName(idt); XAssert.AreEqual(@"a", atom.ToString(idt.StringTable)); }
/// <nodoc /> public static string ToDisplayString(this SymbolAtom atom, StringTable stringTable) { if (!atom.IsValid) { return("undefined"); } return(atom.ToString(stringTable)); }
/// <summary> /// Gets the string representation of a symbol atom. /// </summary> protected static string ToDebugString(SymbolAtom name) { Contract.Requires(name.IsValid); #if DEBUG return(FrontEndContext.DebugContext != null?name.ToString(FrontEndContext.DebugContext.StringTable) : name.StringId.ToString()); #else return(name.StringId.ToString()); #endif }
/// <inheritdoc /> protected override EvaluationResult ToStringMethod(Context context, EnumValue receiver, EvaluationStackFrame captures) { // Technically, this is the violation from the typescript behavior. // In TypeScript enumValue.toString() returns the number, but DScript returns a string representation of the enum SymbolAtom name = receiver.Name; return(EvaluationResult.Create( name.IsValid ? name.ToString(context.FrontEndContext.StringTable) : receiver.Value.ToString(CultureInfo.InvariantCulture))); }
/// <nodoc /> public void ReportUnexpectedValueTypeForName( ModuleLiteral env, SymbolAtom name, string expectedTypes, EvaluationResult value, LineInfo lineInfo = default(LineInfo)) { Contract.Requires(env != null); Contract.Requires(name.IsValid); Contract.Requires(expectedTypes != null); var location = lineInfo.AsUniversalLocation(env, Context); Logger.ReportUnexpectedValueTypeForName( LoggingContext, location.AsLoggingLocation(), name.ToString(Context.FrontEndContext.SymbolTable), expectedTypes, ValueToString(value, Context), ValueTypeToString(value, Context), Context.GetStackTraceAsErrorMessage(location)); }
/// <summary> /// Gets the string representation of a name. /// </summary> public string ToString(SymbolAtom name) { return(name.ToString(SymbolTable)); }
public ObjectInfo GetObjectInfo(object context, object obj) { obj = obj is EvaluationResult evalResult ? evalResult.Value : obj; if (obj == null || IsInvalid(obj)) { return(s_nullObj); } if (obj.GetType().IsArray) { return(ArrayObjInfo(((IEnumerable)obj).Cast <object>().ToArray())); } var customResult = m_customRenderer?.Invoke(this, context, obj); if (customResult != null) { return(customResult); } return(obj switch { ScopeLocals scope => new ObjectInfo(LocalsScopeName, null, Lazy.Create(() => GetLocalsForStackEntry(scope.EvalState, scope.FrameIndex))), ScopePipGraph scope => PipGraphInfo(scope.Graph).WithPreview(PipGraphScopeName), ScopeAllModules scope => ArrayObjInfo(scope.EvaluatedModules.ToArray()).WithPreview(EvaluatedModulesScopeName), IModuleAndContext mc => GetObjectInfo(mc.Tree.RootContext, mc.Module), ObjectInfo objInf => objInf, IPipGraph graph => PipGraphInfo(graph), Pip pip => GenericObjectInfo(pip, $"<{pip.PipType}>").Build(), PipProvenance prov => ProvenanceInfo(prov), EnvironmentVariable envVar => EnvironmentVariableInfo(envVar), PipFragment pipFrag => PipFragmentInfo(context, pipFrag), Thunk thunk => thunk.Value != null?GetObjectInfo(context, thunk.Value) : new ObjectInfo("<not evaluated>"), FunctionLikeExpression lambda => LambdaInfo(lambda), Closure cls => LambdaInfo(cls.Function), SymbolAtom sym => new ObjectInfo(sym.ToString(StringTable)), StringId id => new ObjectInfo(id.ToString(StringTable)), PipId id => new ObjectInfo($"{id.Value}"), UndefinedLiteral _ => new ObjectInfo("undefined", UndefinedLiteral.Instance), UndefinedValue _ => new ObjectInfo("undefined", UndefinedValue.Instance), AbsolutePath path => new ObjectInfo($"p`{path.ToString(PathTable)}`", path), RelativePath path => new ObjectInfo($"r`{path.ToString(StringTable)}`", path), PathAtom atom => new ObjectInfo($"a`{atom.ToString(StringTable)}`", atom), FileArtifact file => new ObjectInfo($"f`{file.Path.ToString(PathTable)}`", file), DirectoryArtifact dir => new ObjectInfo($"d`{dir.Path.ToString(PathTable)}`", dir), int num => new ObjectInfo($"{num}"), uint num => new ObjectInfo($"{num}"), short num => new ObjectInfo($"{num}", (int)num), long num => new ObjectInfo($"{num}"), char ch => new ObjectInfo($"'{ch}'", ch.ToString()), string str => new ObjectInfo($"\"{str}\"", str), Enum e => new ObjectInfo($"{e.GetType().Name}.{e}", e), NumberLiteral numLit => new ObjectInfo(numLit.UnboxedValue.ToString(), numLit), Func <object> func => FuncObjInfo(func), ArraySegment <object> arrSeg => ArrayObjInfo(arrSeg), IEnumerable enu => new ObjectInfoBuilder().Preview("IEnumerable").Prop("Result", Lazy.Create <object>(() => enu.Cast <object>().ToArray())).Build(), ArrayLiteral arrLit => ArrayObjInfo(arrLit.Values.Select(v => v.Value).ToArray()).WithOriginal(arrLit), ModuleBinding binding => GetObjectInfo(context, binding.Body), ErrorValue error => ErrorValueInfo(), object o => GenericObjectInfo(o).Build(), _ => s_nullObj });