Methods do not collide and are properly retrievable
This commit is contained in:
parent
5641220986
commit
dfa7d31163
@ -3,7 +3,8 @@ package parser
|
|||||||
import "git.tebibyte.media/arf/arf/types"
|
import "git.tebibyte.media/arf/arf/types"
|
||||||
|
|
||||||
// LookupSection looks returns the section under the give name. If the section
|
// LookupSection looks returns the section under the give name. If the section
|
||||||
// does not exist, nil is returned.
|
// does not exist, nil is returned. If a method is being searched for, the type
|
||||||
|
// name of its receiver should be passed. If not, it should just be left blank.
|
||||||
func (tree SyntaxTree) LookupSection (name string) (section Section) {
|
func (tree SyntaxTree) LookupSection (name string) (section Section) {
|
||||||
section = tree.sections[name]
|
section = tree.sections[name]
|
||||||
return
|
return
|
||||||
|
@ -53,7 +53,17 @@ func (parser *parsingOperation) parseBody () (err error) {
|
|||||||
// addSection adds a section to the tree, ensuring it has a unique name within
|
// addSection adds a section to the tree, ensuring it has a unique name within
|
||||||
// the module.
|
// the module.
|
||||||
func (tree *SyntaxTree) addSection (section Section) (err error) {
|
func (tree *SyntaxTree) addSection (section Section) (err error) {
|
||||||
_, exists := tree.sections[section.Name()]
|
index := section.Name()
|
||||||
|
|
||||||
|
funcSection, isFuncSection := section.(FuncSection)
|
||||||
|
if isFuncSection {
|
||||||
|
receiver := funcSection.receiver
|
||||||
|
if receiver != nil {
|
||||||
|
index = receiver.what.points.name.trail[0] + "_" + index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, exists := tree.sections[index]
|
||||||
if exists {
|
if exists {
|
||||||
err = section.NewError (
|
err = section.NewError (
|
||||||
"cannot have multiple sections with the same name",
|
"cannot have multiple sections with the same name",
|
||||||
@ -61,6 +71,6 @@ func (tree *SyntaxTree) addSection (section Section) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tree.sections[section.Name()] = section
|
tree.sections[index] = section
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,13 @@ func TestFunc (test *testing.T) {
|
|||||||
checkTree ("../tests/parser/func", false,
|
checkTree ("../tests/parser/func", false,
|
||||||
`:arf
|
`:arf
|
||||||
---
|
---
|
||||||
func ro aBasicExternal
|
func ro bMethod
|
||||||
|
@ bird:{Bird}
|
||||||
> someInput:Int:mut
|
> someInput:Int:mut
|
||||||
< someOutput:Int 4
|
< someOutput:Int 4
|
||||||
---
|
---
|
||||||
external
|
external
|
||||||
func ro bMethod
|
func ro aBasicExternal
|
||||||
@ bird:{Bird}
|
|
||||||
> someInput:Int:mut
|
> someInput:Int:mut
|
||||||
< someOutput:Int 4
|
< someOutput:Int 4
|
||||||
---
|
---
|
||||||
|
Reference in New Issue
Block a user