Skip to content

Commit bad3b1e

Browse files
committed
Add dbscheme table isParenthesized
1 parent c7f49f2 commit bad3b1e

9 files changed

Lines changed: 2284 additions & 4 deletions

File tree

go/downgrades/b4012cfa6fa7de1878c247155b7dfcd76df2604d/go.dbscheme

Lines changed: 564 additions & 0 deletions
Large diffs are not rendered by default.

go/downgrades/b4012cfa6fa7de1878c247155b7dfcd76df2604d/old.dbscheme

Lines changed: 565 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
description: Remove table recording the number of parentheses around expressions
2+
compatibility: full
3+
isParenthesized.rel: delete

go/extractor/dbscheme/tables.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,12 @@ var ExprsTable = NewTable("exprs",
996996
IntColumn("idx"),
997997
).KeySet("parent", "idx")
998998

999+
// IsParenthesizedTable is the table associating expressions with how many parentheses they originally had
1000+
var IsParenthesizedTable = NewTable("isParenthesized",
1001+
EntityColumn(ExprType, "id").Unique(),
1002+
IntColumn("parentheses"),
1003+
)
1004+
9991005
// LiteralsTable is the table associating literal expression AST nodes with their values
10001006
var LiteralsTable = NewTable("literals",
10011007
EntityColumn(ExprType, "expr").Unique(),

go/extractor/extractor.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,12 +1026,22 @@ func extractExpr(tw *trap.Writer, expr ast.Expr, parent trap.Label, idx int, ski
10261026
}
10271027

10281028
// Skip parenthesised expressions and extract their child directly in their place
1029-
if paren, ok := expr.(*ast.ParenExpr); ok {
1030-
extractExpr(tw, paren.X, parent, idx, skipExtractingValue)
1031-
return
1029+
nParens := 0
1030+
for {
1031+
paren, ok := expr.(*ast.ParenExpr)
1032+
if !ok {
1033+
break
1034+
}
1035+
nParens++
1036+
expr = paren.X
10321037
}
10331038

10341039
lbl := tw.Labeler.LocalID(expr)
1040+
1041+
if nParens > 0 {
1042+
dbscheme.IsParenthesizedTable.Emit(tw, lbl, nParens)
1043+
}
1044+
10351045
extractTypeOf(tw, expr, lbl)
10361046

10371047
var kind int

go/ql/lib/go.dbscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ doc_comments(unique int node: @documentable ref, int comment: @comment_group ref
162162
#keyset[parent, idx]
163163
exprs(unique int id: @expr, int kind: int ref, int parent: @exprparent ref, int idx: int ref);
164164

165+
isParenthesized(unique int id: @expr ref, int parentheses: int ref);
166+
165167
literals(unique int expr: @expr ref, string value: string ref, string raw: string ref);
166168

167169
constvalues(unique int expr: @expr ref, string value: string ref, string exact: string ref);
@@ -561,4 +563,3 @@ case @error.kind of
561563
| 1 = @listerror
562564
| 2 = @parseerror
563565
| 3 = @typeerror;
564-

0 commit comments

Comments
 (0)