本文整理汇总了C#中Boo.Lang.Compiler.Ast.BlockExpression类的典型用法代码示例。如果您正苦于以下问题:C# BlockExpression类的具体用法?C# BlockExpression怎么用?C# BlockExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlockExpression类属于Boo.Lang.Compiler.Ast命名空间,在下文中一共展示了BlockExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LeaveBlockExpression
override public void LeaveBlockExpression(BlockExpression node)
{
var closureEntity = GetEntity(node) as InternalMethod;
if (closureEntity == null)
return;
var collector = new ForeignReferenceCollector();
{
collector.CurrentMethod = closureEntity.Method;
collector.CurrentType = (IType)closureEntity.DeclaringType;
closureEntity.Method.Body.Accept(collector);
if (collector.ContainsForeignLocalReferences)
{
BooClassBuilder closureClass = CreateClosureClass(collector, closureEntity);
closureClass.ClassDefinition.LexicalInfo = node.LexicalInfo;
collector.AdjustReferences();
ReplaceCurrentNode(
CodeBuilder.CreateMemberReference(
collector.CreateConstructorInvocationWithReferencedEntities(
closureClass.Entity),
closureEntity));
}
else
{
Expression expression = CodeBuilder.CreateMemberReference(closureEntity);
expression.LexicalInfo = node.LexicalInfo;
TypeSystemServices.GetConcreteExpressionType(expression);
ReplaceCurrentNode(expression);
}
}
}
示例2: evaluate
public static Expression evaluate(BlockExpression formula)
{
var body = new Block(formula.LexicalInfo);
for (int i = 0; i < formula.Body.Statements.Count; ++i)
{
var statement = formula.Body.Statements[i];
if (statement is ExpressionStatement &&
i == formula.Body.Statements.Count - 1)
{
var last = (ExpressionStatement)statement;
body.Statements.Add(new ReturnStatement(last.Expression));
}
else
body.Statements.Add(formula.Body.Statements[i]);
}
var result = new BlockExpression(body);
result.Parameters.Add(new ParameterDeclaration("this",
CompilerContext.Current.CodeBuilder
.CreateTypeReference(EvaluationContext.CurrentContext.GetType())));
result.ReturnType = CompilerContext.Current.CodeBuilder
.CreateTypeReference(typeof(bool));
return new MethodInvocationExpression(
new ReferenceExpression("SetEvaluationFunction"), result);
}
示例3: OnBlockExpression
public override void OnBlockExpression(BlockExpression node)
{
if (node.LexicalInfo.Line <= resolver.CaretLine && GetEndSourceLocation(node).Line >= resolver.CaretLine - 1) {
foreach (ParameterDeclaration param in node.Parameters) {
DeclarationFound(param.Name, param.Type ?? (resolver.IsDucky ? new SimpleTypeReference("duck") : new SimpleTypeReference("object")), null, param.LexicalInfo);
}
base.OnBlockExpression(node);
}
}
示例4: when
public static Expression when(Expression expression)
{
BlockExpression right = new BlockExpression();
right.Body.Add(new ReturnStatement(expression));
return new BinaryExpression(
BinaryOperatorType.Assign,
new ReferenceExpression("condition"),
right
);
}
示例5: when
public static Expression when(Expression expression, Expression action)
{
BlockExpression condition = new BlockExpression();
condition.Body.Add(new ReturnStatement(expression));
return new MethodInvocationExpression(
new ReferenceExpression("When"),
condition,
action
);
}
示例6: when
public static Statement when(Expression expression)
{
var body = new Block(expression.LexicalInfo);
body.Add(new ReturnStatement(expression));
var result = new BlockExpression(body);
result.Parameters.Add(
new ParameterDeclaration("order",
CurrentContext.CodeBuilder.CreateTypeReference(typeof(Order))));
result.Parameters.Add(
new ParameterDeclaration("customer",
CurrentContext.CodeBuilder.CreateTypeReference(typeof(Customer))));
return new ReturnStatement(result);
}
示例7: CreateCallableFromMacroBody
public static Expression CreateCallableFromMacroBody(BooCodeBuilder builder, MacroStatement macro)
{
// create closure for macro's body or null
Expression macroBody = new NullLiteralExpression();
if (macro.Block.Statements.Count > 0)
{
var callableExpr = new BlockExpression {Body = macro.Block};
callableExpr.Parameters.Add(
new ParameterDeclaration("OutputStream",
builder.CreateTypeReference(typeof(TextWriter))));
macroBody = callableExpr;
}
return macroBody;
}
示例8: exclude
public static Expression exclude(BlockExpression action)
{
var arrayExpression = new ArrayLiteralExpression();
foreach (Statement statement in action.Body.Statements)
{
var stringLiteral =
new StringLiteralExpression(
((MethodInvocationExpression) (((ExpressionStatement) (statement)).Expression)).Arguments[0].ToString().Trim(new[]{'\''}));
arrayExpression.Items.Add(stringLiteral);
}
return new MethodInvocationExpression(
new ReferenceExpression("SetExcludeList"),
arrayExpression
);
}
示例9: OnBlockExpression
public override void OnBlockExpression(BlockExpression node)
{
var dependencies = new ArrayLiteralExpression();
foreach (Statement statement in node.Body.Statements)
{
var expressionStatement = (ExpressionStatement)statement;
var expression = (MethodInvocationExpression)expressionStatement.Expression;
OnMethodInvocationExpression(dependencies, expression);
}
if (dependencies.Items.Count == 0)
return;
var referenceExpression = new ReferenceExpression("AddDependencies");
var replacementMethod = new MethodInvocationExpression(referenceExpression, dependencies);
ReplaceCurrentNode(replacementMethod);
}
示例10: AddInferredClosureParameterTypes
private void AddInferredClosureParameterTypes(BlockExpression node, ICallableType callableType)
{
IParameter[] parameters = (callableType == null ? null : callableType.GetSignature().Parameters);
for (int i = 0; i < node.Parameters.Count; i++)
{
ParameterDeclaration pd = node.Parameters[i];
if (pd.Type != null) continue;
IType inferredType;
if (parameters != null && i < parameters.Length)
{
inferredType = parameters[i].Type;
}
else if (pd.IsParamArray)
{
inferredType = TypeSystemServices.ObjectArrayType;
}
else
{
inferredType = TypeSystemServices.ObjectType;
}
pd.Type = CodeBuilder.CreateTypeReference(inferredType);
}
}
示例11: InferClosureSignature
private void InferClosureSignature(BlockExpression node)
{
ClosureSignatureInferrer inferrer = new ClosureSignatureInferrer(node);
ICallableType inferredCallableType = inferrer.InferCallableType();
BindExpressionType(node, inferredCallableType);
AddInferredClosureParameterTypes(node, inferredCallableType);
}
示例12: nested_function
protected Statement nested_function() //throws RecognitionException, TokenStreamException
{
Statement stmt;
IToken def = null;
IToken id = null;
stmt = null;
BlockExpression be = null;
Block body = null;
TypeReference rt = null;
try { // for error handling
def = LT(1);
match(DEF);
id = LT(1);
match(ID);
if (0==inputState.guessing)
{
be = new BlockExpression(ToLexicalInfo(id));
body = be.Body;
}
{
switch ( LA(1) )
{
case LPAREN:
{
match(LPAREN);
parameter_declaration_list(be.Parameters);
match(RPAREN);
{
switch ( LA(1) )
{
case AS:
{
match(AS);
rt=type_reference();
if (0==inputState.guessing)
{
be.ReturnType = rt;
}
break;
}
case COLON:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
break;
}
case COLON:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
compound_stmt(body);
if (0==inputState.guessing)
{
string name = id.getText();
stmt = new DeclarationStatement(
ToLexicalInfo(def),
new Declaration(
ToLexicalInfo(id),
name),
be);
be[BlockExpression.ClosureNameAnnotation] = name;
}
}
catch (RecognitionException ex)
{
if (0 == inputState.guessing)
{
reportError(ex, "nested_function");
recover(ex,tokenSet_84_);
}
else
{
throw ex;
}
}
return stmt;
}
示例13: ClosureSignatureInferrer
public ClosureSignatureInferrer(BlockExpression closure)
{
_closure = closure;
InitializeInputTypes();
}
示例14: InferExplicits
/// <summary>
/// Performs inference on explicitly typed arguments.
/// </summary>
/// <remarks>
/// Corresponds to the first phase in generic parameter inference according to the C# 3.0 spec.
/// </remarks>
private void InferExplicits()
{
foreach (TypedArgument typedArgument in Arguments)
{
_currentClosure = typedArgument.Expression as BlockExpression;
Infer(
typedArgument.FormalType,
typedArgument.Expression.ExpressionType,
TypeInference.AllowCovariance);
}
}
示例15: callable_expression
protected Expression callable_expression() //throws RecognitionException, TokenStreamException
{
Expression e;
IToken doAnchor = null;
IToken defAnchor = null;
e = null;
Block body = null;
BlockExpression cbe = null;
TypeReference rt = null;
IToken anchor = null;
try { // for error handling
switch ( LA(1) )
{
case COLON:
{
{
if (0==inputState.guessing)
{
body = new Block();
}
compound_stmt(body);
if (0==inputState.guessing)
{
e = new BlockExpression(body.LexicalInfo, body);
}
}
break;
}
case DEF:
case DO:
{
{
{
switch ( LA(1) )
{
case DO:
{
{
doAnchor = LT(1);
match(DO);
if (0==inputState.guessing)
{
anchor = doAnchor;
}
}
break;
}
case DEF:
{
{
defAnchor = LT(1);
match(DEF);
if (0==inputState.guessing)
{
anchor = defAnchor;
}
}
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
if (0==inputState.guessing)
{
e = cbe = new BlockExpression(ToLexicalInfo(anchor));
body = cbe.Body;
}
{
switch ( LA(1) )
{
case LPAREN:
{
match(LPAREN);
parameter_declaration_list(cbe.Parameters);
match(RPAREN);
{
switch ( LA(1) )
{
case AS:
{
match(AS);
rt=type_reference();
if (0==inputState.guessing)
{
cbe.ReturnType = rt;
}
break;
}
case COLON:
{
break;
//.........这里部分代码省略.........