51 строка
884 Б
Go
51 строка
884 Б
Go
package service
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/token"
|
|
)
|
|
|
|
func handleGenDecl(decl ast.Decl) string {
|
|
gd := decl.(*ast.GenDecl)
|
|
code := ""
|
|
switch gd.Tok {
|
|
case token.CONST:
|
|
code += "const "
|
|
case token.VAR:
|
|
code += ""
|
|
}
|
|
code += handleSpecs(gd.Specs)
|
|
return code
|
|
}
|
|
|
|
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
|
|
}
|