本文整理汇总了C#中ExpressionStatement类的典型用法代码示例。如果您正苦于以下问题:C# ExpressionStatement类的具体用法?C# ExpressionStatement怎么用?C# ExpressionStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExpressionStatement类属于命名空间,在下文中一共展示了ExpressionStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitAssignmentStatement
public override Statement VisitAssignmentStatement(AssignmentStatement assignment)
{
MemberBinding binding = assignment.Target as MemberBinding;
if (binding != null)
{
Expression target = VisitExpression(binding.TargetObject);
Field boundMember = (Field) binding.BoundMember;
Expression source = VisitExpression(assignment.Source);
if (!boundMember.IsStatic && !boundMember.DeclaringType.IsValueType && boundMember.DeclaringType.Contract != null && boundMember.DeclaringType.Contract.FramePropertyGetter != null && boundMember != boundMember.DeclaringType.Contract.FrameField)
{
Local targetLocal = new Local(boundMember.DeclaringType);
Statement evaluateTarget = new AssignmentStatement(targetLocal, target, assignment.SourceContext);
Local sourceLocal = new Local(boundMember.Type);
Statement evaluateSource = new AssignmentStatement(sourceLocal, source, assignment.SourceContext);
Expression guard = new MethodCall(new MemberBinding(targetLocal, boundMember.DeclaringType.Contract.FramePropertyGetter), null, NodeType.Call, SystemTypes.Guard);
Statement check = new ExpressionStatement(new MethodCall(new MemberBinding(guard, SystemTypes.Guard.GetMethod(Identifier.For("CheckIsWriting"))), null, NodeType.Call, SystemTypes.Void));
Statement stfld = new AssignmentStatement(new MemberBinding(targetLocal, boundMember), sourceLocal, assignment.SourceContext);
return new Block(new StatementList(new Statement[] {evaluateTarget, evaluateSource, check, stfld}));
}
else
{
binding.TargetObject = target;
assignment.Source = source;
return assignment;
}
}
else
{
return base.VisitAssignmentStatement(assignment);
}
}
示例2: VisitMethodDeclaration
public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration)
{
Guard.AgainstNullArgument("methodDeclaration", methodDeclaration);
IEnumerable<ParameterDeclaration> parameters = methodDeclaration
.GetChildrenByRole(Roles.Parameter)
.Select(x => (ParameterDeclaration)x.Clone());
var isVoid = false;
var isAsync = methodDeclaration.Modifiers.HasFlag(Modifiers.Async);
AstType returnType = methodDeclaration.GetChildByRole(Roles.Type).Clone();
var type = returnType as PrimitiveType;
if (type != null)
{
isVoid = string.Compare(
type.Keyword, "void", StringComparison.OrdinalIgnoreCase) == 0;
}
var methodType = new SimpleType(Identifier.Create(isVoid ? "Action" : "Func"));
IEnumerable<AstType> types = parameters.Select(
x => x.GetChildByRole(Roles.Type).Clone());
methodType
.TypeArguments
.AddRange(types);
if (!isVoid)
{
methodType.TypeArguments.Add(returnType);
}
var methodName = GetIdentifierName(methodDeclaration);
var methodBody = methodDeclaration
.GetChildrenByRole(Roles.Body)
.FirstOrDefault();
if (methodBody == null)
{
throw new NullReferenceException(string.Format("Method '{0}' has no method body", methodName));
}
methodBody = (BlockStatement)methodBody.Clone();
var prototype = new VariableDeclarationStatement { Type = methodType };
prototype.Variables.Add(new VariableInitializer(methodName));
var anonymousMethod = new AnonymousMethodExpression(methodBody, parameters) { IsAsync = isAsync };
var expression = new ExpressionStatement
{
Expression = new AssignmentExpression(
new IdentifierExpression(methodName),
anonymousMethod)
};
_methods.Add(new MethodVisitorResult
{
MethodDefinition = methodDeclaration,
MethodPrototype = prototype,
MethodExpression = expression
});
}
示例3: GetActions
public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
var property = context.GetNode<PropertyDeclaration>();
if (property == null || !property.NameToken.Contains(context.Location))
yield break;
var field = RemoveBackingStoreAction.GetBackingField(context);
if (field == null)
yield break;
var resolvedType = ReflectionHelper.ParseReflectionName ("System.EventHandler").Resolve (context.Compilation);
if (resolvedType == null)
yield break;
var type = (TypeDeclaration)property.Parent;
yield return new CodeAction(context.TranslateString("Create changed event"), script => {
var eventDeclaration = CreateChangedEventDeclaration (context, property);
var methodDeclaration = CreateEventInvocatorAction.CreateEventInvocator (context, type, eventDeclaration, eventDeclaration.Variables.First (), resolvedType.GetDelegateInvokeMethod (), false);
var stmt = new ExpressionStatement (new InvocationExpression (
new IdentifierExpression (methodDeclaration.Name),
new MemberReferenceExpression (context.CreateShortType("System", "EventArgs"), "Empty")
));
script.InsertWithCursor(
context.TranslateString("Create event invocator"),
Script.InsertPosition.After,
new AstNode[] { eventDeclaration, methodDeclaration }
).ContinueScript(delegate {
script.InsertBefore (property.Setter.Body.RBraceToken, stmt);
script.FormatText (stmt);
});
}, property.NameToken);
}
示例4: FalseLt
public void FalseLt()
{
var firstop = new IntegerLiteral("2", 0);
var secondop = new IntegerLiteral("1", 0);
var lt = new LogicalOp("<", firstop, secondop, 0);
var assert = new ExpressionStatement("assert", lt, 0);
program.Add(assert);
Assert.Throws<MiniPLAssertionFailed>(() => interpreter.Run(new Program(program)));
}
示例5: VisitExpressionStatement
public override void VisitExpressionStatement(ExpressionStatement expressionStatement)
{
base.VisitExpressionStatement(expressionStatement);
var invocation = expressionStatement.Expression as InvocationExpression;
if (invocation == null)
return;
var rr = ctx.Resolve(invocation) as InvocationResolveResult;
if (rr != null && (rr.Type.IsKnownType(KnownTypeCode.Task) || rr.Type.IsKnownType(KnownTypeCode.TaskOfT))) {
AddIssue(invocation, ctx.TranslateString("Exceptions in async call will be silently ignored because the returned task is unused"));
}
}
示例6: VisitExpressionStatement
public override void VisitExpressionStatement(ExpressionStatement expressionStatement)
{
StartNode(expressionStatement);
expressionStatement.Expression.AcceptVisitor(this);
WriteToken(Roles.Semicolon);
if (_currentStatementIsNotValidCSharp) {
Space();
VisitComment(new Comment(" This is not valid C#, but it represents the IL correctly."));
_currentStatementIsNotValidCSharp = false;
}
NewLine();
EndNode(expressionStatement);
}
示例7: Dispatch
public override void Dispatch(ICodeVisitor visitor) {
CompileTimeConstant labelIndex = new CompileTimeConstant(this.rootClass.GetLabelIndex(this.TargetLabel.Name), this.TargetLabel.SourceLocation);
labelIndex.SetContainingExpression(this.TargetLabel);
List<Expression> arguments = new List<Expression>(1);
arguments.Add(labelIndex);
IMethodDefinition constructor = Dummy.Method;
foreach (IMethodDefinition cons in this.rootClass.TypeDefinition.GetMembersNamed(this.Compilation.NameTable.Ctor, false)) {
constructor = cons; break;
}
Expression thisArgument = new CreateObjectInstanceForResolvedConstructor(constructor, arguments, this.SourceLocation);
//^ assume this.ContainingBlock.ContainingMethodDeclaration != null;
MethodCall mcall = new ResolvedMethodCall(this.rootClass.MainMethod.MethodDefinition, thisArgument, new List<Expression>(0), this.SourceLocation);
ExpressionStatement gosub = new ExpressionStatement(mcall);
gosub.Dispatch(visitor);
}
示例8: HandleExpressionStatement
CodeAction HandleExpressionStatement(RefactoringContext context, ExpressionStatement expressionStatement)
{
var expression = expressionStatement.Expression as AssignmentExpression;
if (expression == null)
return null;
if (!(expression.Right is ObjectCreateExpression))
return null;
var expressionResolveResult = context.Resolve(expression.Left);
if (!(expressionResolveResult is LocalResolveResult) && !(expressionResolveResult is MemberResolveResult))
return null;
IList<AstNode> statements = GetNodes(context.GetNode<Statement>());
var converter = new StatementsToInitializerConverter(context);
var newExpression = converter.ConvertToInitializer(expression, ref statements);
if (statements.Count == 0)
return null;
return MakeAction(context, expression, newExpression, statements);
}
示例9: VisitExpressionStatement
public override object VisitExpressionStatement(ExpressionStatement expressionStatement, object data)
{
UnaryOperatorExpression uoe = expressionStatement.Expression as UnaryOperatorExpression;
if (uoe != null) {
switch (uoe.Op) {
case UnaryOperatorType.Increment:
case UnaryOperatorType.PostIncrement:
expressionStatement.Expression = new AssignmentExpression(uoe.Expression, AssignmentOperatorType.Add, new PrimitiveExpression(1, "1"));
break;
case UnaryOperatorType.Decrement:
case UnaryOperatorType.PostDecrement:
expressionStatement.Expression = new AssignmentExpression(uoe.Expression, AssignmentOperatorType.Subtract, new PrimitiveExpression(1, "1"));
break;
}
}
return base.VisitExpressionStatement(expressionStatement, data);
}
示例10: VisitMemberBinding
public override Expression VisitMemberBinding(MemberBinding binding)
{
Member boundMember = binding.BoundMember;
if (boundMember is Field && !boundMember.IsStatic && boundMember.DeclaringType != null && boundMember.DeclaringType.Contract != null && boundMember.DeclaringType.Contract.FramePropertyGetter != null && boundMember != boundMember.DeclaringType.Contract.FrameField)
{
Expression target = VisitExpression(binding.TargetObject);
// Since we do not visit member bindings of assignment statements, we know/guess that this is a ldfld.
Local targetLocal = new Local(boundMember.DeclaringType);
Statement evaluateTarget = new AssignmentStatement(targetLocal, target, binding.SourceContext);
Expression guard = new MethodCall(new MemberBinding(targetLocal, boundMember.DeclaringType.Contract.FramePropertyGetter), null, NodeType.Call, SystemTypes.Guard);
Statement check = new ExpressionStatement(new MethodCall(new MemberBinding(guard, SystemTypes.Guard.GetMethod(Identifier.For("CheckIsReading"))), null, NodeType.Call, SystemTypes.Void));
Statement ldfld = new ExpressionStatement(new MemberBinding(targetLocal, boundMember, binding.SourceContext));
return new BlockExpression(new Block(new StatementList(new Statement[] {evaluateTarget, check, ldfld})), binding.Type);
}
else
{
return base.VisitMemberBinding(binding);
}
}
示例11: GetActions
public IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
//TODO: implement variable assignment & ctor param
var varInit = context.GetNode<VariableInitializer>();
if (varInit != null) {
AstType type = varInit.GetPrevNode() as AstType;
if (type == null) yield break;
if (varInit.Parent is FieldDeclaration) yield break;
if (CannotExtractField(varInit)) yield break;
yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
var name = varInit.Name;
FieldDeclaration field = new FieldDeclaration(){
ReturnType = type.Clone(),
Variables = { new VariableInitializer(name) }
};
AstNode nodeToRemove = RemoveDeclaration(varInit) ? varInit.Parent : type;
s.Remove(nodeToRemove, true);
s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
s.FormatText(varInit.Parent);
});
}
var idntf = context.GetNode<Identifier>();
if (idntf == null) yield break;
var paramDec = idntf.Parent as ParameterDeclaration;
if (paramDec != null) {
var ctor = paramDec.Parent as ConstructorDeclaration;
if (ctor == null) yield break;
MemberReferenceExpression thisField = new MemberReferenceExpression(new ThisReferenceExpression(), idntf.Name, new AstType[]{});
var assign = new AssignmentExpression(thisField, AssignmentOperatorType.Assign, new IdentifierExpression(idntf.Name));
var statement = new ExpressionStatement(assign);
var type = (idntf.GetPrevNode() as AstType).Clone();
FieldDeclaration field = new FieldDeclaration(){
ReturnType = type.Clone(),
Variables = { new VariableInitializer(idntf.Name) }
};
yield return new CodeAction(context.TranslateString("Assign to new field"), s=>{
s.InsertWithCursor(context.TranslateString("Insert new field"),Script.InsertPosition.Before,field);
s.AddTo(ctor.Body, statement);
});
}
}
示例12: Walk
// ExpressionStatement
public override bool Walk(ExpressionStatement node) { return false; }
示例13: PostWalk
public override void PostWalk(ExpressionStatement node) { }
示例14: Visit
public override object Visit (InvalidStatementExpression statementExpression)
{
var result = new ExpressionStatement ();
if (statementExpression.Expression == null)
return result;
var expr = statementExpression.Expression.Accept (this) as Expression;
if (expr != null)
result.AddChild (expr, Roles.Expression);
var location = LocationsBag.GetLocations (statementExpression);
if (location != null)
result.AddChild (new CSharpTokenNode (Convert (location [0]), Roles.Semicolon), Roles.Semicolon);
return result;
}
示例15: CSharpGrammar
//.........这里部分代码省略.........
}
result.Clauses.Add((LinqClause) node.Children[2].Result);
return result;
});
expression.Rule = conditionalExpression
| linqExpression
| lambdaExpression
| assignmentExpression;
#endregion
#region Statements
var statement = new GrammarDefinition("Statement");
var embeddedStatement = new GrammarDefinition("EmbeddedStatement");
var emptyStatement = new GrammarDefinition("EmptyStatement",
rule: ToElement(SEMICOLON),
createNode: node =>
{
var result = new EmptyStatement();
result.AddChild(AstNodeTitles.Semicolon, node.Children[0].Result);
return result;
});
var labelStatement = new GrammarDefinition("LabelStatement",
rule: identifierInsideBody + ToElement(COLON),
createNode: node => new LabelStatement((Identifier) node.Children[0].Result)
{
Colon = (AstToken) node.Children[1].Result
});
var expressionStatement = new GrammarDefinition("ExpressionStatement",
rule: expression + ToElement(SEMICOLON)
| Error + ToElement(SEMICOLON)
| Error + ToElement(CLOSE_BRACE)
| expression + ToElement(CLOSE_BRACE), // Common mistake in C# is to forget the semicolon at the end of a statement.
createNode: node =>
{
var result = new ExpressionStatement(node.Children[0].Result as Expression);
var endingToken = (AstToken) node.Children[1].Result;
if (endingToken.GetTokenCode() == (int) SEMICOLON)
{
result.AddChild(AstNodeTitles.Semicolon, node.Children[1].Result);
}
else
{
node.Context.SyntaxErrors.Add(new SyntaxError(
node.Children[1].Range.End,
"';' expected.",
MessageSeverity.Error));
node.Context.Lexer.PutBack((AstToken) endingToken);
}
return result;
});
blockStatement.Rule = ToElement(OPEN_BRACE)
+ statementListOptional
+ ToElement(CLOSE_BRACE);
blockStatement.ComputeResult = node =>
{
var result = new BlockStatement();