Пример #1
0
func addSourceUnitFiles(u *unit.SourceUnit, file string) {
	for _, f := range u.Files {
		if f == file {
			return
		}
	}
	u.Files = append(u.Files, file)
}
Пример #2
0
func addSourceUnitFilesFromData(u *unit.SourceUnit, data *graph.Output) {
	files := map[string]struct{}{}
	for _, def := range data.Defs {
		files[def.File] = struct{}{}
	}
	for _, ref := range data.Refs {
		files[ref.File] = struct{}{}
	}
	for f := range files {
		u.Files = append(u.Files, f)
	}
	sort.Strings(u.Files)
}
Пример #3
0
func (c *SimpleRepoCmd) genUnit(ut *unit.SourceUnit) error {
	defs := make([]*graph.Def, 0)
	refs := make([]*graph.Ref, 0)
	docs := make([]*graph.Doc, 0)

	for _, filename := range hierarchicalNames("dir", "file", ut.Name, c.NFiles) {
		ut.Files = append(ut.Files, filename)
		fileDefs, fileRefs, fileDocs, err := c.genFile(ut, filename)
		if err != nil {
			return err
		}
		defs, refs, docs = append(defs, fileDefs...), append(refs, fileRefs...), append(docs, fileDocs...)
	}

	if !c.GenSource {
		gr := graph.Output{Defs: defs, Refs: refs, Docs: docs}
		deps := make([]*dep.Resolution, 0)
		if err := writeSrclibCache(ut, &gr, deps); err != nil {
			return err
		}
	}

	return nil
}
Пример #4
0
func (c *URefsRepoCmd) genDefsFile(ut *unit.SourceUnit, filename string) (defs []*graph.Def, defRefs []*graph.Ref, err error) {
	filename = filepath.Join(ut.Name, filename)
	ut.Files = append(ut.Files, filename)

	offset := 0
	defName := "foo"

	var sourceFile *os.File
	if c.GenSource {
		err := os.MkdirAll(filepath.Dir(filename), 0700)
		if err != nil {
			return nil, nil, err
		}
		file, err := os.Create(filename)
		if err != nil {
			return nil, nil, err
		}
		sourceFile = file
	}

	for i := 0; i < c.NDefs; i++ {
		def := &graph.Def{
			DefKey: graph.DefKey{
				Repo:     ut.Repo,
				CommitID: ut.CommitID,
				UnitType: ut.Type,
				Unit:     ut.Name,
				Path:     filepath.ToSlash(filepath.Join(filename, fmt.Sprintf("method_%d", i))),
			},
			Name:     defName,
			Exported: true,
			File:     filename,
			DefStart: uint32(offset),
			DefEnd:   uint32(offset + len(defName) - 1),
		}
		if sourceFile != nil {
			_, err := sourceFile.WriteString(def.Name + "\n")
			if err != nil {
				return nil, nil, err
			}
		}
		offset += len(defName) + 1
		defs = append(defs, def)

		defRef := &graph.Ref{
			DefRepo:     def.Repo,
			DefUnitType: def.UnitType,
			DefUnit:     def.Unit,
			DefPath:     def.Path,
			Repo:        def.Repo,
			CommitID:    def.CommitID,
			UnitType:    def.UnitType,
			Unit:        def.Unit,
			Def:         true,
			File:        def.File,
			Start:       def.DefStart,
			End:         def.DefEnd,
		}
		defRefs = append(defRefs, defRef)
	}

	// Close source file
	if sourceFile != nil {
		sourceFile.WriteString("\n")
		sourceFile.Close()
	}

	return defs, defRefs, nil
}