示例#1
0
func NewLinkingContext(pkg *tp.Package) *LinkingContext {
	// Setup the function map!
	functionLookup := make([]FuncMap, len(pkg.Types))
	types := make([]string, len(pkg.Types))

	for typeId, typeObj := range pkg.Types {
		funcMap := make(FuncMap)
		types[typeId] = typeObj.GetName()
		implements := functionLookup[typeObj.GetImplements()]
		for index, fun := range pkg.Functions {
			stub := fun.Stub(pkg)

			funScopeId := fun.GetScopeTypeId()
			inherited := false
			// funScopeId is ancestor of typeId
			if (implements != nil) && pkg.AncestorOf(funScopeId, int32(typeId)) {
				_, inherited = implements[stub]
			}
			if (funScopeId == int32(typeId)) || inherited {
				funcMap[stub] = index
			}
		}
		functionLookup[typeId] = funcMap
	}

	// Setup the main context object
	ctx := &LinkingContext{
		funList: functionLookup,
		types:   types,
		Errors:  make([]string, 0),
		Transform: &tp.Transform{
			Pkg: pkg,
		},
	}

	// Find Text type int -- need its ID to deal with Text literals during processing
	ctx.textType = pkg.GetTypeId("Text")

	return ctx
}