This commit is contained in:
Sasha Koshka 2022-09-07 15:50:37 -04:00
parent f6aeae1d55
commit 596deaf0c3
3 changed files with 42 additions and 7 deletions

View File

@ -1,6 +1,46 @@
package analyzer
import "os"
import "path/filepath"
import "git.tebibyte.media/arf/arf/parser"
// AnalysisOperation holds information about an ongoing analysis operation.
type AnalysisOperation struct {
sectionTable SectionTable
modulePath string
}
// Analyze performs a semantic analyisys on the module specified by path, and
// returns a SectionTable that can be translated into C.
func Analyze (modulePath string, skim bool) (table SectionTable, err error) {
if modulePath[0] != '/' {
cwd, _ := os.Getwd()
modulePath = filepath.Join(cwd, modulePath)
}
analyzer := AnalysisOperation {
sectionTable: make(SectionTable),
modulePath: modulePath,
}
err = analyzer.analyze()
table = analyzer.sectionTable
return
}
// analyze performs an analysis operation given the state of the operation
// struct.
func (analyzer *AnalysisOperation) analyze () (err error) {
tree, err := parser.Fetch(analyzer.modulePath, false)
sections := tree.Sections()
for !sections.End() {
switch sections.Value().Kind() {
}
sections.Next()
}
return
}

View File

@ -18,13 +18,6 @@ type ParsingOperation struct {
tree SyntaxTree
}
// TODO:
// * implement parser cache
// * have this try to hit the cache, and actually parse on miss
// * rename this to Fetch
// - add `skim bool` argument. when this is true, don't parse any code or data
// section initialization values, just definitions and their default values.
// Fetch returns the parsed module located at the specified path, and returns an
// abstract syntax tree. If the module has not yet been parsed, it parses it
// first.

View File

@ -4,6 +4,8 @@ import "git.tebibyte.media/arf/arf/file"
import "git.tebibyte.media/arf/arf/types"
import "git.tebibyte.media/arf/arf/infoerr"
// TODO: implement table of import names -> full paths from /. perhaps replace
// requires[] with this, and build it when parsing the meta section.
// SyntaxTree represents an abstract syntax tree. It covers an entire module. It
// can be expected to be syntactically correct, but it might not be semantically
// correct (because it has not been analyzed yet.)