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); }
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); }
public override void OnRaiseStatement(RaiseStatement node) { BoundSpillSequenceBuilder builder = null; node.Exception = VisitExpression(ref builder, node.Exception); ReplaceCurrentNode(UpdateStatement(builder, node)); }
public override bool Walk(RaiseStatement node) { UpdateLineInfo(node); AddBlock(); return(false); }
public override bool Walk(RaiseStatement node) { _eval.EvaluateMaybeNull(node.Value); _eval.EvaluateMaybeNull(node.Traceback); _eval.EvaluateMaybeNull(node.ExceptType); return(false); }
public override bool Visit(RaiseStatement node) { Visit((Statement)node); TraversePrint(node.lvalue); TraversePrint(node.expr); return(true); }
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); }
public override void Switch(IAstTransformer transformer, out Node resultingNode) { RaiseStatement thisNode = (RaiseStatement)this; Statement resultingTypedNode = thisNode; transformer.OnRaiseStatement(thisNode, ref resultingTypedNode); resultingNode = resultingTypedNode; }
override public void OnRaiseStatement(RaiseStatement rs) { WriteIndented(); WriteKeyword("raise "); Visit(rs.Exception); Visit(rs.Modifier); WriteLine(); }
public void Raise() { var statement = new RaiseStatement("error1"); SerializeAndAssert(statement, (serialized, deserialized) => { Assert.IsNotNull(deserialized); Assert.AreEqual("error1", deserialized.ExceptionName); }); }
public override void OnRaiseStatement(RaiseStatement node) { if (node.Exception != null || _currentAwaitCatchFrame == null) { base.OnRaiseStatement(node); } ReplaceCurrentNode(Rethrow(_currentAwaitCatchFrame.pendingCaughtException)); }
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); }
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)); }
public void VisitRaise(RaiseStatement r) { if (r.exToRaise != null) { gen.Throw(r.exToRaise.Accept(xlat)); } else { gen.Throw(); } }
override public void LeaveRaiseStatement(RaiseStatement node) { if (node.Exception != null) { return; } if (_state.InExceptionHandler) { return; } Error(CompilerErrorFactory.ReRaiseOutsideExceptionHandler(node)); }
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); }
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); }
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(); } }
// RaiseStatement public override bool Walk(RaiseStatement node) { return(Location >= node.StartIndex && Location <= node.EndIndex); }
public override bool EnterRaiseStatement(RaiseStatement rs) { WriteIndented("raise "); return(true); }
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) { }
// RaiseStatement public override bool Walk(RaiseStatement node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
override public bool EnterRaiseStatement(RaiseStatement node) { RemoveUnreachableCode(node); return(false); }
public void VisitRaise(RaiseStatement r) { w.Write("raise"); w.Write(" "); r.exToRaise.Write(writer); if (r.exOriginal != null) { w.Write(", "); r.exOriginal.Write(writer); } }
// RaiseStatement public override bool Walk(RaiseStatement node) { return(false); }
public override bool Walk(RaiseStatement node) { UpdateChildRanges(node); return(base.Walk(node)); }
public void PostWalk(RaiseStatement node) { PostProcess(node); }
override public void LeaveRaiseStatement(RaiseStatement node) { LeaveStatement(node); }
// RaiseStatement public virtual bool Walk(RaiseStatement node) { return(true); }