37 строки
655 Б
Go
37 строки
655 Б
Go
package service
|
|
|
|
import (
|
|
"go/ast"
|
|
)
|
|
|
|
func handleSpecs(specs []ast.Spec) string {
|
|
code := ""
|
|
for _, spec := range specs {
|
|
switch spec.(type) {
|
|
case *ast.ImportSpec:
|
|
code += handleImportSpec(spec)
|
|
case *ast.ValueSpec:
|
|
code += handleValueSpec(spec) + ";"
|
|
case *ast.TypeSpec:
|
|
code += handleTypeSpec(spec)
|
|
}
|
|
}
|
|
return code
|
|
}
|
|
|
|
func handleImportSpec(spec ast.Spec) string {
|
|
s := spec.(*ast.ImportSpec)
|
|
code := ""
|
|
if s.Name != nil {
|
|
name := handleIdentExpr(s.Name)
|
|
if val, ok := mapping[name]; ok {
|
|
name = val
|
|
}
|
|
if name != "" {
|
|
if name != "controller" {
|
|
code = "#include <" + name + ".h>\n"
|
|
}
|
|
}
|
|
}
|
|
return code
|
|
}
|