📄 cs.atg
字号:
cd.StartLocation = startPos;
cd.EndLocation = t.EndLocation;
.)
( Block<out stmt> | ";" ) (. cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); .)
/*--- conversion operator declaration: */
| (. m.Check(Modifier.Operators);
if (m.isNone) Error("at least one modifier must be set");
bool isImplicit = true;
.)
( "implicit" | "explicit" (. isImplicit = false; .) )
"operator" Type<out type> (. TypeReference operatorType = type; .)
"(" Type<out type> ident (. string varName = t.val; .) ")" ( Block<out stmt> | ";" (. stmt = null; .) )
(.
OperatorDeclarator operatorDeclarator = new OperatorDeclarator(isImplicit ? OperatorType.Implicit : OperatorType.Explicit,
operatorType,
type,
varName);
OperatorDeclaration operatorDeclaration = new OperatorDeclaration(operatorDeclarator, m.Modifier, attributes);
operatorDeclaration.Body = stmt;
compilationUnit.AddChild(operatorDeclaration);
.)
/*--- inner type declaration: */
| TypeDecl<m, attributes>
| Type<out type> (. Point startPos = t.Location; .)
(
/*--- operator declaration: */ (. Token op;
m.Check(Modifier.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 (ParserUtil.IsUnaryOperator(op) && !ParserUtil.IsBinaryOperator(op))
Error("too many operands for unary operator");
.)
| /* empty */ (. if (ParserUtil.IsBinaryOperator(op))
Error("too few operands for binary operator");
.)
)
")" ( Block<out stmt> | ";" )
(.
OperatorDeclarator operatorDeclarator = new OperatorDeclarator(secondType != null ? OperatorType.Binary : OperatorType.Unary,
type,
op.kind,
firstType,
firstName,
secondType,
secondName);
OperatorDeclaration operatorDeclaration = new OperatorDeclaration(operatorDeclarator, m.Modifier, attributes);
operatorDeclaration.Body = stmt;
compilationUnit.AddChild(operatorDeclaration);
.)
/*--- field declaration: */
| IF (IsVarDecl()) (. m.Check(Modifier.Fields);
FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier);
fd.StartLocation = startPos;
.)
VariableDeclarator<variableDeclarators>
{ "," VariableDeclarator<variableDeclarators> }
";" (. fd.EndLocation = t.EndLocation; fd.Fields = variableDeclarators; compilationUnit.AddChild(fd); .)
/*--- unqualified indexer declaration (without interface name): */
| (. m.Check(Modifier.Indexers); .)
"this" "[" FormalParameterList<out p> "]" (. Point 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);
.)
| Qualident<out qualident> (. Point qualIdentEndLocation = t.EndLocation; .)
(
/*--- "not void" method (function) declaration: */
( (. m.Check(Modifier.PropertysEventsMethods); .)
"(" [ FormalParameterList<out p> ] ")" (. MethodDeclaration methodDeclaration = new MethodDeclaration(qualident,
m.Modifier,
type,
p,
attributes);
methodDeclaration.StartLocation = startPos;
methodDeclaration.EndLocation = t.EndLocation;
compilationUnit.AddChild(methodDeclaration);
.)
( Block<out stmt> | ";" ) (. methodDeclaration.Body = (BlockStatement)stmt; .)
/*--- property declaration: */
| "{" (. PropertyDeclaration pDecl = new PropertyDeclaration(qualident, type, m.Modifier, attributes);
pDecl.StartLocation = 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(Modifier.Indexers); .)
"." "this" "[" FormalParameterList<out p> "]" (.
IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes);
indexer.StartLocation = startPos;
indexer.EndLocation = t.EndLocation;
indexer.NamespaceName = qualident;
PropertyGetRegion getRegion;
PropertySetRegion setRegion;
.)
"{" (. Point 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<Modifiers m, ArrayList attributes>
(. Statement stmt = null; .)
=
StructMemberDecl<m, attributes>
| /*--- destructor declaration: */ (. m.Check(Modifier.Destructors); Point startPos = t.Location; .)
"~" ident (. DestructorDeclaration d = new DestructorDeclaration(t.val, attributes);
d.Modifier = m.Modifier;
d.StartLocation = startPos;
.)
"(" ")" (. d.EndLocation = t.EndLocation; .) ( Block<out stmt> | ";" ) (.
d.Body = (BlockStatement)stmt;
compilationUnit.AddChild(d);
.)
.
InterfaceMemberDecl
(.
TypeReference type;
ArrayList p;
AttributeSection section;
Modifier mod = Modifier.None;
ArrayList attributes = new ArrayList();
ArrayList parameters = new ArrayList();
string name;
PropertyGetRegion getBlock;
PropertySetRegion setBlock;
Point startLocation = new Point(-1, -1);
.)
=
{ AttributeSection<out section> (. attributes.Add(section); .)}
[ "new" (. mod = Modifier.New; startLocation = t.Location; .) ]
(
/*--- interface void method (procedure) declaration: */
IF (NotVoidPointer()) "void" (. if (startLocation.X == -1) startLocation = t.Location; .) ident (. name = t.val; .)
"(" [ FormalParameterList<out parameters> ] ")" ";" (. MethodDeclaration md = new MethodDeclaration(name, mod, new TypeReference("void"), parameters, attributes);
md.StartLocation = startLocation;
md.EndLocation = t.EndLocation;
compilationUnit.AddChild(md);
.)
| (
Type<out type> (. if (startLocation.X == -1) startLocation = t.Location; .)
(
ident (. name = t.val; Point qualIdentEndLocation = t.EndLocation; .)
(
/*--- interface "not void" method (function) declaration: */
"(" [ FormalParameterList<out parameters> ] ")" ";" (. MethodDeclaration md = new MethodDeclaration(name, mod, type, parameters, attributes);
md.StartLocation = startLocation;
md.EndLocation = t.EndLocation;
compilationUnit.AddChild(md);
.)
/*--- interface property declaration: */
| (. PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes); compilationUnit.AddChild(pd); .)
"{" (. Point bodyStart = t.Location;.) InterfaceAccessors<out getBlock, out setBlock> "}" (. pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; .)
)
/*--- interface indexer declaration: */
| "this" "[" FormalParameterList<out p> "]" (.Point bracketEndLocation = t.EndLocation; .) (. IndexerDeclaration id = new IndexerDeclaration(type, p, mod, attributes); compilationUnit.AddChild(id); .)
"{" (. Point bodyStart = t.Location;.) InterfaceAccessors<out getBlock, out setBlock> "}" (. id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation;.)
)
/*--- interface event declaration: */
| "event" (. if (startLocation.X == -1) startLocation = t.Location; .) Type<out type> ident (. EventDeclaration ed = new EventDeclaration(type, t.val, mod, attributes);
compilationUnit.AddChild(ed);
.)
";" (. ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; .)
)
)
.
EnumMemberDecl<out FieldDeclaration f>
(.
Expression expr = null;
ArrayList attributes = new ArrayList();
AttributeSection section = null;
VariableDeclaration varDecl = null;
.)
=
{ AttributeSection<out section> (. attributes.Add(section); .) }
ident (. f = new FieldDeclaration(attributes);
varDecl = new VariableDeclaration(t.val);
f.Fields.Add(varDecl);
f.StartLocation = t.Location;
.)
[ "=" Expr<out expr> (. varDecl.Initializer = expr; .) ]
.
AccessorDecls<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
(.
ArrayList attributes = new ArrayList();
AttributeSection section;
getBlock = null;
setBlock = null;
.)
=
{ AttributeSection<out section> (. attributes.Add(section); .) }
(
IF (IdentIsGet())
GetAccessorDecl<out getBlock, attributes>
[ (. attributes = new ArrayList(); .)
{ AttributeSection<out section> (. attributes.Add(section); .) }
SetAccessorDecl<out setBlock, attributes>
]
| IF (IdentIsSet())
SetAccessorDecl<out setBlock, attributes>
[ (. attributes = new ArrayList(); .)
{ AttributeSection<out section> (. attributes.Add(section); .) }
GetAccessorDecl<out getBlock, attributes>
]
| ident (. Error("get or set accessor declaration expected"); .)
)
.
GetAccessorDecl<out PropertyGetRegion getBlock, ArrayList attributes>
(. Statement stmt = null; .)
=
ident /* "get" is not a keyword!? */
(. if (t.val != "get") Error("get expected"); .)
( Block<out stmt> | ";" ) (. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .)
.
SetAccessorDecl<out PropertySetRegion setBlock, ArrayList attributes>
(. Statement stmt = null; .)
=
ident /* "set" is not a keyword!? */
(. if (t.val != "set") Error("set expected"); .)
( Block<out stmt> | ";" ) (. setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); .)
.
EventAccessorDecls<out EventAddRegion addBlock, out EventRemoveRegion removeBlock>
(. AttributeSection section;
ArrayList attributes = new ArrayList();
Statement stmt;
addBlock = null;
removeBlock = null;
.)
=
{ AttributeSection<out section> (. attributes.Add(section); .) }
(
IF (IdentIsAdd()) (. addBlock = new EventAddRegion(attributes); .)
AddAccessorDecl<out stmt> (. attributes = new ArrayList(); addBlock.Block = (BlockStatement)stmt; .)
{ AttributeSection<out section> (. attributes.Add(section); .)}
RemoveAccessorDecl<out stmt> (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; .)
| IF (IdentIsRemove())
RemoveAccessorDecl <out stmt> (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; attributes = new ArrayList(); .)
{ AttributeSection<out section> (. attributes.Add(section); .) }
AddAccessorDecl<out stmt> (. addBlock = new EventAddRegion(attributes); addBlock.Block = (BlockStatement)stmt; .)
| ident (. Error("add or remove accessor declaration expected"); .)
)
.
InterfaceAccessors<out PropertyGetRegion getBlock, out PropertySetRegion setBlock>
(.
AttributeSection section;
ArrayList attributes = new ArrayList();
getBlock = null; setBlock = null;
.)
=
{ AttributeSection<out section> (. attributes.Add(section); .) }
(
IF (IdentIsGet()) ident (. getBlock = new PropertyGetRegion(null, attributes); .)
| IF (IdentIsSet()) ident (. setBlock = new PropertySetRegion(null, attributes); .)
| ident (. Error("set or get expected"); .)
)
";" (. attributes = new ArrayList(); .)
[
{ AttributeSection<out section> (. attributes.Add(section); .) }
(
IF (IdentIsGet()) ident (. if (getBlock != null) Error("get already declared");
else getBlock = new PropertyGetRegion(null, attributes);
.)
| IF (IdentIsSet()) ident (. if (setBlock != null) Error("set already declared");
else setBlock = new PropertySetRegion(null, attributes);
.)
| ident (. Error("set or get expected"); .)
)
";"
]
.
VariableDeclarator<ArrayList fieldDeclaration>
(. Expression expr = null; .)
=
ident (. VariableDeclaration f = new VariableDeclaration(t.val); .)
[ "=" VariableInitializer<out expr> (. f.Initializer = expr; .) ] (. fieldDeclaration.Add(f); .)
.
Block<out Statement stmt> /* not BlockStatement because of EmbeddedStatement */
=
"{" (. BlockStatement blockStmt = new BlockStatement();
blockStmt.StartLocation = t.Location;
compilationUnit.BlockStart(blockStmt);
.)
{ Statement }
"}" (. stmt = blockStmt;
blockStmt.EndLocation = t.EndLocation;
compilationUnit.BlockEnd();
.)
.
AddAccessorDecl<out Statement stmt>
(.stmt = null;.)
=
/* "add" is not a keyword!? */
ident (. if (t.val != "add") Error("add expected"); .)
Block<out stmt>
.
RemoveAccessorDecl<out Statement stmt>
(.stmt = null;.)
=
/* "remove" is not a keyword!? */
ident (. if (t.val != "remove") Error("remove expected"); .)
Block<out stmt>
.
ConstructorInitializer<out ConstructorInitializer ci>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -