예제 #1
0
        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(' ', ',') + ")");
        }
예제 #2
0
        static bool IsBlockKw(byte tk)
        {
            switch (tk)
            {
            case DTokens.Enum:

            case DTokens.Alias:
            case DTokens.This:                     // ctor

            case DTokens.If:
            case DTokens.Static:
            case DTokens.Assert:
            case DTokens.Mixin:
            case DTokens.Import:
            case DTokens.Module:
            case DTokens.Unittest:
            case DTokens.New:
            case DTokens.Version:
            case DTokens.Debug:
                return(true);

            default:
                return(DTokens.IsBasicType(tk) ||
                       DTokens.IsClassLike(tk) ||
                       DTokens.IsStorageClass(tk) || DTokens.IsParamModifier(tk) ||
                       DTokens.IsVisibilityModifier(tk));
            }
        }
예제 #3
0
        public static bool IsCompletionAllowed(IEditorData Editor, char enteredChar)
        {
            if (Editor.CaretOffset > 0)
            {
                if (Editor.CaretLocation.Line == 1 && Editor.ModuleCode.Length > 0 && Editor.ModuleCode[0] == '#')
                {
                    return(false);
                }

                if (enteredChar == '.' || enteredChar == '_')
                {
                    // Don't complete on a double/multi-dot
                    if (Editor.CaretOffset > 1 && Editor.ModuleCode[Editor.CaretOffset - 2] == enteredChar)
                    {
                        // ISSUE: When a dot was typed, off-1 is the dot position,
                        // if a letter was typed, off-1 is the char before the typed letter..
                        return(false);
                    }
                }
                // If typing a begun identifier, return immediately
                else if ((DTokens.IsIdentifierChar(enteredChar) || enteredChar == '\0') &&
                         DTokens.IsIdentifierChar(Editor.ModuleCode[Editor.CaretOffset - 1]))
                {
                    return(false);
                }

                return(!CaretContextAnalyzer.IsInCommentAreaOrString(Editor.ModuleCode, Editor.CaretOffset));
            }

            return(true);
        }
예제 #4
0
        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());
        }
예제 #5
0
            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);
                }
            }
예제 #6
0
파일: DModule.cs 프로젝트: nazriel/Mono-D
        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(','));
        }
예제 #7
0
        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(')');
            }
        }
예제 #8
0
파일: Attribute.cs 프로젝트: Orvid/D_Parser
 public override string ToString()
 {
     if (ContentHash != 0 || content != null)
     {
         return(DTokens.GetTokenString(Token) + "(" + LiteralContent.ToString() + ")");
     }
     return(DTokens.GetTokenString(Token));
 }
예제 #9
0
파일: DType.cs 프로젝트: windygu/DSharp
        public override string ToCode()
        {
            if (Modifier != 0)
            {
                return(DTokens.GetTokenString(Modifier) + "(" + DTokens.GetTokenString(TypeToken) + ")");
            }

            return(DTokens.GetTokenString(TypeToken));
        }
 bool EnsureIntegralType(IExpression x, PrimitiveValue v)
 {
     if (!DTokens.IsBasicType_Integral(v.BaseTypeToken))
     {
         EvalError(x, "Literal must be of integral type", new[] { (ISemantic)v });
         return(false);
     }
     return(true);
 }
예제 #11
0
        // Check to see if linebuf contains a keyword we're interested in (not all keywords)
        byte WordIsKeyword()
        {
            var kw = DTokens.GetTokenID(linebuf.ToString(wordStart, Math.Min(linebuf.Length - wordStart, 15)));

            if (interestingKeywords[kw])
            {
                return(kw);
            }
            return(DTokens.INVALID);
        }
예제 #12
0
        public override TooltipInformation CreateTooltipInformation(bool smartWrap)
        {
            var tti = new TooltipInformation();

            tti.SignatureMarkup = DisplayText;

            tti.SummaryMarkup = DTokens.GetDescription(Token);

            return(tti);
        }
예제 #13
0
파일: Attribute.cs 프로젝트: Orvid/D_Parser
 /// <summary>
 /// Removes all public,private,protected or package attributes from the list
 /// </summary>
 public static void CleanupAccessorAttributes(List <DAttribute> HayStack)
 {
     foreach (var i in HayStack.ToArray())
     {
         if (i is Modifier && DTokens.IsVisibilityModifier(((Modifier)i).Token))
         {
             HayStack.Remove(i);
         }
     }
 }
예제 #14
0
        public ISymbolValue VisitArrayType(ArrayType t)
        {
            var valueType          = DResolver.StripMemberSymbols(t.ValueType);
            var primitiveValueType = valueType as PrimitiveType;

            ulong arraySize;
            ulong firstElement;

            var arrSymb = Symbol as IDBacktraceArraySymbol;

            if (arrSymb != null)
            {
                arraySize    = (ulong)arrSymb.ArrayLength;
                firstElement = arrSymb.FirstElementOffset;
            }
            else
            {
                if (Symbol.Offset == 0)
                {
                    return(new NullValue(t));
                }

                byte[] arrayInfo = Backtrace.BacktraceHelper.ReadBytes(Symbol.Offset, PointerSize * 2);
                arraySize    = PointerSize == 8 ? BitConverter.ToUInt64(arrayInfo, 0) : (ulong)BitConverter.ToUInt32(arrayInfo, 0);
                firstElement = PointerSize == 8 ? BitConverter.ToUInt64(arrayInfo, 8) : BitConverter.ToUInt32(arrayInfo, 4);
            }

            arraySize = Math.Min(arraySize, DLocalExamBacktrace.MaximumArrayChildrenDisplayCount);

            if (firstElement == 0)
            {
                return(new NullValue(t));
            }

            var values = new List <ISymbolValue>();

            if (primitiveValueType != null)
            {
                var tt        = primitiveValueType.TypeToken;
                var sz        = ExamHelpers.SizeOf(tt, Is64Bit);
                var charBytes = Backtrace.BacktraceHelper.ReadBytes(firstElement, sz * arraySize);

                if (DTokens.IsBasicType_Character(tt))
                {
                    return(new ArrayValue(t, ExamHelpers.GetStringValue(charBytes, tt)));
                }

                for (uint i = 0; i < arraySize; i++)
                {
                    values.Add(new PrimitiveValue(ExamHelpers.GetNumericValue(charBytes, (int)i * sz, tt), primitiveValueType));
                }
            }

            return(new ArrayValue(t, values.ToArray()));
        }
예제 #15
0
파일: Attribute.cs 프로젝트: Orvid/D_Parser
 public static bool ContainsAccessorAttribute(Stack <DAttribute> HayStack)
 {
     foreach (var i in HayStack)
     {
         if (i is Modifier && DTokens.IsVisibilityModifier(((Modifier)i).Token))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #16
0
        public void Add(byte token)
        {
            var tokenString = DTokens.GetTokenString(token);

            AddItem(new CompletionItem
            {
                Kind     = CompletionItemKind.Keyword,
                Label    = tokenString,
                TextEdit = CalculateTextEdit(tokenString)
            });
        }
예제 #17
0
 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)
                }
     }
     ;
 }
예제 #18
0
        public static PrimitiveType Resolve(DTokenDeclaration token)
        {
            var tk = (token as DTokenDeclaration).Token;

            if (DTokens.IsBasicType(tk))
            {
                return(new PrimitiveType(tk, 0, token));
            }

            return(null);
        }
예제 #19
0
 public new string ToString()
 {
     if (Token == DTokens.PropertyAttribute)
     {
         return("@" + LiteralContent.ToString());
     }
     if (LiteralContent != null)
     {
         return(DTokens.GetTokenString(Token) + "(" + LiteralContent.ToString() + ")");
     }
     return(DTokens.GetTokenString(Token));
 }
예제 #20
0
        static PropOwnerType GetOwnerType(ISemantic t)
        {
            if (t is TypeValue)
            {
                t = (t as TypeValue).RepresentedType;
            }

            if (t is ArrayValue || t is ArrayType)
            {
                return(PropOwnerType.Array);
            }
            else if (t is AssociativeArrayValue || t is AssocArrayType)
            {
                return(PropOwnerType.AssocArray);
            }
            else if (t is DelegateValue || t is DelegateType)
            {
                return(PropOwnerType.Delegate);
            }
            else if (t is PrimitiveValue || t is PrimitiveType)
            {
                var tk = t is PrimitiveType ? (t as PrimitiveType).TypeToken : (t as PrimitiveValue).BaseTypeToken;
                if (DTokens.IsBasicType_Integral(tk))
                {
                    return(PropOwnerType.Integral);
                }
                if (DTokens.IsBasicType_FloatingPoint(tk))
                {
                    return(PropOwnerType.FloatingPoint);
                }
            }
            else if (t is InstanceValue || t is ClassType || t is InterfaceType || t is TemplateType || t is StructType)
            {
                return(PropOwnerType.ClassLike);
            }
            else if (t is DTuple)
            {
                return(PropOwnerType.TypeTuple);
            }
            else if (t is TemplateParameterSymbol)
            {
                var tps = t as TemplateParameterSymbol;
                if (tps != null &&
                    (tps.Parameter is TemplateThisParameter ?
                     (tps.Parameter as TemplateThisParameter).FollowParameter : tps.Parameter) is TemplateTupleParameter)
                {
                    return(PropOwnerType.TypeTuple);
                }
            }
            return(PropOwnerType.None);
        }
예제 #21
0
 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);
     }
 }
예제 #22
0
        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());
        }
예제 #23
0
        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);
        }
예제 #24
0
파일: Attribute.cs 프로젝트: Orvid/D_Parser
        /// <summary>
        /// Removes all public,private,protected or package attributes from the stack
        /// </summary>
        public static void CleanupAccessorAttributes(Stack <DAttribute> HayStack, byte furtherAttrToRemove = 0)
        {
            var l = new List <DAttribute>();

            while (HayStack.Count > 0)
            {
                var attr = HayStack.Pop();
                var m    = attr as Modifier;
                if (m == null || (!DTokens.IsVisibilityModifier(m.Token) && m.Token != furtherAttrToRemove))
                {
                    l.Add(attr);
                }
            }

            foreach (var i in l)
            {
                HayStack.Push(i);
            }
        }
예제 #25
0
        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);
        }
예제 #27
0
        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);
        }
예제 #28
0
 public override string ToString(bool IncludesBase)
 {
     return((IncludesBase && InnerDeclaration != null?(InnerDeclaration.ToString() + '.'):"") + DTokens.GetTokenString(Token));
 }
예제 #29
0
		public override string ToString()
		{
			return DTokens.GetTokenString(ForeToken) + UnaryExpression.ToString();
		}
예제 #30
0
 public override string ToString(bool IncludesBase)
 {
     return((IncludesBase && InnerDeclaration != null ? (InnerDeclaration.ToString() + " ") : "") + DTokens.GetTokenString(Modifier) + "(" + (InnerType != null ? InnerType.ToString() : "") + ")");
 }