Пример #1
0
        protected MemberContainer(TypeContainer parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, Modifiers def_mod, MemberName name, VSharpAttributes attrs, SymbolKind sym)
        {
            caching_flags   = Flags.Obsolete_Undetected;
            this.SymbolKind = sym;
            this.Parent     = parent;
            this.declaringTypeDefinition = parent;
            this.name = name.Name;
            if (parent != null)
            {
                this.UnresolvedFile = parent.UnresolvedFile;
            }
            this.type_expr = type;
            this.attribs   = attrs;
            member_name    = name;
            mod_flags      = mod;

            mod_flags = ModifiersExtensions.Check(allowed_mod, mod, def_mod, name.Location, Report);
            if (DeclaringTypeDefinition.Kind == TypeKind.Interface)
            {
                mod_flags |= Modifiers.PUBLIC | Modifiers.ABSTRACT;
            }


            if (attrs != null)
            {
                foreach (var a in attrs.Attrs)
                {
                    this.attributes.Add(a);
                }
            }

            this.returnType = type as ITypeReference;

            if (member_name.ExplicitInterface != null)
            {
                ApplyExplicit(null);
            }
        }
Пример #2
0
 public FieldDeclaration(TypeContainer parent, FullNamedExpression type, Modifiers mods, Modifiers allowed, MemberName name, VSharpAttributes attr)
     : base(parent, type, mods, allowed, name, attr, SymbolKind.Field)
 {
 }
Пример #3
0
 public FieldDeclaration(TypeContainer parent, FullNamedExpression type, Modifiers mods, MemberName name, VSharpAttributes attr)
     : this(parent, type, mods, AllowedFieldModifiers, name, attr)
 {
 }
Пример #4
0
 public NewAnonymousTypeExpression(List <AnonymousTypeParameter> parameters, TypeContainer parent, Location loc)
     : base(null, null, loc)
 {
     this.parameters = parameters;
     this.parent     = parent;
 }
Пример #5
0
 protected PropertyBasedMember(TypeContainer parent, FullNamedExpression type, Modifiers mod,
                               Modifiers allowed_mod, MemberName name, VSharpAttributes attrs, SymbolKind sym)
     : base(parent, type, mod, allowed_mod, name, attrs, sym)
 {
 }
Пример #6
0
 public InterfaceDeclaration(TypeContainer parent, MemberName name, Modifiers mod, VSharpAttributes attrs, Location l, CompilationSourceFile file)
     : base(parent, mod, AllowedModifiers, name, attrs, l, TypeKind.Interface, file)
 {
     mod_flags |= Modifiers.ABSTRACT;
 }
Пример #7
0
 public ConstantDeclaration(TypeContainer parent, ITypeReference type, Modifiers mods, MemberName name, VSharpAttributes attr)
     : base(parent, new TypeExpression(type, name.Location), mods, AllowedModifiers, name, attr, SymbolKind.Field)
 {
     mod_flags |= Modifiers.STATIC;
 }
Пример #8
0
 public DestructorDeclaration(TypeContainer parent, Modifiers mod, ParametersCompiled parameters, VSharpAttributes attrs, Location l)
     : base(parent, new TypeExpression(KnownTypeReference.Void, l), mod, AllowedModifiers, new MemberName(MetadataName, l), parameters, attrs, SymbolKind.Destructor)
 {
     ModFlags &= ~Modifiers.PRIVATE;
     ModFlags |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
 }
Пример #9
0
 public ClassDeclaration(TypeContainer parent, MemberName name, Modifiers mod, VSharpAttributes attrs, Location l, CompilationSourceFile file)
     : base(parent, mod, AllowedModifiers, name, attrs, l, TypeKind.Class, file)
 {
 }
Пример #10
0
 public MethodOrOperator(TypeContainer parent, FullNamedExpression returnType, Modifiers mod, Modifiers allowed,
                         MemberName name, ParametersCompiled parameters, VSharpAttributes attrs, SymbolKind sym)
     : base(parent, returnType, mod, allowed, name, parameters, attrs, sym)
 {
 }
Пример #11
0
        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 UnresolvedTypeParameterSpec(SymbolKind.TypeDefinition, i, p.Location, t_args[i].Name));
                    ctor_params[i] = new Parameter(t_args[i], p.Name, ParameterModifier.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.UnresolvedFile as CompilationSourceFile, new MemberName(name, tparams, loc), parameters, loc);

            ConstructorDeclaration c = new ConstructorDeclaration(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];

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

                c.Block.AddStatement(new StatementExpression(
                                         new SimpleAssign(new MemberAccess(new SelfReference(p.Location), f.Name),
                                                          new SimpleName(all_parameters[i].Name, p.Location))));

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

                PropertyDeclaration prop = new PropertyDeclaration(a_type, t_args[i], Modifiers.PUBLIC,
                                                                   new MemberName(p.Name, p.Location), null);
                prop.Getter = new GetterDeclaration(prop, 0, null, p.Location);
                (prop.Getter as GetterDeclaration).Block = get_block;
                a_type.AddMember(prop);
            }

            a_type.AddMember(c);
            return(a_type);
        }
Пример #12
0
 protected CompilerGeneratedContainer(TypeContainer parent, MemberName name, Modifiers mod, TypeKind kind, CompilationSourceFile f)
     : base(parent, mod, mod, name, null, Location.Null, kind, f)
 {
     ModFlags = mod | Modifiers.COMPILER_GENERATED | Modifiers.SEALED;
 }
Пример #13
0
 protected CompilerGeneratedContainer(TypeContainer parent, MemberName name, Modifiers mod, CompilationSourceFile f)
     : this(parent, name, mod, TypeKind.Class, f)
 {
 }
Пример #14
0
 void ConvertAccessor(TypeContainer currentTypeDefinition, Modifiers accessorModifiers, IUnresolvedMember p, bool memberIsExtern)
 {
     SymbolKind    = SymbolKind.Accessor;
     AccessorOwner = p;
 }
Пример #15
0
 public StructDeclaration(TypeContainer parent, MemberName name, Modifiers mod, VSharpAttributes attrs, Location l, CompilationSourceFile file)
     : base(parent, mod, AllowedModifiers, name, attrs, l, TypeKind.Struct, file)
 {
     mod_flags |= Modifiers.SEALED;
 }
Пример #16
0
 public ClassOrStructDeclaration(TypeContainer ns, Modifiers mods, Modifiers allowed, MemberName name, VSharpAttributes attr, Location l, TypeKind kind, CompilationSourceFile file)
     : base(ns, mods, allowed, name, attr, l, kind, file)
 {
 }
Пример #17
0
 public ConstructorDeclaration(TypeContainer parent, string name, Modifiers mod, VSharpAttributes attrs, ParametersCompiled args, Location loc)
     : base(parent, new TypeExpression(parent, loc), mod, AllowedModifiers, new MemberName(name, loc), args, attrs, SymbolKind.Constructor)
 {
 }
Пример #18
0
 public ConstantDeclaration(TypeContainer parent, FullNamedExpression type, Modifiers mods, MemberName name, VSharpAttributes attr)
     : base(parent, type, mods, AllowedModifiers, name, attr, SymbolKind.Field)
 {
     mod_flags |= Modifiers.STATIC;
 }
Пример #19
0
 public EventDeclaration(TypeContainer parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, VSharpAttributes attrs, bool autogen = false)
     : base(parent, type, mod_flags, name, attrs)
 {
     IsAutoGenerated = autogen;
 }
Пример #20
0
        //
        // If true, this is an explicit interface implementation
        //

        protected InterfaceMemberContainer(TypeContainer parent, FullNamedExpression type, Modifiers mod, Modifiers allowed_mod, MemberName name, VSharpAttributes attrs, SymbolKind sym)
            : base(parent, type, mod, allowed_mod, Modifiers.PRIVATE, name, attrs, sym)
        {
            IsInterfaceMember = parent.Kind == TypeKind.Interface;
        }
Пример #21
0
 public EventFieldDeclaration(TypeContainer parent, FullNamedExpression type, Modifiers mod_flags, MemberName name, VSharpAttributes attrs)
     : base(parent, type, mod_flags, name, attrs, true)
 {
 }