mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 16:55:11 +01:00
Parse a "ptr T" type.
This commit is contained in:
1 parent
1617d5eb34
commit
8dbc476375
3 files changed
+51
-7
No files matched your search
+21
-4
@@ -28,14 +28,30 @@ const (
|
|||||||
// - RHS: Right
|
// - RHS: Right
|
||||||
KAssign
|
KAssign
|
||||||
|
|
||||||
// KParam is a "name package.type" parameter:
|
// KParam is a "name type" parameter:
|
||||||
// - ID0: name
|
// - ID0: name
|
||||||
// - ID1: package (optional)
|
// - RHS: <KType>
|
||||||
// - ID2: type
|
|
||||||
KParam
|
KParam
|
||||||
|
|
||||||
|
// KType is a type, such as "u32", "pkg.foo", "ptr T" or "[8] T".
|
||||||
|
// - ID0: <0|IDPtr>
|
||||||
|
// - ID1: <0|package name>
|
||||||
|
// - ID2: <0|type name>
|
||||||
|
// - LHS: TODO.
|
||||||
|
// - RHS: <nil|KType>
|
||||||
|
//
|
||||||
|
// A zero ID0 means an undecorated type like "u32" or "pkg.foo". ID1 is
|
||||||
|
// zero or "pkg". ID2 is "u32" or "foo". RHS is nil.
|
||||||
|
//
|
||||||
|
// A non-zero ID0 means a decorated type like "ptr T" or "[8] T". ID0 is
|
||||||
|
// the decoration. LHS is nil or "8". RHS is the T. ID1 and ID2 are zero.
|
||||||
|
//
|
||||||
|
// TODO: LHS for arrays (and slices?), such as "[8] T".
|
||||||
|
// TODO: refinements, such as "u32~[:4096]".
|
||||||
|
KType
|
||||||
|
|
||||||
// KFunc is "func ID0.ID1 (List0) (List1) { List2 }":
|
// KFunc is "func ID0.ID1 (List0) (List1) { List2 }":
|
||||||
// - ID0: receiver (optional)
|
// - ID0: <0|receiver>
|
||||||
// - ID1: name
|
// - ID1: name
|
||||||
// - List0: <KParam> in-parameters
|
// - List0: <KParam> in-parameters
|
||||||
// - List1: <KParam> out-parameters
|
// - List1: <KParam> out-parameters
|
||||||
@@ -63,6 +79,7 @@ var kindStrings = [...]string{
|
|||||||
KInvalid: "KInvalid",
|
KInvalid: "KInvalid",
|
||||||
KLiteral: "KLiteral",
|
KLiteral: "KLiteral",
|
||||||
KParam: "KParam",
|
KParam: "KParam",
|
||||||
|
KType: "KType",
|
||||||
}
|
}
|
||||||
|
|
||||||
type Flags uint32
|
type Flags uint32
|
||||||
|
|||||||
+28
-3
@@ -167,17 +167,42 @@ func (p *parser) parseParamList() ([]*a.Node, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) parseParam() (*a.Node, error) {
|
func (p *parser) parseParam() (*a.Node, error) {
|
||||||
id0, err := p.parseIdent()
|
id, err := p.parseIdent()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
id1, id2, err := p.parseQualifiedIdent()
|
rhs, err := p.parseType()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &a.Node{
|
return &a.Node{
|
||||||
Kind: a.KParam,
|
Kind: a.KParam,
|
||||||
ID0: id0,
|
ID0: id,
|
||||||
|
RHS: rhs,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *parser) parseType() (*a.Node, error) {
|
||||||
|
switch p.peekID() {
|
||||||
|
case t.IDPtr:
|
||||||
|
p.src = p.src[1:]
|
||||||
|
rhs, err := p.parseType()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &a.Node{
|
||||||
|
Kind: a.KType,
|
||||||
|
ID0: t.IDPtr,
|
||||||
|
RHS: rhs,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
id1, id2, err := p.parseQualifiedIdent()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &a.Node{
|
||||||
|
Kind: a.KType,
|
||||||
ID1: id1,
|
ID1: id1,
|
||||||
ID2: id2,
|
ID2: id2,
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ const (
|
|||||||
|
|
||||||
// TODO: sort these by name, when the list has stabilized.
|
// TODO: sort these by name, when the list has stabilized.
|
||||||
IDFunc = ID(0xA0<<idShift | FlagsOther)
|
IDFunc = ID(0xA0<<idShift | FlagsOther)
|
||||||
|
IDPtr = ID(0xA1<<idShift | FlagsOther)
|
||||||
|
|
||||||
IDFalse = ID(0xD0<<idShift | FlagsLiteral | FlagsImplicitSemicolon)
|
IDFalse = ID(0xD0<<idShift | FlagsLiteral | FlagsImplicitSemicolon)
|
||||||
IDTrue = ID(0xD1<<idShift | FlagsLiteral | FlagsImplicitSemicolon)
|
IDTrue = ID(0xD1<<idShift | FlagsLiteral | FlagsImplicitSemicolon)
|
||||||
@@ -206,6 +207,7 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
|||||||
IDAs >> idShift: {"as", IDAs},
|
IDAs >> idShift: {"as", IDAs},
|
||||||
|
|
||||||
IDFunc >> idShift: {"func", IDFunc},
|
IDFunc >> idShift: {"func", IDFunc},
|
||||||
|
IDPtr >> idShift: {"ptr", IDPtr},
|
||||||
|
|
||||||
IDFalse >> idShift: {"false", IDFalse},
|
IDFalse >> idShift: {"false", IDFalse},
|
||||||
IDTrue >> idShift: {"true", IDTrue},
|
IDTrue >> idShift: {"true", IDTrue},
|
||||||
|
|||||||
Reference in new issue
Block a user