本文整理汇总了C#中Statement.GetExpressions方法的典型用法代码示例。如果您正苦于以下问题:C# Statement.GetExpressions方法的具体用法?C# Statement.GetExpressions怎么用?C# Statement.GetExpressions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statement
的用法示例。
在下文中一共展示了Statement.GetExpressions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Translate
public static SUnit Translate(Statement statement)
{
// Return empty SUnit for empty statement.
if(statement.GetExpressions().Count() == 0)
{
return new SUnit(SUnitType.SingleMethodCall, "", "", "", new List<string>(), "void");
}
if(statement is ReturnStatement)
{
//Console.WriteLine("TRANSLATE RETURN");
return TranslateReturn(statement);
}
//
if (statement.GetExpressions().First() is VariableDeclaration)
{
//Console.WriteLine("TRANSLATE ASSIGNMENT");
return TranslateAssignment(statement);
}
else
{
//Console.WriteLine("TRANSLATE METHODCALL");
return TranslateMethodCall(statement);
}
}
示例2: TranslateMethodCall
public static SUnit TranslateMethodCall(Statement statement)
{
var expressions = statement.GetExpressions();
// Give an empty SUnit if statement has no expressions.
if (expressions.Count() == 0)
{
return new SUnit(SUnitType.SingleMethodCall, "", "", "", new List<string>(), "void");
}
// Build a minimal method context and declaration node required by SWUM.
var exp = expressions.First();
string type = exp.ResolveType().ToString();
MethodContext mc = new MethodContext(type);
MethodDeclarationNode mdn = new MethodDeclarationNode(exp.ToString(), mc);
// Apply the SWUM to our statement
var swumRule = SetupBaseVerbRule();
swumRule.InClass(mdn);
swumRule.ConstructSwum(mdn);
// Build and return SUnit from the SWUM
SUnit sunit = new SUnit();
sunit.action = GetAction(mdn);
sunit.theme = GetTheme(mdn);
sunit.args = GetArgs(mdn);
return sunit;
}
示例3: TranslateReturn
public static SUnit TranslateReturn(Statement statement)
{
var action = "return";
var expressions = statement.GetExpressions();
var theme = String.Join(" ", expressions);
return new SUnit(SUnitType.Return, action, theme, "", new List<string>(), "");
}
示例4: TranslateAssignment
private static SUnit TranslateAssignment(Statement statement)
{
// action = "Assign"
// define left-hand-side (lhs)
// theme = right hand side
var fieldRule = SetupFieldRule();
// var equalsSign = statement.GetDescendants<OperatorUse>()
// .Where(o => o.Text.Equals("=")).First();
// var lhs = equalsSign.GetSiblingsBeforeSelf<VariableUse>().First();
var assignExpression = (VariableDeclaration) statement.GetExpressions().First();
var lhs = assignExpression.Name;
var lhsFieldContext = new FieldContext(assignExpression.VariableType.ToString(), false, "");
var lhsDecNode = new FieldDeclarationNode(lhs.ToString(), lhsFieldContext);
fieldRule.InClass(lhsDecNode);
fieldRule.ConstructSwum(lhsDecNode);
var rhsString = "";
var rhsAction = "";
var rhsTheme = "";
Expression rhs = new Expression();
if (assignExpression.Initializer != null)
{
rhs = assignExpression.Initializer;
}
if (rhs is VariableUse)
{
var rhsFieldContext = new FieldContext(rhs.ResolveType().First().ToString(), false, "");
var rhsDecNode = new FieldDeclarationNode(rhs.ToString(), lhsFieldContext);
fieldRule.InClass(rhsDecNode);
fieldRule.ConstructSwum(rhsDecNode);
rhsAction = "Assign";
rhsString = rhsDecNode.ToPlainString();
}
else if (rhs is MethodCall)
{
string type = rhs.ResolveType().ToString();
MethodContext mc = new MethodContext(type);
MethodDeclarationNode mdn = new MethodDeclarationNode(rhs.ToString(), mc);
var swumRule = SetupBaseVerbRule();
swumRule.InClass(mdn);
swumRule.ConstructSwum(mdn);
rhsAction = mdn.Action.ToPlainString();
rhsTheme = mdn.Action.ToPlainString();
rhsString = mdn.ToPlainString();
}
else
{
rhsString = rhs.ToString();
}
var sunit = new SUnit();
sunit.type = SUnitType.Assignment;
sunit.action = rhsString;
//sunit.lhs = lhsDecNode.ToPlainString();
sunit.lhs = lhs.ToString();
sunit.theme = rhsString;
return sunit;
}