示例#1
0
文件: decl.cs 项目: johnluetke/mono
		public MemberName (string name, TypeParameters tparams, Location loc)
		{
			this.Name = name;
			this.Location = loc;

			this.TypeParameters = tparams;
		}
示例#2
0
        // if the user says ( forall x :: forall y ::  ... ) and specifies *no* triggers, we transform it to
        // (forall x, y ::  ... ) which may help the prover to pick trigger terms
        //
        // (Note: there used to be a different criterion here, which allowed merging when triggers were specified, which could cause prover errors due to resulting unbound variables in the triggers)
        private void MergeAdjecentQuantifier()
        {
            QuantifierExpr qbody = Body as QuantifierExpr;

            if (!(qbody != null && (qbody is ForallExpr) == (this is ForallExpr) && Triggers == null))
            {
                return;
            }
            qbody.MergeAdjecentQuantifier();
            if (this.Triggers != null || qbody.Triggers != null)
            {
                return;
            }
            Body = qbody.Body;
            TypeParameters.AddRange(qbody.TypeParameters);
            Dummies.AddRange(qbody.Dummies);
            Triggers = qbody.Triggers;
            if (qbody.Attributes != null)
            {
                if (Attributes == null)
                {
                    Attributes = qbody.Attributes;
                }
                else
                {
                    QKeyValue p = Attributes;
                    while (p.Next != null)
                    {
                        p = p.Next;
                    }
                    p.Next = qbody.Attributes;
                }
            }
        }
示例#3
0
 public MemberName(MemberName left, MemberName right)
 {
     this.Name           = right.Name;
     this.Location       = right.Location;
     this.TypeParameters = right.TypeParameters;
     this.Left           = left;
 }
示例#4
0
        public MemberName(string name, TypeParameters tparams, Location loc)
        {
            this.Name     = name;
            this.Location = loc;

            this.TypeParameters = tparams;
        }
示例#5
0
        public static string MakeName(string name, TypeParameters args)
        {
            if (args == null)
                return name;

            return name + "`" + args.Count;
        }
示例#6
0
 public bool Equals(TypeDoc other)
 => other != null &&
 Name == other.Name && Meta == other.Meta &&
 TypeParameters.OrderBy(p => p.Name).SequenceEqual(other.TypeParameters.OrderBy(p => p.Name)) &&
 Fields.OrderBy(p => p.Key).SequenceEqual(other.Fields.OrderBy(p => p.Key)) &&
 Properties.OrderBy(p => p.Key).SequenceEqual(other.Properties.OrderBy(p => p.Key)) &&
 Events.OrderBy(p => p.Key).SequenceEqual(other.Events.OrderBy(p => p.Key)) &&
 Methods.OrderBy(p => p.Key).SequenceEqual(other.Methods.OrderBy(p => p.Key));
示例#7
0
        public void TypeParametersToSource(StringBuilder sb)
        {
            sb.Append("<");

            TypeParameters.ToSource(sb);

            sb.Append(">");
        }
示例#8
0
        protected override bool OnValidate(CodeGenerationOptions opt, GenericParameterDefinitionList type_params)
        {
            if (validated)
            {
                return(is_valid);
            }

            validated = true;

            if (!support.OnValidate(opt))
            {
                is_valid = false;
                return(false);
            }

            // We're validating this in prior to BaseType.
            if (TypeParameters != null && !TypeParameters.Validate(opt, type_params))
            {
                is_valid = false;
                return(false);
            }

            if (Char.IsNumber(Name [0]))
            {
                // it is an anonymous class which does not need output.
                is_valid = false;
                return(false);
            }

            base_symbol = IsAnnotation ? opt.SymbolTable.Lookup("java.lang.Object") : BaseType != null?opt.SymbolTable.Lookup(BaseType) : null;

            if (base_symbol == null && FullName != "Java.Lang.Object" && FullName != "System.Object")
            {
                Report.Warning(0, Report.WarningClassGen + 2, "Class {0} has unknown base type {1}.", FullName, BaseType);
                is_valid = false;
                return(false);
            }

            if ((base_symbol != null && !base_symbol.Validate(opt, TypeParameters)) || !base.OnValidate(opt, type_params))
            {
                Report.Warning(0, Report.WarningClassGen + 3, "Class {0} has invalid base type {1}.", FullName, BaseType);
                is_valid = false;
                return(false);
            }

            List <Ctor> valid_ctors = new List <Ctor> ();

            foreach (Ctor c in ctors)
            {
                if (c.Validate(opt, TypeParameters))
                {
                    valid_ctors.Add(c);
                }
            }
            ctors = valid_ctors;

            return(true);
        }
示例#9
0
        public static string MakeName(string name, TypeParameters args)
        {
            if (args == null)
            {
                return(name);
            }

            return(name + "`" + args.Count);
        }
        public string ToPythonString(bool ignoreAlias = false)
        {
            if (!ignoreAlias && Alias != null)
            {
                return(Alias);
            }

            if (IsNamedTypeParameter)
            {
                return($"{Namespace}_{Name}".Replace('.', '_'));
            }

            var str = "";

            if (Namespace != null)
            {
                str += $"{Namespace}.";
            }

            str += Name;

            if (TypeParameters.Count == 0)
            {
                return(str);
            }

            str += "[";

            // Callable requires Callable[[ParameterType1, ParameterType2, ...], ReturnType]
            if (Namespace == "typing" && Name == "Callable")
            {
                if (IsAction)
                {
                    str += "[";
                    str += string.Join(", ", TypeParameters.Select(type => type.ToPythonString()));
                    str += "], None";
                }
                else
                {
                    str += "[";
                    str += string.Join(
                        ", ",
                        TypeParameters.SkipLast(1).Select(type => type.ToPythonString()));
                    str += "], ";
                    str += TypeParameters.Last().ToPythonString();
                }
            }
            else
            {
                str += string.Join(", ", TypeParameters.Select(type => type.ToPythonString()));
            }

            str += "]";

            return(str);
        }
示例#11
0
        /// <inheritdoc />
        public override string ToDebugString()
        {
            string typeParameters = TypeParameters.Count > 0
                ? "<" + string.Join(", ", TypeParameters.Select(tp => tp.ToDebugString())) + ">"
                : string.Empty;

            string parameters = string.Join(", ", Parameters.Select(p => p.ToDebugString()));

            return(I($"{typeParameters}({parameters}) => {ReturnType.ToDebugString()}"));
        }
示例#12
0
 public void Expand(Dictionary <string, ApiReferenceBuildOutput> references, string[] supportedLanguages)
 {
     if (_needExpand)
     {
         _needExpand = false;
         Parameters?.ForEach(p => p.Expand(references, supportedLanguages));
         TypeParameters?.ForEach(t => t.Expand(references, supportedLanguages));
         Return?.Expand(references, supportedLanguages);
     }
 }
示例#13
0
 public void AddTypeParameter(TypeParameter p)
 {
     p.Container           = new Property();
     p.Container.Container = this;
     if (TypeParameters == null)
     {
         TypeParameters = new List <TypeParameter>();
     }
     TypeParameters.Add(p);
 }
示例#14
0
 public void Expand(Dictionary <string, ApiReferenceBuildOutput> references, string[] supportedLanguages)
 {
     if (!_isExpanded)
     {
         Parameters?.ForEach(p => p.Expand(references, supportedLanguages));
         TypeParameters?.ForEach(t => t.Expand(references, supportedLanguages));
         Return?.Expand(references, supportedLanguages);
         _isExpanded = true;
     }
 }
示例#15
0
 /// <summary>
 /// Returns the <see cref="CodeTypeReference"/> which links back to the
 /// <see cref="TypeInstance"/>.
 /// </summary>
 /// <returns>A <see cref="CodeTypeReference"/> which links back to the <see cref="TypeInstance"/>.</returns>
 public virtual CodeTypeReference GenerateCodeDom(ICodeDOMTranslationOptions options)
 {
     if (this.ArrayElementType != null && this.ArrayRank > 0)
     {
         return(new CodeTypeReference(this.ArrayElementType.GenerateCodeDom(options), this.ArrayRank));
     }
     else
     {
         CodeTypeReference ctr = new CodeTypeReference();
         CodeTypeReference n   = null;
         if (nullable)
         {
             n = new CodeTypeReference(typeof(Nullable <>));
         }
         bool autoResolve = false;
         if ((this.resolutionOptions & TypeReferenceResolveOptions.GlobalType) == TypeReferenceResolveOptions.GlobalType)
         {
             ctr.Options |= CodeTypeReferenceOptions.GlobalReference;
         }
         if ((this.resolutionOptions & TypeReferenceResolveOptions.FullType) == TypeReferenceResolveOptions.FullType || (this.resolutionOptions & TypeReferenceResolveOptions.GlobalType) == TypeReferenceResolveOptions.GlobalType)
         {
             autoResolve = options.AutoResolveReferences;
             if (autoResolve)
             {
                 options.AutoResolveReferences = false;
             }
         }
         if ((this.resolutionOptions & TypeReferenceResolveOptions.TypeParameter) == TypeReferenceResolveOptions.TypeParameter)
         {
             ctr.Options |= CodeTypeReferenceOptions.GenericTypeParameter;
         }
         ctr.BaseType = this.TypeInstance.GetTypeName(options, TypeParameters.ToArray());
         if (autoResolve && ((this.resolutionOptions & TypeReferenceResolveOptions.FullType) == TypeReferenceResolveOptions.FullType || (this.resolutionOptions & TypeReferenceResolveOptions.GlobalType) == TypeReferenceResolveOptions.GlobalType))
         {
             options.AutoResolveReferences = autoResolve;
         }
         //Clear auto-inferred entries.
         ctr.TypeArguments.Clear();
         foreach (ITypeReference itr in this.TypeParameters)
         {
             if (itr != null)
             {
                 ctr.TypeArguments.Add(itr.GenerateCodeDom(options));
             }
         }
         if (nullable)
         {
             n.TypeArguments.Add(ctr);
             ctr = n;
         }
         //Pointers: Not supported by CodeDOM.
         return(ctr);
     }
 }
示例#16
0
        /// <inheritdoc />
        public override string ToDebugString()
        {
            string typeParameters = TypeParameters.Count > 0
                ? "<" + string.Join(", ", TypeParameters.Select(tp => tp.ToDebugString())) + ">"
                : string.Empty;

            string parameters = I($"({string.Join(", ", Parameters.Select(p => p.ToDebugString()))})");

            string returnType = ReturnType != null ? ": " + ReturnType.ToDebugString() : string.Empty;

            return(typeParameters + parameters + returnType);
        }
示例#17
0
        // Body (ClassBody) [class_body] ClassMemberDeclarations
        //  method_declaration
        //  property_declaration

        //  constructor_declaration

        //  field_declaration
        //  constant_declaration
        //  event_declaration
        //  indexer_declaration
        //  operator_declaration
        //  destructor_declaration
        //  static_constructor_declaration
        //  type_declaration

        // Body (InterfaceBody) [interface_body] InterfaceMemberDeclarations
        //  interface_method_declaration
        //  interface_property_declaration

        //  interface_event_declaration
        //  interface_indexer_declaration

        public ClassInterfaceDeclaration CopyHeader()
        {
            return(new ClassInterfaceDeclaration()
            {
                IsInterface = IsInterface.Copy(),
                Attributes = Attributes?.Copy(),
                Modifiers = Modifiers?.Copy(),
                Identifier = Identifier?.Copy(),
                TypeParameters = TypeParameters?.Copy(),
                Base = Base?.Copy()
            });
        }
示例#18
0
        /// <summary> Creates new method signature with brand new type parameters. Since you can't have declared multiple methods with the same type parameters, you should use Clone to create similar method signatures. </summary>
        public MethodSignature Clone()
        {
            if (this.TypeParameters.Length == 0)
            {
                return(this);
            }
            var newTypeParams = TypeParameters.EagerSelect(tp => new GenericParameter(Guid.NewGuid(), tp.Name));
            var resultType    = ResultType.SubstituteGenerics(TypeParameters, newTypeParams.EagerSelect(TypeReference.GenericParameter));
            var @params       = Params.EagerSelect(p => p.SubstituteGenerics(TypeParameters, newTypeParams.EagerSelect(TypeReference.GenericParameter)));

            return(this.With(@params: @params, resultType: resultType, typeParameters: newTypeParams));
        }
示例#19
0
        protected bool DoResolveCore(ResolveContext rc)
        {
            int i = 0;

            foreach (var arg in arguments)
            {
                if (arg.Type == InternalType.VarOutType)
                {
                    // Should be special error message about dynamic dispatch
                    rc.Report.Error(8197, arg.Expr.Location, "Cannot infer the type of implicitly-typed out variable `{0}'", ((DeclarationExpression)arg.Expr).Variable.Name);
                }
                else if (arg.Type == InternalType.DefaultType)
                {
                    rc.Report.Error(8311, arg.Expr.Location, "Cannot use a default literal as an argument to a dynamically dispatched operation");
                }

                // Forced limitation because Microsoft.CSharp needs to catch up
                if (i > 0 && arguments [i - 1] is NamedArgument && !(arguments [i] is NamedArgument))
                {
                    rc.Report.Error(8324, loc, "Named argument specifications must appear after all fixed arguments have been specified in a dynamic invocation");
                }
                ++i;
            }

            if (rc.CurrentTypeParameters != null && rc.CurrentTypeParameters[0].IsMethodTypeParameter)
            {
                context_mvars = rc.CurrentTypeParameters;
            }

            int errors = rc.Report.Errors;
            var pt     = rc.Module.PredefinedTypes;

            binder_type = pt.Binder.Resolve();
            pt.CallSite.Resolve();
            pt.CallSiteGeneric.Resolve();

            eclass = ExprClass.Value;

            if (type == null)
            {
                type = rc.BuiltinTypes.Dynamic;
            }

            if (rc.Report.Errors == errors)
            {
                return(true);
            }

            rc.Report.Error(1969, loc,
                            "Dynamic operation cannot be compiled without `Microsoft.CSharp.dll' assembly reference");
            return(false);
        }
示例#20
0
        protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
        {
            var o = other as DelegateDeclaration;

            return(o != null &&
                   MatchAttributesAndModifiers(o, match) &&
                   IsSub == o.IsSub &&
                   TypeParameters.DoMatch(o.TypeParameters, match) &&
                   Name.DoMatch(o.Name, match) &&
                   Parameters.DoMatch(o.Parameters, match) &&
                   ReturnTypeAttributes.DoMatch(o.ReturnTypeAttributes, match) &&
                   ReturnType.DoMatch(o.ReturnType, match));
        }
示例#21
0
		protected static MemberName MakeMemberName (MemberBase host, string name, int unique_id, TypeParameter[] tparams, Location loc)
		{
			string host_name = host == null ? null : host is InterfaceMemberBase ? ((InterfaceMemberBase)host).GetFullName (host.MemberName) : host.Name;
			string tname = MakeName (host_name, "c", name, unique_id);
			TypeParameters args = null;
			if (tparams != null) {
				args = new TypeParameters ();
				foreach (TypeParameter tparam in tparams)
					args.Add (new TypeParameterName (tparam.Name, null, loc));
			}

			return new MemberName (tname, args, loc);
		}
示例#22
0
        protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
        {
            TypeDeclaration t = other as TypeDeclaration;

            return(t != null &&
                   MatchAttributesAndModifiers(t, match) &&
                   Members.DoMatch(t.Members, match) &&
                   ClassType == t.ClassType &&
                   Name.DoMatch(t.Name, match) &&
                   TypeParameters.DoMatch(t.TypeParameters, match) &&
                   InheritsType.DoMatch(t.InheritsType, match) &&
                   ImplementsTypes.DoMatch(t.ImplementsTypes, match));
        }
示例#23
0
        protected bool DoResolveCore(ResolveContext rc)
        {
            if (rc.CurrentTypeParameters != null && rc.CurrentTypeParameters [0].IsMethodTypeParameter)
            {
                context_mvars = rc.CurrentTypeParameters;
            }

            int errors = rc.Report.Errors;
            var pt     = rc.Module.PredefinedTypes;

            binder_type = pt.GetBinder(rc).Resolve();

            isPlayScriptDynamicMode = pt.IsPlayScriptDynamicMode;
            isPlayScriptAotMode     = pt.IsPlayScriptAotMode;

            // NOTE: Use AsCallSite if in PlayScript AOT mode only.
            if (isPlayScriptAotMode)
            {
                pt.AsCallSite.Resolve();
                pt.AsCallSiteGeneric.Resolve();
            }
            else
            {
                pt.CallSite.Resolve();
                pt.CallSiteGeneric.Resolve();
            }

            eclass = ExprClass.Value;

            if (type == null)
            {
                type = rc.BuiltinTypes.Dynamic;
            }

            if (rc.Report.Errors == errors)
            {
                return(true);
            }

            if (isPlayScriptDynamicMode)
            {
                rc.Report.Error(7027, loc,
                                "PlayScript dynamic operation cannot be compiled without `ascorlib.dll' assembly reference");
            }
            else
            {
                rc.Report.Error(1969, loc,
                                "Dynamic operation cannot be compiled without `Microsoft.CSharp.dll' assembly reference");
            }
            return(false);
        }
示例#24
0
        /// <summary>
        /// Initializes a type with its parent model and the XML node is represents.
        /// </summary>
        /// <param name="model">The parent model containing this type.</param>
        /// <param name="node">The XML node represented by this type.</param>
        /// <exception cref="FormatException">The name attribute has an invalid format.</exception>
        public Type(XmlDocumentationModel model, XmlNode node) : base(model, node)
        {
            // ReSharper disable once PossibleNullReferenceException
            var name = node.Attributes["name"].Value;

            if (!name.StartsWith("T:"))
            {
                throw new FormatException($"Bad type name format: {name}");
            }
            name = name.Substring(2);
            if (name.StartsWith(Model.AssemblyName + "."))
            {
                name = name.Substring(Model.AssemblyName.Length + 1);
            }
            var parts = name.Split(new[] { "." }, StringSplitOptions.None);

            Name = parts[parts.Length - 1];
            var potentialContainingTypeName =
                $"T:{Model.AssemblyName}.{string.Join(".", parts.Take(parts.Length - 1))}";
            var potentialContainingTypeId = potentialContainingTypeName;

            if (Model.Members.ContainsKey(potentialContainingTypeId))
            {
                var containingType = (Type)Model.Members[potentialContainingTypeId];
                NamespaceStrings = containingType.NamespaceStrings;
                containingType.NestedTypes.Add(this);
                ContainingType = containingType;
            }
            else
            {
                NamespaceStrings = parts.Take(parts.Length - 1).Select(p => Regex.Replace(p, "`(\\d+)", "")).ToArray();
            }
            var summary = node.SelectSingleNode("summary");

            if (summary != null)
            {
                Documentation = new Documentation(summary);
            }
            var paramTypes = node.SelectNodes("typeparam");

            if (paramTypes != null)
            {
                foreach (XmlNode paramType in paramTypes)
                {
                    TypeParameters.Add(new TypeParameter(paramType));
                }
            }
        }
示例#25
0
        public override IEnumerable <INotation> GetMembers()
        {
            yield return(CustomAttributes.InsertBlank().Combine());

            yield return(Accessibility.ToDisplayString().ToNotation());

            if (IsAsync)
            {
                yield return(ConstNotations.Blank);

                yield return(ConstNotations.Async);
            }
            if (IsOverride)
            {
                yield return(ConstNotations.Blank);

                yield return(ConstNotations.Override);
            }
            yield return(ConstNotations.Blank);

            yield return(ReturnType.ToNotation());

            yield return(ConstNotations.Blank);

            yield return(Name.ToNotation());

            if (TypeParameters.Count > 0)
            {
                yield return(ConstNotations.OpenAngleBracket);

                yield return(TypeParameters.Select(i => i.ToOnlyTypeDefinitionNotation()).InsertComma().Combine());

                yield return(ConstNotations.CloseAngleBracket);
            }
            yield return(ConstNotations.OpenParen);

            yield return(Parameters.InsertComma().Combine());

            yield return(ConstNotations.CloseParen);

            yield return(TypeParameters.Select(i => i.ToConstantNotation(IsOverride)).InsertBlank().Combine());

            yield return(ConstNotations.OpenBrace);

            yield return(Body.Combine());

            yield return(ConstNotations.CloseBrace);
        }
示例#26
0
        protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
        {
            var method = other as MethodDeclaration;

            return(method != null &&
                   MatchAttributesAndModifiers(method, match) &&
                   IsSub == method.IsSub &&
                   Name.DoMatch(method.Name, match) &&
                   TypeParameters.DoMatch(method.TypeParameters, match) &&
                   Parameters.DoMatch(method.Parameters, match) &&
                   ReturnTypeAttributes.DoMatch(method.ReturnTypeAttributes, match) &&
                   ReturnType.DoMatch(method.ReturnType, match) &&
                   HandlesClause.DoMatch(method.HandlesClause, match) &&
                   ImplementsClause.DoMatch(method.ImplementsClause, match) &&
                   Body.DoMatch(method.Body, match));
        }
        public StructDefinitionSyntax(ISyntaxNode parent, JurParser.StructDeclarationContext context) : base(parent, context)
        {
            Name           = context.ID(0).GetText();
            IsNominal      = context.NOMINAL() != null;
            TypeParameters = context.ID().Skip(1).Select(x => new TypeParameterSyntax(this, x.GetText(), Line, this)).ToImmutableArray();
            InlinedTypes   = ToTypes(context.inlinedType().Select(x => x.type()).ToArray());
            Fields         = ToFields(context.uninitializedVarDeclaration());

            FullName = IsGeneric
                           ? Name + "<" + string.Join(",", TypeParameters.Select(x => x.Name)) + ">"
                           : Name;

            ImmediateChildren = ImmutableArray.Create <ITreeNode>()
                                .AddRange(InlinedTypes)
                                .AddRange(Fields);
        }
示例#28
0
        /// <inheritdoc />
        public override string ToDebugString()
        {
            var decorators = ToDebugString(Decorators);

            string typeParameters = TypeParameters.Count > 0
                ? "<" + string.Join(", ", TypeParameters.Select(p => p.ToString())) + ">"
                : string.Empty;
            string extendedTypes = ExtendedTypes.Count > 0
                ? " extends " + string.Join(", ", ExtendedTypes.Select(t => t.ToString()))
                : string.Empty;

            return(decorators + GetModifierString() + "interface " + ToDebugString(Name)
                   + typeParameters
                   + extendedTypes
                   + Body);
        }
示例#29
0
文件: anonymous.cs 项目: rabink/mono
		protected static MemberName MakeMemberName (MemberBase host, string name, int unique_id, TypeParameters tparams, Location loc)
		{
			string host_name = host == null ? null : host is InterfaceMemberBase ? ((InterfaceMemberBase)host).GetFullName (host.MemberName) : host.MemberName.Name;
			string tname = MakeName (host_name, "c", name, unique_id);
			TypeParameters args = null;
			if (tparams != null) {
				args = new TypeParameters (tparams.Count);

				// Type parameters will be filled later when we have TypeContainer
				// instance, for now we need only correct arity to create valid name
				for (int i = 0; i < tparams.Count; ++i)
					args.Add ((TypeParameter) null);
			}

			return new MemberName (tname, args, loc);
		}
示例#30
0
        /// <summary>
        /// The declartion part of the method, e.g. 'private int MyMethod(in MyType type, out ThatType that)'
        /// </summary>
        public string GetDeclarationString()
        {
            return(_declarationCache ??= BuildString());

            string BuildString()
            {
                var str = new StringBuilder();

                str.Append(Accessibility.ToCodeString()); // private
                str.Append(' ');
                str.Append(ReturnType);                   // int
                str.Append(' ');
                if (!IsConstructor)
                {
                    str.Append(MethodName); // MyMethod
                }
                if (TypeParameters.Count > 0)
                {
                    str.Append('<');
                    str.Append(string.Join(",", TypeParameters.Select(x => x.GenericName)));
                    str.Append('>');
                }
                str.Append("(");
                str.Append(string.Join(", ", Arguments.Select(x => x.ToParamString())));
                str.Append(")");
                if (TypeParameters.All(x => !x.HasConstrain))
                {
                    return(str.ToString());
                }
                foreach (var generic in TypeParameters)
                {
                    if (!generic.HasConstrain)
                    {
                        continue;
                    }
                    str.Append("where");
                    str.Append(' ');
                    str.Append(generic.GenericName);
                    str.Append(" : ");
                    str.Append(string.Join(",", GetGenericsArgs(generic)));
                    str.Append(' ');
                }
                return(str.ToString());
            }
示例#31
0
        protected bool DoResolveCore(ResolveContext rc)
        {
            foreach (var arg in arguments)
            {
                if (arg.Type == InternalType.VarOutType)
                {
                    // Should be special error message about dynamic dispatch
                    rc.Report.Error(8047, arg.Expr.Location, "Declaration expression cannot be used in this context");
                }
            }

            if (rc.CurrentTypeParameters != null && rc.CurrentTypeParameters[0].IsMethodTypeParameter)
            {
                context_mvars = rc.CurrentTypeParameters;
            }

            int errors = rc.Report.Errors;
            var pt     = rc.Module.PredefinedTypes;

            binder_type = pt.Binder.Resolve();
            pt.CallSite.Resolve();
            pt.CallSiteGeneric.Resolve();

            eclass = ExprClass.Value;

            if (type == null)
            {
                type = rc.BuiltinTypes.Dynamic;
            }

            if (rc.Report.Errors == errors)
            {
                return(true);
            }

            rc.Report.Error(1969, loc,
                            "Dynamic operation cannot be compiled without `Microsoft.CSharp.dll' assembly reference");
            return(false);
        }
示例#32
0
        void GenerateDeclaration(StreamWriter sw, string indent, CodeGenerationOptions opt)
        {
            StringBuilder sb = new StringBuilder();

            foreach (ISymbol isym in Interfaces)
            {
                InterfaceGen igen = (isym is GenericSymbol ? (isym as GenericSymbol).Gen : isym) as InterfaceGen;
                if (igen.IsConstSugar)
                {
                    continue;
                }
                if (sb.Length > 0)
                {
                    sb.Append(", ");
                }
                sb.Append(opt.GetOutputName(isym.FullName));
            }

            sw.WriteLine("{0}// Metadata.xml XPath interface reference: path=\"{1}\"", indent, MetadataXPathReference);

            if (this.IsDeprecated)
            {
                sw.WriteLine("{0}[ObsoleteAttribute (@\"{1}\")]", indent, DeprecatedComment);
            }
            sw.WriteLine("{0}[Register (\"{1}\", \"\", \"{2}\"{3})]", indent, RawJniName, Namespace + "." + FullName.Substring(Namespace.Length + 1).Replace('.', '/') + "Invoker", this.AdditionalAttributeString());
            if (this.TypeParameters != null && this.TypeParameters.Any())
            {
                sw.WriteLine("{0}{1}", indent, TypeParameters.ToGeneratedAttributeString());
            }
            sw.WriteLine("{0}{1} partial interface {2} : {3} {{", indent, Visibility, Name,
                         Interfaces.Count == 0 || sb.Length == 0 ? "IJavaObject" : sb.ToString());
            sw.WriteLine();
            GenProperties(sw, indent + "\t", opt);
            GenMethods(sw, indent + "\t", opt);
            sw.WriteLine(indent + "}");
            sw.WriteLine();
        }
示例#33
0
        private void GetParameters()
        {
            // get instance parameters
            List <Parameter> instanceParameters = new List <Parameter>();

            foreach (Parameter parameter in NestedFamilyInstance.Parameters)
            {
                if (NestedFamilyInstance.Document.FamilyManager.CanElementParameterBeAssociated(parameter))
                {
                    instanceParameters.Add(parameter);
                }
            }

            instanceParameters.Sort((p1, p2) => string.Compare(p1.Definition.Name, p2.Definition.Name, StringComparison.Ordinal));
            instanceParameters.ForEach(parameter =>
            {
                InstanceParameters.Add(new NestedFamilyParameterModel(parameter, this, true, _mainViewModel));
            });

            // get type parameters
            List <Parameter> typeParameters = new List <Parameter>();

            foreach (Parameter parameter in NestedFamilyInstance.Symbol.Parameters)
            {
                if (NestedFamilyInstance.Document.FamilyManager.CanElementParameterBeAssociated(parameter))
                {
                    typeParameters.Add(parameter);
                }
            }

            typeParameters.Sort((p1, p2) => string.Compare(p1.Definition.Name, p2.Definition.Name, StringComparison.Ordinal));
            typeParameters.ForEach(parameter =>
            {
                TypeParameters.Add(new NestedFamilyParameterModel(parameter, this, false, _mainViewModel));
            });
        }
示例#34
0
		//
		// Creates a host for the anonymous method
		//
		AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
		{
			//
			// Anonymous method body can be converted to
			//
			// 1, an instance method in current scope when only `this' is hoisted
			// 2, a static method in current scope when neither `this' nor any variable is hoisted
			// 3, an instance method in compiler generated storey when any hoisted variable exists
			//

			Modifiers modifiers;
			TypeDefinition parent = null;

			var src_block = Block.Original.Explicit;
			if (src_block.HasCapturedVariable || src_block.HasCapturedThis) {
				parent = storey = FindBestMethodStorey ();

				if (storey == null) {
					var top_block = src_block.ParametersBlock.TopBlock;
					var sm = top_block.StateMachine;

					if (src_block.HasCapturedThis) {
						//
						// Remove hoisted 'this' request when simple instance method is
						// enough. No hoisted variables only 'this' and don't need to
						// propagate this to value type state machine.
						//
						StateMachine sm_parent;
						var pb = src_block.ParametersBlock;
						do {
							sm_parent = pb.StateMachine;
							pb = pb.Parent == null ? null : pb.Parent.ParametersBlock;
						} while (sm_parent == null && pb != null);

						if (sm_parent == null) {
							top_block.RemoveThisReferenceFromChildrenBlock (src_block);
						} else if (sm_parent.Kind == MemberKind.Struct) {
							//
							// Special case where parent class is used to emit instance method
							// because currect storey is of value type (async host) and we cannot
							// use ldftn on non-boxed instances either to share mutated state
							//
							parent = sm_parent.Parent.PartialContainer;
						} else if (sm is IteratorStorey) {
							//
							// For iterators we can host everything in one class
							//
							parent = storey = sm;
						}
					}
				}

				modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
			} else {
				if (ec.CurrentAnonymousMethod != null)
					parent = storey = ec.CurrentAnonymousMethod.Storey;

				modifiers = Modifiers.STATIC | Modifiers.PRIVATE;
			}

			if (parent == null)
				parent = ec.CurrentTypeDefinition.Parent.PartialContainer;

			string name = CompilerGeneratedContainer.MakeName (parent != storey ? block_name : null,
				"m", null, parent.PartialContainer.CounterAnonymousMethods++);

			MemberName member_name;
			if (storey == null && ec.CurrentTypeParameters != null) {

				var hoisted_tparams = ec.CurrentTypeParameters;
				var type_params = new TypeParameters (hoisted_tparams.Count);
				for (int i = 0; i < hoisted_tparams.Count; ++i) {
				    type_params.Add (hoisted_tparams[i].CreateHoistedCopy (null));
				}

				member_name = new MemberName (name, type_params, Location);
			} else {
				member_name = new MemberName (name, Location);
			}

			return new AnonymousMethodMethod (parent,
				this, storey, new TypeExpression (ReturnType, Location), modifiers,
				member_name, parameters);
		}
示例#35
0
文件: anonymous.cs 项目: rabink/mono
		//
		// Creates a host for the anonymous method
		//
		AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
		{
			//
			// Anonymous method body can be converted to
			//
			// 1, an instance method in current scope when only `this' is hoisted
			// 2, a static method in current scope when neither `this' nor any variable is hoisted
			// 3, an instance method in compiler generated storey when any hoisted variable exists
			//

			Modifiers modifiers;
			TypeDefinition parent = null;

			var src_block = Block.Original.Explicit;
			if (src_block.HasCapturedVariable || src_block.HasCapturedThis) {
				parent = storey = FindBestMethodStorey ();

				if (storey == null) {
					var sm = src_block.ParametersBlock.TopBlock.StateMachine;

					//
					// Remove hoisted this demand when simple instance method is enough (no hoisted variables only this)
					//
					if (src_block.HasCapturedThis && src_block.ParametersBlock.StateMachine == null) {
						src_block.ParametersBlock.TopBlock.RemoveThisReferenceFromChildrenBlock (src_block);

						//
						// Special case where parent class is used to emit instance method
						// because currect storey is of value type (async host) and we don't
						// want to create another childer storey to host this reference only
						//
						if (sm != null && sm.Kind == MemberKind.Struct)
							parent = sm.Parent.PartialContainer;
					}

					//
					// For iterators we can host everything in one class
					//
					if (sm is IteratorStorey)
						parent = storey = sm;
				}

				modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
			} else {
				if (ec.CurrentAnonymousMethod != null)
					parent = storey = ec.CurrentAnonymousMethod.Storey;

				modifiers = Modifiers.STATIC | Modifiers.PRIVATE;
			}

			if (parent == null)
				parent = ec.CurrentTypeDefinition.Parent.PartialContainer;

			string name = CompilerGeneratedContainer.MakeName (parent != storey ? block_name : null,
				"m", null, ec.Module.CounterAnonymousMethods++);

			MemberName member_name;
			if (storey == null && ec.CurrentTypeParameters != null) {

				var hoisted_tparams = ec.CurrentTypeParameters;
				var type_params = new TypeParameters (hoisted_tparams.Count);
				for (int i = 0; i < hoisted_tparams.Count; ++i) {
				    type_params.Add (hoisted_tparams[i].CreateHoistedCopy (null));
				}

				member_name = new MemberName (name, type_params, Location);
			} else {
				member_name = new MemberName (name, Location);
			}

			return new AnonymousMethodMethod (parent,
				this, storey, new TypeExpression (ReturnType, Location), modifiers,
				member_name, parameters);
		}
示例#36
0
文件: anonymous.cs 项目: rabink/mono
		public AnonymousMethodStorey (ExplicitBlock block, TypeDefinition parent, MemberBase host, TypeParameters tparams, string name, MemberKind kind)
			: base (parent, MakeMemberName (host, name, parent.Module.CounterAnonymousContainers, tparams, block.StartLocation),
				tparams, 0, kind)
		{
			OriginalSourceBlock = block;
			ID = parent.Module.CounterAnonymousContainers++;
		}
示例#37
0
文件: class.cs 项目: fvalette/mono
		string[] CreateTypeParameters (TypeParameters parentAllTypeParameters)
		{
			string[] names;
			int parent_offset = 0;
			if (parentAllTypeParameters != null) {
				if (CurrentTypeParameters == null) {
					all_type_parameters = parentAllTypeParameters;
					return parentAllTypeParameters.GetAllNames ();
				}

				names = new string[parentAllTypeParameters.Count + CurrentTypeParameters.Count];
				all_type_parameters = new TypeParameters (names.Length);
				all_type_parameters.Add (parentAllTypeParameters);

				parent_offset = all_type_parameters.Count;
				for (int i = 0; i < parent_offset; ++i)
					names[i] = all_type_parameters[i].MemberName.Name;

			} else {
				names = new string[CurrentTypeParameters.Count];
			}

			for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
				if (all_type_parameters != null)
					all_type_parameters.Add (MemberName.TypeParameters[i]);

				var name = CurrentTypeParameters[i].MemberName.Name;
				names[parent_offset + i] = name;
				for (int ii = 0; ii < parent_offset + i; ++ii) {
					if (names[ii] != name)
						continue;

					var tp = CurrentTypeParameters[i];
					var conflict = all_type_parameters[ii];

					tp.WarningParentNameConflict (conflict);
				}
			}

			if (all_type_parameters == null)
				all_type_parameters = CurrentTypeParameters;

			return names;
		}
示例#38
0
文件: class.cs 项目: fvalette/mono
		//
		// Defines the type in the appropriate ModuleBuilder or TypeBuilder.
		//
		public override bool CreateContainer ()
		{
			if (TypeBuilder != null)
				return !error;

			if (error)
				return false;

			if (IsPartialPart) {
				spec = PartialContainer.spec;
				TypeBuilder = PartialContainer.TypeBuilder;
				all_tp_builders = PartialContainer.all_tp_builders;
				all_type_parameters = PartialContainer.all_type_parameters;
			} else {
				if (!CreateTypeBuilder ()) {
					error = true;
					return false;
				}
			}

			return base.CreateContainer ();
		}
示例#39
0
void case_347()
#line 2854 "cs-parser.jay"
{
		var tparams = new TypeParameters ();
		tparams.Add ((TypeParameter)yyVals[0+yyTop]);
		yyVal = tparams;
	  }
示例#40
0
文件: decl.cs 项目: johnluetke/mono
		public MemberName (string name, TypeParameters tparams, FullNamedExpression explicitInterface, Location loc)
			: this (name, tparams, loc)
		{
			this.ExplicitInterface = explicitInterface;
		}
示例#41
0
void case_364()
#line 2999 "cs-parser.jay"
{
		var tparams = new TypeParameters ();
		tparams.Add ((TypeParameter)yyVals[0+yyTop]);
		yyVal = tparams;
		locationListStack.Push (new List<Location> ());
	  }
示例#42
0
文件: decl.cs 项目: johnluetke/mono
		public static string MakeName (string name, TypeParameters args)
		{
			if (args == null)
				return name;

			return name + "`" + args.Count;
		}
示例#43
0
		public AnonymousMethodStorey (Block block, TypeContainer parent, MemberBase host, TypeParameters tparams, string name)
			: base (parent, MakeMemberName (host, name, unique_id, tparams, block.StartLocation),
				tparams, Modifiers.SEALED)
		{
			OriginalSourceBlock = block;
			ID = unique_id++;
		}
示例#44
0
		//
		// Creates a host for the anonymous method
		//
		AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
		{
			//
			// Anonymous method body can be converted to
			//
			// 1, an instance method in current scope when only `this' is hoisted
			// 2, a static method in current scope when neither `this' nor any variable is hoisted
			// 3, an instance method in compiler generated storey when any hoisted variable exists
			//

			Modifiers modifiers;
			if (Block.HasCapturedVariable || Block.HasCapturedThis) {
				storey = FindBestMethodStorey ();
				modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
			} else {
				if (ec.CurrentAnonymousMethod != null)
					storey = ec.CurrentAnonymousMethod.Storey;

				modifiers = Modifiers.STATIC | Modifiers.PRIVATE;
			}

			TypeContainer parent = storey != null ? storey : ec.CurrentTypeDefinition.Parent.PartialContainer;

			MemberCore mc = ec.MemberContext as MemberCore;
			string name = CompilerGeneratedClass.MakeName (parent != storey ? block_name : null,
				"m", null, unique_id++);

			MemberName member_name;
			if (storey == null && ec.CurrentTypeParameters != null) {

				var hoisted_tparams = ec.CurrentTypeParameters;
				var type_params = new TypeParameters (hoisted_tparams.Count);
				for (int i = 0; i < hoisted_tparams.Count; ++i) {
				    type_params.Add (hoisted_tparams[i].CreateHoistedCopy (null));
				}

				member_name = new MemberName (name, type_params, Location);
			} else {
				member_name = new MemberName (name, Location);
			}

			string real_name = String.Format (
				"{0}~{1}{2}", mc.GetSignatureForError (), GetSignatureForError (),
				parameters.GetSignatureForError ());

			return new AnonymousMethodMethod (parent,
				this, storey, new TypeExpression (ReturnType, Location), modifiers,
				real_name, member_name, parameters);
		}
void case_357()
{
		var tparams = new TypeParameters ();
		tparams.Add ((TypeParameter)yyVals[0+yyTop]);
		yyVal = tparams;
	  }
示例#46
0
			void AddConstraints(AstNode parent, TypeParameters d)
			{
				if (d == null)
					return;
				for (int i = 0; i < d.Count; i++) {
					var typeParameter = d [i];
					if (typeParameter == null)
						continue;
					var c = typeParameter.Constraints;
					if (c == null)
						continue;
					var location = LocationsBag.GetLocations(c);
					var constraint = new Constraint();
					constraint.AddChild(new CSharpTokenNode(Convert(c.Location), Roles.WhereKeyword), Roles.WhereKeyword);
					constraint.AddChild(new SimpleType(Identifier.Create(c.TypeParameter.Value, Convert(c.TypeParameter.Location))), Roles.ConstraintTypeParameter);
					if (location != null)
						constraint.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.Colon), Roles.Colon);
					var commaLocs = LocationsBag.GetLocations(c.ConstraintExpressions);
					int curComma = 0;
					if (c.ConstraintExpressions != null) {
						foreach (var expr in c.ConstraintExpressions) {
							constraint.AddChild(ConvertToType(expr), Roles.BaseType);
							var sce = expr as SpecialContraintExpr;
							if (sce != null) {
								switch (sce.Constraint) {
									case SpecialConstraint.Class:
										break;
									case SpecialConstraint.Struct:
										break;
									case SpecialConstraint.Constructor:
										var bl = LocationsBag.GetLocations(expr);
										if (bl != null) {
											constraint.AddChild(new CSharpTokenNode(Convert(bl [0]), Roles.LPar), Roles.LPar);
											constraint.AddChild(new CSharpTokenNode(Convert(bl [1]), Roles.RPar), Roles.RPar);
										}
										break;
								}
							}

							if (commaLocs != null && curComma < commaLocs.Count)
								constraint.AddChild(new CSharpTokenNode(Convert(commaLocs [curComma++]), Roles.Comma), Roles.Comma);
						}
					}
					
					// We need to sort the constraints by position; as they might be in a different order than the type parameters
					AstNode prevSibling = parent.LastChild;
					while (prevSibling.StartLocation > constraint.StartLocation && prevSibling.PrevSibling != null)
						prevSibling = prevSibling.PrevSibling;
					parent.InsertChildAfter(prevSibling, constraint, Roles.Constraint);
				}
			}
示例#47
0
		protected bool DoResolveCore (ResolveContext rc)
		{
			if (rc.CurrentTypeParameters != null && rc.CurrentTypeParameters [0].IsMethodTypeParameter)
				context_mvars = rc.CurrentTypeParameters;

			int errors = rc.Report.Errors;
			var pt = rc.Module.PredefinedTypes;

			binder_type = pt.GetBinder (rc).Resolve ();

			isPlayScriptDynamicMode = pt.IsPlayScriptDynamicMode;
			isPlayScriptAotMode = pt.IsPlayScriptAotMode;

			// NOTE: Use AsCallSite if in PlayScript AOT mode only.
			if (isPlayScriptAotMode) { 
				pt.AsCallSite.Resolve ();
				pt.AsCallSiteGeneric.Resolve ();
			} else {
				pt.CallSite.Resolve ();
				pt.CallSiteGeneric.Resolve ();
			}

			eclass = ExprClass.Value;

			if (type == null)
				type = rc.BuiltinTypes.Dynamic;

			if (rc.Report.Errors == errors)
				return true;

			if (isPlayScriptDynamicMode) {
				rc.Report.Error (7027, loc,
					"PlayScript dynamic operation cannot be compiled without `ascorlib.dll' assembly reference");
			} else {
				rc.Report.Error (1969, loc,
					"Dynamic operation cannot be compiled without `Microsoft.CSharp.dll' assembly reference");
			}
			return false;
		}
示例#48
0
文件: anonymous.cs 项目: zzlang/mono
		//
		// Creates a host for the anonymous method
		//
		AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
		{
			//
			// Anonymous method body can be converted to
			//
			// 1, an instance method in current scope when only `this' is hoisted
			// 2, a static method in current scope when neither `this' nor any variable is hoisted
			// 3, an instance method in compiler generated storey when any hoisted variable exists
			//

			Modifiers modifiers;
			var src_block = Block.Original.Explicit;
			if (src_block.HasCapturedVariable || src_block.HasCapturedThis) {
				storey = FindBestMethodStorey ();

				//
				// For iterators we can host everything in one class
				//
				if (storey == null && Block.TopBlock.StateMachine is IteratorStorey)
					storey = block.TopBlock.StateMachine;

				modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
			} else {
				if (ec.CurrentAnonymousMethod != null)
					storey = ec.CurrentAnonymousMethod.Storey;

				modifiers = Modifiers.STATIC | Modifiers.PRIVATE;
			}

			var parent = storey != null ? storey : ec.CurrentTypeDefinition.Parent.PartialContainer;

			string name = CompilerGeneratedContainer.MakeName (parent != storey ? block_name : null,
				"m", null, ec.Module.CounterAnonymousMethods++);

			MemberName member_name;
			if (storey == null && ec.CurrentTypeParameters != null) {

				var hoisted_tparams = ec.CurrentTypeParameters;
				var type_params = new TypeParameters (hoisted_tparams.Count);
				for (int i = 0; i < hoisted_tparams.Count; ++i) {
				    type_params.Add (hoisted_tparams[i].CreateHoistedCopy (null));
				}

				member_name = new MemberName (name, type_params, Location);
			} else {
				member_name = new MemberName (name, Location);
			}

			return new AnonymousMethodMethod (parent,
				this, storey, new TypeExpression (ReturnType, Location), modifiers,
				member_name, parameters);
		}
示例#49
0
文件: dynamic.cs 项目: caomw/mono
		public DynamicSiteClass (TypeDefinition parent, MemberBase host, TypeParameters tparams)
			: base (parent, MakeMemberName (host, "DynamicSite", parent.DynamicSitesCounter, tparams, Location.Null), tparams, Modifiers.STATIC, MemberKind.Class)
		{
			parent.DynamicSitesCounter++;
		}
示例#50
0
文件: class.cs 项目: fvalette/mono
		//
		// Creates a proxy base method call inside this container for hoisted base member calls
		//
		public MethodSpec CreateHoistedBaseCallProxy (ResolveContext rc, MethodSpec method)
		{
			Method proxy_method;

			//
			// One proxy per base method is enough
			//
			if (hoisted_base_call_proxies == null) {
				hoisted_base_call_proxies = new Dictionary<MethodSpec, Method> ();
				proxy_method = null;
			} else {
				hoisted_base_call_proxies.TryGetValue (method, out proxy_method);
			}

			if (proxy_method == null) {
				string name = CompilerGeneratedContainer.MakeName (method.Name, null, "BaseCallProxy", hoisted_base_call_proxies.Count);

				MemberName member_name;
				TypeArguments targs = null;
				TypeSpec return_type = method.ReturnType;
				var local_param_types = method.Parameters.Types;

				if (method.IsGeneric) {
					//
					// Copy all base generic method type parameters info
					//
					var hoisted_tparams = method.GenericDefinition.TypeParameters;
					var tparams = new TypeParameters ();

					targs = new TypeArguments ();
					targs.Arguments = new TypeSpec[hoisted_tparams.Length];
					for (int i = 0; i < hoisted_tparams.Length; ++i) {
						var tp = hoisted_tparams[i];
						var local_tp = new TypeParameter (tp, null, new MemberName (tp.Name, Location), null);
						tparams.Add (local_tp);

						targs.Add (new SimpleName (tp.Name, Location));
						targs.Arguments[i] = local_tp.Type;
					}

					member_name = new MemberName (name, tparams, Location);

					//
					// Mutate any method type parameters from original
					// to newly created hoisted version
					//
					var mutator = new TypeParameterMutator (hoisted_tparams, tparams);
					return_type = mutator.Mutate (return_type);
					local_param_types = mutator.Mutate (local_param_types);
				} else {
					member_name = new MemberName (name);
				}

				var base_parameters = new Parameter[method.Parameters.Count];
				for (int i = 0; i < base_parameters.Length; ++i) {
					var base_param = method.Parameters.FixedParameters[i];
					base_parameters[i] = new Parameter (new TypeExpression (local_param_types [i], Location),
						base_param.Name, base_param.ModFlags, null, Location);
					base_parameters[i].Resolve (this, i);
				}

				var cloned_params = ParametersCompiled.CreateFullyResolved (base_parameters, method.Parameters.Types);
				if (method.Parameters.HasArglist) {
					cloned_params.FixedParameters[0] = new Parameter (null, "__arglist", Parameter.Modifier.NONE, null, Location);
					cloned_params.Types[0] = Module.PredefinedTypes.RuntimeArgumentHandle.Resolve ();
				}

				// Compiler generated proxy
				proxy_method = new Method (this, new TypeExpression (return_type, Location),
					Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED | Modifiers.DEBUGGER_HIDDEN,
					member_name, cloned_params, null);

				var block = new ToplevelBlock (Compiler, proxy_method.ParameterInfo, Location) {
					IsCompilerGenerated = true
				};

				var mg = MethodGroupExpr.CreatePredefined (method, method.DeclaringType, Location);
				mg.InstanceExpression = new BaseThis (method.DeclaringType, Location);
				if (targs != null)
					mg.SetTypeArguments (rc, targs);

				// Get all the method parameters and pass them as arguments
				var real_base_call = new Invocation (mg, block.GetAllParametersArguments ());
				Statement statement;
				if (method.ReturnType.Kind == MemberKind.Void)
					statement = new StatementExpression (real_base_call);
				else
					statement = new Return (real_base_call, Location);

				block.AddStatement (statement);
				proxy_method.Block = block;

				members.Add (proxy_method);
				proxy_method.Define ();
				proxy_method.PrepareEmit ();

				hoisted_base_call_proxies.Add (method, proxy_method);
			}

			return proxy_method.Spec;
		}
示例#51
0
文件: dynamic.cs 项目: caomw/mono
		protected bool DoResolveCore (ResolveContext rc)
		{
			foreach (var arg in arguments) {
				if (arg.Type == InternalType.VarOutType) {
					// Should be special error message about dynamic dispatch
					rc.Report.Error (8047, arg.Expr.Location, "Declaration expression cannot be used in this context");
				}
			}

			if (rc.CurrentTypeParameters != null && rc.CurrentTypeParameters[0].IsMethodTypeParameter)
				context_mvars = rc.CurrentTypeParameters;

			int errors = rc.Report.Errors;
			var pt = rc.Module.PredefinedTypes;

			binder_type = pt.Binder.Resolve ();
			pt.CallSite.Resolve ();
			pt.CallSiteGeneric.Resolve ();

			eclass = ExprClass.Value;

			if (type == null)
				type = rc.BuiltinTypes.Dynamic;

			if (rc.Report.Errors == errors)
				return true;

			rc.Report.Error (1969, loc,
				"Dynamic operation cannot be compiled without `Microsoft.CSharp.dll' assembly reference");
			return false;
		}
示例#52
0
文件: anonymous.cs 项目: rabink/mono
		public HoistedStoreyClass (TypeDefinition parent, MemberName name, TypeParameters tparams, Modifiers mods, MemberKind kind)
			: base (parent, name, mods | Modifiers.PRIVATE, kind)
		{

			if (tparams != null) {
				var type_params = name.TypeParameters;
				var src = new TypeParameterSpec[tparams.Count];
				var dst = new TypeParameterSpec[tparams.Count];

				for (int i = 0; i < tparams.Count; ++i) {
					type_params[i] = tparams[i].CreateHoistedCopy (spec);

					src[i] = tparams[i].Type;
					dst[i] = type_params[i].Type;
				}

				// A copy is not enough, inflate any type parameter constraints
				// using a new type parameters
				var inflator = new TypeParameterInflator (this, null, src, dst);
				for (int i = 0; i < tparams.Count; ++i) {
					src[i].InflateConstraints (inflator, dst[i]);
				}

				mutator = new TypeParameterMutator (tparams, type_params);
			}
		}
示例#53
0
文件: class.cs 项目: agallero/mono
		string[] CreateTypeParameters ()
		{
			string[] names;
			int parent_offset = 0;
			var parent_all = Parent.all_type_parameters;
			if (parent_all != null) {
				if (CurrentTypeParameters == null) {
					all_type_parameters = Parent.all_type_parameters;
					return Parent.all_tp_builders.Select (l => l.Name).ToArray ();
				}

				names = new string[parent_all.Count + CurrentTypeParameters.Count];
				all_type_parameters = new TypeParameters (names.Length);
				all_type_parameters.Add (Parent.all_type_parameters);

				parent_offset = all_type_parameters.Count;
				for (int i = 0; i < parent_offset; ++i)
					names[i] = all_type_parameters[i].MemberName.Name;

			} else {
				names = new string[CurrentTypeParameters.Count];
			}

			for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
				if (all_type_parameters != null)
					all_type_parameters.Add (MemberName.TypeParameters[i]);

				var name = CurrentTypeParameters[i].MemberName.Name;
				names[parent_offset + i] = name;
				for (int ii = 0; ii < parent_offset + i; ++ii) {
					if (names[ii] != name)
						continue;

					var tp = CurrentTypeParameters[i];
					var conflict = all_type_parameters[ii];

					tp.WarningParentNameConflict (conflict);
				}
			}

			if (all_type_parameters == null)
				all_type_parameters = CurrentTypeParameters;

			return names;
		}
示例#54
0
文件: anonymous.cs 项目: rabink/mono
		public static AnonymousTypeClass Create (TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc)
		{
			string name = ClassNamePrefix + parent.Module.CounterAnonymousTypes++;

			ParametersCompiled all_parameters;
			TypeParameters tparams = null;
			SimpleName[] t_args;

			if (parameters.Count == 0) {
				all_parameters = ParametersCompiled.EmptyReadOnlyParameters;
				t_args = null;
			} else {
				t_args = new SimpleName[parameters.Count];
				tparams = new TypeParameters ();
				Parameter[] ctor_params = new Parameter[parameters.Count];
				for (int i = 0; i < parameters.Count; ++i) {
					AnonymousTypeParameter p = parameters[i];
					for (int ii = 0; ii < i; ++ii) {
						if (parameters[ii].Name == p.Name) {
							parent.Compiler.Report.Error (833, parameters[ii].Location,
								"`{0}': An anonymous type cannot have multiple properties with the same name",
									p.Name);

							p = new AnonymousTypeParameter (null, "$" + i.ToString (), p.Location);
							parameters[i] = p;
							break;
						}
					}

					t_args[i] = new SimpleName ("<" + p.Name + ">__T", p.Location);
					tparams.Add (new TypeParameter (i, new MemberName (t_args[i].Name, p.Location), null, null, Variance.None));
					ctor_params[i] = new Parameter (t_args[i], p.Name, Parameter.Modifier.NONE, null, p.Location);
				}

				all_parameters = new ParametersCompiled (ctor_params);
			}

			//
			// Create generic anonymous type host with generic arguments
			// named upon properties names
			//
			AnonymousTypeClass a_type = new AnonymousTypeClass (parent.Module, new MemberName (name, tparams, loc), parameters, loc);

			Constructor c = new Constructor (a_type, name, Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
				null, all_parameters, loc);
			c.Block = new ToplevelBlock (parent.Module.Compiler, c.ParameterInfo, loc);

			// 
			// Create fields and constructor body with field initialization
			//
			bool error = false;
			for (int i = 0; i < parameters.Count; ++i) {
				AnonymousTypeParameter p = parameters [i];

				Field f = new Field (a_type, t_args [i], Modifiers.PRIVATE | Modifiers.READONLY | Modifiers.DEBUGGER_HIDDEN,
					new MemberName ("<" + p.Name + ">", p.Location), null);

				if (!a_type.AddField (f)) {
					error = true;
					continue;
				}

				c.Block.AddStatement (new StatementExpression (
					new SimpleAssign (new MemberAccess (new This (p.Location), f.Name),
						c.Block.GetParameterReference (i, p.Location))));

				ToplevelBlock get_block = new ToplevelBlock (parent.Module.Compiler, p.Location);
				get_block.AddStatement (new Return (
					new MemberAccess (new This (p.Location), f.Name), p.Location));

				Property prop = new Property (a_type, t_args [i], Modifiers.PUBLIC,
					new MemberName (p.Name, p.Location), null);
				prop.Get = new Property.GetMethod (prop, 0, null, p.Location);
				prop.Get.Block = get_block;
				a_type.AddMember (prop);
			}

			if (error)
				return null;

			a_type.AddConstructor (c);
			return a_type;
		}
示例#55
0
            void AddConstraints(AstNode parent, TypeParameters d)
            {
                if (d == null)
                    return;
                for (int i = d.Count - 1; i >= 0; i--) {
                    var typeParameter = d [i];
                    if (typeParameter == null)
                        continue;
                    var c = typeParameter.Constraints;
                    if (c == null)
                        continue;
                    var location = LocationsBag.GetLocations (c);
                    var constraint = new Constraint ();
                    constraint.AddChild (new CSharpTokenNode (Convert (c.Location), Roles.WhereKeyword), Roles.WhereKeyword);
                    constraint.AddChild (new SimpleType (Identifier.Create (c.TypeParameter.Value, Convert (c.TypeParameter.Location))), Roles.ConstraintTypeParameter);
                    if (location != null)
                        constraint.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.Colon), Roles.Colon);
                    var commaLocs = LocationsBag.GetLocations (c.ConstraintExpressions);
                    int curComma = 0;
                    if (c.ConstraintExpressions != null) {
                        foreach (var expr in c.ConstraintExpressions) {
                            constraint.AddChild (ConvertToType (expr), Roles.BaseType);
                            if (commaLocs != null && curComma < commaLocs.Count)
                                constraint.AddChild (new CSharpTokenNode (Convert (commaLocs [curComma++]), Roles.Comma), Roles.Comma);
                        }
                    }

                    parent.AddChild (constraint, Roles.Constraint);
                }
            }
示例#56
0
文件: decl.cs 项目: johnluetke/mono
		public MemberName (MemberName left, MemberName right)
		{
			this.Name = right.Name;
			this.Location = right.Location;
			this.TypeParameters = right.TypeParameters;
			this.Left = left;
		}
示例#57
0
		protected bool DoResolveCore (ResolveContext rc)
		{
			if (rc.CurrentTypeParameters != null && rc.CurrentTypeParameters[0].IsMethodTypeParameter)
				context_mvars = rc.CurrentTypeParameters;

			int errors = rc.Report.Errors;
			var pt = rc.Module.PredefinedTypes;

			binder_type = pt.Binder.Resolve ();
			pt.CallSite.Resolve ();
			pt.CallSiteGeneric.Resolve ();

			eclass = ExprClass.Value;

			if (type == null)
				type = rc.BuiltinTypes.Dynamic;

			if (rc.Report.Errors == errors)
				return true;

			rc.Report.Error (1969, loc,
				"Dynamic operation cannot be compiled without `Microsoft.CSharp.dll' assembly reference");
			return false;
		}