Skip to content

Commit b809a64

Browse files
Denys Smirnovdennwc
authored andcommitted
fix identifier conversion
Signed-off-by: Denys Smirnov <denys@sourced.tech>
1 parent 287e55f commit b809a64

82 files changed

Lines changed: 3991 additions & 43252 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

driver/fixtures/fixtures_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var Suite = &fixtures.Suite{
2929
"ConstructorDeclaration",
3030
"DestructorDeclaration",
3131
"FalseLiteralExpression",
32-
//"IdentifierName", // FIXME
32+
"IdentifierName",
3333
"IdentifierToken",
3434
"MethodDeclaration",
3535
"MultiLineCommentTrivia",

driver/normalizer/normalizer.go

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ var Preprocessors = []Mapping{
282282
// Normalizers is the main block of normalization rules to convert native AST to semantic UAST.
283283
var Normalizers = []Mapping{
284284

285-
// remove empty identifiers
285+
// remove empty identifier tokens
286286
Map(
287287
Check(
288288
Has{
@@ -313,6 +313,43 @@ var Normalizers = []Mapping{
313313
},
314314
)),
315315

316+
// remove empty identifiers
317+
Map(
318+
Check(
319+
Has{
320+
uast.KeyType: String("IdentifierName"),
321+
"Identifier": Is(nil),
322+
},
323+
Any(),
324+
),
325+
Is(nil),
326+
),
327+
328+
Map(
329+
Obj{
330+
uast.KeyType: String("IdentifierName"),
331+
uast.KeyPos: Any(), // TODO(dennwc): assert that it's the same
332+
333+
"Identifier": Var("ident"),
334+
335+
"Arity": Int(0),
336+
337+
// TODO(dennwc): these assertions might not be valid for all cases
338+
// and will break this annotation, but at least it will
339+
// help us detect the case when it's not valid
340+
"IsMissing": Bool(false),
341+
"IsStructuredTrivia": Bool(false),
342+
343+
// TODO(dennwc): this is true for Value == "unmanaged" and it looks
344+
// more like a keyword, probably unrecognized one
345+
"IsUnmanaged": Any(),
346+
347+
// TODO(dennwc): might be useful later; drop it for now
348+
"IsVar": Any(),
349+
},
350+
Var("ident"),
351+
),
352+
316353
// Special: is a keyword, but used as an identifier (Parameter name)
317354
MapSemantic("ArgListKeyword", uast.Identifier{}, MapObj(
318355
Obj{
@@ -483,30 +520,12 @@ var Normalizers = []Mapping{
483520
CasesObj("case",
484521
// common
485522
Obj{
486-
"Right": Obj{
487-
uast.KeyType: String("IdentifierName"),
488-
uast.KeyPos: Any(),
489-
"Arity": Int(0),
490-
"IsMissing": Bool(false),
491-
"IsStructuredTrivia": Bool(false),
492-
"IsUnmanaged": Any(),
493-
"IsVar": Any(),
494-
"Identifier": Var("right"),
495-
},
523+
"Right": Var("right"),
496524
},
497525
Objs{
498526
// the last name = identifier
499527
{
500-
"Left": Obj{
501-
uast.KeyType: String("IdentifierName"),
502-
uast.KeyPos: Any(),
503-
"Arity": Int(0),
504-
"IsMissing": Bool(false),
505-
"IsStructuredTrivia": Bool(false),
506-
"IsUnmanaged": Any(),
507-
"IsVar": Any(), // TODO: mmmm...
508-
"Identifier": Var("left"),
509-
},
528+
"Left": Check(HasType(uast.Identifier{}), Var("left")),
510529
},
511530
// linked list
512531
{

fixtures/Program.cs.sem.uast

Lines changed: 178 additions & 1838 deletions
Large diffs are not rendered by default.

fixtures/_integration.cs.sem.uast

Lines changed: 16 additions & 176 deletions
Large diffs are not rendered by default.

fixtures/accesor_list.cs.sem.uast

Lines changed: 18 additions & 198 deletions
Large diffs are not rendered by default.

fixtures/accumulator_factory.cs.sem.uast

Lines changed: 26 additions & 286 deletions
Large diffs are not rendered by default.

fixtures/add_accesor.cs.sem.uast

Lines changed: 20 additions & 220 deletions
Large diffs are not rendered by default.

fixtures/alias.cs.sem.uast

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
},
5656
All: true,
5757
Names: ~,
58-
Path: { '@type': "csharp:IdentifierName",
59-
'@role': [Identifier],
58+
Path: { '@type': "uast:Identifier",
6059
'@pos': { '@type': "uast:Positions",
6160
start: { '@type': "uast:Position",
6261
offset: 12,
@@ -69,26 +68,7 @@
6968
col: 16,
7069
},
7170
},
72-
Arity: 0,
73-
Identifier: { '@type': "uast:Identifier",
74-
'@pos': { '@type': "uast:Positions",
75-
start: { '@type': "uast:Position",
76-
offset: 12,
77-
line: 1,
78-
col: 13,
79-
},
80-
end: { '@type': "uast:Position",
81-
offset: 15,
82-
line: 1,
83-
col: 16,
84-
},
85-
},
86-
Name: "Bar",
87-
},
88-
IsMissing: false,
89-
IsStructuredTrivia: false,
90-
IsUnmanaged: false,
91-
IsVar: false,
71+
Name: "Bar",
9272
},
9373
Target: ~,
9474
},

fixtures/anonymous_object.cs.sem.uast

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@
191191
},
192192
IsMissing: false,
193193
IsStructuredTrivia: false,
194-
Type: { '@type': "csharp:IdentifierName",
195-
'@role': [Identifier],
194+
Type: { '@type': "uast:Identifier",
196195
'@pos': { '@type': "uast:Positions",
197196
start: { '@type': "uast:Position",
198197
offset: 62,
@@ -205,26 +204,7 @@
205204
col: 12,
206205
},
207206
},
208-
Arity: 0,
209-
Identifier: { '@type': "uast:Identifier",
210-
'@pos': { '@type': "uast:Positions",
211-
start: { '@type': "uast:Position",
212-
offset: 62,
213-
line: 3,
214-
col: 9,
215-
},
216-
end: { '@type': "uast:Position",
217-
offset: 65,
218-
line: 3,
219-
col: 12,
220-
},
221-
},
222-
Name: "var",
223-
},
224-
IsMissing: false,
225-
IsStructuredTrivia: false,
226-
IsUnmanaged: false,
227-
IsVar: true,
207+
Name: "var",
228208
},
229209
Variables: [
230210
{ '@type': "csharp:VariableDeclarator",
@@ -421,8 +401,7 @@
421401
},
422402
IsMissing: false,
423403
IsStructuredTrivia: false,
424-
Name: { '@type': "csharp:IdentifierName",
425-
'@role': [Identifier],
404+
Name: { '@type': "uast:Identifier",
426405
'@pos': { '@type': "uast:Positions",
427406
start: { '@type': "uast:Position",
428407
offset: 76,
@@ -435,26 +414,7 @@
435414
col: 29,
436415
},
437416
},
438-
Arity: 0,
439-
Identifier: { '@type': "uast:Identifier",
440-
'@pos': { '@type': "uast:Positions",
441-
start: { '@type': "uast:Position",
442-
offset: 76,
443-
line: 3,
444-
col: 23,
445-
},
446-
end: { '@type': "uast:Position",
447-
offset: 82,
448-
line: 3,
449-
col: 29,
450-
},
451-
},
452-
Name: "Amount",
453-
},
454-
IsMissing: false,
455-
IsStructuredTrivia: false,
456-
IsUnmanaged: false,
457-
IsVar: false,
417+
Name: "Amount",
458418
},
459419
},
460420
},
@@ -527,8 +487,7 @@
527487
},
528488
IsMissing: false,
529489
IsStructuredTrivia: false,
530-
Name: { '@type': "csharp:IdentifierName",
531-
'@role': [Identifier],
490+
Name: { '@type': "uast:Identifier",
532491
'@pos': { '@type': "uast:Positions",
533492
start: { '@type': "uast:Position",
534493
offset: 90,
@@ -541,26 +500,7 @@
541500
col: 44,
542501
},
543502
},
544-
Arity: 0,
545-
Identifier: { '@type': "uast:Identifier",
546-
'@pos': { '@type': "uast:Positions",
547-
start: { '@type': "uast:Position",
548-
offset: 90,
549-
line: 3,
550-
col: 37,
551-
},
552-
end: { '@type': "uast:Position",
553-
offset: 97,
554-
line: 3,
555-
col: 44,
556-
},
557-
},
558-
Name: "Message",
559-
},
560-
IsMissing: false,
561-
IsStructuredTrivia: false,
562-
IsUnmanaged: false,
563-
IsVar: false,
503+
Name: "Message",
564504
},
565505
},
566506
},

0 commit comments

Comments
 (0)