@@ -11,15 +11,24 @@ import (
1111)
1212
1313type PkgHfilesInfo struct {
14- Inters []string // From types.Config.Include
15- Impls []string // From same root of types.Config.Include
16- Thirds []string // Not Current Pkg's Files
14+ Inters []string // From types.Config.Include
15+ Impls []string // From same root of types.Config.Include
16+ Thirds []string // Not Current Pkg's Files
17+ PlatDiff []string // Platform Difference Files
1718}
1819
1920func (p * PkgHfilesInfo ) CurPkgFiles () []string {
2021 return append (p .Inters , p .Impls ... )
2122}
2223
24+ type Config struct {
25+ Includes []string
26+ // todo(zzy):support platform difference files
27+ PlatDiff []string
28+ Args []string
29+ Mix bool
30+ }
31+
2332// PkgHfileInfo analyzes header files dependencies and categorizes them into three groups:
2433// 1. Inters: Direct includes from types.Config.Include
2534// 2. Impls: Header files from the same root directory as Inters
@@ -29,7 +38,7 @@ func (p *PkgHfilesInfo) CurPkgFiles() []string {
2938// 1. Creating a temporary header file that includes all headers from conf.Include
3039// 2. Using clang to parse the translation unit and analyze includes
3140// 3. Categorizing includes based on their inclusion level and path relationship
32- func PkgHfileInfo (includes [] string , args [] string , mix bool ) * PkgHfilesInfo {
41+ func PkgHfileInfo (conf * Config ) * PkgHfilesInfo {
3342 info := & PkgHfilesInfo {
3443 Inters : []string {},
3544 Impls : []string {},
@@ -43,12 +52,12 @@ func PkgHfileInfo(includes []string, args []string, mix bool) *PkgHfilesInfo {
4352
4453 inters := make (map [string ]struct {})
4554 others := []string {} // impl & third
46- for _ , f := range includes {
55+ for _ , f := range conf . Includes {
4756 content := "#include <" + f + ">"
4857 index , unit , err := clangutils .CreateTranslationUnit (& clangutils.Config {
4958 File : content ,
5059 Temp : true ,
51- Args : args ,
60+ Args : conf . Args ,
5261 })
5362 if err != nil {
5463 panic (err )
@@ -64,11 +73,11 @@ func PkgHfileInfo(includes []string, args []string, mix bool) *PkgHfilesInfo {
6473 index .Dispose ()
6574 }
6675
67- clangtool .ComposeIncludes (includes , outfile .Name ())
76+ clangtool .ComposeIncludes (conf . Includes , outfile .Name ())
6877 index , unit , err := clangutils .CreateTranslationUnit (& clangutils.Config {
6978 File : outfile .Name (),
7079 Temp : false ,
71- Args : args ,
80+ Args : conf . Args ,
7281 })
7382 defer unit .Dispose ()
7483 defer index .Dispose ()
@@ -84,7 +93,7 @@ func PkgHfileInfo(includes []string, args []string, mix bool) *PkgHfilesInfo {
8493 }
8594 })
8695
87- if mix {
96+ if conf . Mix {
8897 info .Thirds = others
8998 return info
9099 }
0 commit comments