本文整理汇总了C#中CastExpression类的典型用法代码示例。如果您正苦于以下问题:C# CastExpression类的具体用法?C# CastExpression怎么用?C# CastExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CastExpression类属于命名空间,在下文中一共展示了CastExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitCastExpression
public override void VisitCastExpression (CastExpression castExpression)
{
base.VisitCastExpression (castExpression);
VisitTypeCastExpression (castExpression, ctx.Resolve (castExpression.Expression).Type,
ctx.ResolveType (castExpression.Type));
}
示例2: VisitCastExpression
public override void VisitCastExpression (CastExpression castExpression)
{
base.VisitCastExpression (castExpression);
CheckTypeCast (castExpression, castExpression.Expression, castExpression.StartLocation,
castExpression.Expression.StartLocation);
}
示例3: Visit
public ISymbolValue Visit(CastExpression ce)
{
var toCast = ce.UnaryExpression != null ? ce.UnaryExpression.Accept (this) : null;
var targetType = ce.Type != null ? TypeDeclarationResolver.ResolveSingle(ce.Type, ctxt) : null;
var pv = toCast as PrimitiveValue;
var pt = targetType as PrimitiveType;
if (pv != null && pt != null) {
//TODO: Truncate value bytes if required and/or treat Value/ImaginaryPart in any way!
return new PrimitiveValue(pt.TypeToken, pv.Value, pv.ImaginaryPart, pt.Modifier);
}
// TODO: Convert actual object
return null;
}
示例4: VisitCastExpression
public override void VisitCastExpression(CastExpression castExpression)
{
base.VisitCastExpression(castExpression);
var expression = castExpression.Expression;
if (expression is ParenthesizedExpression)
expression = (expression as ParenthesizedExpression).Expression;
object value = null;
if (expression is PrimitiveExpression)
value = (expression as PrimitiveExpression).Value;
else if (expression is UnaryOperatorExpression &&
(expression as UnaryOperatorExpression).Expression is PrimitiveExpression)
{
var primitive = (expression as UnaryOperatorExpression).Expression as PrimitiveExpression;
value = primitive.Value;
}
if (value != null)
{
var type = (castExpression.Type as PrimitiveType).KnownTypeCode;
if ((type == KnownTypeCode.Int16 && value is short) ||
(type == KnownTypeCode.Int32 && value is int) ||
(type == KnownTypeCode.Int64 && value is long) ||
(type == KnownTypeCode.UInt16 && value is ushort) ||
(type == KnownTypeCode.UInt32 && value is uint) ||
(type == KnownTypeCode.UInt64 && value is ulong) ||
(type == KnownTypeCode.Double && value is double) ||
(type == KnownTypeCode.Single && value is float) ||
(type == KnownTypeCode.String && value is string) ||
(type == KnownTypeCode.Boolean && value is bool) ||
(type == KnownTypeCode.Char && value is char) ||
(type == KnownTypeCode.Byte && value is byte) ||
(type == KnownTypeCode.SByte && value is sbyte) ||
(type == KnownTypeCode.Decimal && value is decimal))
{
castExpression.ReplaceWith(expression);
}
}
}
示例5: Visit
public override object Visit (Cast castExpression)
{
var result = new CastExpression ();
var location = LocationsBag.GetLocations (castExpression);
result.AddChild (new CSharpTokenNode (Convert (castExpression.Location), 1), CastExpression.Roles.LPar);
if (castExpression.TargetType != null)
result.AddChild ((INode)castExpression.TargetType.Accept (this), CastExpression.Roles.ReturnType);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), CastExpression.Roles.RPar);
if (castExpression.Expr != null)
result.AddChild ((INode)castExpression.Expr.Accept (this), CastExpression.Roles.Expression);
return result;
}
示例6: VisitCastExpression
public virtual void VisitCastExpression (CastExpression castExpression)
{
VisitChildren (castExpression);
}
示例7: VisitCastExpression
public virtual void VisitCastExpression(CastExpression castExpression)
{
if (this.ThrowException)
{
throw (Exception)this.CreateException(castExpression);
}
}
示例8: VisitCastExpression
public override void VisitCastExpression(CastExpression castExpression)
{
if (castExpression.RParToken != null) {
ForceSpacesAfter(castExpression.LParToken, policy.SpacesWithinCastParentheses);
ForceSpacesBefore(castExpression.RParToken, policy.SpacesWithinCastParentheses);
ForceSpacesAfter(castExpression.RParToken, policy.SpaceAfterTypecast);
}
base.VisitCastExpression(castExpression);
}
示例9: Visit
public void Visit(CastExpression x)
{
}
示例10: UnaryExpression
IExpression UnaryExpression(IBlockNode Scope = null)
{
switch (laKind)
{
// Note: PowExpressions are handled in PowExpression()
case BitwiseAnd:
case Increment:
case Decrement:
case Times:
case Minus:
case Plus:
case Not:
case Tilde:
Step();
SimpleUnaryExpression sue;
switch (t.Kind)
{
case BitwiseAnd:
sue = new UnaryExpression_And();
break;
case Increment:
sue = new UnaryExpression_Increment();
break;
case Decrement:
sue = new UnaryExpression_Decrement();
break;
case Times:
sue = new UnaryExpression_Mul();
break;
case Minus:
sue = new UnaryExpression_Sub();
break;
case Plus:
sue = new UnaryExpression_Add();
break;
case Tilde:
sue = new UnaryExpression_Cat();
break;
case Not:
sue = new UnaryExpression_Not();
break;
default:
SynErr(t.Kind, "Illegal token for unary expressions");
return null;
}
sue.Location = t.Location;
sue.UnaryExpression = UnaryExpression(Scope);
return sue;
// CastExpression
case Cast:
Step();
var ce = new CastExpression { Location= t.Location };
if (Expect(OpenParenthesis))
{
if (laKind != CloseParenthesis) // Yes, it is possible that a cast() can contain an empty type!
ce.Type = Type();
Expect(CloseParenthesis);
}
ce.UnaryExpression = UnaryExpression(Scope);
ce.EndLocation = t.EndLocation;
return ce;
// DeleteExpression
case Delete:
Step();
return new DeleteExpression() { UnaryExpression = UnaryExpression(Scope) };
// PowExpression
default:
var left = PostfixExpression(Scope);
if (laKind != Pow)
return left;
Step();
var pe = new PowExpression();
pe.LeftOperand = left;
pe.RightOperand = UnaryExpression(Scope);
return pe;
}
}
示例11: VisitCastExpression
public abstract StringBuilder VisitCastExpression(CastExpression castExpression, int data);
示例12: Visit
public ISymbolValue Visit(CastExpression ce)
{
// TODO: Convert actual object
return null;
}
示例13: VisitCastExpression
public override void VisitCastExpression(CastExpression castExpression)
{
new CastBlock(this, castExpression).Emit();
}
示例14: UnaryExpression
IExpression UnaryExpression(IBlockNode Scope = null)
{
// Note: PowExpressions are handled in PowExpression()
if (laKind == (BitwiseAnd) || laKind == (Increment) ||
laKind == (Decrement) || laKind == (Times) ||
laKind == (Minus) || laKind == (Plus) ||
laKind == (Not) || laKind == (Tilde))
{
Step();
SimpleUnaryExpression ae = null;
switch (t.Kind)
{
case BitwiseAnd:
ae = new UnaryExpression_And();
break;
case Increment:
ae = new UnaryExpression_Increment();
break;
case Decrement:
ae = new UnaryExpression_Decrement();
break;
case Times:
ae = new UnaryExpression_Mul();
break;
case Minus:
ae = new UnaryExpression_Sub();
break;
case Plus:
ae = new UnaryExpression_Add();
break;
case Tilde:
ae = new UnaryExpression_Cat();
break;
case Not:
ae = new UnaryExpression_Not();
break;
}
LastParsedObject = ae;
ae.Location = t.Location;
ae.UnaryExpression = UnaryExpression(Scope);
return ae;
}
// ( Type ) . Identifier
if (laKind == OpenParenthesis)
{
var wkParsing = AllowWeakTypeParsing;
AllowWeakTypeParsing = true;
var curLA = la;
Step();
var td = Type();
AllowWeakTypeParsing = wkParsing;
if (td!=null && ((t.Kind!=OpenParenthesis && laKind == CloseParenthesis && Peek(1).Kind == Dot && Peek(2).Kind == Identifier) ||
(IsEOF || Peek(1).Kind==EOF || Peek(2).Kind==EOF))) // Also take it as a type declaration if there's nothing following (see Expression Resolving)
{
Step(); // Skip to )
Step(); // Skip to .
Step(); // Skip to identifier
var accExpr = new UnaryExpression_Type() { Type=td, AccessIdentifier=t.Value };
accExpr.Location = curLA.Location;
accExpr.EndLocation = t.EndLocation;
return accExpr;
}
else
{
// Reset the current token with the earlier one to enable Expression parsing
la = curLA;
Peek(1);
}
}
// CastExpression
if (laKind == (Cast))
{
Step();
var ae = new CastExpression { Location= t.Location };
if (Expect(OpenParenthesis))
{
if (laKind != CloseParenthesis) // Yes, it is possible that a cast() can contain an empty type!
ae.Type = Type();
Expect(CloseParenthesis);
}
ae.UnaryExpression = UnaryExpression(Scope);
ae.EndLocation = t.EndLocation;
//.........这里部分代码省略.........
示例15: SimpleNonInvocationExpression
//.........这里部分代码省略.........
#line 1688 "VBNET.ATG"
pexpr = expr;
break;
}
case 81: case 93: case 204: {
#line 1690 "VBNET.ATG"
CastType castType = CastType.Cast;
if (la.kind == 93) {
lexer.NextToken();
} else if (la.kind == 81) {
lexer.NextToken();
#line 1692 "VBNET.ATG"
castType = CastType.Conversion;
} else if (la.kind == 204) {
lexer.NextToken();
#line 1693 "VBNET.ATG"
castType = CastType.TryCast;
} else SynErr(259);
Expect(25);
Expr(
#line 1695 "VBNET.ATG"
out expr);
Expect(12);
TypeName(
#line 1695 "VBNET.ATG"
out type);
Expect(26);
#line 1696 "VBNET.ATG"
pexpr = new CastExpression(type, expr, castType);
break;
}
case 63: case 64: case 65: case 66: case 67: case 68: case 70: case 72: case 73: case 77: case 78: case 79: case 80: case 82: case 83: case 84: {
CastTarget(
#line 1697 "VBNET.ATG"
out type);
Expect(25);
Expr(
#line 1697 "VBNET.ATG"
out expr);
Expect(26);
#line 1697 "VBNET.ATG"
pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion);
break;
}
case 44: {
lexer.NextToken();
Expr(
#line 1698 "VBNET.ATG"
out expr);
#line 1698 "VBNET.ATG"
pexpr = new AddressOfExpression(expr);
break;
}
case 116: {
lexer.NextToken();
Expect(25);
GetTypeTypeName(
#line 1699 "VBNET.ATG"
out type);