예제 #1
0
 public MixinPatch(
     ExpressionContext context,
     MethodBodySymbolContext methodBodySymbolContext,
     DiagnosticBag diagnostics) : base(diagnostics)
 {
     _context = context;
     _methodBodySymbolContext = methodBodySymbolContext;
     _expression = new Lazy <IExpression>(BindExpression);
 }
예제 #2
0
        public ConditionalExpression(Conditional_expressionContext context, MethodBodySymbolContext methodBodySymbolContext, DiagnosticBag diagnostics) : base(diagnostics)
        {
            _context = context;
            _methodBodySymbolContext = methodBodySymbolContext;

            _condition = new Lazy <IExpression>(BindCondition);
            _ifTrue    = new Lazy <IExpression>(BindIfTrue);
            _ifFalse   = new Lazy <IExpression>(BindIfFalse);
            _type      = new Lazy <IType>(BindType);
        }
예제 #3
0
 public MethodPatch(
     Method_referenceContext context,
     MethodBodySymbolContext methodBodySymbolContext,
     DiagnosticBag diagnostics) : base(diagnostics)
 {
     _context = context;
     _methodBodySymbolContext = methodBodySymbolContext;
     _method        = new Lazy <IMethod>(BindMethod);
     _typeArguments = new Lazy <ImmutableArray <IType> >(BindTypeArguments);
 }
예제 #4
0
 public ReturnStatement(
     Return_statementContext context,
     int ordinalPositionInMethod,
     MethodBodySymbolContext methodBodySymbolContext,
     DiagnosticBag diagnostics) : base(diagnostics)
 {
     _context = context;
     OrdinalPositionInMethod  = ordinalPositionInMethod;
     _methodBodySymbolContext = methodBodySymbolContext.WithStatement(this);
     _expression = new Lazy <IExpression>(BindExpression);
 }
예제 #5
0
        public LocalReferenceExpression(
            Local_reference_expressionContext context,
            MethodBodySymbolContext methodBodySymbolContext,
            DiagnosticBag diagnostics) : base(diagnostics)
        {
            _context = context;
            _methodBodySymbolContext = methodBodySymbolContext;

            Identifier = context.LOWERCASE_IDENTIFIER().Symbol.Text;
            _local     = new Lazy <ILocal>(BindLocal);
        }
예제 #6
0
 public ObjectPatchingExpression(
     Object_patching_expressionContext context,
     MethodBodySymbolContext methodBodySymbolContext,
     DiagnosticBag diagnostics) : base(diagnostics)
 {
     _context = context;
     _methodBodySymbolContext = methodBodySymbolContext;
     _expression = new Lazy <IExpression>(BindExpression);
     _patches    = new Lazy <ImmutableArray <IObjectPatch> >(BindPatches);
     Type        = new PatchedType(this);
 }
예제 #7
0
 public MatchExpression(
     Match_expressionContext context,
     MethodBodySymbolContext methodBodySymbolContext,
     DiagnosticBag diagnostics) : base(diagnostics)
 {
     _context = context;
     _methodBodySymbolContext = methodBodySymbolContext;
     _expression          = new Lazy <IExpression>(BindExpression);
     _matchExpressionArms = new Lazy <ImmutableArray <IMatchExpressionArm> >(BindMatchExpressionArms);
     _type = new Lazy <IType>(BindType);
 }
예제 #8
0
        public PrefixUnaryOperatorExpression(
            Prefix_unary_operator_expressionContext context,
            MethodBodySymbolContext methodBodySymbolContext,
            DiagnosticBag diagnostics) : base(diagnostics)
        {
            _context = context;
            _methodBodySymbolContext = methodBodySymbolContext;

            _expression = new Lazy <IExpression>(BindExpression);
            _operator   = new Lazy <Operator>(BindOperator);
            _type       = new Lazy <IType>(BindType);
        }
예제 #9
0
        public BinaryOperatorExpression(
            Binary_operator_expressionContext context,
            MethodBodySymbolContext methodBodySymbolContext,
            DiagnosticBag diagnostics) : base(diagnostics)
        {
            _context = context;
            _methodBodySymbolContext = methodBodySymbolContext;

            _left     = new Lazy <IExpression>(BindLeft);
            _right    = new Lazy <IExpression>(BindRight);
            _operator = new Lazy <Operator>(BindOperator);
            _type     = new Lazy <IType>(BindType);
        }
예제 #10
0
        public MemberInvocationExpression(
            Member_invocation_expressionContext context,
            MethodBodySymbolContext methodBodySymbolContext,
            DiagnosticBag diagnostics) : base(diagnostics)
        {
            _context = context;
            _methodBodySymbolContext = methodBodySymbolContext;

            MemberName  = _context.UPPERCASE_IDENTIFIER().Symbol.Text;
            _expression = new Lazy <IExpression>(BindExpression);
            _arguments  = new Lazy <ImmutableArray <IExpression> >(BindArguments);
            _method     = new Lazy <IInterfaceMethod>(BindMethod);
        }
        public StaticInvocationExpression(
            Static_invocation_expressionContext context,
            MethodBodySymbolContext methodBodySymbolContext,
            DiagnosticBag diagnostics) : base(diagnostics)
        {
            _context = context;
            _methodBodySymbolContext = methodBodySymbolContext;

            MethodName     = _context.method_reference().qualified_name().GetQualifiedName();
            _arguments     = new Lazy <ImmutableArray <IExpression> >(BindArguments);
            _method        = new Lazy <IMethod>(BindMethod);
            _typeArguments = new Lazy <ImmutableArray <IType> >(BindTypeArguments);
        }
예제 #12
0
        public MatchExpressionArm(
            Match_expression_armContext context,
            MethodBodySymbolContext methodBodySymbolContext,
            DiagnosticBag diagnostics) : base(diagnostics)
        {
            _context = context;
            _methodBodySymbolContext = methodBodySymbolContext;

            IdentifierName = _context.LOWERCASE_IDENTIFIER()?.Symbol.Text;
            Local          = IdentifierName is null ? null : new MatchExpressionArmLocal(this);
            _type          = new Lazy <IType>(BindType);
            _expression    = new Lazy <IExpression>(BindExpression);
        }
예제 #13
0
 public DeclarationStatement(
     Declaration_statementContext context,
     int ordinalPositionInMethod,
     MethodBodySymbolContext methodBodySymbolContext,
     DiagnosticBag diagnostics) : base(diagnostics)
 {
     _context = context;
     OrdinalPositionInMethod  = ordinalPositionInMethod;
     _methodBodySymbolContext = methodBodySymbolContext.WithStatement(this);
     IdentifierName           = _context.LOWERCASE_IDENTIFIER()?.Symbol.Text ?? null;
     _declaredType            = new Lazy <IType?>(BindDeclaredType);
     _expression = new Lazy <IExpression>(BindExpression);
     _type       = new Lazy <IType>(BindType);
     _local      = new Lazy <IDeclaredLocal?>(BindLocal);
 }
        public static void WarnIfUseOfMethodWhichCapturesUnassignedLocals(this MethodBodySymbolContext methodBodySymbolContext, IMethod target, DiagnosticBag diagnostics, Method_referenceContext syntax)
        {
            var currentMethod = methodBodySymbolContext.SourceSymbolContext.Scope;

            Release.Assert(currentMethod != null);
            if (target.DeclaringMethod == currentMethod)
            {
                if (target.InScopeAfter is { } declarationStatement)
                {
                    var currentStatement = methodBodySymbolContext.CurrentStatement;
                    Release.Assert(currentStatement != null);
                    if (declarationStatement.OrdinalPositionInMethod >= currentStatement.OrdinalPositionInMethod)
                    {
                        diagnostics.Add(new Diagnostic(
                                            new Location(syntax),
                                            ErrorCode.UseOfMethodWhichCapturesUnassignedLocals,
                                            ImmutableArray.Create <object?>(target)));
                    }
                }
            }
        }
        public PipedStaticInvocationExpression(
            Piped_static_invocation_expressionContext context,
            MethodBodySymbolContext methodBodySymbolContext,
            DiagnosticBag diagnostics) : base(diagnostics)
        {
            _context = context;
            _methodBodySymbolContext = methodBodySymbolContext;

            _methodName = _context.method_reference().qualified_name().GetQualifiedName();
            if (_methodName.Parent != null)
            {
                _diagnostics.Add(
                    new Diagnostic(
                        new Location(_context.method_reference().qualified_name()),
                        ErrorCode.PipedStaticInvocationExpressionCannotHaveQualifiedName,
                        ImmutableArray.Create <object?>(_methodName.ToString())));
            }

            _arguments     = new Lazy <ImmutableArray <IExpression> >(BindArguments);
            _method        = new Lazy <IMethod>(BindMethod);
            _typeArguments = new Lazy <ImmutableArray <IType> >(BindTypeArguments);
        }
        public static IMethod BindMethod(
            QualifiedName MethodName,
            ImmutableArray <IType> TypeArguments,
            ImmutableArray <IExpression> Arguments,
            Method_referenceContext method_reference,
            MethodBodySymbolContext _methodBodySymbolContext,
            DiagnosticBag _diagnostics)
        {
            var methods = _methodBodySymbolContext.SourceSymbolContext.GetPossibleMethods(MethodName, TypeArguments);

            var matching =
                methods
                .Where(x => x.Parameters.Length == Arguments.Length)
                .Select(x =>
            {
                Diagnostic?diagnostic = null;
                if (TypeArguments.Length > 0)
                {
                    var typeParameters = x.TypeParameters;
                    if (!SourceSymbolContextExtensions.HasValidTypeArguments(
                            TypeArguments,
                            typeParameters,
                            out var diagnosticFunc))
                    {
                        diagnostic = diagnosticFunc(new Location(method_reference));
                    }
                    var substituted = x.Substitute(
                        SourceSymbolContextExtensions.CreateTypeMap(TypeArguments, typeParameters),
                        new Dictionary <IType, IType>());

                    return(method: substituted, diagnostic);
                }
                return(method: x, diagnostic: null);
            })
                .Where(x => x.method.Parameters.Zip(Arguments, (p, a) => a.Type.IsSubtypeOf(p.Type)).All(x => x))
                .ToList();

            if (matching.Count == 1)
            {
                var(target, diagnostic) = matching[0];

                if (diagnostic != null)
                {
                    _diagnostics.Add(diagnostic);
                }

                _methodBodySymbolContext.WarnIfUseOfMethodWhichCapturesUnassignedLocals(target, _diagnostics, method_reference);
                return(target);
            }


            if (matching.Count == 0)
            {
                _diagnostics.Add(new Diagnostic(
                                     new Location(method_reference),
                                     ErrorCode.MethodNotFound,
                                     ImmutableArray.Create <object?>(MethodName, Arguments)));
            }
            else
            {
                _diagnostics.Add(new Diagnostic(
                                     new Location(method_reference),
                                     ErrorCode.AmbigiousMethodReference,
                                     ImmutableArray.Create <object?>(matching)));
            }

            return(new ErrorMethod(MethodName, Arguments.Length));
        }