File tree 4 files changed +26
-12
lines changed
4 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -113,15 +113,9 @@ or to fix crashes with the symbol handling`,
113
113
continue
114
114
}
115
115
116
- symbols := symbol .ParseSymbols (file .Ast , file .Source )
117
-
118
- files [index ].Symbols = symbols
119
-
120
- if _ , exist := symbol .GlobalScope .Packages [symbols .Package ]; ! exist {
121
- symbol .GlobalScope .Packages [symbols .Package ] = & symbol.PackageScope {Files : make (map [string ]* symbol.FileScope )}
122
- }
123
-
124
- symbol .GlobalScope .Packages [symbols .Package ].AddSymbolsFromFile (symbols )
116
+ symbols := files [index ].ParseSymbols ()
117
+ // Add the symbols to the global symbol table
118
+ symbol .AddSymbolsToPackage (symbols )
125
119
}
126
120
127
121
// Go back through the symbol tables and fill in anything that could not be resolved
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ func (file *SourceFile) ParseAST() error {
32
32
return nil
33
33
}
34
34
35
- func (file * SourceFile ) ParseSymbols () {
36
- file .Symbols = symbol .ParseSymbols (file .Ast , file .Source )
35
+ func (file * SourceFile ) ParseSymbols () * symbol.FileScope {
36
+ symbols := symbol .ParseSymbols (file .Ast , file .Source )
37
+ file .Symbols = symbols
38
+ return symbols
37
39
}
Original file line number Diff line number Diff line change 1
1
package symbol
2
2
3
3
var (
4
- // The global symbol table
4
+ // GlobalScope represents the global symbol table, and contains a mapping
5
+ // between the package's path, and its symbols
6
+ //
7
+ // Example:
8
+ // "net.java.math" -> Symbols { Vectors, Cos }
5
9
GlobalScope = & GlobalSymbols {Packages : make (map [string ]* PackageScope )}
6
10
)
7
11
12
+ // AddSymbolsToPackage adds a given file's symbols to the global package scope
13
+ func AddSymbolsToPackage (symbols * FileScope ) {
14
+ if _ , exist := GlobalScope .Packages [symbols .Package ]; ! exist {
15
+ GlobalScope .Packages [symbols .Package ] = NewPackageScope ()
16
+ }
17
+ GlobalScope .Packages [symbols .Package ].Files [symbols .BaseClass .Class .Name ] = symbols
18
+ }
19
+
8
20
// A GlobalSymbols represents a global view of all the packages in the parsed source
9
21
type GlobalSymbols struct {
10
22
// Every package's path associatedd with its definition
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ type PackageScope struct {
6
6
Files map [string ]* FileScope
7
7
}
8
8
9
+ func NewPackageScope () * PackageScope {
10
+ return & PackageScope {
11
+ Files : make (map [string ]* FileScope ),
12
+ }
13
+ }
14
+
9
15
func (ps * PackageScope ) ExcludeFile (excludedFileName string ) * PackageScope {
10
16
newScope := & PackageScope {Files : make (map [string ]* FileScope )}
11
17
for fileName , fileScope := range ps .Files {
You can’t perform that action at this time.
0 commit comments