wip
This commit is contained in:
parent
82c868f0c1
commit
fd9b1b3d11
@ -14,6 +14,7 @@ package analyzer
|
|||||||
import "os"
|
import "os"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "path/filepath"
|
import "path/filepath"
|
||||||
|
import "git.tebibyte.media/arf/arf/types"
|
||||||
import "git.tebibyte.media/arf/arf/parser"
|
import "git.tebibyte.media/arf/arf/parser"
|
||||||
import "git.tebibyte.media/arf/arf/infoerr"
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
@ -135,23 +136,42 @@ func (analyzer *analysisOperation) fetchSection (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchSectionFromIdentifier is like fetchSection, but takes in an identifier
|
// TODO: make this method a generalized "get this from an identifier in context
|
||||||
// referring to a section and returns the section. This works within the context
|
// of the current scope" method. have it return various things like sections,
|
||||||
// of whatever module is currently being analyzed. The identifier in question
|
// variables, functions, members, methods, etc. have it return an any.
|
||||||
// may have more items than 1 or 2, but those will be ignored. This method
|
// if no node could be found, return an error saying entity not found. if a node
|
||||||
// "consumes" items from the identifier, it will return an identifier without
|
// is found, but other identifier items describe members of that node that do
|
||||||
// those items. If the section comes from a different module (and permissions
|
// not exist, return an error saying nonexistent member. if the node is private,
|
||||||
// should therefore be respected), external will be set to true.
|
// also return an error.
|
||||||
func (analyzer *analysisOperation) fetchSectionFromIdentifier (
|
//
|
||||||
|
// when new things are defined, they should not be allowed to shadow anything
|
||||||
|
// else in above scopes. nevertheless, the method should search in this order:
|
||||||
|
//
|
||||||
|
// 1. search scopes starting with closest -> farthest
|
||||||
|
// 2. if first part of identifier is a require, get section from other module
|
||||||
|
// 3. search for section in current module
|
||||||
|
//
|
||||||
|
// look into making a unified structure for data sections and variables, and
|
||||||
|
// having data section variables be part of a "root" scope at the base of every
|
||||||
|
// module.
|
||||||
|
|
||||||
|
// fetchNodeFromIdentifier is like fetchSection, but takes in an identifier
|
||||||
|
// referring to any node accessible within the current scope and returns it.
|
||||||
|
// This method works within the current scope and current module. This method
|
||||||
|
// consumes the entire identifier, and will produce an error if there are
|
||||||
|
// identifier items left unconsumed.
|
||||||
|
func (analyzer *analysisOperation) fetchNodeFromIdentifier (
|
||||||
which parser.Identifier,
|
which parser.Identifier,
|
||||||
) (
|
) (
|
||||||
section Section,
|
node any,
|
||||||
external bool,
|
err error,
|
||||||
bitten parser.Identifier,
|
|
||||||
err error,
|
|
||||||
) {
|
) {
|
||||||
item, bitten := which.Bite()
|
item, bitten := which.Bite()
|
||||||
|
|
||||||
|
// TODO: search scopes for variables
|
||||||
|
|
||||||
|
// the identifier must be referring to a section
|
||||||
|
var external bool
|
||||||
path, exists := analyzer.currentTree.ResolveRequire(item)
|
path, exists := analyzer.currentTree.ResolveRequire(item)
|
||||||
if exists {
|
if exists {
|
||||||
// we have our module path, so get the section name
|
// we have our module path, so get the section name
|
||||||
@ -163,20 +183,40 @@ func (analyzer *analysisOperation) fetchSectionFromIdentifier (
|
|||||||
path = analyzer.currentPosition.modulePath
|
path = analyzer.currentPosition.modulePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// attempt to get section
|
||||||
|
var section Section
|
||||||
section, err = analyzer.fetchSection (locator {
|
section, err = analyzer.fetchSection (locator {
|
||||||
name: item,
|
name: item,
|
||||||
modulePath: path,
|
modulePath: path,
|
||||||
})
|
})
|
||||||
|
node = section
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
if section == nil {
|
// return error if nothing mentioned in the identifier is accessible
|
||||||
|
if node == nil {
|
||||||
err = which.NewError (
|
err = which.NewError (
|
||||||
"section \"" + item + "\" does not exist",
|
"can't find anything called \"" + item + "\" within " +
|
||||||
|
"current scope",
|
||||||
infoerr.ErrorKindError,
|
infoerr.ErrorKindError,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return error if the section is private
|
||||||
|
if external && section.Permission() == types.PermissionPrivate {
|
||||||
|
err = which.NewError(
|
||||||
|
"this section is private, and cannot be used " +
|
||||||
|
"outside of its module",
|
||||||
|
infoerr.ErrorKindError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// see if we can do member selection on the section
|
||||||
|
// TODO: at this point, we are gonna return an argument.
|
||||||
|
if bitten.Length > 0 {
|
||||||
|
switch
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,11 +12,11 @@ type List struct {
|
|||||||
func (list List) ToString (indent int) (output string) {
|
func (list List) ToString (indent int) (output string) {
|
||||||
// TODO
|
// TODO
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
return
|
// return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (list List) canBePassedAs (what Type) (allowed bool) {
|
func (list List) canBePassedAs (what Type) (allowed bool) {
|
||||||
// TODO
|
// TODO
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
return
|
// return
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package analyzer
|
package analyzer
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "git.tebibyte.media/arf/arf/types"
|
|
||||||
import "git.tebibyte.media/arf/arf/parser"
|
import "git.tebibyte.media/arf/arf/parser"
|
||||||
import "git.tebibyte.media/arf/arf/infoerr"
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
@ -292,48 +291,22 @@ func (analyzer analysisOperation) analyzeType (
|
|||||||
outputType.points = &points
|
outputType.points = &points
|
||||||
} else {
|
} else {
|
||||||
// analyze the type section this type uses
|
// analyze the type section this type uses
|
||||||
var bitten parser.Identifier
|
var node any
|
||||||
var external bool
|
|
||||||
var actual Section
|
|
||||||
|
|
||||||
actual,
|
node, err = analyzer.fetchNodeFromIdentifier(inputType.Name())
|
||||||
external,
|
|
||||||
bitten,
|
|
||||||
err = analyzer.fetchSectionFromIdentifier(inputType.Name())
|
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
if actual == nil {
|
switch node.(type) {
|
||||||
err = inputType.NewError (
|
|
||||||
"this type does not exist",
|
|
||||||
infoerr.ErrorKindError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch actual.(type) {
|
|
||||||
// TODO: uncomment once these sections are implemented
|
// TODO: uncomment once these sections are implemented
|
||||||
case *TypeSection, *EnumSection /* , *FaceSection */:
|
case *TypeSection, *EnumSection /* , *FaceSection */:
|
||||||
outputType.actual = actual
|
outputType.actual = node.(Section)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = inputType.NewError (
|
err = inputType.Name().NewError (
|
||||||
"this must refer to a type, interface, or enum",
|
"this must refer to a type, interface, or enum",
|
||||||
infoerr.ErrorKindError)
|
infoerr.ErrorKindError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if external && actual.Permission() == types.PermissionPrivate {
|
|
||||||
err = bitten.NewError(
|
|
||||||
"this type is private, and cannot be used " +
|
|
||||||
"outside of its module",
|
|
||||||
infoerr.ErrorKindError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if bitten.Length() > 0 {
|
|
||||||
err = bitten.NewError(
|
|
||||||
"cannot use member selection in this context",
|
|
||||||
infoerr.ErrorKindError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user