本文整理汇总了C#中IronRuby.Compiler.Ast.AstGenerator类的典型用法代码示例。如果您正苦于以下问题:C# AstGenerator类的具体用法?C# AstGenerator怎么用?C# AstGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AstGenerator类属于IronRuby.Compiler.Ast命名空间,在下文中一共展示了AstGenerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TransformRead
internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) {
return AstFactory.Condition(
_condition.TransformCondition(gen, false),
gen.TransformStatementsToExpression(_statements),
gen.TransformStatementsToExpression(_elseClause != null ? _elseClause.Statements : null)
);
}
开发者ID:jschementi,项目名称:iron,代码行数:7,代码来源:UnlessExpression.cs
示例2: TransformWriteVariable
/*!*/
internal override MSA.Expression TransformWriteVariable(AstGenerator/*!*/ gen, MSA.Expression/*!*/ rightValue)
{
Assert.NotNull(gen, rightValue);
// no-op
return rightValue;
}
开发者ID:TerabyteX,项目名称:main,代码行数:8,代码来源:Placeholder.cs
示例3: TransformBody
private void TransformBody(AstGenerator/*!*/ gen) {
ScopeBuilder scope = DefineLocals();
var scopeVariable = gen.TopLevelScope.Builder.DefineHiddenVariable("#scope", typeof(RubyScope));
gen.EnterFileInitializer(
scope,
gen.TopLevelScope.SelfVariable,
scopeVariable
);
// visit nested initializers depth-first:
var body = gen.TransformStatements(_statements, ResultOperation.Ignore);
gen.LeaveFileInitializer();
gen.AddFileInitializer(
scope.CreateScope(
scopeVariable,
Methods.CreateFileInitializerScope.OpCall(
scope.MakeLocalsStorage(),
scope.GetVariableNamesExpression(),
gen.TopLevelScope.RuntimeScopeVariable
),
body
)
);
}
开发者ID:BenHall,项目名称:ironruby,代码行数:28,代码来源:FileInitializerStatement.cs
示例4: String
MSA.Expression/*!*/ StringConstructor.IFactory.CreateExpressionM(AstGenerator/*!*/ gen, MSAst.ExpressionCollectionBuilder/*!*/ args) {
string suffix = new String('M', args.Count);
args.Add(gen.Encoding.Expression);
args.Add(AstUtils.Constant(_options));
args.Add(AstUtils.Constant(new StrongBox<RubyRegex>(null)));
return Methods.CreateRegex(suffix).OpCall(args);
}
开发者ID:jschementi,项目名称:iron,代码行数:7,代码来源:RegularExpression.cs
示例5: TransformRead
internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) {
return AstFactory.Condition(
Methods.IsFalse.OpCall(AstFactory.Box(_condition.TransformRead(gen))),
gen.TransformStatementsToExpression(_statements),
gen.TransformStatementsToExpression(_elseClause != null ? _elseClause.Statements : null)
);
}
开发者ID:aslakhellesoy,项目名称:ironruby,代码行数:7,代码来源:UnlessExpression.cs
示例6:
MSA.Expression/*!*/ StringConstructor.IFactory.CreateExpressionN(AstGenerator/*!*/ gen, IEnumerable<MSA.Expression>/*!*/ args) {
return Methods.CreateRegex("N").OpCall(
Ast.NewArrayInit(typeof(MutableString), args),
AstUtils.Constant(_options),
AstUtils.Constant(new StrongBox<RubyRegex>(null))
);
}
开发者ID:jschementi,项目名称:iron,代码行数:7,代码来源:RegularExpression.cs
示例7: TransformRead
internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) {
return Methods.MatchString.OpCall(
Ast.Dynamic(ConvertToStrAction.Make(gen.Context), typeof(MutableString), _expression.Transform(gen)),
_regex.Transform(gen),
gen.CurrentScopeVariable
);
}
开发者ID:aceptra,项目名称:ironruby,代码行数:7,代码来源:MatchExpression.cs
示例8: TransformOptionalsInitialization
internal MSA.Expression/*!*/ TransformOptionalsInitialization(AstGenerator/*!*/ gen) {
Assert.NotNull(gen);
if (_optional.Length == 0) {
return AstUtils.Empty();
}
MSA.Expression singleton = gen.CurrentScope.DefineHiddenVariable("#default", typeof(object));
MSA.Expression result = AstUtils.Empty();
for (int i = 0; i < _optional.Length; i++) {
result = AstUtils.IfThen(
Ast.Equal(_optional[i].Left.TransformRead(gen), singleton),
Ast.Block(
result,
_optional[i].TransformRead(gen) // assignment
)
);
}
return Ast.Block(
Ast.Assign(singleton, Ast.Field(null, Fields.DefaultArgument)),
result,
AstUtils.Empty()
);
}
开发者ID:jschementi,项目名称:iron,代码行数:26,代码来源:Parameters.cs
示例9: Transform
// see Ruby Language.doc/Runtime/Control Flow Implementation/Next
/*!*/
internal override MSA.Expression Transform(AstGenerator/*!*/ gen)
{
MSA.Expression transformedReturnValue = TransformReturnValue(gen);
// eval:
if (gen.CompilerOptions.IsEval) {
return Methods.EvalNext.OpCall(gen.CurrentScopeVariable, AstUtils.Box(transformedReturnValue));
}
// loop:
if (gen.CurrentLoop != null) {
return Ast.Block(
transformedReturnValue, // evaluate for side-effects
Ast.Continue(gen.CurrentLoop.ContinueLabel),
AstUtils.Empty()
);
}
// block:
if (gen.CurrentBlock != null) {
return gen.Return(transformedReturnValue);
}
// method:
return Methods.MethodNext.OpCall(gen.CurrentScopeVariable, AstUtils.Box(transformedReturnValue));
}
开发者ID:TerabyteX,项目名称:main,代码行数:28,代码来源:NextStatement.cs
示例10: TransformBody
private MSA.Expression/*!*/ TransformBody(AstGenerator/*!*/ gen, MSA.Expression/*!*/ methodDefinitionVariable) {
string encodedName = RubyExceptionData.EncodeMethodName(gen.SourceUnit, _name, Location);
ScopeBuilder scope = new ScopeBuilder();
MSA.Expression parentScope = gen.CurrentScopeVariable;
MSA.ParameterExpression[] parameters = DefineParameters(gen, scope);
MSA.Expression currentMethodVariable = scope.DefineHiddenVariable("#method", typeof(RubyMethodInfo));
MSA.Expression rfcVariable = scope.DefineHiddenVariable("#rfc", typeof(RuntimeFlowControl));
MSA.Expression scopeVariable = scope.DefineHiddenVariable("#scope", typeof(RubyMethodScope));
MSA.Expression selfParameter = parameters[0];
MSA.Expression blockParameter = parameters[1];
gen.EnterMethodDefinition(
scope,
selfParameter,
scopeVariable,
blockParameter,
rfcVariable,
currentMethodVariable,
_name,
_parameters
);
DefinedScope.TransformLocals(scope);
MSA.ParameterExpression unwinder = scope.DefineHiddenVariable("#unwinder", typeof(MethodUnwinder));
MSA.Expression body = AstFactory.MakeUserMethodBody(
gen, Location.End.Line,
blockParameter,
rfcVariable,
unwinder,
Ast.Block(
Ast.Assign(currentMethodVariable, methodDefinitionVariable),
Ast.Assign(scopeVariable, Methods.CreateMethodScope.OpCall(
scope.VisibleVariables(), parentScope, currentMethodVariable, rfcVariable, selfParameter, blockParameter)
),
_parameters.TransformOptionalsInitialization(gen),
gen.TraceEnabled ? Methods.TraceMethodCall.OpCall(scopeVariable, Ast.Convert(AstUtils.Constant(gen.SourceUnit.Path), typeof(string)), AstUtils.Constant(Location.Start.Line)) : AstUtils.Empty(),
Body.TransformResult(gen, ResultOperation.Return),
AstUtils.Empty()
),
ResultOperation.Return,
(gen.Profiler != null) ? gen.Profiler.GetTickIndex(encodedName) : -1,
(gen.Profiler != null) ? scope.DefineHiddenVariable("#stamp", typeof(long)) : null,
gen.ReturnLabel
);
body = gen.AddReturnTarget(scope.CreateScope(body));
gen.LeaveMethodDefinition();
return CreateLambda(
encodedName,
parameters,
body
);
}
开发者ID:jcteague,项目名称:ironruby,代码行数:60,代码来源:MethodDeclaration.cs
示例11: Transform
// see Ruby Language.doc/Runtime/Control Flow Implementation/Break
internal override MSA.Expression/*!*/ Transform(AstGenerator/*!*/ gen) {
MSA.Expression transformedReturnValue = TransformReturnValue(gen);
// eval:
if (gen.CompilerOptions.IsEval) {
return Methods.EvalBreak.OpCall(gen.CurrentRfcVariable, AstFactory.Box(transformedReturnValue));
}
// loop:
if (gen.CurrentLoop != null) {
return Ast.Block(
Ast.Assign(
gen.CurrentLoop.ResultVariable,
Ast.Convert(transformedReturnValue, gen.CurrentLoop.ResultVariable.Type)
),
Ast.Break(gen.CurrentLoop.BreakLabel),
Ast.Empty()
);
}
// block:
if (gen.CurrentBlock != null) {
return gen.Return(Methods.BlockBreak.OpCall(gen.CurrentBlock.BfcVariable, AstFactory.Box(transformedReturnValue)));
}
// primary frame:
return Methods.MethodBreak.OpCall(AstFactory.Box(transformedReturnValue));
}
开发者ID:joshholmes,项目名称:ironruby,代码行数:30,代码来源:BreakStatement.cs
示例12: TransformRead
internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) {
return AstFactory.Condition(
_condition.TransformReadBoolean(gen, true),
_trueExpression.TransformRead(gen),
_falseExpression.TransformRead(gen)
);
}
开发者ID:jschementi,项目名称:iron,代码行数:7,代码来源:ConditionalExpression.cs
示例13: Transform
internal override MSA.Expression/*!*/ Transform(AstGenerator/*!*/ gen) {
return AstUtils.IfThenElse(
_condition.TransformCondition(gen, !_negateCondition),
_body.Transform(gen),
_elseStatement != null ? _elseStatement.Transform(gen) : AstUtils.Empty()
);
}
开发者ID:atczyc,项目名称:ironruby,代码行数:7,代码来源:ConditionalStatement.cs
示例14: TransformRead
internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) {
return Ast.Condition(
_condition.TransformReadBoolean(gen, !_negateCondition),
AstUtils.Box(_body.TransformRead(gen)),
(_elseStatement != null) ? AstUtils.Box(_elseStatement.TransformRead(gen)) : (MSA.Expression)AstUtils.Constant(null)
);
}
开发者ID:atczyc,项目名称:ironruby,代码行数:7,代码来源:ConditionalStatement.cs
示例15: TransformRead
// see Ruby Language.doc/Runtime/Control Flow Implementation/Yield
internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) {
MSA.Expression bfcVariable = gen.CurrentScope.DefineHiddenVariable("#yielded-bfc", typeof(BlockParam));
MSA.Expression resultVariable = gen.CurrentScope.DefineHiddenVariable("#result", typeof(object));
MSA.Expression postYield;
if (gen.CompilerOptions.IsEval) {
// eval:
postYield = Methods.EvalYield.OpCall(gen.CurrentScopeVariable, bfcVariable, resultVariable);
} else if (gen.CurrentBlock != null) {
// block:
postYield = Methods.BlockYield.OpCall(gen.CurrentScopeVariable, gen.CurrentBlock.BfcVariable, bfcVariable, resultVariable);
} else {
// method:
postYield = Methods.MethodYield.OpCall(gen.CurrentScopeVariable, bfcVariable, resultVariable);
}
return new AstBlock {
gen.DebugMarker("#RB: yield begin"),
Ast.Assign(bfcVariable, Methods.CreateBfcForYield.OpCall(gen.MakeMethodBlockParameterRead())),
Ast.Assign(
resultVariable,
(Arguments ?? Arguments.Empty).TransformToYield(gen, bfcVariable, gen.MakeMethodBlockParameterSelfRead())
),
AstUtils.IfThen(postYield, gen.Return(resultVariable)),
gen.DebugMarker("#RB: yield end"),
resultVariable
};
}
开发者ID:jschementi,项目名称:iron,代码行数:35,代码来源:YieldCall.cs
示例16: TransformRead
internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) {
MSA.Expression result;
int i = _elseIfClauses.Count - 1;
if (i >= 0 && _elseIfClauses[i].Condition == null) {
// ... else body end
result = gen.TransformStatementsToExpression(_elseIfClauses[i].Statements);
i--;
} else {
// no else clause => the result of the if-expression is nil:
result = AstUtils.Constant(null);
}
while (i >= 0) {
// emit: else (if (condition) body else result)
result = AstFactory.Condition(
_elseIfClauses[i].Condition.TransformCondition(gen, true),
gen.TransformStatementsToExpression(_elseIfClauses[i].Statements),
result
);
i--;
}
// if (condition) body else result
return AstFactory.Condition(
_condition.TransformCondition(gen, true),
gen.TransformStatementsToExpression(_body),
result
);
}
开发者ID:ExpertsInside,项目名称:IronSP,代码行数:32,代码来源:IfExpression.cs
示例17: TransformWriteVariable
internal override MSA.Expression/*!*/ TransformWriteVariable(AstGenerator/*!*/ gen, MSA.Expression/*!*/ rightValue) {
if (gen.CompilerOptions.IsEval || gen.GetCurrentNonSingletonModule() != null) {
return Methods.SetClassVariable.OpCall(AstFactory.Box(rightValue), gen.CurrentScopeVariable, AstUtils.Constant(Name));
} else {
return Methods.SetObjectClassVariable.OpCall(AstFactory.Box(rightValue), gen.CurrentScopeVariable, AstUtils.Constant(Name));
}
}
开发者ID:jcteague,项目名称:ironruby,代码行数:7,代码来源:ClassVariable.cs
示例18: TransformRead
internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) {
string setterName = _memberName + "=";
MSA.Expression transformedLeftTarget = _leftTarget.TransformRead(gen);
MSA.Expression transformedRight = _right.TransformRead(gen);
MSA.Expression leftTemp = gen.CurrentScope.DefineHiddenVariable(String.Empty, transformedLeftTarget.Type);
bool leftIsSelf = _leftTarget.NodeType == NodeTypes.SelfReference;
// lhs &&= rhs --> left.member && (left.member = rhs)
// lhs ||= rhs --> left.member || (left.member = rhs)
if (Operation == Symbols.And || Operation == Symbols.Or) {
MSA.Expression leftMemberRead = MethodCall.TransformRead(this, gen, false, _memberName, Ast.Assign(leftTemp, transformedLeftTarget), null, null, null, null);
MSA.Expression transformedWrite = MethodCall.TransformRead(this, gen, leftIsSelf, setterName, leftTemp, null, null, null, transformedRight);
if (Operation == Symbols.And) {
return AndExpression.TransformRead(gen, leftMemberRead, transformedWrite);
} else {
return OrExpression.TransformRead(gen, leftMemberRead, transformedWrite);
}
} else {
// left.member= left.member().op(right)
MSA.Expression leftMemberRead = MethodCall.TransformRead(this, gen, false, _memberName, leftTemp, null, null, null, null);
MSA.Expression operationCall = MethodCall.TransformRead(this, gen, false, Operation, leftMemberRead, null, null, transformedRight, null);
MSA.Expression transformedWrite = MethodCall.TransformRead(this, gen, leftIsSelf, setterName, Ast.Assign(leftTemp, transformedLeftTarget), null, null, null, operationCall);
return transformedWrite;
}
}
开发者ID:jcteague,项目名称:ironruby,代码行数:29,代码来源:MemberAssignmentExpression.cs
示例19: TransformConcatentation
internal static MSA.Expression/*!*/ TransformConcatentation(AstGenerator/*!*/ gen, List<Expression>/*!*/ parts,
Func<string, MethodInfo>/*!*/ opFactory, MSA.Expression additionalArg) {
var opSuffix = new StringBuilder(Math.Min(parts.Count, 4));
List<MSA.Expression> merged = ConcatLiteralsAndTransform(gen, parts, opSuffix);
if (merged.Count <= RubyOps.MakeStringParamCount) {
if (merged.Count == 0) {
merged.Add(Ast.Constant(String.Empty));
opSuffix.Append(RubyOps.SuffixBinary);
}
if (opSuffix.IndexOf(RubyOps.SuffixEncoded) != -1) {
merged.Add(Ast.Constant(RubyEncoding.GetCodePage(gen.Encoding)));
}
if (additionalArg != null) {
merged.Add(additionalArg);
}
return opFactory(opSuffix.ToString()).OpCall(merged);
} else {
var paramArray = Ast.NewArrayInit(typeof(object), merged);
var codePage = Ast.Constant(RubyEncoding.GetCodePage(gen.Encoding));
return (additionalArg != null) ?
opFactory("N").OpCall(paramArray, codePage, additionalArg) :
opFactory("N").OpCall(paramArray, codePage);
}
}
开发者ID:joshholmes,项目名称:ironruby,代码行数:31,代码来源:StringConstructor.cs
示例20: TransformRead
// arguments: complex arguments (expressions, maplets, splat, block)
// singleArgument: siple argument (complex are not used)
// assignmentRhsArgument: rhs of the assignment: target.method=(rhs)
internal static MSA.Expression/*!*/ TransformRead(Expression/*!*/ node, AstGenerator/*!*/ gen, bool hasImplicitSelf,
string/*!*/ methodName, MSA.Expression/*!*/ transformedTarget,
Arguments arguments, Block block, MSA.Expression singleArgument, MSA.Expression assignmentRhsArgument) {
Debug.Assert(assignmentRhsArgument == null || block == null, "Block not allowed in assignment");
Debug.Assert(singleArgument == null || arguments == null && assignmentRhsArgument == null);
Assert.NotNull(gen, transformedTarget);
Assert.NotEmpty(methodName);
// Pass args in this order:
// 1. instance
// 2. block (if present)
// 3. passed args: normal args, maplets, array
// 4. RHS of assignment (if present)
MSA.Expression blockArgVariable;
MSA.Expression transformedBlock;
if (block != null) {
blockArgVariable = gen.CurrentScope.DefineHiddenVariable("#block-def", typeof(Proc));
transformedBlock = block.Transform(gen);
} else {
blockArgVariable = transformedBlock = null;
}
var siteBuilder = new CallSiteBuilder(gen, transformedTarget, blockArgVariable);
if (arguments != null) {
arguments.TransformToCall(gen, siteBuilder);
} else if (singleArgument != null) {
siteBuilder.Add(singleArgument);
}
MSA.Expression rhsVariable = null;
if (assignmentRhsArgument != null) {
rhsVariable = gen.CurrentScope.DefineHiddenVariable("#rhs", assignmentRhsArgument.Type);
siteBuilder.RhsArgument = Ast.Assign(rhsVariable, assignmentRhsArgument);
}
var dynamicSite = siteBuilder.MakeCallAction(methodName, hasImplicitSelf);
#if FEATURE_CALL_SITE_TRACER
if (gen.Context.CallSiteCreated != null) {
gen.Context.CallSiteCreated(node, dynamicSite);
}
#endif
MSA.Expression result = gen.DebugMark(dynamicSite, methodName);
if (block != null) {
result = gen.DebugMark(MakeCallWithBlockRetryable(gen, result, blockArgVariable, transformedBlock, block.IsDefinition),
"#RB: method call with a block ('" + methodName + "')");
}
if (assignmentRhsArgument != null) {
result = Ast.Block(result, rhsVariable);
}
return result;
}
开发者ID:jschementi,项目名称:iron,代码行数:62,代码来源:MethodCall.cs
注:本文中的IronRuby.Compiler.Ast.AstGenerator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论