// ParseAndBuildScopeGraph conducts full parsing and type graph construction for the project // starting at the given root source file. func ParseAndBuildScopeGraph(rootSourceFilePath string, vcsDevelopmentDirectories []string, libraries ...packageloader.Library) Result { graph, err := compilergraph.NewGraph(rootSourceFilePath) if err != nil { log.Fatalf("Could not instantiate graph: %v", err) } // Create the SRG for the source and load it. sourcegraph := srg.NewSRG(graph) webidlgraph := webidl.NewIRG(graph) loader := packageloader.NewPackageLoader(rootSourceFilePath, vcsDevelopmentDirectories, sourcegraph.PackageLoaderHandler(), webidlgraph.PackageLoaderHandler()) loaderResult := loader.Load(libraries...) if !loaderResult.Status { return Result{ Status: false, Errors: loaderResult.Errors, Warnings: loaderResult.Warnings, } } // Construct the type graph. resolver := typerefresolver.NewResolver(sourcegraph) srgConstructor := srgtc.GetConstructorWithResolver(sourcegraph, resolver) typeResult := typegraph.BuildTypeGraph(sourcegraph.Graph, srgConstructor, webidltc.GetConstructor(webidlgraph)) if !typeResult.Status { return Result{ Status: false, Errors: typeResult.Errors, Warnings: combineWarnings(loaderResult.Warnings, typeResult.Warnings), } } // Freeze the resolver's cache. resolver.FreezeCache() // Construct the scope graph. scopeResult := buildScopeGraphWithResolver(sourcegraph, webidlgraph, typeResult.Graph, resolver) return Result{ Status: scopeResult.Status, Errors: scopeResult.Errors, Warnings: combineWarnings(loaderResult.Warnings, typeResult.Warnings, scopeResult.Warnings), Graph: scopeResult.Graph, } }
// GetConstructor returns a TypeGraph constructor for the given SRG. func GetConstructor(srg *srg.SRG) *srgTypeConstructor { return GetConstructorWithResolver(srg, typerefresolver.NewResolver(srg)) }
// BuildScopeGraph returns a new ScopeGraph that is populated from the given SRG and TypeGraph, // computing scope for all statements and expressions and semantic checking along the way. func BuildScopeGraph(srg *srg.SRG, irg *webidl.WebIRG, tdg *typegraph.TypeGraph) Result { return buildScopeGraphWithResolver(srg, irg, tdg, typerefresolver.NewResolver(srg)) }