// File compiles the statements of a file into a program.
160242
func File(stmts []syntax.Stmt, locals, globals []*syntax.Ident) *Program {
	pcomp := &pcomp{
		prog: &Program{
			Globals: idents(globals),
		},
		names:     make(map[string]uint32),
		constants: make(map[interface{}]uint32),
		functions: make(map[*Funcode]uint32),
	}

	var pos syntax.Position
	if len(stmts) > 0 {
		pos = syntax.Start(stmts[0])
	}

	pcomp.prog.Toplevel = pcomp.function("<toplevel>", pos, stmts, locals, nil)

	return pcomp.prog
}
126718
func compile(ctx context.Context, prog *progInfo, dir *directoryInfo, debug bool) (err error) {
	args := make([]string, 0, 16)
	if prog.OutputType == outputSource {
		args = append(args, "-E") // Preprocessor
	} else {
		args = append(args, "-emit-llvm")
		if debug {
			args = append(args, "-g")
		}
	}
	args = append(args, standardCFlags...)
	args = append(args, progCFlags(prog, dir)...)

	// Compilation is split between two exec calls. First clang generates
	// LLVM bitcode and then later llc compiles it to byte-code.
	log.WithFields(logrus.Fields{
		"target": compiler,
		"args":   args,
	}).Debug("Launching compiler")
	if prog.OutputType == outputSource {
		compileCmd := exec.CommandContext(ctx, compiler, args...)
		_, err = compileCmd.CombinedOutput(log, debug)
	} else {
		switch prog.OutputType {
		case outputObject:
			err = compileAndLink(ctx, prog, dir, debug, args...)
		case outputAssembly:
			err = compileAndLink(ctx, prog, dir, false, args...)
		default:
			log.Fatalf("Unhandled progInfo.OutputType %s", prog.OutputType)
		}
	}

	return err
}
1116801
func (f Frame) file() string {
	fn := runtime.FuncForPC(f.pc())
	if fn == nil {
		return "unknown"
	}
	file, _ := fn.FileLine(f.pc())
	return file
}
1301988
func File(buffer Buffer, event *cue.Event) {
	if len(event.Frames) == 0 {
		buffer.AppendString(cue.UnknownFile)
		return
	}
	buffer.AppendString(event.Frames[0].File)
}
841926
func (f *File) String() string {
	src, _ := ioutil.ReadAll(f)
	f.Reader = bytes.NewReader(src)
	return string(src)
}
1025267
func (f *SourceFile) Write(b []byte) (int, error) {
	return f.osFile.Write(b)
}
20233
func (z *Zone) File() string {
	z.reloadMu.Lock()
	defer z.reloadMu.Unlock()
	return z.file
}
1295341
func ParseFile(path string) (*Template, error) {
	var f *os.File
	var err error
	if path == "-" {
		// Create a temp file for stdin in case of errors
		f, err = tmp.File("parse")
		if err != nil {
			return nil, err
		}
		defer os.Remove(f.Name())
		defer f.Close()
		io.Copy(f, os.Stdin)
		f.Seek(0, os.SEEK_SET)
	} else {
		f, err = os.Open(path)
		if err != nil {
			return nil, err
		}
		defer f.Close()
	}
	tpl, err := Parse(f)
	if err != nil {
		syntaxErr, ok := err.(*json.SyntaxError)
		if !ok {
			return nil, err
		}
		// Rewind the file and get a better error
		f.Seek(0, os.SEEK_SET)
		// Grab the error location, and return a string to point to offending syntax error
		line, col, highlight := highlightPosition(f, syntaxErr.Offset)
		err = fmt.Errorf("Error parsing JSON: %s\nAt line %d, column %d (offset %d):\n%s", err, line, col, syntaxErr.Offset, highlight)
		return nil, err
	}

	if !filepath.IsAbs(path) {
		path, err = filepath.Abs(path)
		if err != nil {
			return nil, err
		}
	}

	tpl.Path = path
	return tpl, nil
}
205193
func format(f *os.File) {
	// Run go fmt on the file.
	cmd := exec.Command("go", "fmt")
	cmd.Stdin = f
	_ = cmd.Run()
}
725045
func (g *Group) File(path, file string) {
	g.server.File(g.prefix+path, file)
}
269579
func Executable() (string, error) {
	p, err := executable()
	return filepath.Clean(p), err
}
1292544
func (f *File) Write(w io.Writer) error {
	_, err := f.WriteTo(w)
	return err
}
930515
func File(t TestReporter, path string, content string) afero.File {
	file, err := appFs.OpenFile(path, os.O_RDWR|os.O_CREATE, 0600)
	if err != nil {
		t.Error("Failed to create the file: "+path, err)
		return nil
	}

	file.WriteString(content)
	Files = append(Files, file.Name())

	return file
}
31520
func Create(fn string) (*os.File, error) {
	tfn := strings.TrimSpace(fn)
	f, err := os.Create(tfn)
	if err != nil {
		return f, err
	}

	return f, nil
}
217944
func (s *Server) File(path, file string) {
	s.Get(path, func(c Context) error {
		return c.Content(file)
	})
}
12126
func (p *Package) Compile(bin string) (string, error) {
	gobin, err := exec.LookPath("go")
	if err != nil {
		return "", fmt.Errorf(`failed to find a go compiler, looked in "%s"`, os.Getenv("PATH"))
	}
	if runtime.GOOS == "windows" {
		bin += ".exe"
	}
	c := exec.Cmd{
		Path: gobin,
		Args: []string{gobin, "build", "-o", bin},
		Dir:  p.Abs(),
	}
	out, err := c.CombinedOutput()
	if err != nil {
		if len(out) > 0 {
			return "", fmt.Errorf(string(out))
		}
		return "", fmt.Errorf("failed to compile %s: %s", bin, err)
	}
	return filepath.Join(p.Abs(), bin), nil
}
634536
func (r *Request) File(path string) *Request {
	r.BodyBuffer, r.Error = ioutil.ReadFile(path)
	return r
}