本文整理汇总了C#中Boo.Lang.Compiler.Ast.SlicingExpression类的典型用法代码示例。如果您正苦于以下问题:C# SlicingExpression类的具体用法?C# SlicingExpression怎么用?C# SlicingExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SlicingExpression类属于Boo.Lang.Compiler.Ast命名空间,在下文中一共展示了SlicingExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnSlicingExpression
public override void OnSlicingExpression(SlicingExpression node)
{
base.OnSlicingExpression(node);
var arrayType = GetExpressionType(node.Target) as IArrayType;
if (arrayType == null)
return;
if (arrayType.Rank != node.Indices.Count)
Error(CompilerErrorFactory.InvalidArrayRank(node, node.Target.ToCodeString(), arrayType.Rank, node.Indices.Count));
}
示例2: LeaveSlicingExpression
public override void LeaveSlicingExpression(SlicingExpression node)
{
if (IsDuckTyped(node.Target) && !HasDefaultMember(node.Target))
{
BindDuck(node);
}
else
{
base.LeaveSlicingExpression(node);
}
}
示例3: ExpandComplexSlicing
private void ExpandComplexSlicing(SlicingExpression node)
{
var targetType = GetExpressionType(node.Target);
if (IsString(targetType))
ExpandComplexStringSlicing(node);
else if (IsList(targetType))
ExpandComplexListSlicing(node);
else if (targetType.IsArray)
ExpandComplexArraySlicing(node);
else
NotImplemented(node, "complex slicing for anything but lists, arrays and strings");
}
示例4: ExpandComplexArraySlicing
void ExpandComplexArraySlicing(SlicingExpression node)
{
if (node.Indices.Count > 1)
{
MethodInvocationExpression mie = null;
var computeEnd = new ArrayLiteralExpression();
var collapse = new ArrayLiteralExpression();
var ranges = new ArrayLiteralExpression();
for (int i = 0; i < node.Indices.Count; i++)
{
ranges.Items.Add(node.Indices[i].Begin);
if (node.Indices[i].End == null )
{
var end = new BinaryExpression(BinaryOperatorType.Addition, node.Indices[i].Begin, new IntegerLiteralExpression(1));
ranges.Items.Add(end);
BindExpressionType(end, GetExpressionType(node.Indices[i].Begin));
computeEnd.Items.Add(new BoolLiteralExpression(false));
collapse.Items.Add(new BoolLiteralExpression(true));
}
else if (node.Indices[i].End == OmittedExpression.Default)
{
var end = new IntegerLiteralExpression(0);
ranges.Items.Add(end);
BindExpressionType(end, GetExpressionType(node.Indices[i].Begin));
computeEnd.Items.Add(new BoolLiteralExpression(true));
collapse.Items.Add(new BoolLiteralExpression(false));
}
else
{
ranges.Items.Add(node.Indices[i].End);
computeEnd.Items.Add(new BoolLiteralExpression(false));
collapse.Items.Add(new BoolLiteralExpression(false));
}
}
mie = CodeBuilder.CreateMethodInvocation(MethodCache.RuntimeServices_GetMultiDimensionalRange1, node.Target, ranges);
mie.Arguments.Add(computeEnd);
mie.Arguments.Add(collapse);
BindExpressionType(ranges, TypeSystemServices.Map(typeof(int[])));
BindExpressionType(computeEnd, TypeSystemServices.Map(typeof(bool[])));
BindExpressionType(collapse, TypeSystemServices.Map(typeof(bool[])));
node.ParentNode.Replace(node, mie);
}
else
{
var slice = node.Indices[0];
var mie = IsNullOrOmitted(slice.End)
? CodeBuilder.CreateMethodInvocation(MethodCache.RuntimeServices_GetRange1, node.Target, slice.Begin)
: CodeBuilder.CreateMethodInvocation(MethodCache.RuntimeServices_GetRange2, node.Target, slice.Begin, slice.End);
node.ParentNode.Replace(node, mie);
}
}
示例5: OnSlicingExpression
public override void OnSlicingExpression(SlicingExpression node)
{
base.OnSlicingExpression(node);
if (!node.IsComplexSlicing())
return;
if (node.IsTargetOfAssignment())
return;
CompleteOmittedExpressions(node);
ExpandComplexSlicing(node);
}
示例6: ExpandComplexListSlicing
void ExpandComplexListSlicing(SlicingExpression node)
{
var slice = node.Indices[0];
MethodInvocationExpression mie;
if (IsNullOrOmitted(slice.End))
{
mie = CodeBuilder.CreateMethodInvocation(node.Target, MethodCache.List_GetRange1);
mie.Arguments.Add(slice.Begin);
}
else
{
mie = CodeBuilder.CreateMethodInvocation(node.Target, MethodCache.List_GetRange2);
mie.Arguments.Add(slice.Begin);
mie.Arguments.Add(slice.End);
}
node.ParentNode.Replace(node, mie);
}
示例7: Apply
public override void Apply(Node targetNode) {
var cls = targetNode as ClassDefinition;
if(cls==null) {
this.Context.Errors.Add(new CompilerError(this.LexicalInfo,
"ControllerAttribute is applyable only to classes"));
return;
}
targetNode.GetEnclosingModule().Imports.Add(new Import(this.LexicalInfo,"Comdiv.Controllers"));
cls.BaseTypes.Clear();
cls.BaseTypes.Insert(0, new SimpleTypeReference("Comdiv.Controllers.ExtensionBaseController"));
if(!cls.Name.EndsWith("Controller")) {
cls.Name = cls.Name + "Controller";
}
var body = targetNode.GetEnclosingModule()["regmethod"] as Block;
var registrycall = new SlicingExpression(new ReferenceExpression("registry"), new StringLiteralExpression(cls.Name.ToLower()));
var assign = new ReferenceExpression(cls.Name);
var aexpr = new BinaryExpression(BinaryOperatorType.Assign, registrycall, assign);
body.Add(aexpr);
}
示例8: tryClass
private void tryClass(Node targetNode) {
var cls = targetNode as ClassDefinition;
if (cls == null)
{
return;
}
if (cls.BaseTypes.Count == 0)
{
cls.BaseTypes.Insert(0, new SimpleTypeReference("Comdiv.Framework.Quick.QuickBase"));
}
var attr = new Attribute("Comdiv.Framework.Quick.actionAttribute");
attr.Arguments.Add(new StringLiteralExpression(cls.Name.Replace("_", ".")));
cls.Attributes.Add(attr);
var body = targetNode.GetEnclosingModule()["regmethod"] as Block;
var registrycall = new SlicingExpression(new ReferenceExpression("registry"), new StringLiteralExpression(cls.Name.Replace("_", ".") + ".quick"));
var assign = new ReferenceExpression(cls.Name);
var aexpr = new BinaryExpression(BinaryOperatorType.Assign, registrycall, assign);
body.Add(aexpr);
}
示例9: ResultingTypeForComplexSlicing
private IType ResultingTypeForComplexSlicing(SlicingExpression node)
{
var targetType = GetExpressionType(node.Target);
return targetType.IsArray ? ResultingTypeForArraySlicing(node) : targetType;
}
示例10: LeaveSlicingExpression
public override void LeaveSlicingExpression(SlicingExpression node)
{
if (node.Target.Entity.IsAmbiguous())
{
BindIndexedPropertySlicing(node);
return;
}
// target[indices]
var targetType = GetExpressionType(node.Target);
if (IsError(targetType))
{
Error(node);
return;
}
if (node.IsComplexSlicing())
{
BindExpressionType(node, ResultingTypeForComplexSlicing(node));
return;
}
if (IsIndexedProperty(node.Target))
{
BindIndexedPropertySlicing(node);
return;
}
if (targetType.IsArray)
{
BindExpressionType(node, targetType.ElementType);
return;
}
var member = TypeSystemServices.GetDefaultMember(targetType);
if (member == null)
{
Error(node, CompilerErrorFactory.TypeDoesNotSupportSlicing(node.Target, targetType));
return;
}
node.Target = new MemberReferenceExpression(node.LexicalInfo, node.Target, member.Name)
{
Entity = member,
ExpressionType = Null.Default // to be resolved later
};
SliceMember(node, member);
}
示例11: CreateSideEffectAwareSlicingOperation
private Expression CreateSideEffectAwareSlicingOperation(LexicalInfo lexicalInfo, BinaryOperatorType binaryOperator, SlicingExpression lvalue, Expression rvalue, InternalLocal returnValue)
{
MethodInvocationExpression eval = CodeBuilder.CreateEvalInvocation(lexicalInfo);
if (HasSideEffect(lvalue.Target))
{
InternalLocal temp = AddInitializedTempLocal(eval, lvalue.Target);
lvalue.Target = CodeBuilder.CreateReference(temp);
}
foreach (Slice slice in lvalue.Indices)
{
Expression index = slice.Begin;
if (HasSideEffect(index))
{
InternalLocal temp = AddInitializedTempLocal(eval, index);
slice.Begin = CodeBuilder.CreateReference(temp);
}
}
BinaryExpression addition = CodeBuilder.CreateBoundBinaryExpression(
GetExpressionType(lvalue),
binaryOperator,
CloneOrAssignToTemp(returnValue, lvalue),
rvalue);
Expression expansion = CodeBuilder.CreateAssignment(
lvalue.CloneNode(),
addition);
// Resolve operator overloads if any
BindArithmeticOperator(addition);
if (eval.Arguments.Count > 0 || null != returnValue)
{
eval.Arguments.Add(expansion);
if (null != returnValue)
{
eval.Arguments.Add(CodeBuilder.CreateReference(returnValue));
}
BindExpressionType(eval, GetExpressionType(lvalue));
expansion = eval;
}
return expansion;
}
示例12: AssertIsNotComplexSlicing
void AssertIsNotComplexSlicing(SlicingExpression node)
{
if (node.IsComplexSlicing())
NotImplemented(node, "complex slicing");
}
示例13: slice
protected void slice(
SlicingExpression se
) //throws RecognitionException, TokenStreamException
{
Expression begin = null;
Expression end = null;
Expression step = null;
try { // for error handling
{
switch ( LA(1) )
{
case COLON:
{
{
match(COLON);
if (0==inputState.guessing)
{
begin = OmittedExpression.Default;
}
{
switch ( LA(1) )
{
case ESEPARATOR:
case CAST:
case CHAR:
case FALSE:
case NOT:
case NULL:
case SELF:
case SUPER:
case THEN:
case TRUE:
case TYPEOF:
case TRIPLE_QUOTED_STRING:
case LPAREN:
case DOUBLE_QUOTED_STRING:
case SINGLE_QUOTED_STRING:
case ID:
case MULTIPLY:
case LBRACK:
case SPLICE_BEGIN:
case DOT:
case LBRACE:
case QQ_BEGIN:
case SUBTRACT:
case LONG:
case INCREMENT:
case DECREMENT:
case ONES_COMPLEMENT:
case INT:
case BACKTICK_QUOTED_STRING:
case RE_LITERAL:
case DOUBLE:
case FLOAT:
case TIMESPAN:
{
end=expression();
break;
}
case COLON:
{
{
match(COLON);
if (0==inputState.guessing)
{
end = OmittedExpression.Default;
}
step=expression();
}
break;
}
case RBRACK:
case COMMA:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
}
break;
}
case ESEPARATOR:
case CAST:
case CHAR:
case FALSE:
case NOT:
case NULL:
case SELF:
case SUPER:
case THEN:
case TRUE:
case TYPEOF:
//.........这里部分代码省略.........
示例14: EmitNormalizedArrayIndex
void EmitNormalizedArrayIndex(SlicingExpression sourceNode, Expression index)
{
bool isNegative = false;
if (CanBeNegative(index, ref isNegative)
&& !_rawArrayIndexing
&& !AstAnnotations.IsRawIndexing(sourceNode))
{
if (isNegative)
{
_il.Emit(OpCodes.Dup);
_il.Emit(OpCodes.Ldlen);
EmitLoadInt(index);
_il.Emit(OpCodes.Add);
}
else
{
_il.Emit(OpCodes.Dup);
EmitLoadInt(index);
_il.EmitCall(OpCodes.Call, RuntimeServices_NormalizeArrayIndex, null);
}
}
else
{
EmitLoadInt(index);
}
}
示例15: BindMultiDimensionalArraySlicing
void BindMultiDimensionalArraySlicing(SlicingExpression node)
{
if (AstUtil.IsLhsOfAssignment(node))
{
// leave it to LeaveBinaryExpression to resolve
return;
}
MethodInvocationExpression mie = CodeBuilder.CreateMethodInvocation(
node.Target,
CachedMethod("Array_GetValue", () => Methods.InstanceFunctionOf<Array, int[], object>(a => a.GetValue)));
for (int i = 0; i < node.Indices.Count; i++)
{
mie.Arguments.Add(node.Indices[i].Begin);
}
IType elementType = node.Target.ExpressionType.ElementType;
node.ParentNode.Replace(node, CodeBuilder.CreateCast(elementType, mie));
}