mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 00:38:14 +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
|
||||
KAssign
|
||||
|
||||
// KParam is a "name package.type" parameter:
|
||||
// KParam is a "name type" parameter:
|
||||
// - ID0: name
|
||||
// - ID1: package (optional)
|
||||
// - ID2: type
|
||||
// - RHS: <KType>
|
||||
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 }":
|
||||
// - ID0: receiver (optional)
|
||||
// - ID0: <0|receiver>
|
||||
// - ID1: name
|
||||
// - List0: <KParam> in-parameters
|
||||
// - List1: <KParam> out-parameters
|
||||
@@ -63,6 +79,7 @@ var kindStrings = [...]string{
|
||||
KInvalid: "KInvalid",
|
||||
KLiteral: "KLiteral",
|
||||
KParam: "KParam",
|
||||
KType: "KType",
|
||||
}
|
||||
|
||||
type Flags uint32
|
||||
|
||||
+28
-3
@@ -167,17 +167,42 @@ func (p *parser) parseParamList() ([]*a.Node, error) {
|
||||
}
|
||||
|
||||
func (p *parser) parseParam() (*a.Node, error) {
|
||||
id0, err := p.parseIdent()
|
||||
id, err := p.parseIdent()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id1, id2, err := p.parseQualifiedIdent()
|
||||
rhs, err := p.parseType()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &a.Node{
|
||||
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,
|
||||
ID2: id2,
|
||||
}, nil
|
||||
|
||||
@@ -132,6 +132,7 @@ const (
|
||||
|
||||
// TODO: sort these by name, when the list has stabilized.
|
||||
IDFunc = ID(0xA0<<idShift | FlagsOther)
|
||||
IDPtr = ID(0xA1<<idShift | FlagsOther)
|
||||
|
||||
IDFalse = ID(0xD0<<idShift | FlagsLiteral | FlagsImplicitSemicolon)
|
||||
IDTrue = ID(0xD1<<idShift | FlagsLiteral | FlagsImplicitSemicolon)
|
||||
@@ -206,6 +207,7 @@ var builtInsByKey = [nBuiltInKeys]struct {
|
||||
IDAs >> idShift: {"as", IDAs},
|
||||
|
||||
IDFunc >> idShift: {"func", IDFunc},
|
||||
IDPtr >> idShift: {"ptr", IDPtr},
|
||||
|
||||
IDFalse >> idShift: {"false", IDFalse},
|
||||
IDTrue >> idShift: {"true", IDTrue},
|
||||
|
||||
Reference in new issue
Block a user