Example #1
0
 /// <summary>
 /// Creates a closured method in the current scope's closure type using function argument records.
 /// </summary>
 public MethodEntity CreateClosureMethod(Context ctx, IEnumerable<FunctionArgument> args, TypeSignature returnType = null)
 {
     return createClosureMethodInternal(ctx, name => ClosureType.CreateMethod(name, returnType ?? "Unit", args));
 }
Example #2
0
        /// <summary>
        /// type                                        = namespace [ type_args ] { "[]" | "?" | "~" }
        /// </summary>
        private TypeSignature parseType()
        {
            var node = attempt(parseNamespace);
            if (node == null)
                return null;

            var args = attempt(parseTypeArgs);
            if(args != null)
                node = new TypeSignature(node.Name, args.ToArray());

            while (true)
            {
                if(check(LexemType.ArrayDef))
                    node = new TypeSignature(null, "[]", node);
                else if(check(LexemType.Tilde))
                    node = new TypeSignature(null, "~", node);
                else if(check(LexemType.QuestionMark))
                    node = new TypeSignature(null, "?", node);
                else
                    return node;
            }
        }
Example #3
0
        /// <summary>
        /// Resolves a type by its string signature.
        /// </summary>
        public Type ResolveType(TypeSignature signature)
        {
            Type cached;
            if (_Cache.TryGetValue(signature.FullSignature, out cached))
                return cached;

            var type = parseTypeSignature(signature);
            if (type != null)
                _Cache.Add(signature.FullSignature, type);

            return type;
        }
Example #4
0
        /// <summary>
        /// Parses the type signature.
        /// </summary>
        private Type parseTypeSignature(TypeSignature signature)
        {
            try
            {
                if (!string.IsNullOrEmpty(signature.Postfix))
                    return processPostfix(parseTypeSignature(signature.Arguments[0]), signature.Postfix);

                var name = signature.Name;
                var hasArgs = signature.Arguments != null && signature.Arguments.Length > 0;
                if (hasArgs)
                    name += "`" + signature.Arguments.Length;

                if (TypeAliases.ContainsKey(name))
                    return TypeAliases[name];

                var type = findType(name);
                return hasArgs
                    ? GenericHelper.MakeGenericTypeChecked(type, signature.Arguments.Select(parseTypeSignature).ToArray())
                    : type;
            }
            catch (ArgumentException ex)
            {
                throw new LensCompilerException(ex.Message, signature);
            }
        }
Example #5
0
        protected bool Equals(TypeSignature other)
        {
            var basic = string.Equals(Name, other.Name)
                        && string.Equals(Postfix, other.Postfix);

            if (!basic || (Arguments == null ^ other.Arguments == null))
                return false;

            return Arguments == null || Arguments.SequenceEqual(other.Arguments);
        }
Example #6
0
        /// <summary>
        /// Builds the full string representation of the signature tree.
        /// </summary>
        private string getSignature(string name, TypeSignature[] args)
        {
            if (args.Length == 0)
                return name;

            if (!string.IsNullOrEmpty(Postfix))
                return Arguments[0].FullSignature + Postfix;

            var sb = new StringBuilder(name);
            sb.Append("<");

            var idx = 0;
            foreach (var curr in args)
            {
                if (idx > 0)
                    sb.Append(", ");

                sb.Append(curr.FullSignature);

                idx++;
            }

            sb.Append(">");

            return sb.ToString();
        }
Example #7
0
 /// <summary>
 /// Resolves a type by its string signature.
 /// Warning: this method might return a TypeBuilder as well as a Type, if the signature points to an inner type.
 /// </summary>
 public Type ResolveType(string signature)
 {
     return(ResolveType(TypeSignature.Parse(signature)));
 }
Example #8
0
 public FunctionArgument(string name, TypeSignature type, bool isRefArg = false)
 {
     Name          = name;
     TypeSignature = type;
     IsRefArgument = isRefArg;
 }
Example #9
0
 public FunctionArgument(string name, TypeSignature type, bool isRefArg = false)
 {
     Name = name;
     TypeSignature = type;
     IsRefArgument = isRefArg;
 }
Example #10
0
 public DefaultOperatorNode(TypeSignature type = null)
 {
     TypeSignature = type;
 }
Example #11
0
        /// <summary>
        /// Resolves a type by its signature.
        /// </summary>
        public Type ResolveType(TypeSignature signature, bool allowUnspecified = false)
        {
            if (allowUnspecified && signature.FullSignature == "_")
                return null;

            var declared = FindType(signature.FullSignature);
            return declared != null
                ? declared.TypeInfo
                : _TypeResolver.ResolveType(signature);
        }