Пример #1
0
// getDeps reads the types.Package objects referred to by depRefs from vr and returns a map of ref: PackageDef.
func getDeps(deps []ref.Ref, vr types.ValueReader) map[ref.Ref]types.Package {
	depsMap := map[ref.Ref]types.Package{}
	for _, depRef := range deps {
		v := vr.ReadValue(depRef)
		d.Chk.NotNil(v, "Importing package by ref %s failed.", depRef.String())
		depsMap[depRef] = v.(types.Package)
	}
	return depsMap
}
Пример #2
0
func generateDepCode(packageName, outDir string, written map[string]bool, p types.Package, localPkgs refSet, vr types.ValueReader) depsMap {
	deps := depsMap{}
	for _, r := range p.Dependencies() {
		p := vr.ReadValue(r).(types.Package)
		pDeps := generateDepCode(packageName, outDir, written, p, localPkgs, vr)
		tag := code.ToTag(p.Ref())
		parsed := pkg.Parsed{Package: p, Name: packageName}
		if !localPkgs[parsed.Ref()] {
			generateAndEmit(tag, filepath.Join(outDir, tag+"."+*outputLang), written, pDeps, parsed)
			localPkgs[parsed.Ref()] = true
		}
		for depRef, dep := range pDeps {
			deps[depRef] = dep
		}
		deps[r] = p
	}
	return deps
}
Пример #3
0
func doChunkWalkP(r ref.Ref, vr types.ValueReader, callback SomeChunksCallback, concurrency int) {
	rq := newRefQueue()
	wg := sync.WaitGroup{}
	mu := sync.Mutex{}
	visitedRefs := map[ref.Ref]bool{}

	walkChunk := func(r ref.Ref) {
		defer wg.Done()

		mu.Lock()
		visited := visitedRefs[r]
		visitedRefs[r] = true
		mu.Unlock()

		if visited || callback(r) {
			return
		}

		v := vr.ReadValue(r)
		for _, r1 := range v.Chunks() {
			wg.Add(1)
			rq.tail() <- r1.TargetRef()
		}
	}

	iter := func() {
		for r := range rq.head() {
			walkChunk(r)
		}
	}

	for i := 0; i < concurrency; i++ {
		go iter()
	}

	wg.Add(1)
	rq.tail() <- r
	wg.Wait()
	rq.close()
}
Пример #4
0
func (r RefOfRemotePhoto) TargetValue(vr types.ValueReader) RemotePhoto {
	return vr.ReadValue(r.target).(RemotePhoto)
}
Пример #5
0
func (r RefOfUser) TargetValue(vr types.ValueReader) User {
	return vr.ReadValue(r.target).(User)
}
Пример #6
0
func (r RefOfCompany) TargetValue(vr types.ValueReader) Company {
	return vr.ReadValue(r.target).(Company)
}
Пример #7
0
func (r RefOfMapOfStringToRefOfCompany) TargetValue(vr types.ValueReader) MapOfStringToRefOfCompany {
	return vr.ReadValue(r.target).(MapOfStringToRefOfCompany)
}
Пример #8
0
func (r RefOfFloat32) TargetValue(vr types.ValueReader) float32 {
	return float32(vr.ReadValue(r.target).(types.Float32))
}
Пример #9
0
func (r RefOfSetOfFloat32) TargetValue(vr types.ValueReader) SetOfFloat32 {
	return vr.ReadValue(r.target).(SetOfFloat32)
}
Пример #10
0
func (r RefOfListOfString) TargetValue(vr types.ValueReader) ListOfString {
	return vr.ReadValue(r.target).(ListOfString)
}
Пример #11
0
func (r RefOfKey) TargetValue(vr types.ValueReader) Key {
	return vr.ReadValue(r.target).(Key)
}
Пример #12
0
func (r RefOfAlbum) TargetValue(vr types.ValueReader) Album {
	return vr.ReadValue(r.target).(Album)
}
Пример #13
0
func (r RefOfMapOfStringToValue) TargetValue(vr types.ValueReader) MapOfStringToValue {
	return vr.ReadValue(r.target).(MapOfStringToValue)
}
Пример #14
0
func (r RefOfCommit) TargetValue(vr types.ValueReader) Commit {
	return vr.ReadValue(r.target).(Commit)
}
Пример #15
0
func (r RefOfListOfPitch) TargetValue(vr types.ValueReader) ListOfPitch {
	return vr.ReadValue(r.target).(ListOfPitch)
}
Пример #16
0
func doTreeWalkP(v types.Value, vr types.ValueReader, cb SomeCallback, concurrency int) {
	rq := newRefQueue()
	f := newFailure()

	visited := map[ref.Ref]bool{}
	mu := sync.Mutex{}
	wg := sync.WaitGroup{}

	var processVal func(v types.Value)
	processVal = func(v types.Value) {
		if cb(v) {
			return
		}

		if r, ok := v.(types.RefBase); ok {
			wg.Add(1)
			rq.tail() <- r.TargetRef()
		} else {
			for _, c := range v.ChildValues() {
				processVal(c)
			}
		}
	}

	processRef := func(r ref.Ref) {
		defer wg.Done()

		mu.Lock()
		skip := visited[r]
		visited[r] = true
		mu.Unlock()

		if skip || f.didFail() {
			return
		}

		v := vr.ReadValue(r)
		if v == nil {
			f.fail(fmt.Errorf("Attempt to copy absent ref:%s", r.String()))
			return
		}
		processVal(v)
	}

	iter := func() {
		for r := range rq.head() {
			processRef(r)
		}
	}

	for i := 0; i < concurrency; i++ {
		go iter()
	}

	processVal(v)
	wg.Wait()

	rq.close()

	f.checkNotFailed()
}