Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 32510eb

Browse files
author
Sauyon Lee
authored
Merge pull request #255 from max-schaefer/alias-types
Improve modelling of alias declarations
2 parents 9347413 + 4eac5a1 commit 32510eb

14 files changed

Lines changed: 1534 additions & 579 deletions

File tree

extractor/cli/go-gen-dbscheme/go-gen-dbscheme.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ func main() {
2222

2323
f, err := os.Create(out)
2424
if err != nil {
25-
fmt.Fprintf(os.Stderr, "Unable to open file %s for writing.", out)
25+
fmt.Fprintf(os.Stderr, "Unable to open file %s for writing.\n", out)
2626
os.Exit(1)
2727
}
2828
dbscheme.PrintDbScheme(f)
2929
f.Close()
30-
fmt.Printf("Dbscheme written to file %s.", out)
30+
fmt.Printf("Dbscheme written to file %s.\n", out)
3131
}

extractor/dbscheme/tables.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,13 @@ var ImportSpecType = SpecKind.NewBranch("@importspec")
441441
var ValueSpecType = SpecKind.NewBranch("@valuespec")
442442

443443
// TypeSpecType is the type of type declaration specification nodes
444-
var TypeSpecType = SpecKind.NewBranch("@typespec")
444+
var TypeSpecType = NewUnionType("@typespec")
445+
446+
// TypeDefSpecType is the type of type declaration specification nodes corresponding to type definitions
447+
var TypeDefSpecType = SpecKind.NewBranch("@typedefspec", TypeSpecType)
448+
449+
// AliasSpecType is the type of type declaration specification nodes corresponding to alias declarations
450+
var AliasSpecType = SpecKind.NewBranch("@aliasspec", TypeSpecType)
445451

446452
// ObjectType is the type of objects (that is, declared entities)
447453
var ObjectType = NewPrimaryKeyType("@object")

extractor/extractor.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,11 @@ func extractSpec(tw *trap.Writer, spec ast.Spec, parent trap.Label, idx int) {
11491149
if spec == nil {
11501150
return
11511151
}
1152-
kind = dbscheme.TypeSpecType.Index()
1152+
if spec.Assign.IsValid() {
1153+
kind = dbscheme.AliasSpecType.Index()
1154+
} else {
1155+
kind = dbscheme.TypeDefSpecType.Index()
1156+
}
11531157
extractExpr(tw, spec.Name, lbl, 0)
11541158
extractExpr(tw, spec.Type, lbl, 1)
11551159
extractDoc(tw, spec.Doc, lbl)

ql/src/go.dbscheme

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ case @decl.kind of
317317
case @spec.kind of
318318
0 = @importspec
319319
| 1 = @valuespec
320-
| 2 = @typespec;
320+
| 2 = @typedefspec
321+
| 3 = @aliasspec;
322+
323+
@typespec = @typedefspec | @aliasspec;
321324

322325
case @object.kind of
323326
0 = @pkgobject

0 commit comments

Comments
 (0)