Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 5db4160

Browse files
kuba--Denys Smirnov
authored andcommitted
Serialize comments for preproc (drop include comments for semantic). (#63)
* Serialize comments for preproc (drop them in sem). Signed-off-by: kuba-- <[email protected]>
1 parent 1c06489 commit 5db4160

22 files changed

+3031
-19
lines changed

driver/normalizer/normalizer.go

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,40 @@ var _ Op = opJoinNamesArray{}
131131

132132
var Normalizers = []Mapping{
133133

134+
// After adding "LeadingComments" to pre-proc statements in native ast,
135+
// we must drop them in the semantic representation.
134136
MapSemantic("ASTInclusionStatement", uast.InlineImport{}, MapObj(
135-
CasesObj("isSystemCase", Obj{},
136-
Objs{
137-
{
138-
"Name": Var("path"),
139-
"IsSystem": Bool(true),
140-
// Always empty on current tests, this should detect other cases
141-
"Path": String(""),
142-
// FIXME(juanjux): save this once we've a way
143-
"Resolved": Any(),
144-
},
145-
{
146-
"Name": StringConv(Var("path"), prependDotSlash, removeDotSlash),
147-
"IsSystem": Bool(false),
148-
"Path": String(""),
149-
// FIXME(juanjux): save this once we've a way
150-
"Resolved": Any(),
151-
},
137+
Fields{
138+
{Name: "Name", Op: Var("path")},
139+
{Name: "IsSystem", Op: Bool(true)},
140+
// Always empty on current tests, this should detect other cases
141+
{Name: "Path", Op: String("")},
142+
// FIXME(juanjux): save this once we've a way
143+
{Name: "Resolved", Op: Any()},
144+
{Name: "LeadingComments", Drop: true, Op: Any()},
145+
{Name: "TrailingComments", Drop: true, Op: Any()},
146+
},
147+
Obj{
148+
"Path": UASTType(uast.String{}, Obj{
149+
"Value": Var("path"),
150+
"Format": String(""),
152151
}),
152+
"All": Bool(true),
153+
"Names": Is(nil),
154+
},
155+
)),
156+
157+
MapSemantic("ASTInclusionStatement", uast.InlineImport{}, MapObj(
158+
Fields{
159+
{Name: "Name", Op: StringConv(Var("path"), prependDotSlash, removeDotSlash)},
160+
{Name: "IsSystem", Op: Bool(false)},
161+
// Always empty on current tests, this should detect other cases
162+
{Name: "Path", Op: String("")},
163+
// FIXME(juanjux): save this once we've a way
164+
{Name: "Resolved", Op: Any()},
165+
{Name: "LeadingComments", Drop: true, Op: Any()},
166+
{Name: "TrailingComments", Drop: true, Op: Any()},
167+
},
153168
Obj{
154169
"Path": UASTType(uast.String{}, Obj{
155170
"Value": Var("path"),

fixtures/bench_server.cpp.native

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73776,6 +73776,15 @@
7377673776
{
7377773777
IASTClass: "ASTInclusionStatement",
7377873778
IsSystem: true,
73779+
LeadingComments: [
73780+
{
73781+
Comment: "/*\n * Copyright 2015 gRPC authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */",
73782+
IASTClass: "Comment",
73783+
IsBlockComment: true,
73784+
LocOffsetEnd: 599,
73785+
LocOffsetStart: 0,
73786+
},
73787+
],
7377973788
LocOffsetEnd: 627,
7378073789
LocOffsetStart: 601,
7378173790
Name: "grpcpp/server.h",
@@ -74037,6 +74046,43 @@
7403774046
{
7403874047
IASTClass: "ASTMacroDefinition",
7403974048
IsActive: true,
74049+
LeadingComments: [
74050+
{
74051+
Comment: "// The default value for maximum number of threads that can be created in the",
74052+
IASTClass: "Comment",
74053+
IsBlockComment: false,
74054+
LocOffsetEnd: 1888,
74055+
LocOffsetStart: 1811,
74056+
},
74057+
{
74058+
Comment: "// sync server. This value of INT_MAX is chosen to match the default behavior if",
74059+
IASTClass: "Comment",
74060+
IsBlockComment: false,
74061+
LocOffsetEnd: 1969,
74062+
LocOffsetStart: 1889,
74063+
},
74064+
{
74065+
Comment: "// no ResourceQuota is set. To modify the max number of threads in a sync",
74066+
IASTClass: "Comment",
74067+
IsBlockComment: false,
74068+
LocOffsetEnd: 2043,
74069+
LocOffsetStart: 1970,
74070+
},
74071+
{
74072+
Comment: "// server, pass a custom ResourceQuota object (with the desired number of",
74073+
IASTClass: "Comment",
74074+
IsBlockComment: false,
74075+
LocOffsetEnd: 2118,
74076+
LocOffsetStart: 2044,
74077+
},
74078+
{
74079+
Comment: "// max-threads set) to the server builder.",
74080+
IASTClass: "Comment",
74081+
IsBlockComment: false,
74082+
LocOffsetEnd: 2161,
74083+
LocOffsetStart: 2119,
74084+
},
74085+
],
7404074086
LocOffsetEnd: 2209,
7404174087
LocOffsetStart: 2162,
7404274088
MacroBodyText: "INT_MAX",
@@ -74057,6 +74103,15 @@
7405774103
{
7405874104
IASTClass: "ASTMacroDefinition",
7405974105
IsActive: true,
74106+
LeadingComments: [
74107+
{
74108+
Comment: "// How many callback requests of each method should we pre-register at start",
74109+
IASTClass: "Comment",
74110+
IsBlockComment: false,
74111+
LocOffsetEnd: 2287,
74112+
LocOffsetStart: 2211,
74113+
},
74114+
],
7406074115
LocOffsetEnd: 2331,
7406174116
LocOffsetStart: 2288,
7406274117
MacroBodyText: "32",

fixtures/bench_server.cpp.sem.uast

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123253,6 +123253,103 @@
123253123253
},
123254123254
},
123255123255
IsActive: true,
123256+
LeadingComments: [
123257+
{ '@type': "uast:Comment",
123258+
'@pos': { '@type': "uast:Positions",
123259+
start: { '@type': "uast:Position",
123260+
offset: 1811,
123261+
line: 54,
123262+
col: 1,
123263+
},
123264+
end: { '@type': "uast:Position",
123265+
offset: 1888,
123266+
line: 54,
123267+
col: 78,
123268+
},
123269+
},
123270+
Block: false,
123271+
Prefix: " ",
123272+
Suffix: "",
123273+
Tab: "",
123274+
Text: "The default value for maximum number of threads that can be created in the",
123275+
},
123276+
{ '@type': "uast:Comment",
123277+
'@pos': { '@type': "uast:Positions",
123278+
start: { '@type': "uast:Position",
123279+
offset: 1889,
123280+
line: 55,
123281+
col: 1,
123282+
},
123283+
end: { '@type': "uast:Position",
123284+
offset: 1969,
123285+
line: 55,
123286+
col: 81,
123287+
},
123288+
},
123289+
Block: false,
123290+
Prefix: " ",
123291+
Suffix: "",
123292+
Tab: "",
123293+
Text: "sync server. This value of INT_MAX is chosen to match the default behavior if",
123294+
},
123295+
{ '@type': "uast:Comment",
123296+
'@pos': { '@type': "uast:Positions",
123297+
start: { '@type': "uast:Position",
123298+
offset: 1970,
123299+
line: 56,
123300+
col: 1,
123301+
},
123302+
end: { '@type': "uast:Position",
123303+
offset: 2043,
123304+
line: 56,
123305+
col: 74,
123306+
},
123307+
},
123308+
Block: false,
123309+
Prefix: " ",
123310+
Suffix: "",
123311+
Tab: "",
123312+
Text: "no ResourceQuota is set. To modify the max number of threads in a sync",
123313+
},
123314+
{ '@type': "uast:Comment",
123315+
'@pos': { '@type': "uast:Positions",
123316+
start: { '@type': "uast:Position",
123317+
offset: 2044,
123318+
line: 57,
123319+
col: 1,
123320+
},
123321+
end: { '@type': "uast:Position",
123322+
offset: 2118,
123323+
line: 57,
123324+
col: 75,
123325+
},
123326+
},
123327+
Block: false,
123328+
Prefix: " ",
123329+
Suffix: "",
123330+
Tab: "",
123331+
Text: "server, pass a custom ResourceQuota object (with the desired number of",
123332+
},
123333+
{ '@type': "uast:Comment",
123334+
'@pos': { '@type': "uast:Positions",
123335+
start: { '@type': "uast:Position",
123336+
offset: 2119,
123337+
line: 58,
123338+
col: 1,
123339+
},
123340+
end: { '@type': "uast:Position",
123341+
offset: 2161,
123342+
line: 58,
123343+
col: 43,
123344+
},
123345+
},
123346+
Block: false,
123347+
Prefix: " ",
123348+
Suffix: "",
123349+
Tab: "",
123350+
Text: "max-threads set) to the server builder.",
123351+
},
123352+
],
123256123353
MacroBodyText: "INT_MAX",
123257123354
Name: "DEFAULT_MAX_SYNC_SERVER_THREADS",
123258123355
'Prop_Expansions': [
@@ -123303,6 +123400,27 @@
123303123400
},
123304123401
},
123305123402
IsActive: true,
123403+
LeadingComments: [
123404+
{ '@type': "uast:Comment",
123405+
'@pos': { '@type': "uast:Positions",
123406+
start: { '@type': "uast:Position",
123407+
offset: 2211,
123408+
line: 61,
123409+
col: 1,
123410+
},
123411+
end: { '@type': "uast:Position",
123412+
offset: 2287,
123413+
line: 61,
123414+
col: 77,
123415+
},
123416+
},
123417+
Block: false,
123418+
Prefix: " ",
123419+
Suffix: "",
123420+
Tab: "",
123421+
Text: "How many callback requests of each method should we pre-register at start",
123422+
},
123423+
],
123306123424
MacroBodyText: "32",
123307123425
Name: "DEFAULT_CALLBACK_REQS_PER_METHOD",
123308123426
'Prop_Expansions': [

0 commit comments

Comments
 (0)