Example #1
0
        private static int FitsOnOneLine(IPropertySignature expression, int remainingSpace)
        {
            var space = remainingSpace;

            if (expression.Name.Kind == SyntaxKind.Identifier)
            {
                space = FitsOnOneLine(expression.Name.Cast <IIdentifier>(), space);
            }
            else
            {
                return(-1);
            }

            if (expression.QuestionToken.HasValue)
            {
                space -= 1; // question mark
            }

            if (space > 0 && expression.Type != null)
            {
                space -= 2; // colon space
                space  = FitsOnOneLine(expression.Type, space);
            }

            if (space > 0 && expression.Initializer != null)
            {
                space -= 3; // space equals space
                space  = FitsOnOneLine(expression.Initializer, space);
            }

            return(space);
        }
Example #2
0
        /// <summary>
        /// Gets a function signature from the given symbol
        /// </summary>
        /// <param name="symbol">Function's symbol</param>
        /// <returns>The symbol broken down into a friendlier representation</returns>
        public static DScriptFunctionSignature FromSymbol(ISymbol symbol)
        {
            var declaration = symbol.GetFirstDeclarationOrDefault();

            if (declaration == null)
            {
                return(null);
            }

            var functionLikeDeclaration = NodeUtilities.IsFunctionLike(declaration);

            if (functionLikeDeclaration != null)
            {
                return(GetSymbolFromFunction(symbol.Name, functionLikeDeclaration.Parameters));
            }

            // check to see if this is a property that's really just a function reference - if so treat it like a function
            // instead of a property
            IPropertySignature propertySignature = declaration.As <IPropertySignature>();

            if (propertySignature == null)
            {
                return(null);
            }

            IFunctionOrConstructorTypeNode functionTypeNode = propertySignature?.Type.As <IFunctionOrConstructorTypeNode>();

            if (functionTypeNode == null)
            {
                return(null);
            }

            return(GetSymbolFromFunction(symbol.Name, functionTypeNode.Parameters));
        }
Example #3
0
        private void WriteProperty(ref int pos, IPropertySignature property)
        {
            _blob.Write(ref pos, (byte)SignatureType.Property);
            WriteString(ref pos, property.Name);

            var arguments = property.Arguments;

            _blob.Write7BitEncodedInt(ref pos, arguments.Count);

            var  owner      = property.Owner;
            bool writeOwner = (owner != null);

            _blob.Write(ref pos, (bool)writeOwner);

            int addLength = (arguments.Count + 1) * 4;

            if (writeOwner)
            {
                addLength += 4;
            }

            _blob.Length += addLength;

            if (writeOwner)
            {
                WriteReferenced(ref pos, owner);
            }

            WriteReferenced(ref pos, property.ReturnType);
            WriteReferenced(ref pos, arguments);
        }
        public static string ToString(this IPropertySignature propertySig, IModule module = null, SignaturePrintingFlags flags = SignaturePrintingFlags.None)
        {
            var printer = new SignaturePrinter(flags);

            printer.PrintProperty(propertySig, module);

            return(printer.ToString());
        }
        public IProperty Resolve(IPropertySignature propertySig, ICodeNode context, bool throwOnFailure = false)
        {
            var property = ResolveProperty(propertySig, context.Module, context);

            if (property == null)
            {
                if (throwOnFailure)
                {
                    throw new ResolveReferenceException(string.Format(SR.PropertyResolveError, propertySig.ToString()));
                }

                return(null);
            }

            return(property);
        }
        internal bool Equals(IPropertySignature x, IPropertySignature y)
        {
            if (x.Name != y.Name)
            {
                return(false);
            }

            if (!EqualsTypes(x.Arguments, y.Arguments))
            {
                return(false);
            }

            if (!EqualsType(x.ReturnType, y.ReturnType))
            {
                return(false);
            }

            return(true);
        }
        private bool EqualsProperty(IPropertySignature x, IPropertySignature y)
        {
            if (x == y)
            {
                return(true);
            }

            if (x == null || y == null)
            {
                return(false);
            }

            if (x.Name != y.Name)
            {
                return(false);
            }

            if (x.Arguments.Count != y.Arguments.Count)
            {
                return(false);
            }

            if (!EqualsType(x.ReturnType, y.ReturnType))
            {
                return(false);
            }

            if (!EqualsTypes(x.Arguments, y.Arguments))
            {
                return(false);
            }

            if (!EqualsType(x.Owner, y.Owner))
            {
                return(false);
            }

            return(true);
        }
Example #8
0
        protected int GetHashCode(IPropertySignature obj, bool canIgnoreOwner)
        {
            int hashCode = 0x9000;

            if (obj.Name != null)
            {
                hashCode ^= obj.Name.GetHashCode();
            }

            hashCode += obj.Arguments.Count;

            if (!canIgnoreOwner || (_flags & SignatureComparisonFlags.IgnoreMemberOwner) != SignatureComparisonFlags.IgnoreMemberOwner)
            {
                var owner = obj.Owner;
                if (owner != null)
                {
                    hashCode ^= GetHashCode(owner, canIgnoreOwner);
                }
            }

            return(hashCode);
        }
        protected IProperty ResolveProperty(IPropertySignature propertySig, IModule context, ICodeNode genericContext)
        {
            var ownerType = ResolveType(propertySig.Owner, context, genericContext);

            if (ownerType == null)
            {
                return(null);
            }

            var comparer = new ResolveSignatureComparer(context, ownerType.Module);

            // Find
            foreach (var property in ownerType.Properties)
            {
                if (comparer.Equals(propertySig, property.DeclaringProperty))
                {
                    return(property);
                }
            }

            return(null);
        }
Example #10
0
        protected bool Equals(IPropertySignature x, IPropertySignature y, bool canIgnoreOwner)
        {
            if (x == y)
            {
                return(true);
            }

            if (x == null || y == null)
            {
                return(false);
            }

            if (x.Name != y.Name)
            {
                return(false);
            }

            if (!Equals(x.Arguments, y.Arguments, false))
            {
                return(false);
            }

            if (!Equals(x.ReturnType, y.ReturnType, false))
            {
                return(false);
            }

            if (!canIgnoreOwner || (_flags & SignatureComparisonFlags.IgnoreMemberOwner) != SignatureComparisonFlags.IgnoreMemberOwner)
            {
                if (!Equals(x.Owner, y.Owner, canIgnoreOwner))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #11
0
        public void PrintProperty(IPropertySignature propertySig, IModule module)
        {
            if ((_flags & SignaturePrintingFlags.IgnoreMemberOwner) != SignaturePrintingFlags.IgnoreMemberOwner)
            {
                var owner = propertySig.Owner;
                if (owner != null)
                {
                    PrintType(owner, module);
                }
                else
                {
                    _builder.Append(CodeModelUtils.GlobalTypeName);
                }

                _builder.Append("::");
            }

            PrintIdentifier(propertySig.Name);

            PrintMethodArguments(propertySig.Arguments, -1, module);

            _builder.Append(" : ");
            PrintType(propertySig.ReturnType, module, false);
        }
 public static IProperty Resolve(this IPropertySignature propertySig, ICodeNode context, bool throwOnFailure = false)
 {
     return(context.AssemblyManager.Resolve(propertySig, context, throwOnFailure));
 }
Example #13
0
 public int GetHashCode(IPropertySignature obj)
 {
     return(GetHashCode(obj, true));
 }
Example #14
0
 public bool Equals(IPropertySignature x, IPropertySignature y)
 {
     return(Equals(x, y, true));
 }
Example #15
0
 /// <inheritdoc />
 public override void VisitPropertySignature(IPropertySignature node)
 {
     Register(node, node.Flags, DocNodeType.Property, node.Name.Text, base.VisitPropertySignature);
 }