alien.parser: array types where the base type was a pointer didn't parse (reported by Dmitry Shubin)

db4
Slava Pestov 2010-08-15 01:51:55 -07:00
parent cbb9ff61fb
commit e8152e9098
2 changed files with 15 additions and 7 deletions

View File

@ -23,6 +23,9 @@ CONSTANT: eleven 11
[ pointer: int* ] [ "int**" parse-c-type ] unit-test
[ pointer: int** ] [ "int***" parse-c-type ] unit-test
[ pointer: int*** ] [ "int****" parse-c-type ] unit-test
[ { pointer: int 3 } ] [ "int*[3]" parse-c-type ] unit-test
[ "void[3]" parse-c-type ] must-fail
[ { pointer: void 3 } ] [ "void*[3]" parse-c-type ] unit-test
[ c-string ] [ "c-string" parse-c-type ] unit-test
[ char2 ] [ "char2" parse-c-type ] unit-test
[ pointer: char2 ] [ "char2*" parse-c-type ] unit-test

View File

@ -12,21 +12,26 @@ SYMBOL: current-library
: parse-c-type-name ( name -- word )
dup search [ ] [ no-word ] ?if ;
: parse-array-type ( name -- dims c-type )
DEFER: (parse-c-type)
: parse-array-type ( name -- c-type )
"[" split unclip
[ [ "]" ?tail drop parse-word ] map ] dip ;
[ [ "]" ?tail drop parse-word ] map ] [ (parse-c-type) ] bi*
prefix ;
: (parse-c-type) ( string -- type )
{
{ [ dup "void" = ] [ drop void ] }
{ [ CHAR: ] over member? ] [ parse-array-type parse-c-type-name prefix ] }
{ [ "*" ?tail ] [ (parse-c-type) <pointer> ] }
{ [ dup search ] [ parse-c-type-name ] }
{ [ CHAR: ] over member? ] [ parse-array-type ] }
{ [ "*" ?tail ] [ (parse-c-type) <pointer> ] }
{ [ dup search ] [ parse-c-type-name ] }
[ dup search [ ] [ no-word ] ?if ]
} cond ;
: c-array? ( c-type -- ? )
{ [ array? ] [ first { [ c-type-word? ] [ pointer? ] } 1|| ] } 1&& ;
: valid-c-type? ( c-type -- ? )
{ [ array? ] [ c-type-word? ] [ pointer? ] [ void? ] } 1|| ;
{ [ c-array? ] [ c-type-word? ] [ pointer? ] [ void? ] } 1|| ;
: parse-c-type ( string -- type )
(parse-c-type) dup valid-c-type? [ no-c-type ] unless ;