public override string ToString(bool Attributes, bool IncludePath) { var ret = (Attributes? (AttributeString + " "):"") + DTokens.GetTokenString(ClassType) + " "; if (IncludePath) { ret += GetNodePath(this, true); } else { ret += Name; } if (TemplateParameters != null && TemplateParameters.Length > 0) { ret += "("; foreach (var tp in TemplateParameters) { ret += tp.ToString() + ","; } ret = ret.TrimEnd(',') + ")"; } if (BaseClasses.Count > 0) { ret += ":"; } foreach (var c in BaseClasses) { ret += c.ToString() + ", "; } return(ret.Trim().TrimEnd(',')); }
public AbstractType Visit(DClassLike dc) { var invisibleTypeParams = GetInvisibleTypeParameters(dc); switch (dc.ClassType) { case DTokens.Struct: return(new StructType(dc, typeBase, invisibleTypeParams)); case DTokens.Union: return(new UnionType(dc, typeBase, invisibleTypeParams)); case DTokens.Interface: case DTokens.Class: return(DResolver.ResolveClassOrInterface(dc, ctxt, typeBase, false, invisibleTypeParams)); case DTokens.Template: if (dc.ContainsAttribute(DTokens.Mixin)) { return(new MixinTemplateType(dc, typeBase, invisibleTypeParams)); } return(new TemplateType(dc, typeBase, invisibleTypeParams)); default: ctxt.LogError(new ResolutionError(dc, "Unknown type (" + DTokens.GetTokenString(dc.ClassType) + ")")); return(null); } }
void AcceptType(AbstractType t) { if (t == null) { return; } if (pretty) { var aliasTag = t.Tag as TypeResolution.TypeDeclarationResolver.AliasTag; if (aliasTag != null) { sb.Append(aliasTag.typeBase != null ? aliasTag.typeBase.ToString() : aliasTag.aliasDefinition.ToString(false, false)).Append('='); } } if (t.Modifier != 0) { sb.Append(DTokens.GetTokenString(t.Modifier)).Append('('); } t.Accept(this); if (t.Modifier != 0) { sb.Append(')'); } }
public override string ToString() { var ret = "is("; if (TestedType != null) { ret += TestedType.ToString(); } if (TypeAliasIdentifierHash != 0) { ret += ' ' + TypeAliasIdentifier; } if (TypeSpecialization != null || TypeSpecializationToken != 0) { ret += (EqualityTest ? "==" : ":") + (TypeSpecialization != null ? TypeSpecialization.ToString() : // Either the specialization declaration DTokens.GetTokenString(TypeSpecializationToken)); // or the spec token } if (TemplateParameterList != null) { ret += ","; foreach (var p in TemplateParameterList) { ret += p.ToString() + ","; } } return(ret.TrimEnd(' ', ',') + ")"); }
public override string ToString() { var ret = new StringBuilder("cast("); if (IsTypeCast) { ret.Append(Type.ToString()); } else if (CastParamTokens != null && CastParamTokens.Length != 0) { foreach (var tk in CastParamTokens) { ret.Append(DTokens.GetTokenString(tk)).Append(' '); } ret.Remove(ret.Length - 1, 1); } ret.Append(')'); if (UnaryExpression != null) { ret.Append(' ').Append(UnaryExpression.ToString()); } return(ret.ToString()); }
public override string ToString() { if (ContentHash != 0 || content != null) { return(DTokens.GetTokenString(Token) + "(" + LiteralContent.ToString() + ")"); } return(DTokens.GetTokenString(Token)); }
public override string ToCode() { if (Modifier != 0) { return(DTokens.GetTokenString(Modifier) + "(" + DTokens.GetTokenString(TypeToken) + ")"); } return(DTokens.GetTokenString(TypeToken)); }
public static IEnumerable <IAttribute> TransferAttributes(DNode n) { foreach (var attr in n.Attributes) { yield return new DomAttribute() { Role = DomAttribute.Roles.Attribute, Name = DTokens.GetTokenString(attr.Token) } } ; }
public void Add(byte token) { var tokenString = DTokens.GetTokenString(token); AddItem(new CompletionItem { Kind = CompletionItemKind.Keyword, Label = tokenString, TextEdit = CalculateTextEdit(tokenString) }); }
public new string ToString() { if (Token == DTokens.PropertyAttribute) { return("@" + LiteralContent.ToString()); } if (LiteralContent != null) { return(DTokens.GetTokenString(Token) + "(" + LiteralContent.ToString() + ")"); } return(DTokens.GetTokenString(Token)); }
public TokenCompletionData(byte Token) { try { this.Token = Token; Text = DTokens.GetTokenString(Token); Description = ToolTipContentHelper.CreateToolTipContent(Text, DTokens.GetDescription(Token)); Image = DCodeCompletionSupport.GetNodeImage("keyword"); } catch (Exception ex) { ErrorLogger.Log(ex); } }
public override string ToString() { if (IsLambda) { var sb = new StringBuilder(); if (AnonymousMethod.Parameters.Count == 1 && AnonymousMethod.Parameters[0].Type == null) { sb.Append(AnonymousMethod.Parameters[0].Name); } else { sb.Append('('); foreach (INode param in AnonymousMethod.Parameters) { sb.Append(param).Append(','); } if (AnonymousMethod.Parameters.Count > 0) { sb.Remove(sb.Length - 1, 1); } sb.Append(')'); } sb.Append(" => "); if (AnonymousMethod.Body != null) { var en = AnonymousMethod.Body.SubStatements.GetEnumerator(); if (en.MoveNext() && en.Current is ReturnStatement) { sb.Append((en.Current as ReturnStatement).ReturnExpression.ToString()); } else { sb.Append(AnonymousMethod.Body.ToCode()); } en.Dispose(); } else { sb.Append("{}"); } return(sb.ToString()); } return(DTokens.GetTokenString(LiteralToken) + (AnonymousMethod.NameHash == 0 ? "" : " ") + AnonymousMethod.ToString()); }
static AbstractType HandleClassLikeMatch(DClassLike dc, ResolutionContext ctxt, object typeBase, bool canResolveBase) { AbstractType ret; UserDefinedType udt = null; var invisibleTypeParams = GetInvisibleTypeParameters(dc, ctxt); switch (dc.ClassType) { case DTokens.Struct: ret = new StructType(dc, typeBase as ISyntaxRegion, invisibleTypeParams); break; case DTokens.Union: ret = new UnionType(dc, typeBase as ISyntaxRegion, invisibleTypeParams); break; case DTokens.Class: udt = new ClassType(dc, typeBase as ISyntaxRegion, null, null, invisibleTypeParams); ret = null; break; case DTokens.Interface: udt = new InterfaceType(dc, typeBase as ISyntaxRegion, null, invisibleTypeParams); ret = null; break; case DTokens.Template: if (dc.ContainsAttribute(DTokens.Mixin)) { ret = new MixinTemplateType(dc, typeBase as ISyntaxRegion, invisibleTypeParams); } else { ret = new TemplateType(dc, typeBase as ISyntaxRegion, invisibleTypeParams); } break; default: ret = null; ctxt.LogError(new ResolutionError(dc, "Unknown type (" + DTokens.GetTokenString(dc.ClassType) + ")")); break; } if (dc.ClassType == DTokens.Class || dc.ClassType == DTokens.Interface) { ret = canResolveBase ? DResolver.ResolveBaseClasses(udt, ctxt) : udt; } return(ret); }
public override string ToString(bool Attributes, bool IncludePath) { var sb = new StringBuilder(); if (Attributes) { sb.Append(AttributeString).Append(' '); } sb.Append(DTokens.GetTokenString(ClassType)).Append(' '); sb.Append(IncludePath ? GetNodePath(this, true) : Name); if (TemplateParameters != null && TemplateParameters.Length > 0) { sb.Append('('); foreach (var tp in TemplateParameters) { if (tp != null) { sb.Append(tp.ToString()); } sb.Append(','); } if (TemplateParameters.Length > 0) { sb.Remove(sb.Length - 1, 1); } sb.Append(')'); } if (BaseClasses.Count > 0) { sb.Append(':'); foreach (var c in BaseClasses) { sb.Append(c.ToString()).Append(", "); } sb.Remove(sb.Length - 2, 2); } return(sb.ToString()); }
void S(DClassLike dc, StringBuilder sb, DeducedTypeDictionary deducedTypes = null) { AppendAttributes(dc, sb); sb.Append(DCodeToMarkup(DTokens.GetTokenString(dc.ClassType))).Append(' '); sb.Append(DCodeToMarkup(dc.Name)); AppendTemplateParams(dc, sb, -1, deducedTypes); if (dc.BaseClasses != null && dc.BaseClasses.Count != 0) { sb.AppendLine(" : "); sb.Append(" "); foreach (var bc in dc.BaseClasses) { sb.Append(' ').Append(DCodeToMarkup(bc.ToString())).Append(','); } RemoveLastChar(sb, ','); } AppendConstraint(dc, sb); }
public static TooltipInformation Generate(DMethod dm, bool isTemplateParamInsight = false, int currentParam = -1) { var tti = new TooltipInformation(); var sb = new StringBuilder("<i>("); string name; switch (dm.SpecialType) { case DMethod.MethodType.Constructor: sb.Append("Constructor"); name = dm.Parent.Name; break; case DMethod.MethodType.Destructor: sb.Append("Destructor"); name = dm.Parent.Name; break; case DMethod.MethodType.Allocator: sb.Append("Allocator"); name = dm.Parent.Name; break; default: sb.Append("Method"); name = dm.Name; break; } sb.Append(")</i> "); if (dm.Type != null) { sb.Append(dm.Type.ToString(true)); sb.Append(" "); } else if (dm.Attributes != null && dm.Attributes.Count != 0) { foreach (var attr in dm.Attributes) { var m = attr as Modifier; if (m != null && DTokens.StorageClass[m.Token]) { sb.Append(DTokens.GetTokenString(m.Token)); sb.Append(" "); break; } } } sb.Append(name); /*TODO: Show attributes? * if (dm.Attributes != null && dm.Attributes.Count > 0) * s = dm.AttributeString + ' '; */ // Template parameters if (dm.TemplateParameters != null && dm.TemplateParameters.Length > 0) { sb.Append("("); for (int i = 0; i < dm.TemplateParameters.Length; i++) { var p = dm.TemplateParameters[i]; if (isTemplateParamInsight && i == currentParam) { sb.Append("<u>"); tti.AddCategory(p.Name, p.ToString()); sb.Append(p.ToString()); sb.Append("</u>"); } else { sb.Append(p.ToString()); } if (i < dm.TemplateParameters.Length - 1) { sb.Append(","); } } sb.Append(")"); } // Parameters sb.Append("("); for (int i = 0; i < dm.Parameters.Count; i++) { var p = dm.Parameters[i] as DNode; if (!isTemplateParamInsight && i == currentParam) { sb.Append("<u>"); if (!string.IsNullOrEmpty(p.Description)) { tti.AddCategory(p.Name, p.Description); } sb.Append(p.ToString(true, false)); sb.Append("</u>"); } else { sb.Append(p.ToString(true, false)); } if (i < dm.Parameters.Count - 1) { sb.Append(","); } } sb.Append(")"); tti.SignatureMarkup = sb.ToString(); tti.SummaryMarkup = dm.Description; tti.FooterMarkup = dm.ToString(); return(tti); }
public override string ToString(bool IncludesBase) { return((IncludesBase && InnerDeclaration != null?(InnerDeclaration.ToString() + '.'):"") + DTokens.GetTokenString(Token)); }
public override string ToString() { return DTokens.GetTokenString(ForeToken) + UnaryExpression.ToString(); }
/// <summary> /// The variable's or method's base type will be resolved (if auto type, the intializer's type will be taken). /// A class' base class will be searched. /// etc.. /// </summary> public static AbstractType HandleNodeMatch( INode m, ResolverContextStack ctxt, AbstractType resultBase = null, object typeBase = null) { stackNum_HandleNodeMatch++; /* * Pushing a new scope is only required if current scope cannot be found in the handled node's hierarchy. */ bool popAfterwards = !ctxt.NodeIsInCurrentScopeHierarchy(m); if (popAfterwards) { ctxt.PushNewScope(m is IBlockNode ? (IBlockNode)m : m.Parent as IBlockNode); } //HACK: Really dirty stack overflow prevention via manually counting call depth var canResolveBaseGenerally = stackNum_HandleNodeMatch < 6; var DoResolveBaseType = canResolveBaseGenerally && !ctxt.Options.HasFlag(ResolutionOptions.DontResolveBaseClasses) && (m.Type == null || m.Type.ToString(false) != m.Name); AbstractType ret = null; // To support resolving type parameters to concrete types if the context allows this, introduce all deduced parameters to the current context if (canResolveBaseGenerally && resultBase is DSymbol) { ctxt.CurrentContext.IntroduceTemplateParameterTypes((DSymbol)resultBase); } // Only import symbol aliases are allowed to search in the parse cache if (m is ImportSymbolAlias) { var isa = (ImportSymbolAlias)m; if (isa.IsModuleAlias ? isa.Type != null : isa.Type.InnerDeclaration != null) { var mods = new List <DModule>(); var td = isa.IsModuleAlias ? isa.Type : isa.Type.InnerDeclaration; foreach (var mod in ctxt.ParseCache.LookupModuleName(td.ToString())) { mods.Add(mod as DModule); } if (mods.Count == 0) { ctxt.LogError(new NothingFoundError(isa.Type)); } else if (mods.Count > 1) { var m__ = new List <ISemantic>(); foreach (var mod in mods) { m__.Add(new ModuleSymbol(mod, isa.Type)); } ctxt.LogError(new AmbiguityError(isa.Type, m__)); } var bt = mods.Count != 0 ? (AbstractType) new ModuleSymbol(mods[0], td) : null; //TODO: Is this correct behaviour? if (!isa.IsModuleAlias) { var furtherId = ResolveFurtherTypeIdentifier(isa.Type.ToString(false), new[] { bt }, ctxt, isa.Type); ctxt.CheckForSingleResult(furtherId, isa.Type); if (furtherId != null && furtherId.Length != 0) { bt = furtherId[0]; } else { bt = null; } } ret = new AliasedType(isa, bt, isa.Type); } } else if (m is DVariable) { var v = (DVariable)m; AbstractType bt = null; if (DoResolveBaseType) { var bts = TypeDeclarationResolver.Resolve(v.Type, ctxt); if (bts != null && bts.Length != 0 && ctxt.CheckForSingleResult(bts, v.Type)) { bt = bts[0]; } // For auto variables, use the initializer to get its type else if (v.Initializer != null) { bt = ExpressionSemantics.Evaluation.EvaluateType(v.Initializer, ctxt); } // Check if inside an foreach statement header if (bt == null && ctxt.ScopedStatement != null) { bt = GetForeachIteratorType(v, ctxt); } } // Note: Also works for aliases! In this case, we simply try to resolve the aliased type, otherwise the variable's base type ret = v.IsAlias ? (DSymbol) new AliasedType(v, bt, typeBase as ISyntaxRegion) : new MemberSymbol(v, bt, typeBase as ISyntaxRegion); } else if (m is DMethod) { ret = new MemberSymbol((DNode)m, DoResolveBaseType ? GetMethodReturnType((DMethod)m, ctxt) : null , typeBase as ISyntaxRegion); } else if (m is DClassLike) { UserDefinedType udt = null; var dc = (DClassLike)m; var invisibleTypeParams = new Dictionary <string, TemplateParameterSymbol>(); /* * Add 'superior' template parameters to the current symbol because the parameters * might be re-used in the nested class. */ var tStk = new Stack <ResolverContext>(); do { var curCtxt = ctxt.Pop(); tStk.Push(curCtxt); foreach (var kv in curCtxt.DeducedTemplateParameters) { if (!dc.ContainsTemplateParameter(kv.Key) && !invisibleTypeParams.ContainsKey(kv.Key)) { invisibleTypeParams.Add(kv.Key, kv.Value); } } } while (ctxt.PrevContextIsInSameHierarchy); while (tStk.Count != 0) { ctxt.Push(tStk.Pop()); } switch (dc.ClassType) { case DTokens.Struct: ret = new StructType(dc, typeBase as ISyntaxRegion, invisibleTypeParams); break; case DTokens.Union: ret = new UnionType(dc, typeBase as ISyntaxRegion, invisibleTypeParams); break; case DTokens.Class: udt = new ClassType(dc, typeBase as ISyntaxRegion, null, null, invisibleTypeParams); break; case DTokens.Interface: udt = new InterfaceType(dc, typeBase as ISyntaxRegion, null, invisibleTypeParams); break; case DTokens.Template: ret = new TemplateType(dc, typeBase as ISyntaxRegion, invisibleTypeParams); break; default: ctxt.LogError(new ResolutionError(m, "Unknown type (" + DTokens.GetTokenString(dc.ClassType) + ")")); break; } if (dc.ClassType == DTokens.Class || dc.ClassType == DTokens.Interface) { if (canResolveBaseGenerally && !ctxt.Options.HasFlag(ResolutionOptions.DontResolveBaseClasses)) { ret = DResolver.ResolveBaseClasses(udt, ctxt); } else { ret = udt; } } } else if (m is IAbstractSyntaxTree) { var mod = (IAbstractSyntaxTree)m; if (typeBase != null && typeBase.ToString() != mod.ModuleName) { var pack = ctxt.ParseCache.LookupPackage(typeBase.ToString()).First(); if (pack != null) { ret = new PackageSymbol(pack, typeBase as ISyntaxRegion); } } else { ret = new ModuleSymbol(m as DModule, typeBase as ISyntaxRegion); } } else if (m is DEnum) { ret = new EnumType((DEnum)m, typeBase as ISyntaxRegion); } else if (m is TemplateParameterNode) { //ResolveResult[] templateParameterType = null; //TODO: Resolve the specialization type //var templateParameterType = TemplateInstanceHandler.ResolveTypeSpecialization(tmp, ctxt); ret = new TemplateParameterSymbol((TemplateParameterNode)m, null, typeBase as ISyntaxRegion); } if (canResolveBaseGenerally && resultBase is DSymbol) { ctxt.CurrentContext.RemoveParamTypesFromPreferredLocals((DSymbol)resultBase); } if (popAfterwards) { ctxt.Pop(); } stackNum_HandleNodeMatch--; return(ret); }
public override string ToString(bool IncludesBase) { return((IncludesBase && InnerDeclaration != null ? (InnerDeclaration.ToString() + " ") : "") + DTokens.GetTokenString(Modifier) + "(" + (InnerType != null ? InnerType.ToString() : "") + ")"); }
/// <summary> /// Adds a token entry /// </summary> public void Add(byte Token) { addExpansion(DTokens.GetTokenString(Token), "KW", ""); }
public override string ToCode() { return(DTokens.GetTokenString(Token) + "=" + (SpecifiedValue != null?SpecifiedValue.ToString():"")); }
public static string GeneratePrototype(DMethod dm, bool isTemplateParamInsight = false, int currentParam = -1) { var sb = new StringBuilder(""); string name; switch (dm.SpecialType) { case DMethod.MethodType.Constructor: sb.Append("Constructor"); name = dm.Parent.Name; break; case DMethod.MethodType.Destructor: sb.Append("Destructor"); name = dm.Parent.Name; break; case DMethod.MethodType.Allocator: sb.Append("Allocator"); name = dm.Parent.Name; break; default: sb.Append("Method"); name = dm.Name; break; } sb.Append(" in "); sb.Append(AbstractNode.GetNodePath(dm, false)); sb.Append(": "); if (dm.Attributes != null && dm.Attributes.Count > 0) { sb.Append(dm.AttributeString + ' '); } if (dm.Type != null) { sb.Append(dm.Type.ToString(true)); sb.Append(" "); } else if (dm.Attributes != null && dm.Attributes.Count != 0) { foreach (var attr in dm.Attributes) { var m = attr as Modifier; if (m != null && DTokens.StorageClass[m.Token]) { sb.Append(DTokens.GetTokenString(m.Token)); sb.Append(" "); break; } } } sb.Append(name); // Template parameters if (dm.TemplateParameters != null && dm.TemplateParameters.Length > 0) { sb.Append("("); for (int i = 0; i < dm.TemplateParameters.Length; i++) { var p = dm.TemplateParameters[i]; if (isTemplateParamInsight && i == currentParam) { sb.Append(p.ToString()); } else { sb.Append(p.ToString()); } if (i < dm.TemplateParameters.Length - 1) { sb.Append(","); } } sb.Append(")"); } // Parameters sb.Append("("); for (int i = 0; i < dm.Parameters.Count; i++) { var p = dm.Parameters[i] as DNode; if (!isTemplateParamInsight && i == currentParam) { sb.Append(p.ToString(true, false)); } else { sb.Append(p.ToString(true, false)); } if (i < dm.Parameters.Count - 1) { sb.Append(","); } } sb.Append(")"); return(sb.ToString()); }
public void VisitPrimitiveType(PrimitiveType t) { sb.Append(DTokens.GetTokenString(t.TypeToken)); }
public TokenCompletionData(int Token) { this.Token = Token; CompletionText = DisplayText = DTokens.GetTokenString(Token); Description = DTokens.GetDescription(Token); }
public TokenCompletionData(byte Token) { this.Token = Token; CompletionText = DisplayText = DTokens.GetTokenString(Token); }
public override string ToString() { return(string.Format("[Node: inside={0}, keyword={1}, indent={2}, nSpaces={3}, lineNr={4}]", inside, DTokens.GetTokenString(keyword), indent, nSpaces, lineNr)); }
public override string ToString() { return(LeftOperand.ToString() + DTokens.GetTokenString(OperatorToken) + (RightOperand != null ? RightOperand.ToString() : "")); }
public override string ToString() { return(DTokens.GetTokenString(Token)); }