示例#1
0
        public override void Bind(BindContext context)
        {
            if (IsBound)
            {
                return;
            }

            if (!IsUntypedGenericMethod)
            {
                foreach (ParameterSymbol param in Parameters)
                {
                    param.Bind(context);
                }
            }

            if (RoslynSymbol.IsAbstract)
            {
                return;
            }

            IMethodSymbol methodSymbol = RoslynSymbol;

            if (methodSymbol.DeclaringSyntaxReferences.IsEmpty)
            {
                throw new CompilerException($"Could not find syntax reference for {methodSymbol}");
            }

            SyntaxNode declaringSyntax = methodSymbol.DeclaringSyntaxReferences.First().GetSyntax();

            context.CurrentNode = declaringSyntax;

            CheckHiddenMethods(context);

            if (OverridenMethod != null)
            {
                OverridenMethod.AddOverride(this);
            }

            if (methodSymbol.MethodKind != MethodKind.PropertyGet && methodSymbol.MethodKind != MethodKind.PropertySet &&
                ((MethodDeclarationSyntax)methodSymbol.DeclaringSyntaxReferences.First().GetSyntax()).Modifiers.Any(SyntaxKind.PartialKeyword))
            {
                throw new NotSupportedException(LocStr.CE_PartialMethodsNotSupported, methodSymbol.DeclaringSyntaxReferences.FirstOrDefault());
            }

            BinderSyntaxVisitor bodyVisitor = new BinderSyntaxVisitor(this, context);

            if (declaringSyntax is MethodDeclarationSyntax methodSyntax)
            {
                if (methodSyntax.Body != null)
                {
                    MethodBody = bodyVisitor.Visit(methodSyntax.Body);
                }
                else if (methodSyntax.ExpressionBody != null)
                {
                    MethodBody = bodyVisitor.VisitExpression(methodSyntax.ExpressionBody, ReturnType);
                }
                else
                {
                    throw new CompilerException("No method body or expression body found", methodSyntax.GetLocation());
                }
            }
            else if (declaringSyntax is AccessorDeclarationSyntax propertySyntax)
            {
                if (propertySyntax.Body != null)
                {
                    MethodBody = bodyVisitor.Visit(propertySyntax.Body);
                }
                else if (propertySyntax.ExpressionBody != null)
                {
                    MethodBody = bodyVisitor.VisitExpression(propertySyntax.ExpressionBody, ReturnType);
                }
                else if (methodSymbol.MethodKind == MethodKind.PropertySet)
                {
                    MethodBody = GeneratePropertyAutoSetter(context, propertySyntax);
                }
                else if (methodSymbol.MethodKind == MethodKind.PropertyGet)
                {
                    MethodBody = GeneratePropertyAutoGetter(context, propertySyntax);
                }
                else
                {
                    throw new CompilerException("No method body or expression body found", propertySyntax.GetLocation());
                }
            }
            else if (declaringSyntax is ArrowExpressionClauseSyntax arrowExpression)
            {
                MethodBody = bodyVisitor.VisitExpression(arrowExpression.Expression, ReturnType);
            }
            else
            {
                throw new Exception($"Declaring syntax {declaringSyntax.Kind()} was not a method or property");
            }

            SetupAttributes(context);
        }
示例#2
0
 public override void Bind(BindContext context) => throw new SemanticExecutionException("ExprRef inherits its expr's bounded_ status");
示例#3
0
 public override void Bind(BindContext context)
 {
     // Extern types do not need to be bound as they will always have their members bound lazily only when referenced and fields just exist already.
 }
示例#4
0
 public override void Bind(BindContext context)
 {
     throw new NotSupportedException("Local symbols cannot be bound");
 }
示例#5
0
        public override void Bind(BindContext context)
        {
            Debug.Assert(IsLeaf());
            Debug.Assert(tabRef_ is null);
            Debug.Assert(tabName_ == tableName_());

            // if table name is not given, search through all tablerefs
            isParameter_ = false;
            tabRef_      = context.GetTableRef(tabName_, colName_);

            // we can't find the column in current context, so it could an outer reference
            if (tabRef_ is null)
            {
                // can't find in my current context, try my ancestors levels up: order is important
                // as we are matching naming with the order closest first
                //    ... from A ... ( from A where exists (... from B where b1 > a.a1))
                // so a.a1 matches the inner side A.
                //
                BindContext parent = context;
                while ((parent = parent.parent_) != null)
                {
                    tabRef_ = parent.GetTableRef(tabName_, colName_);
                    if (tabRef_ != null)
                    {
                        // we are actually switch the context to parent, whichTab_ is not right ...
                        isParameter_ = true;
                        tabRef_.colRefedBySubq_.Add(this);

                        // mark myself a correlated query and remember whom I am correlated to
                        var mystmt = context.stmt_ as SelectStmt;
                        mystmt.isCorrelated_ = true;
                        mystmt.correlatedWhich_.Add(parent.stmt_ as SelectStmt);

                        context = parent;
                        break;
                    }
                }
                if (tabRef_ is null)
                {
                    throw new SemanticAnalyzeException($"can't bind column '{colName_}' to table");
                }
            }

            // we have identified the tableRef this belongs to, make sure outputName not conflicting
            // Eg. select c1 as c2, ... from c
            if (!outputName_.Equals(colName_) &&
                tabRef_.LocateColumn(outputName_) != null)
            {
                throw new SemanticAnalyzeException($"conflicting output name {outputName_} is not allowed");
            }

            Debug.Assert(tabRef_ != null);
            if (!isParameter_)
            {
                Debug.Assert(tableRefs_.Count == 0);
                tableRefs_.Add(tabRef_);
            }
            // FIXME: we shall not decide ordinal_ so early but if not, hard to handle outerref
            ordinal_ = context.ColumnOrdinal(tabRef_.alias_, colName_, out ColumnType type);
            type_    = type;
            markBounded();
        }
示例#6
0
 BindContext <TContext, TSource> ContextProvider(BindContext <TContext, TSource> input, TContext context)
 {
     return(context as BindContext <TContext, TSource> ?? new BindContextProxy <TContext, TSource>(context, input.SourceContext));
 }
示例#7
0
            public async Task Send(BindContext <InputContext, Thing> context, IPipe <BindContext <InputContext, Thing> > next)
            {
                _completed.SetResult(context.Right);

                await next.Send(context);
            }
示例#8
0
 public override BindContext Bind(BindContext parent)
 {
     return(select_.Bind(parent));
 }
示例#9
0
 public override BindContext Bind(BindContext parent) => insert_.Bind(parent);
示例#10
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="BindData"/> class.
 /// </summary>
 /// <param name="target">
 ///     The target.
 /// </param>
 /// <param name="source">
 ///     The source.
 /// </param>
 public BindData(BindContext target, BindContext source)
 {
     this.Target = target;
     this.Source = source;
 }
示例#11
0
 BindContext <TLeft, TRight> ContextProvider(BindContext <TLeft, TRight> input, TLeft context)
 {
     return(context as BindContext <TLeft, TRight> ?? new BindContextProxy <TLeft, TRight>(context, input.Right));
 }
示例#12
0
                internal ILData(ILInstructionsAttribute atrib, FieldBinder fields, MethodBinder methods, LocalBinder locals, ArgBinder args, Pass pass)
                {
                    //int ct = 0;
                    this.canEmit             = false;
                    this.localDatas          = new();
                    this.instructionEmitters = new();
                    foreach (var v in locals.arr)
                    {
                        this.localDatas.Add(v);
                    }
                    var stream      = new InstrStream(atrib);
                    var bindContext = new BindContext(fields, methods, locals, args);

                    var labelManager = this.lblMgr = new LabelManager();

                    labelManager.logger = pass.logger;
                    var currentLabels = new List <String>();

                    while (!stream.IsFinished())
                    {
                        while (stream.Read(out LabelToken tok))
                        {
                            stream.Advance(1);
                            currentLabels.Add(tok.name);
                        }

                        if (stream.Read(out Op op))
                        {
                            stream.Advance(1);
                            var emitter = pass.OpToEmitter(op, stream, labelManager.AddCallback, bindContext);
                            if (emitter is null)
                            {
                                //pass.logger.Error("No emitter produced");
                                return;
                            }
                            //pass.logger.Message($"Successfully got emitter");
                            var ctx = new EmitterContext(emitter);
                            //pass.logger.Message($"Successfully got emitcontext");
                            this.instructionEmitters.Add(ctx);
                            //pass.logger.Message($"Successfully added emitcontext, handling labels");
                            foreach (var l in currentLabels)
                            {
                                //pass.logger.Message($"Applying label {l}");
                                if (!labelManager.LabelCreated(l, ctx))
                                {
                                    pass.logger.Error("Duplicate label");
                                    return;
                                }
                            }
                            currentLabels.Clear();
                        }
                        else
                        {
                            pass.logger.Error("Expected Op or Label");
                            return;
                        }
                    }
                    //pass.logger.Message($"{ct++}");
                    pass.logger.Message($"Building emit data successful");
                    this.canEmit = true;
                }
示例#13
0
 public abstract void Bind(BindContext context);
示例#14
0
 public override void Bind(BindContext context)
 {
     Type             = context.GetTypeSymbol(RoslynSymbol.Type);
     ContainingSymbol = (MethodSymbol)context.GetSymbol(RoslynSymbol.ContainingSymbol);
 }
示例#15
0
 public void EnumObjectParamTest()
 {
     using var bc = new BindContext();
     Assert.That(() => bc.EnumObjectParam(), Throws.Nothing);
 }
示例#16
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="BindData"/> class.
 /// </summary>
 /// <param name="target">
 ///     The target.
 /// </param>
 /// <param name="source">
 ///     The source.
 /// </param>
 public BindData(BindContext target, BindContext source)
 {
     this.Target = target;
     this.Source = source;
 }