本文整理汇总了C#中DirectionExpression类的典型用法代码示例。如果您正苦于以下问题:C# DirectionExpression类的具体用法?C# DirectionExpression怎么用?C# DirectionExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DirectionExpression类属于命名空间,在下文中一共展示了DirectionExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitDirectionExpression
public override void VisitDirectionExpression(DirectionExpression directionExpression)
{
this.DirectionExpression.Add(directionExpression.Expression);
base.VisitDirectionExpression(directionExpression);
}
示例2: TrackedVisitDirectionExpression
public virtual object TrackedVisitDirectionExpression(DirectionExpression directionExpression, object data) {
return base.VisitDirectionExpression(directionExpression, data);
}
示例3: AddArguments
void AddArguments (AbstractCSharpNode parent, object location, Mono.CSharp.Arguments args)
{
if (args == null)
return;
var commaLocations = LocationsBag.GetLocations (args);
for (int i = 0; i < args.Count; i++) {
Argument arg = args[i];
if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) {
DirectionExpression direction = new DirectionExpression ();
direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
var argLocation = LocationsBag.GetLocations (arg);
if (location != null)
direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword);
direction.AddChild ((INode)arg.Expr.Accept (this), InvocationExpression.Roles.Expression);
parent.AddChild (direction, InvocationExpression.Roles.Argument);
} else {
parent.AddChild ((INode)arg.Expr.Accept (this), InvocationExpression.Roles.Argument);
}
if (commaLocations != null && i > 0) {
int idx = commaLocations.Count - i;
if (idx >= 0)
parent.AddChild (new CSharpTokenNode (Convert (commaLocations[idx]), 1), InvocationExpression.Roles.Comma);
}
}
if (commaLocations != null && commaLocations.Count > args.Count)
parent.AddChild (new CSharpTokenNode (Convert (commaLocations[0]), 1), InvocationExpression.Roles.Comma);
}
示例4: VisitDirectionExpression
public virtual void VisitDirectionExpression (DirectionExpression directionExpression)
{
VisitChildren (directionExpression);
}
示例5: CreateFromStatements
CodeAction CreateFromStatements(RefactoringContext context, List<AstNode> statements)
{
if (!(statements [0].Parent is Statement))
return null;
return new CodeAction(context.TranslateString("Extract method"), script => {
string methodName = "NewMethod";
var method = new MethodDeclaration() {
ReturnType = new PrimitiveType("void"),
Name = methodName,
Body = new BlockStatement()
};
bool usesNonStaticMember = false;
foreach (var node in statements) {
usesNonStaticMember |= StaticVisitor.UsesNotStaticMember(context, node);
if (node is Statement) {
method.Body.Add((Statement)node.Clone());
} else {
method.Body.AddChildUnsafe (node.Clone (), node.Role);
}
}
if (!usesNonStaticMember)
method.Modifiers |= Modifiers.Static;
var target = new IdentifierExpression(methodName);
var invocation = new InvocationExpression(target);
var usedVariables = VariableLookupVisitor.Analyze(context, statements);
var inExtractedRegion = new VariableUsageAnalyzation (context, usedVariables);
var lastStatement = statements [statements.Count - 1];
var stmt = statements [0].GetParent<BlockStatement>();
while (stmt.GetParent<BlockStatement> () != null) {
stmt = stmt.GetParent<BlockStatement>();
}
inExtractedRegion.SetAnalyzedRange(statements [0], lastStatement);
stmt.AcceptVisitor (inExtractedRegion);
var beforeExtractedRegion = new VariableUsageAnalyzation (context, usedVariables);
beforeExtractedRegion.SetAnalyzedRange(statements [0].Parent, statements [0], true, false);
stmt.AcceptVisitor (beforeExtractedRegion);
var afterExtractedRegion = new VariableUsageAnalyzation (context, usedVariables);
afterExtractedRegion.SetAnalyzedRange(lastStatement, stmt.Statements.Last(), false, true);
stmt.AcceptVisitor (afterExtractedRegion);
usedVariables.Sort ((l, r) => l.Region.Begin.CompareTo (r.Region.Begin));
IVariable generatedReturnVariable = null;
foreach (var variable in usedVariables) {
if ((variable is IParameter) || beforeExtractedRegion.Has (variable) || !afterExtractedRegion.Has (variable))
continue;
generatedReturnVariable = variable;
method.ReturnType = context.CreateShortType (variable.Type);
method.Body.Add (new ReturnStatement (new IdentifierExpression (variable.Name)));
break;
}
int parameterOutCount = 0;
foreach (var variable in usedVariables) {
if (!(variable is IParameter) && !beforeExtractedRegion.Has (variable) && !afterExtractedRegion.Has (variable))
continue;
if (variable == generatedReturnVariable)
continue;
Expression argumentExpression = new IdentifierExpression(variable.Name);
ParameterModifier mod = ParameterModifier.None;
if (inExtractedRegion.GetStatus (variable) == VariableState.Changed) {
if (beforeExtractedRegion.GetStatus (variable) == VariableState.None) {
mod = ParameterModifier.Out;
argumentExpression = new DirectionExpression(FieldDirection.Out, argumentExpression);
parameterOutCount++;
} else {
mod = ParameterModifier.Ref;
argumentExpression = new DirectionExpression(FieldDirection.Ref, argumentExpression);
}
}
method.Parameters.Add(new ParameterDeclaration(context.CreateShortType(variable.Type), variable.Name, mod));
invocation.Arguments.Add(argumentExpression);
}
ParameterDeclaration parameterToTransform = null;
bool transformParameterToReturn = method.ReturnType is PrimitiveType &&
((PrimitiveType)method.ReturnType).Keyword == "void" &&
parameterOutCount == 1;
if(transformParameterToReturn) {
parameterToTransform = method.Parameters.First(p => p.ParameterModifier == ParameterModifier.Out);
parameterToTransform.Remove();
var argumentExpression = invocation.Arguments.OfType<DirectionExpression>().First(a => a.FieldDirection == FieldDirection.Out);
argumentExpression.Remove();
method.ReturnType = parameterToTransform.Type.Clone();
var argumentDecl = new VariableDeclarationStatement(parameterToTransform.Type.Clone(),parameterToTransform.Name);
method.Body.InsertChildBefore(method.Body.First(),argumentDecl,BlockStatement.StatementRole);
method.Body.Add(new ReturnStatement (new IdentifierExpression (parameterToTransform.Name)));
}
script
.InsertWithCursor(context.TranslateString("Extract method"), Script.InsertPosition.Before, method)
//.........这里部分代码省略.........
示例6: VisitDirectionExpression
public override StringBuilder VisitDirectionExpression(DirectionExpression directionExpression, int data)
{
// at invocation time we wont pass out or inout keywords so
// this just passes through
return directionExpression.Expression.AcceptVisitor(this, data);
}
示例7: ConvertArgument
Expression ConvertArgument (Argument arg)
{
if (arg is NamedArgument) {
var na = (NamedArgument)arg;
NamedArgumentExpression newArg = new NamedArgumentExpression();
newArg.AddChild (Identifier.Create (na.Name, Convert (na.Location)), NamedArgumentExpression.Roles.Identifier);
var loc = LocationsBag.GetLocations (na);
if (loc != null)
newArg.AddChild (new CSharpTokenNode (Convert (loc[0]), 1), NamedArgumentExpression.Roles.Colon);
if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) {
DirectionExpression direction = new DirectionExpression ();
direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
var argLocation = LocationsBag.GetLocations (arg);
if (argLocation != null)
direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword);
direction.AddChild ((Expression)arg.Expr.Accept (this), InvocationExpression.Roles.Expression);
newArg.AddChild (direction, NamedArgumentExpression.Roles.Expression);
} else {
newArg.AddChild ((Expression)na.Expr.Accept (this), NamedArgumentExpression.Roles.Expression);
}
return newArg;
}
if (arg.ArgType == Argument.AType.Out || arg.ArgType == Argument.AType.Ref) {
DirectionExpression direction = new DirectionExpression ();
direction.FieldDirection = arg.ArgType == Argument.AType.Out ? FieldDirection.Out : FieldDirection.Ref;
var argLocation = LocationsBag.GetLocations (arg);
if (argLocation != null)
direction.AddChild (new CSharpTokenNode (Convert (argLocation[0]), "123".Length), InvocationExpression.Roles.Keyword);
direction.AddChild ((Expression)arg.Expr.Accept (this), InvocationExpression.Roles.Expression);
return direction;
}
return (Expression)arg.Expr.Accept (this);
}
示例8: Argument
void Argument(
#line 1372 "cs.ATG"
out Expression argumentexpr) {
#line 1374 "cs.ATG"
Expression expr;
FieldDirection fd = FieldDirection.None;
if (la.kind == 93 || la.kind == 100) {
if (la.kind == 100) {
lexer.NextToken();
#line 1379 "cs.ATG"
fd = FieldDirection.Ref;
} else {
lexer.NextToken();
#line 1380 "cs.ATG"
fd = FieldDirection.Out;
}
}
Expr(
#line 1382 "cs.ATG"
out expr);
#line 1383 "cs.ATG"
argumentexpr = fd != FieldDirection.None ? argumentexpr = new DirectionExpression(fd, expr) : expr;
}
示例9: VisitDirectionExpression
public override void VisitDirectionExpression(DirectionExpression directionExpression)
{
base.VisitDirectionExpression(directionExpression);
HandlePotentialWrite(directionExpression);
}
示例10: VisitDirectionExpression
public void VisitDirectionExpression(DirectionExpression directionExpression)
{
JsonObject expression = CreateJsonExpression(directionExpression);
switch (directionExpression.FieldDirection)
{
case FieldDirection.Out:
//essential
expression.AddJsonValue("keyword", GetKeyword(DirectionExpression.OutKeywordRole));
break;
case FieldDirection.Ref:
//essential
expression.AddJsonValue("keyword", GetKeyword(DirectionExpression.RefKeywordRole));
break;
default:
throw new NotSupportedException("Invalid value for FieldDirection");
}
expression.AddJsonValue("expression", GenExpression(directionExpression.Expression));
Push(expression);
}
示例11: VisitDirectionExpression
public virtual object VisitDirectionExpression(DirectionExpression directionExpression, object data) {
Debug.Assert((directionExpression != null));
Debug.Assert((directionExpression.Expression != null));
return directionExpression.Expression.AcceptVisitor(this, data);
}
示例12: VisitDirectionExpression
public void VisitDirectionExpression(DirectionExpression node)
{
NotSupported(node);
}
示例13: VisitDirectionExpression
public virtual object VisitDirectionExpression(DirectionExpression directionExpression, object data) {
throw new global::System.NotImplementedException("DirectionExpression");
}
示例14: VisitDirectionExpression
public virtual object VisitDirectionExpression(DirectionExpression directionExpression, object data) {
Debug.Assert((directionExpression != null));
Debug.Assert((directionExpression.Expression != null));
nodeStack.Push(directionExpression.Expression);
directionExpression.Expression.AcceptVisitor(this, data);
directionExpression.Expression = ((Expression)(nodeStack.Pop()));
return null;
}
示例15: VisitDirectionExpression
public virtual void VisitDirectionExpression(DirectionExpression directionExpression)
{
if (this.ThrowException)
{
throw (Exception)this.CreateException(directionExpression);
}
}