Beispiel #1
0
        protected void GenerateMethodBodyCore(TypeCompilationState compilationState, BindingDiagnosticBag diagnostics)
        {
            var factory = new SyntheticBoundNodeFactory(this, this.GetNonNullSyntaxNode(), compilationState, diagnostics);

            factory.CurrentFunction = this;
            if (ContainingType.BaseTypeNoUseSiteDiagnostics is MissingMetadataTypeSymbol)
            {
                // System_Attribute was not found or was inaccessible
                factory.CloseMethod(factory.Block());
                return;
            }

            var baseConstructorCall = MethodCompiler.GenerateBaseParameterlessConstructorInitializer(this, diagnostics);

            if (baseConstructorCall == null)
            {
                // Attribute..ctor was not found or was inaccessible
                factory.CloseMethod(factory.Block());
                return;
            }

            var statements = ArrayBuilder <BoundStatement> .GetInstance();

            statements.Add(factory.ExpressionStatement(baseConstructorCall));
            GenerateMethodBodyStatements(factory, statements, diagnostics);
            statements.Add(factory.Return());

            var block = factory.Block(statements.ToImmutableAndFree());

            factory.CloseMethod(block);
        }
Beispiel #2
0
            internal override void GenerateMethodBody(TypeCompilationState compilationState, DiagnosticBag diagnostics)
            {
                if (ContainingType.BaseTypeNoUseSiteDiagnostics is MissingMetadataTypeSymbol)
                {
                    // System_Attribute is missing. Don't generate anything
                    return;
                }

                var factory = new SyntheticBoundNodeFactory(this, this.GetNonNullSyntaxNode(), compilationState, diagnostics);

                factory.CurrentFunction = this;

                var baseConstructorCall = MethodCompiler.GenerateBaseParameterlessConstructorInitializer(this, diagnostics);

                if (baseConstructorCall == null)
                {
                    // This may happen if Attribute..ctor is not found or is inaccessible
                    return;
                }

                var block = factory.Block(
                    factory.ExpressionStatement(baseConstructorCall),
                    factory.Return());

                factory.CloseMethod(block);
            }
            internal override void GenerateMethodBody(TypeCompilationState compilationState, BindingDiagnosticBag diagnostics)
            {
                //  Method body:
                //
                //  {
                //      Object..ctor();
                //      this.backingField_1 = arg1;
                //      ...
                //      this.backingField_N = argN;
                //  }
                SyntheticBoundNodeFactory F = this.CreateBoundNodeFactory(compilationState, diagnostics);

                int paramCount = this.ParameterCount;

                // List of statements
                BoundStatement[] statements = new BoundStatement[paramCount + 2];
                int statementIndex          = 0;

                //  explicit base constructor call
                Debug.Assert(ContainingType.BaseTypeNoUseSiteDiagnostics.SpecialType == SpecialType.System_Object);
                BoundExpression call = MethodCompiler.GenerateBaseParameterlessConstructorInitializer(this, diagnostics);

                if (call == null)
                {
                    // This may happen if Object..ctor is not found or is inaccessible
                    return;
                }
                statements[statementIndex++] = F.ExpressionStatement(call);

                if (paramCount > 0)
                {
                    AnonymousTypeTemplateSymbol anonymousType = (AnonymousTypeTemplateSymbol)this.ContainingType;
                    Debug.Assert(anonymousType.Properties.Length == paramCount);

                    // Assign fields
                    for (int index = 0; index < this.ParameterCount; index++)
                    {
                        // Generate 'field' = 'parameter' statement
                        statements[statementIndex++] =
                            F.Assignment(F.Field(F.This(), anonymousType.Properties[index].BackingField), F.Parameter(_parameters[index]));
                    }
                }

                // Final return statement
                statements[statementIndex++] = F.Return();

                // Create a bound block
                F.CloseMethod(F.Block(statements));
            }
Beispiel #4
0
            internal override void GenerateMethodBody(TypeCompilationState compilationState, DiagnosticBag diagnostics)
            {
                //  Method body:
                //
                //  {
                //      Object..ctor();
                //      this.backingField_1 = arg1;
                //      ...
                //      this.backingField_N = argN;
                //  }
                SyntheticBoundNodeFactory F = this.CreateBoundNodeFactory(compilationState, diagnostics);

                int paramCount = this.ParameterCount;

                // List of statements
                BoundStatement[] statements = new BoundStatement[paramCount + 2];
                int statementIndex          = 0;

                //  explicit base constructor call
#if XSHARP
                BoundExpression call = null;
                if (((AnonymousTypeTemplateSymbol)this.ContainingType).IsCodeblock)
                {
                    NamedTypeSymbol baseType          = this.ContainingType.BaseTypeNoUseSiteDiagnostics;
                    MethodSymbol    objectConstructor = baseType.InstanceConstructors[0];
                    if (objectConstructor.ParameterCount != 1)
                    {
                        diagnostics.Add(ErrorCode.ERR_BadCtorArgCount, this.Locations[0], baseType, /*desired param count*/ 1);
                    }
                    call = F.Call(F.This(), objectConstructor, F.Literal(_parameters[0].Type.GetDelegateType().DelegateParameters().Length));
                }
                else
                {
                    call = MethodCompiler.GenerateBaseParameterlessConstructorInitializer(this, diagnostics);
                }
#else
                Debug.Assert(ContainingType.BaseTypeNoUseSiteDiagnostics.SpecialType == SpecialType.System_Object);
                BoundExpression call = MethodCompiler.GenerateBaseParameterlessConstructorInitializer(this, diagnostics);
#endif
                if (call == null)
                {
                    // This may happen if Object..ctor is not found or is inaccessible
                    return;
                }
                statements[statementIndex++] = F.ExpressionStatement(call);

                if (paramCount > 0)
                {
                    AnonymousTypeTemplateSymbol anonymousType = (AnonymousTypeTemplateSymbol)this.ContainingType;
#if XSHARP
                    Debug.Assert((!anonymousType.IsCodeblock && anonymousType.Properties.Length == paramCount) || (anonymousType.IsCodeblock && paramCount == 2 && anonymousType.Properties.Length == 1));
#else
                    Debug.Assert(anonymousType.Properties.Length == paramCount);
#endif

                    // Assign fields
#if XSHARP
                    if (anonymousType.IsCodeblock)
                    {
                        statements[statementIndex++] =
                            F.Assignment(F.Field(F.This(), (anonymousType.GetMembers()[0] as AnonymousTypePropertySymbol).BackingField), F.Parameter(_parameters[0]));
                        statements[statementIndex++] =
                            F.Assignment(F.Field(F.This(), (anonymousType.GetMembers()[3] as AnonymousTypePropertySymbol).BackingField), F.Parameter(_parameters[1]));
                    }
                    else
#endif
                    for (int index = 0; index < this.ParameterCount; index++)
                    {
                        // Generate 'field' = 'parameter' statement
                        statements[statementIndex++] =
                            F.Assignment(F.Field(F.This(), anonymousType.Properties[index].BackingField), F.Parameter(_parameters[index]));
                    }
                }

                // Final return statement
                statements[statementIndex++] = F.Return();

                // Create a bound block
                F.CloseMethod(F.Block(statements));
            }