📄 cs.atg
字号:
IntegralType<out string name> (. name = ""; .)
=
"sbyte" (. name = "sbyte"; .)
| "byte" (. name = "byte"; .)
| "short" (. name = "short"; .)
| "ushort" (. name = "ushort"; .)
| "int" (. name = "int"; .)
| "uint" (. name = "uint"; .)
| "long" (. name = "long"; .)
| "ulong" (. name = "ulong"; .)
| "char" (. name = "char"; .)
.
MemberModifiers<ModifierList m>
=
{
"abstract" (. m.Add(Modifiers.Abstract, t.Location); .)
| "extern" (. m.Add(Modifiers.Extern, t.Location); .)
| "internal" (. m.Add(Modifiers.Internal, t.Location); .)
| "new" (. m.Add(Modifiers.New, t.Location); .)
| "override" (. m.Add(Modifiers.Override, t.Location); .)
| "private" (. m.Add(Modifiers.Private, t.Location); .)
| "protected" (. m.Add(Modifiers.Protected, t.Location); .)
| "public" (. m.Add(Modifiers.Public, t.Location); .)
| "readonly" (. m.Add(Modifiers.ReadOnly, t.Location); .)
| "sealed" (. m.Add(Modifiers.Sealed, t.Location); .)
| "static" (. m.Add(Modifiers.Static, t.Location); .)
| "fixed" (. m.Add(Modifiers.Fixed, t.Location); .)
| "unsafe" (. m.Add(Modifiers.Unsafe, t.Location); .)
| "virtual" (. m.Add(Modifiers.Virtual, t.Location); .)
| "volatile" (. m.Add(Modifiers.Volatile, t.Location); .)
| ( IF(la.kind == Tokens.Identifier && la.val == "partial")
ident (. m.Add(Modifiers.Partial, t.Location); .)
)
}
.
StructMemberDecl<ModifierList m, List<AttributeSection> attributes>
(.
string qualident = null;
TypeReference type;
Expression expr;
List<ParameterDeclarationExpression> p = new List<ParameterDeclarationExpression>();
Statement stmt = null;
List<VariableDeclaration> variableDeclarators = new List<VariableDeclaration>();
List<TemplateDefinition> templates = new List<TemplateDefinition>();
TypeReference explicitInterface = null;
.)
=
/*--- constant declaration: */ (. m.Check(Modifiers.Constants); .)
"const" (.Location startPos = t.Location; .)
Type<out type> ident (. FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifiers.Const);
fd.StartLocation = m.GetDeclarationLocation(startPos);
VariableDeclaration f = new VariableDeclaration(t.val);
fd.Fields.Add(f);
.)
"=" Expr<out expr> (. f.Initializer = expr; .)
{ "," ident (. f = new VariableDeclaration(t.val);
fd.Fields.Add(f);
.)
"=" Expr<out expr> (. f.Initializer = expr; .)
} ";" (. fd.EndLocation = t.EndLocation; compilationUnit.AddChild(fd); .)
| /*--- void method (procedure) declaration: */
IF (NotVoidPointer()) (. m.Check(Modifiers.PropertysEventsMethods); .)
"void" (. Location startPos = t.Location; .)
( IF (IsExplicitInterfaceImplementation())
TypeName<out explicitInterface, false>
(.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface);
} .)
| ident (. qualident = t.val; .)
)
/* .NET 2.0 */
[ TypeParameterList<templates> ]
"("
[ FormalParameterList<p> ] ")"
(. MethodDeclaration methodDeclaration = new MethodDeclaration(qualident,
m.Modifier,
new TypeReference("void"),
p,
attributes);
methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
methodDeclaration.EndLocation = t.EndLocation;
methodDeclaration.Templates = templates;
if (explicitInterface != null)
methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
compilationUnit.AddChild(methodDeclaration);
compilationUnit.BlockStart(methodDeclaration);
.)
/* .NET 2.0 */
{ IF (IdentIsWhere()) TypeParameterConstraintsClause<templates> }
( Block<out stmt> | ";" ) (. compilationUnit.BlockEnd();
methodDeclaration.Body = (BlockStatement)stmt;
.)
| /*--- event declaration: */ (. m.Check(Modifiers.PropertysEventsMethods); .)
"event" (. EventDeclaration eventDecl = new EventDeclaration(null, null, m.Modifier, attributes, null);
eventDecl.StartLocation = t.Location;
compilationUnit.AddChild(eventDecl);
compilationUnit.BlockStart(eventDecl);
EventAddRegion addBlock = null;
EventRemoveRegion removeBlock = null;
.)
Type<out type> (. eventDecl.TypeReference = type; .)
( IF (IsExplicitInterfaceImplementation())
TypeName<out explicitInterface, false>
(. qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); .)
(. eventDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); .)
| ident (. qualident = t.val; .)
)
(. eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; .)
[ "=" Expr<out expr> (. eventDecl.Initializer = expr; .) ]
[ "{" (. eventDecl.BodyStart = t.Location; .)
EventAccessorDecls<out addBlock, out removeBlock>
"}" (. eventDecl.BodyEnd = t.EndLocation; .)
]
[ ";" ]
(. compilationUnit.BlockEnd();
eventDecl.AddRegion = addBlock;
eventDecl.RemoveRegion = removeBlock;
.)
| /*--- constructor or static contructor declaration: */
IF (IdentAndLPar()) (. m.Check(Modifiers.Constructors | Modifiers.StaticConstructors); .)
ident (. string name = t.val; Location startPos = t.Location; .) "(" [ (. m.Check(Modifiers.Constructors); .)
FormalParameterList<p>
]
")" (.ConstructorInitializer init = null; .)
[ (. m.Check(Modifiers.Constructors); .)
ConstructorInitializer<out init>
] (.
ConstructorDeclaration cd = new ConstructorDeclaration(name, m.Modifier, p, init, attributes);
cd.StartLocation = startPos;
cd.EndLocation = t.EndLocation;
.)
( Block<out stmt> | ";" ) (. cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); .)
| /*--- conversion operator declaration: */ (. m.Check(Modifiers.Operators);
if (m.isNone) Error("at least one modifier must be set");
bool isImplicit = true;
Location startPos = Location.Empty;
.)
( "implicit" (. startPos = t.Location; .) | "explicit" (. isImplicit = false; startPos = t.Location; .) )
"operator" Type<out type> (. TypeReference operatorType = type; .)
"(" Type<out type> ident (. string varName = t.val; .) ")"
(. Location endPos = t.Location; .)
( Block<out stmt> | ";" (. stmt = null; .) )
(.
List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
parameters.Add(new ParameterDeclarationExpression(type, varName));
OperatorDeclaration operatorDeclaration = new OperatorDeclaration(m.Modifier,
attributes,
parameters,
operatorType,
isImplicit ? ConversionType.Implicit : ConversionType.Explicit
);
operatorDeclaration.Body = (BlockStatement)stmt;
operatorDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
operatorDeclaration.EndLocation = endPos;
compilationUnit.AddChild(operatorDeclaration);
.)
| /*--- inner type declaration: */
TypeDecl<m, attributes>
| Type<out type> (. Location startPos = t.Location; .)
(
/*--- operator declaration: */ (. OverloadableOperatorType op;
m.Check(Modifiers.Operators);
if (m.isNone) Error("at least one modifier must be set");
.)
"operator" OverloadableOperator<out op> (. TypeReference firstType, secondType = null; string secondName = null; .)
"(" Type<out firstType> ident (. string firstName = t.val; .)
( "," Type<out secondType> ident (. secondName = t.val; .) /* (. if (Tokens.OverloadableUnaryOp[op.kind] && !Tokens.OverloadableBinaryOp[op.kind])
Error("too many operands for unary operator");
.)*/
| /* empty */ /*(. if (Tokens.OverloadableBinaryOp[op.kind]){
Error("too few operands for binary operator");
}
.)*/
)
(. Location endPos = t.Location; .)
")" ( Block<out stmt> | ";" )
(.
List<ParameterDeclarationExpression> parameters = new List<ParameterDeclarationExpression>();
parameters.Add(new ParameterDeclarationExpression(firstType, firstName));
if (secondType != null) {
parameters.Add(new ParameterDeclarationExpression(secondType, secondName));
}
OperatorDeclaration operatorDeclaration = new OperatorDeclaration(m.Modifier,
attributes,
parameters,
type,
op);
operatorDeclaration.Body = (BlockStatement)stmt;
operatorDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
operatorDeclaration.EndLocation = endPos;
compilationUnit.AddChild(operatorDeclaration);
.)
/*--- field declaration: */
| IF (IsVarDecl())
(. m.Check(Modifiers.Fields);
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
fd.StartLocation = m.GetDeclarationLocation(startPos);
.)
( IF (m.Contains(Modifiers.Fixed))
VariableDeclarator<variableDeclarators>
"["
Expr<out expr> (. if (variableDeclarators.Count > 0)
variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; .)
"]"
{ ","
VariableDeclarator<variableDeclarators>
"["
Expr<out expr> (. if (variableDeclarators.Count > 0)
variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; .)
"]"
}
| /* non-fixed field */
VariableDeclarator<variableDeclarators>
{ "," VariableDeclarator<variableDeclarators> }
)
";" (. fd.EndLocation = t.EndLocation; fd.Fields = variableDeclarators; compilationUnit.AddChild(fd); .)
/*--- unqualified indexer declaration (without interface name): */
| (. m.Check(Modifiers.Indexers); .)
"this" "[" FormalParameterList<p> "]" (. Location endLocation = t.EndLocation; .) "{" (.
IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
indexer.StartLocation = startPos;
indexer.EndLocation = endLocation;
indexer.BodyStart = t.Location;
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
.)
AccessorDecls<out getRegion, out setRegion> "}" (.
indexer.BodyEnd = t.EndLocation;
indexer.GetRegion = getRegion;
indexer.SetRegion = setRegion;
compilationUnit.AddChild(indexer);
.)
| IF (la.kind == Tokens.Identifier)
( IF (IsExplicitInterfaceImplementation())
TypeName<out explicitInterface, false>
(.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) {
qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface);
} .)
| ident (. qualident = t.val; .)
)
(. Location qualIdentEndLocation = t.EndLocation; .)
(
/*--- "not void" method (function) declaration: */
( (. m.Check(Modifiers.PropertysEventsMethods); .)
/* .NET 2.0 */
[ TypeParameterList<templates> ]
"(" [ FormalParameterList<p> ] ")" (.
MethodDeclaration methodDeclaration = new MethodDeclaration(qualident,
m.Modifier,
type,
p,
attributes);
if (explicitInterface != null)
methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
methodDeclaration.EndLocation = t.EndLocation;
methodDeclaration.Templates = templates;
compilationUnit.AddChild(methodDeclaration);
.)
{ IF (IdentIsWhere()) TypeParameterConstraintsClause<templates> }
( Block<out stmt> | ";" ) (. methodDeclaration.Body = (BlockStatement)stmt; .)
/*--- property declaration: */
| "{" (. PropertyDeclaration pDecl = new PropertyDeclaration(qualident, type, m.Modifier, attributes);
if (explicitInterface != null)
pDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident));
pDecl.StartLocation = m.GetDeclarationLocation(startPos);
pDecl.EndLocation = qualIdentEndLocation;
pDecl.BodyStart = t.Location;
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
.)
AccessorDecls<out getRegion, out setRegion>
"}" (.
pDecl.GetRegion = getRegion;
pDecl.SetRegion = setRegion;
pDecl.BodyEnd = t.EndLocation;
compilationUnit.AddChild(pDecl);
.)
)
/*--- qualified indexer declaration (with interface name): */
| (. m.Check(Modifiers.Indexers); .)
"." "this" "[" FormalParameterList<p> "]" (.
IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
indexer.StartLocation = m.GetDeclarationLocation(startPos);
indexer.EndLocation = t.EndLocation;
if (explicitInterface != null)
indexer.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, "this"));
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
.)
"{" (. Location bodyStart = t.Location; .)
AccessorDecls<out getRegion, out setRegion>
"}" (. indexer.BodyStart = bodyStart;
indexer.BodyEnd = t.EndLocation;
indexer.GetRegion = getRegion;
indexer.SetRegion = setRegion;
compilationUnit.AddChild(indexer);
.)
)
)
.
ClassMemberDecl<ModifierList m, List<AttributeSection> attributes>
(. Statement stmt = null; .)
=
StructMemberDecl<m, attributes>
| /*--- destructor declaration: */ (. m.Check(Modifiers.Destructors); Location startPos = t.Location; .)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -