示例#1
0
        public override Statement Expand(MacroStatement macro)
        {
            int argc = macro.Arguments.Count;

            if (argc != 1 && argc != 2)
            {
                // TODO: localize this message
                throw new System.ArgumentException(
                          Boo.Lang.ResourceManager.Format("AssertArgCount", argc));
            }

            // figure out the msg for the exception
            Expression condition = macro.Arguments[0];
            Expression message   = (argc == 1) ?
                                   new StringLiteralExpression(
                condition.LexicalInfo, condition.ToString()) :
                                   macro.Arguments[1];

            // unless <condition>:
            //     raise Boo.AssertionFailedException(<msg>)
            UnlessStatement stmt = new UnlessStatement(macro.LexicalInfo);

            stmt.Condition = condition;
            stmt.Block     = new Block(macro.LexicalInfo);

            RaiseStatement raise = new RaiseStatement(macro.LexicalInfo);

            raise.Exception =
                AstUtil.CreateMethodInvocationExpression(ExceptionTypeReference, message);
            stmt.Block.Add(raise);

            return(stmt);
        }
示例#2
0
        public override void Apply(Boo.Lang.Ast.Node node)
        {
            ParameterDeclaration pd = node as ParameterDeclaration;

            if (null == pd)
            {
                throw new ApplicationException(ResourceManager.Format("InvalidNodeForAttribute", "ParameterDeclaration"));
            }

            // raise ArgumentNullException("<pd.Name>") unless <pd.Name>
            MethodInvocationExpression x = new MethodInvocationExpression();

            x.Target = new ReferenceExpression("ArgumentNullException");
            x.Arguments.Add(new StringLiteralExpression(pd.Name));
            RaiseStatement rs = new RaiseStatement(x);

            rs.Modifier = new StatementModifier(
                StatementModifierType.Unless,
                new ReferenceExpression(pd.Name)
                );

            // associa mensagens de erro com a posio
            // do parmetro no cdigo fonte
            rs.LexicalInfo = LexicalInfo;

            Method method = (Method)pd.ParentNode;

            method.Body.Statements.Insert(0, rs);
        }
示例#3
0
        public override void OnRaiseStatement(RaiseStatement node)
        {
            BoundSpillSequenceBuilder builder = null;

            node.Exception = VisitExpression(ref builder, node.Exception);
            ReplaceCurrentNode(UpdateStatement(builder, node));
        }
示例#4
0
        public override bool Walk(RaiseStatement node)
        {
            UpdateLineInfo(node);
            AddBlock();

            return(false);
        }
示例#5
0
文件: DDG.cs 项目: rsumner33/PTVS
 public override bool Walk(RaiseStatement node)
 {
     _eval.EvaluateMaybeNull(node.Value);
     _eval.EvaluateMaybeNull(node.Traceback);
     _eval.EvaluateMaybeNull(node.ExceptType);
     return(false);
 }
示例#6
0
 public override bool Visit(RaiseStatement node)
 {
     Visit((Statement)node);
     TraversePrint(node.lvalue);
     TraversePrint(node.expr);
     return(true);
 }
示例#7
0
        public TypeMember CreateStub(IMember member)
        {
            IMethod md = (member as IMethod);

            if (null == md)
            {
                return(null);
            }

            Method m   = CreateVirtualMethod(md.Name, md.ReturnType);
            int    idx = 0;

            foreach (IParameter param in md.GetParameters())
            {
                m.Parameters.Add(
                    CreateParameterDeclaration(idx,
                                               param.Name,
                                               param.Type,
                                               param.IsByRef));
                idx++;
            }

            MethodInvocationExpression x = new MethodInvocationExpression();

            x.Target = new MemberReferenceExpression(
                new ReferenceExpression("System"),
                "NotImplementedException");
            RaiseStatement rs = new RaiseStatement(x);

            rs.LexicalInfo = LexicalInfo.Empty;
            m.Body.Statements.Insert(0, rs);

            return(m);
        }
示例#8
0
        public override void Switch(IAstTransformer transformer, out Node resultingNode)
        {
            RaiseStatement thisNode           = (RaiseStatement)this;
            Statement      resultingTypedNode = thisNode;

            transformer.OnRaiseStatement(thisNode, ref resultingTypedNode);
            resultingNode = resultingTypedNode;
        }
示例#9
0
 override public void OnRaiseStatement(RaiseStatement rs)
 {
     WriteIndented();
     WriteKeyword("raise ");
     Visit(rs.Exception);
     Visit(rs.Modifier);
     WriteLine();
 }
示例#10
0
        public void Raise()
        {
            var statement = new RaiseStatement("error1");

            SerializeAndAssert(statement, (serialized, deserialized) => {
                Assert.IsNotNull(deserialized);
                Assert.AreEqual("error1", deserialized.ExceptionName);
            });
        }
示例#11
0
        public override void OnRaiseStatement(RaiseStatement node)
        {
            if (node.Exception != null || _currentAwaitCatchFrame == null)
            {
                base.OnRaiseStatement(node);
            }

            ReplaceCurrentNode(Rethrow(_currentAwaitCatchFrame.pendingCaughtException));
        }
示例#12
0
        public override Statement Expand(MacroStatement macro)
        {
            if (macro.Arguments.Count == 0)
            {
                throw new MonoRailException("Section must be called with a name");
            }

            var component = GetParentComponent(macro);

            componentContextName  = ComponentNaming.GetComponentContextName(component);
            componentVariableName = ComponentNaming.GetComponentNameFor(component);


            var sectionName = macro.Arguments[0].ToString();
            var block       = new Block();
            //if (!Component.SupportsSection(section.Name))
            //   throw new ViewComponentException( String.Format("The section '{0}' is not supported by the ViewComponent '{1}'", section.Name, ComponentName));
            var supportsSection = new MethodInvocationExpression(
                AstUtil.CreateReferenceExpression(componentVariableName + ".SupportsSection"),
                new StringLiteralExpression(sectionName));
            //create the new exception
            var raiseSectionNotSupportted = new RaiseStatement(
                new MethodInvocationExpression(
                    AstUtil.CreateReferenceExpression(typeof(ViewComponentException).FullName),
                    new StringLiteralExpression(
                        String.Format("The section '{0}' is not supported by the ViewComponent '{1}'", sectionName,
                                      component.Arguments[0])
                        )
                    ));

            var trueBlock = new Block();

            trueBlock.Add(raiseSectionNotSupportted);
            var ifSectionNotSupported =
                new IfStatement(new UnaryExpression(UnaryOperatorType.LogicalNot, supportsSection),
                                trueBlock, null);

            block.Add(ifSectionNotSupported);
            //componentContext.RegisterSection(sectionName);
            var mie = new MethodInvocationExpression(
                new MemberReferenceExpression(new ReferenceExpression(componentContextName), "RegisterSection"),
                new StringLiteralExpression(sectionName),
                CodeBuilderHelper.CreateCallableFromMacroBody(CodeBuilder, macro));

            block.Add(mie);

            var sections = (IDictionary)component["sections"];

            if (sections == null)
            {
                component["sections"] = sections = new Hashtable();
            }
            sections.Add(sectionName, block);
            return(null);
        }
示例#13
0
        private SyntaxResult <SyntaxNode> TranslateStatement_Raise(RaiseStatement raiseStatement, TranslatorState state)
        {
            var value = TranslateExpression(raiseStatement.ExceptType, state);

            if (value.IsError)
            {
                return(SyntaxResult <SyntaxNode> .WithErrors(value.Errors));
            }

            return(SyntaxFactory.ThrowStatement(value.Syntax));
        }
示例#14
0
 public void VisitRaise(RaiseStatement r)
 {
     if (r.exToRaise != null)
     {
         gen.Throw(r.exToRaise.Accept(xlat));
     }
     else
     {
         gen.Throw();
     }
 }
示例#15
0
 override public void LeaveRaiseStatement(RaiseStatement node)
 {
     if (node.Exception != null)
     {
         return;
     }
     if (_state.InExceptionHandler)
     {
         return;
     }
     Error(CompilerErrorFactory.ReRaiseOutsideExceptionHandler(node));
 }
示例#16
0
 public DataType VisitRaise(RaiseStatement r)
 {
     if (r.exToRaise != null)
     {
         r.exToRaise.Accept(this);
     }
     if (r.exOriginal != null)
     {
         r.exOriginal.Accept(this);
     }
     if (r.traceback != null)
     {
         r.traceback.Accept(this);
     }
     return(DataType.Cont);
 }
示例#17
0
        public static bool TryGetCompletions(RaiseStatement raiseStatement, CompletionContext context, out CompletionResult result)
        {
            result = null;

            // raise Type, Value, Traceback with Cause
            if (raiseStatement.Cause != null && context.Position >= raiseStatement.CauseFieldStartIndex)
            {
                return(false);
            }

            if (raiseStatement.Traceback != null && context.Position >= raiseStatement.TracebackFieldStartIndex)
            {
                return(false);
            }

            if (raiseStatement.Value != null && context.Position >= raiseStatement.ValueFieldStartIndex)
            {
                return(false);
            }

            if (raiseStatement.ExceptType == null)
            {
                return(false);
            }

            if (context.Position <= raiseStatement.ExceptType.EndIndex)
            {
                return(false);
            }

            if (context.Ast.LanguageVersion.Is3x())
            {
                var applicableSpan = context.GetApplicableSpanFromLastToken(raiseStatement);
                result = new CompletionResult(Enumerable.Repeat(CompletionItemSource.FromKeyword, 1), applicableSpan);
            }

            return(true);
        }
示例#18
0
        private Statement Rethrow(InternalLocal obj)
        {
            // conservative rethrow
            Statement rethrow = new RaiseStatement(_F.CreateLocalReference(obj));

            // if these helpers are available, we can rethrow with original stack info
            // as long as it derives from Exception
            if (_exceptionDispatchInfoCapture != null && _exceptionDispatchInfoThrow != null)
            {
                var ex         = _F.DeclareTempLocal(_containingMethod, _tss.ExceptionType);
                var assignment = _F.CreateAssignment(
                    _F.CreateLocalReference(ex),
                    _F.CreateAsCast(ex.Type, _F.CreateLocalReference(obj)));

                // better rethrow
                rethrow = new Block(
                    new ExpressionStatement(assignment),
                    new IfStatement(
                        _F.CreateBoundBinaryExpression(
                            _tss.BoolType,
                            BinaryOperatorType.ReferenceEquality,
                            _F.CreateLocalReference(ex),
                            new NullLiteralExpression()),
                        new Block(rethrow),
                        null),
                    // ExceptionDispatchInfo.Capture(pendingExceptionLocal).Throw()
                    new ExpressionStatement(
                        _F.CreateMethodInvocation(
                            _F.CreateMethodInvocation(
                                _exceptionDispatchInfoCapture,
                                _F.CreateLocalReference(ex)),
                            _exceptionDispatchInfoThrow))
                    );
            }

            return(rethrow);
        }
        public void VisitRaise(RaiseStatement r)
        {
            if (r.exToRaise != null)
            {
                var dt = types.TypeOf(r.exToRaise);
                if (dt is ClassType)
                {
                    // Python allows expressions like
                    //   raise FooError

                    var(exceptionType, namespaces) = types.Translate(dt);
                    gen.EnsureImports(namespaces);
                    gen.Throw(gen.New(exceptionType));
                }
                else
                {
                    gen.Throw(r.exToRaise.Accept(xlat));
                }
            }
            else
            {
                gen.Throw();
            }
        }
示例#20
0
 // RaiseStatement
 public override bool Walk(RaiseStatement node)
 {
     return(Location >= node.StartIndex && Location <= node.EndIndex);
 }
示例#21
0
 public override bool EnterRaiseStatement(RaiseStatement rs)
 {
     WriteIndented("raise ");
     return(true);
 }
示例#22
0
 public override void LeaveRaiseStatement(RaiseStatement rs)
 {
     WriteLine();
 }
 // RaiseStatement
 public override bool Walk(RaiseStatement node) { return false; }
 public override void PostWalk(RaiseStatement node) { }
 // RaiseStatement
 public virtual bool Walk(RaiseStatement node) { return true; }
 public virtual void PostWalk(RaiseStatement node) { }
示例#27
0
 public virtual void PostWalk(RaiseStatement node)
 {
 }
示例#28
0
 // RaiseStatement
 public override bool Walk(RaiseStatement node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
示例#29
0
 override public bool EnterRaiseStatement(RaiseStatement node)
 {
     RemoveUnreachableCode(node);
     return(false);
 }
示例#30
0
 public void VisitRaise(RaiseStatement r)
 {
     w.Write("raise");
     w.Write(" ");
     r.exToRaise.Write(writer);
     if (r.exOriginal != null)
     {
         w.Write(", ");
         r.exOriginal.Write(writer);
     }
 }
示例#31
0
 public override void PostWalk(RaiseStatement node)
 {
 }
示例#32
0
 // RaiseStatement
 public override bool Walk(RaiseStatement node)
 {
     return(false);
 }
示例#33
0
 public void VisitRaise(RaiseStatement r)
 {
     if (r.exToRaise != null)
     {
         gen.Throw(r.exToRaise.Accept(xlat));
     }
     else
     {
         gen.Throw();
     }
 }
示例#34
0
 public override bool Walk(RaiseStatement node)
 {
     UpdateChildRanges(node);
     return(base.Walk(node));
 }
示例#35
0
 public void PostWalk(RaiseStatement node)
 {
     PostProcess(node);
 }
示例#36
0
 override public void LeaveRaiseStatement(RaiseStatement node)
 {
     LeaveStatement(node);
 }
示例#37
0
 // RaiseStatement
 public virtual bool Walk(RaiseStatement node)
 {
     return(true);
 }