本文整理汇总了C#中MethodDeclaration.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDeclaration.AddChild方法的具体用法?C# MethodDeclaration.AddChild怎么用?C# MethodDeclaration.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MethodDeclaration
的用法示例。
在下文中一共展示了MethodDeclaration.AddChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public override void Visit (Method m)
{
MethodDeclaration newMethod = new MethodDeclaration ();
var location = LocationsBag.GetMemberLocation (m);
AddModifiers (newMethod, location);
newMethod.AddChild ((INode)m.TypeName.Accept (this), AbstractNode.Roles.ReturnType);
newMethod.AddChild (new Identifier (m.Name, Convert (m.Location)), AbstractNode.Roles.Identifier);
if (m.MemberName.TypeArguments != null) {
var typeArgLocation = LocationsBag.GetLocations (m.MemberName);
if (typeArgLocation != null)
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
// AddTypeArguments (newMethod, typeArgLocation, m.MemberName.TypeArguments);
if (typeArgLocation != null)
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
AddConstraints (newMethod, m.GenericMethod);
}
if (location != null)
newMethod.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
AddParameter (newMethod, m.ParameterInfo);
if (location != null)
newMethod.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
if (m.Block != null) {
INode bodyBlock = (INode)m.Block.Accept (this);
// if (m.Block is ToplevelBlock) {
// newMethod.AddChild (bodyBlock.FirstChild.NextSibling, MethodDeclaration.Roles.Body);
// } else {
newMethod.AddChild (bodyBlock, MethodDeclaration.Roles.Body);
// }
}
typeStack.Peek ().AddChild (newMethod, TypeDeclaration.Roles.Member);
}
示例2: CSharpGrammar
// IMPORTANT NOTE:
// The grammar consists of a few LALR(1) conflicts. These issues are, however, correctly handled, due to the fact that the grammar
// is defined in a specific order making the already added parser actions have precedence over the other.
//
// Known conflicts that are correctly handled:
//
// - ELSE: Shift/Reduce conflict Dangling ELSE problem. Lots of articles are around on the internet.
// The shift action is taken here.
//
// - CLOSE_PARENS: Shift/Reduce conflict. This is due to the fact that the explicit cast expression is like the parenthesized
// expression. The shift action is taken here.
//
// - STAR: Reduce/Reduce conflict, between VariableType -> TypeNameExpression and PrimaryExpression -> TypeNameExpression,
// due to the fact variable types can have '*', and look therefore like a binary operator expression.
// The first reduce action is taken here.
public CSharpGrammar()
{
// Please let me know if there is a better way of tidying this :s
TokenMapping.Add((int)ERROR, Error);
#region Definitions to use later
var statementList = new GrammarDefinition("StatementList");
var statementListOptional = new GrammarDefinition("StatementListOptional",
rule: null
| statementList);
var blockStatement = new GrammarDefinition("BlockStatement");
var variableDeclarator = new GrammarDefinition("VariableDeclarator");
var variableDeclaratorList = new GrammarDefinition("VariableDeclaratorList");
variableDeclaratorList.Rule = variableDeclarator
| variableDeclaratorList
+ ToElement(COMMA)
+ variableDeclarator;
var variableDeclaration = new GrammarDefinition("VariableDeclaration");
var variableInitializer = new GrammarDefinition("VariableInitializer");
var arrayInitializer = new GrammarDefinition("ArrayInitializer");
var arrayInitializerOptional = new GrammarDefinition("ArrayInitializerOptional",
rule: null | arrayInitializer);
var identifierInsideBody = new GrammarDefinition("IdentifierInsideBody",
rule: ToElement(IDENTIFIER),
createNode: node => ToIdentifier(node.Children[0].Result));
var identifierInsideBodyOptional = new GrammarDefinition("IdentifierInsideBodyOptional",
rule: null | identifierInsideBody);
variableDeclarator.Rule = identifierInsideBody
| identifierInsideBody
+ ToElement(EQUALS)
+ variableInitializer;
variableDeclarator.ComputeResult = node =>
{
var result = new VariableDeclarator((Identifier) node.Children[0].Result);
if (node.Children.Count > 1)
{
result.OperatorToken = (AstToken) node.Children[1].Result;
result.Value = (Expression) node.Children[2].Result;
}
return result;
};
var typeReference = new GrammarDefinition("TypeReference");
var identifierExpression = new GrammarDefinition("IdentifierExpression",
rule: identifierInsideBody,
createNode: node => new IdentifierExpression((Identifier) node.Children[0].Result));
var usingDirectiveListOptional = new GrammarDefinition("UsingDirectiveListOptional");
#endregion
#region Type References
var namespaceOrTypeExpression = new GrammarDefinition("NamespaceOrTypeExpression");
namespaceOrTypeExpression.Rule = identifierExpression |
namespaceOrTypeExpression
+ ToElement(DOT)
+ ToElement(IDENTIFIER);
namespaceOrTypeExpression.ComputeResult = node =>
{
if (node.Children.Count == 1)
return ToTypeReference((IConvertibleToType) node.Children[0].Result);
var result = new MemberTypeReference();
result.Target = (TypeReference) node.Children[0].Result;
result.AddChild(AstNodeTitles.Accessor, node.Children[1].Result);
result.Identifier = ToIdentifier(node.Children[2].Result);
return result;
};
ComputeResultDelegate createPrimitiveTypeExpression = node =>
{
if (node.Children[0].Result is PrimitiveTypeReference)
return node.Children[0].Result;
return new PrimitiveTypeReference
{
Identifier = ToIdentifier(node.Children[0].Result),
//.........这里部分代码省略.........
示例3: Visit
public override void Visit(Method m)
{
var newMethod = new MethodDeclaration();
AddAttributeSection(newMethod, m);
var location = LocationsBag.GetMemberLocation(m);
AddModifiers(newMethod, location);
newMethod.AddChild(ConvertToType(m.TypeExpression), Roles.Type);
AddExplicitInterface(newMethod, m.MethodName);
newMethod.AddChild(Identifier.Create(m.MethodName.Name, Convert(m.Location)), Roles.Identifier);
AddTypeParameters(newMethod, m.MemberName);
if (location != null && location.Count > 0)
newMethod.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LPar), Roles.LPar);
AddParameter(newMethod, m.ParameterInfo);
if (location != null && location.Count > 1)
newMethod.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RPar), Roles.RPar);
AddConstraints(newMethod, m.CurrentTypeParameters);
if (m.Block != null) {
var bodyBlock = (BlockStatement)m.Block.Accept(this);
// if (m.Block is ToplevelBlock) {
// newMethod.AddChild (bodyBlock.FirstChild.NextSibling, Roles.Body);
// } else {
newMethod.AddChild(bodyBlock, Roles.Body);
// }
} else if (location != null) {
if (location.Count < 3) {
// parser error, set end node to max value.
newMethod.AddChild(new ErrorNode(), Roles.Error);
} else {
newMethod.AddChild(new CSharpTokenNode(Convert(location [2]), Roles.Semicolon), Roles.Semicolon);
}
}
typeStack.Peek().AddChild(newMethod, Roles.TypeMemberRole);
}
示例4: Visit
public override void Visit (Method m)
{
MethodDeclaration newMethod = new MethodDeclaration ();
AddAttributeSection (newMethod, m);
var location = LocationsBag.GetMemberLocation (m);
AddModifiers (newMethod, location);
newMethod.AddChild (ConvertToType (m.TypeName), AstNode.Roles.Type);
if (m.MethodName.Left != null) {
newMethod.AddChild (ConvertToType (m.MethodName.Left), MethodDeclaration.PrivateImplementationTypeRole);
var privateImplTypeLoc = LocationsBag.GetLocations (m.MethodName.Left);
if (privateImplTypeLoc != null)
newMethod.AddChild (new CSharpTokenNode (Convert (privateImplTypeLoc[0]), 1), MethodDeclaration.Roles.Dot);
}
newMethod.AddChild (Identifier.Create (m.MethodName.Name, Convert (m.Location)), AstNode.Roles.Identifier);
if (m.MemberName.TypeArguments != null) {
AddTypeParameters (newMethod, m.MemberName.TypeArguments);
}
if (location != null)
newMethod.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
AddParameter (newMethod, m.ParameterInfo);
if (location != null)
newMethod.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
AddConstraints (newMethod, m.GenericMethod);
if (m.Block != null) {
var bodyBlock = (BlockStatement)m.Block.Accept (this);
// if (m.Block is ToplevelBlock) {
// newMethod.AddChild (bodyBlock.FirstChild.NextSibling, MethodDeclaration.Roles.Body);
// } else {
newMethod.AddChild (bodyBlock, MethodDeclaration.Roles.Body);
// }
} else if (location != null) {
if (location.Count < 3) {
// parser error, set end node to max value.
newMethod.AddChild (new ErrorNode (), AstNode.Roles.Error);
} else {
newMethod.AddChild (new CSharpTokenNode (Convert (location[2]), 1), MethodDeclaration.Roles.Semicolon);
}
}
typeStack.Peek ().AddChild (newMethod, TypeDeclaration.MemberRole);
}