本文整理汇总了C#中ICSharpCode.NRefactory.Ast.UnaryOperatorExpression类的典型用法代码示例。如果您正苦于以下问题:C# UnaryOperatorExpression类的具体用法?C# UnaryOperatorExpression怎么用?C# UnaryOperatorExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnaryOperatorExpression类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了UnaryOperatorExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitUnaryOperatorExpression
public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
{
if (unaryOperatorExpression.Op == UnaryOperatorType.Not) {
return unaryOperatorExpression.Expression.AcceptVisitor(this, data) == SymbolDefined ? null : SymbolDefined;
} else {
return null;
}
}
示例2: GenerateCode
public override void GenerateCode(List<AbstractNode> nodes, IList items)
{
TypeReference intReference = new TypeReference("System.Int32");
MethodDeclaration method = new MethodDeclaration("GetHashCode", Modifiers.Public | Modifiers.Override, intReference, null, null);
Expression expr = CallGetHashCode(new IdentifierExpression(currentClass.Fields[0].Name));
for (int i = 1; i < currentClass.Fields.Count; i++) {
IdentifierExpression identifier = new IdentifierExpression(currentClass.Fields[i].Name);
expr = new BinaryOperatorExpression(expr, BinaryOperatorType.ExclusiveOr,
CallGetHashCode(identifier));
}
method.Body = new BlockStatement();
method.Body.AddChild(new ReturnStatement(expr));
nodes.Add(method);
TypeReference boolReference = new TypeReference("System.Boolean");
TypeReference objectReference = new TypeReference("System.Object");
method = new MethodDeclaration("Equals", Modifiers.Public | Modifiers.Override, boolReference, null, null);
method.Parameters.Add(new ParameterDeclarationExpression(objectReference, "obj"));
method.Body = new BlockStatement();
TypeReference currentType = ConvertType(currentClass.DefaultReturnType);
expr = new TypeOfIsExpression(new IdentifierExpression("obj"), currentType);
expr = new ParenthesizedExpression(expr);
expr = new UnaryOperatorExpression(expr, UnaryOperatorType.Not);
method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(false, "false"))));
expr = new BinaryOperatorExpression(new ThisReferenceExpression(),
BinaryOperatorType.Equality,
new IdentifierExpression("obj"));
method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(true, "true"))));
VariableDeclaration var = new VariableDeclaration("my" + currentClass.Name,
new CastExpression(currentType, new IdentifierExpression("obj"), CastType.Cast),
currentType);
method.Body.AddChild(new LocalVariableDeclaration(var));
expr = TestEquality(var.Name, currentClass.Fields[0]);
for (int i = 1; i < currentClass.Fields.Count; i++) {
expr = new BinaryOperatorExpression(expr, BinaryOperatorType.LogicalAnd,
TestEquality(var.Name, currentClass.Fields[i]));
}
method.Body.AddChild(new ReturnStatement(expr));
nodes.Add(method);
}
示例3: NotExpr
void NotExpr(
//#line 1993 "VBNET.ATG"
out Expression outExpr) {
//#line 1994 "VBNET.ATG"
UnaryOperatorType uop = UnaryOperatorType.None;
while (la.kind == 164) {
lexer.NextToken();
//#line 1995 "VBNET.ATG"
uop = UnaryOperatorType.Not;
}
ComparisonExpr(
//#line 1996 "VBNET.ATG"
out outExpr);
//#line 1997 "VBNET.ATG"
if (uop != UnaryOperatorType.None)
outExpr = new UnaryOperatorExpression(outExpr, uop);
}
示例4: CreateIncrementStatement
private object CreateIncrementStatement(UnaryOperatorExpression unaryOperatorExpression)
{
object obj = this.CreateIncrementStatement(unaryOperatorExpression, 1, NRefactoryToPythonConverter.GetBinaryOperator(BinaryOperatorType.Add));
return obj;
}
示例5: VisitUnaryOperatorExpression
public sealed override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) {
this.BeginVisit(unaryOperatorExpression);
object result = this.TrackedVisitUnaryOperatorExpression(unaryOperatorExpression, data);
this.EndVisit(unaryOperatorExpression);
return result;
}
示例6: VisitUnaryOperatorExpression
public virtual object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) {
throw new global::System.NotImplementedException("UnaryOperatorExpression");
}
示例7: NotExpr
void NotExpr(
#line 1810 "VBNET.ATG"
out Expression outExpr) {
#line 1811 "VBNET.ATG"
UnaryOperatorType uop = UnaryOperatorType.None;
while (la.kind == 150) {
lexer.NextToken();
#line 1812 "VBNET.ATG"
uop = UnaryOperatorType.Not;
}
ComparisonExpr(
#line 1813 "VBNET.ATG"
out outExpr);
#line 1814 "VBNET.ATG"
if (uop != UnaryOperatorType.None)
outExpr = new UnaryOperatorExpression(outExpr, uop);
}
示例8: PrimaryExpr
//.........这里部分代码省略.........
Expect(21);
#line 1986 "cs.ATG"
pexpr = new CheckedExpression(expr);
} else if (la.kind == 118) {
lexer.NextToken();
Expect(20);
Expr(
#line 1987 "cs.ATG"
out expr);
Expect(21);
#line 1987 "cs.ATG"
pexpr = new UncheckedExpression(expr);
} else SynErr(209);
#line 1989 "cs.ATG"
if (pexpr != null) {
if (pexpr.StartLocation.IsEmpty)
pexpr.StartLocation = startLocation;
if (pexpr.EndLocation.IsEmpty)
pexpr.EndLocation = t.EndLocation;
}
while (StartOf(35)) {
#line 1997 "cs.ATG"
startLocation = la.Location;
switch (la.kind) {
case 31: {
lexer.NextToken();
#line 1999 "cs.ATG"
pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement);
break;
}
case 32: {
lexer.NextToken();
#line 2001 "cs.ATG"
pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement);
break;
}
case 47: {
PointerMemberAccess(
#line 2003 "cs.ATG"
out pexpr, pexpr);
break;
}
case 15: {
MemberAccess(
#line 2004 "cs.ATG"
out pexpr, pexpr);
break;
}
case 20: {
lexer.NextToken();
#line 2008 "cs.ATG"
List<Expression> parameters = new List<Expression>();
#line 2009 "cs.ATG"
pexpr = new InvocationExpression(pexpr, parameters);
if (StartOf(25)) {
Argument(
#line 2010 "cs.ATG"
示例9: CreateDecrementStatement
/// <summary>
/// Converts a post or pre decrement expression to an assign statement.
/// This converts "i--" and "--i" to "i -= 1" since python
/// does not support post increment expressions.
/// </summary>
object CreateDecrementStatement(UnaryOperatorExpression unaryOperatorExpression)
{
return CreateIncrementStatement(unaryOperatorExpression, 1, GetBinaryOperator(BinaryOperatorType.Subtract));
}
示例10: TrackedVisitUnaryOperatorExpression
public override object TrackedVisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
{
switch (unaryOperatorExpression.Op) {
case UnaryOperatorType.PostIncrement:
case UnaryOperatorType.Increment:
// Change i++ or ++i to i += 1
return CreateIncrementStatement(unaryOperatorExpression);
case UnaryOperatorType.Decrement:
case UnaryOperatorType.PostDecrement:
// Change --i or i-- to i -= 1.
return CreateDecrementStatement(unaryOperatorExpression);
case UnaryOperatorType.Minus:
return CreateUnaryOperatorStatement(GetBinaryOperator(BinaryOperatorType.Subtract), unaryOperatorExpression.Expression);
case UnaryOperatorType.Plus:
return CreateUnaryOperatorStatement(GetBinaryOperator(BinaryOperatorType.Add), unaryOperatorExpression.Expression);
case UnaryOperatorType.Not:
return CreateUnaryOperatorStatement("not ", unaryOperatorExpression.Expression);
case UnaryOperatorType.BitNot:
return CreateUnaryOperatorStatement("~", unaryOperatorExpression.Expression);
}
return null;
}
示例11: VisitUnaryOperatorExpression
public virtual object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) {
throw CreateException(unaryOperatorExpression);
}
示例12: VisitUnaryOperatorExpression
public virtual object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) {
Debug.Assert((unaryOperatorExpression != null));
Debug.Assert((unaryOperatorExpression.Expression != null));
nodeStack.Push(unaryOperatorExpression.Expression);
unaryOperatorExpression.Expression.AcceptVisitor(this, data);
unaryOperatorExpression.Expression = ((Expression)(nodeStack.Pop()));
return null;
}
示例13: VisitUnaryOperatorExpression
public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
{
TypedValue value = Evaluate(unaryOperatorExpression.Expression);
UnaryOperatorType op = unaryOperatorExpression.Op;
if (op == UnaryOperatorType.Dereference) {
if (!value.Type.IsPointer)
throw new GetValueException("Target object is not a pointer");
return new TypedValue(value.Value.Dereference(), (DebugType)value.Type.GetElementType());
}
if (!value.Type.IsPrimitive)
throw new GetValueException("Primitive value expected");
if (op == UnaryOperatorType.Decrement || op == UnaryOperatorType.PostDecrement ||
op == UnaryOperatorType.Increment || op == UnaryOperatorType.PostIncrement)
{
TypedValue oldValue = value;
TypedValue newValue = null;
try {
if (op == UnaryOperatorType.Decrement || op == UnaryOperatorType.PostDecrement)
newValue = (TypedValue)VisitAssignmentExpression(new AssignmentExpression(unaryOperatorExpression.Expression, AssignmentOperatorType.Subtract, new PrimitiveExpression(1)), null);
if (op == UnaryOperatorType.Increment || op == UnaryOperatorType.PostIncrement)
newValue = (TypedValue)VisitAssignmentExpression(new AssignmentExpression(unaryOperatorExpression.Expression, AssignmentOperatorType.Add, new PrimitiveExpression(1)), null);
} catch (EvaluateException e) {
throw new EvaluateException(unaryOperatorExpression, e.Message);
}
if (op == UnaryOperatorType.PostDecrement || op == UnaryOperatorType.PostIncrement) {
return oldValue;
} else {
// Note: the old unaryOparatorExpression is still cached and still has the old value
return newValue;
}
}
if (op == UnaryOperatorType.Minus) {
object val = value.PrimitiveValue;
// Special case - it would promote the value to long otherwise
if (val is uint && (uint)val == (uint)1 << 31)
return CreateValue(int.MinValue);
// Special case - it would overflow otherwise
if (val is ulong && (ulong)val == (ulong)1 << 63)
return CreateValue(long.MinValue);
}
if (op == UnaryOperatorType.Plus || op == UnaryOperatorType.Minus ||
op == UnaryOperatorType.BitNot || op == UnaryOperatorType.Not)
{
Type[] overloads;
if (op == UnaryOperatorType.Not) {
overloads = new Type[] { typeof(bool) };
} else if (op == UnaryOperatorType.Minus) {
overloads = new Type[] { typeof(int), typeof(long), typeof(ulong), typeof(float), typeof(double) };
} else {
overloads = new Type[] { typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double) };
}
foreach(Type argType in overloads) {
if (value.Type.CanPromoteTo(argType)) {
object a = Convert.ChangeType(value.PrimitiveValue, argType);
object res;
try {
res = PerformUnaryOperation(a, op, argType);
} catch (ArithmeticException e) {
// Can happen for smaller int or long
throw new EvaluateException(unaryOperatorExpression, e.Message);
}
if (res != null)
return CreateValue(res);
break; // Match only one overload
}
}
}
throw new EvaluateException(unaryOperatorExpression, "Can not use the unary operator {0} on type {1}", op.ToString(), value.Type.FullName);
}
示例14: VisitUnaryOperatorExpression
public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
{
if (unaryOperatorExpression.Op == UnaryOperatorType.PostIncrement || unaryOperatorExpression.Op == UnaryOperatorType.Increment)
UnlockWith(unaryOperatorExpression);
return base.VisitUnaryOperatorExpression(unaryOperatorExpression, data);
}
示例15: PrimaryExpr
//.........这里部分代码省略.........
#line 1924 "cs.ATG"
out expr);
Expect(21);
#line 1924 "cs.ATG"
pexpr = new UncheckedExpression(expr);
} else if (la.kind == 64) {
lexer.NextToken();
AnonymousMethodExpr(
#line 1925 "cs.ATG"
out expr);
#line 1925 "cs.ATG"
pexpr = expr;
} else SynErr(208);
#line 1927 "cs.ATG"
if (pexpr != null) {
if (pexpr.StartLocation.IsEmpty)
pexpr.StartLocation = startLocation;
if (pexpr.EndLocation.IsEmpty)
pexpr.EndLocation = t.EndLocation;
}
while (StartOf(36)) {
#line 1935 "cs.ATG"
startLocation = la.Location;
switch (la.kind) {
case 31: {
lexer.NextToken();
#line 1937 "cs.ATG"
pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement);
break;
}
case 32: {
lexer.NextToken();
#line 1939 "cs.ATG"
pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement);
break;
}
case 47: {
PointerMemberAccess(
#line 1941 "cs.ATG"
out pexpr, pexpr);
break;
}
case 15: {
MemberAccess(
#line 1942 "cs.ATG"
out pexpr, pexpr);
break;
}
case 20: {
lexer.NextToken();
#line 1946 "cs.ATG"
List<Expression> parameters = new List<Expression>();
#line 1947 "cs.ATG"
pexpr = new InvocationExpression(pexpr, parameters);
if (StartOf(26)) {
Argument(
#line 1948 "cs.ATG"