func (codegen *_CodeGen) typePrefix(typeDecl ast.TypeDecl) string { langs := gslang.FindAnnotations(typeDecl.Module(), "gslang.Package") compiler := codegen.compiler for _, lang := range langs { langName, ok := lang.Args.NamedArg("Lang") if ok && compiler.Eval().EvalString(langName) == "objc" { packageName, ok := lang.Args.NamedArg("Name") if ok && compiler.Eval().EvalString(packageName) == typeDecl.Package() { redirect, ok := lang.Args.NamedArg("Redirect") if ok { prefix := compiler.Eval().EvalString(redirect) if codegen.script.Name() != typeDecl.Script() { v := fmt.Sprintf("#import <%s>\n\n", filepath.Join(strings.Replace(typeDecl.Package(), ".", "/", -1), filepath.Base(typeDecl.Script())+".h")) codegen.imports[typeDecl.FullName()] = v } return prefix } } } } return "" }
func (codegen *_CodeGen) BeginScript(compiler *gslang.Compiler, script *ast.Script) bool { scriptPath := filepath.ToSlash(filepath.Clean(script.Name())) for _, skip := range codegen.skips { if skip.MatchString(scriptPath) { return false } } if strings.HasPrefix(script.Package, "gslang.") { return false } codegen.header.Reset() codegen.content.Reset() codegen.script = script codegen.packageName = script.Package codegen.scriptPath = strings.Replace(codegen.packageName, ".", "/", -1) langs := gslang.FindAnnotations(script.Module, "gslang.Package") for _, lang := range langs { langName, ok := lang.Args.NamedArg("Lang") if ok && compiler.Eval().EvalString(langName) == "golang" { packageName, ok := lang.Args.NamedArg("Name") if ok && compiler.Eval().EvalString(packageName) == script.Package { redirect, ok := lang.Args.NamedArg("Redirect") if ok { codegen.packageName = compiler.Eval().EvalString(redirect) codegen.scriptPath = codegen.packageName } } } } path := strings.Replace(codegen.packageName, ".", "/", -1) codegen.header.WriteString(fmt.Sprintf("package %s\n\n", filepath.Base(path))) codegen.imports = make(map[string]string) for k, v := range imports { codegen.imports[k] = v } return true }