Skip to content

Commit

Permalink
feat: Add support for owner qualifiers on pointers.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Mar 6, 2024
1 parent c5e6d93 commit f7489fd
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Language/Cimple/Ast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ data NodeF lexeme a
| TyBitwise a
| TyForce a
| TyConst a
| TyOwner a
| TyPointer a
| TyStruct lexeme
| TyFunc lexeme
Expand Down
1 change: 1 addition & 0 deletions src/Language/Cimple/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ tokens :-
<0,ppSC> "if" { mkL KwIf }
<0,ppSC> "non_null" { mkL KwNonNull }
<0,ppSC> "nullable" { mkL KwNullable }
<0,ppSC> "owner" { mkL KwOwner }
<0,ppSC> "return" { mkL KwReturn }
<0,ppSC> "sizeof" { mkL KwSizeof }
<0,ppSC> "static" { mkL KwStatic }
Expand Down
2 changes: 2 additions & 0 deletions src/Language/Cimple/MapAst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ instance MapAst itext otext (Node (Lexeme itext)) where
Fix <$> (TyForce <$> recurse ty)
TyConst ty ->
Fix <$> (TyConst <$> recurse ty)
TyOwner ty ->
Fix <$> (TyOwner <$> recurse ty)
TyPointer ty ->
Fix <$> (TyPointer <$> recurse ty)
TyStruct name ->
Expand Down
11 changes: 10 additions & 1 deletion src/Language/Cimple/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import Language.Cimple.Tokens (LexemeClass (..))
if { L _ KwIf _ }
non_null { L _ KwNonNull _ }
nullable { L _ KwNullable _ }
owner { L _ KwOwner _ }
return { L _ KwReturn _ }
sizeof { L _ KwSizeof _ }
static { L _ KwStatic _ }
Expand Down Expand Up @@ -687,6 +688,13 @@ QualType
| const LeafType '*' const { tyConst (tyPointer (tyConst $2)) }
| const LeafType '*' const '*' { tyPointer (tyConst (tyPointer (tyConst $2))) }
| const LeafType '*' const '*' const { tyConst (tyPointer (tyConst (tyPointer (tyConst $2)))) }
| LeafType '*' owner { tyOwner (tyPointer $1) }
| LeafType '*' const owner { tyOwner (tyConst (tyPointer $1)) }
| LeafType '*' '*' owner { tyOwner (tyPointer (tyPointer $1)) }
| LeafType '*' owner '*' { tyPointer (tyOwner (tyPointer $1)) }
| LeafType '*' owner '*' owner { tyOwner (tyPointer (tyOwner (tyPointer $1))) }
-- This should really not exist, but NGC is playing fast and loose with ownership.
| const LeafType '*' owner { tyOwner (tyPointer (tyConst $2)) }

LeafType :: { NonTerm }
LeafType
Expand Down Expand Up @@ -762,9 +770,10 @@ ConstDecl
type Term = Lexeme Text
type NonTerm = Node Term

tyPointer, tyConst :: NonTerm -> NonTerm
tyPointer, tyConst, tyOwner :: NonTerm -> NonTerm
tyPointer = Fix . TyPointer
tyConst = Fix . TyConst
tyOwner = Fix . TyOwner

lexwrap :: (Lexeme Text -> Alex a) -> Alex a
lexwrap = (alexMonadScan >>=)
Expand Down
2 changes: 2 additions & 0 deletions src/Language/Cimple/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ kwGoto = dullred $ text "goto"
kwIf = dullred $ text "if"
kwNonNull = dullgreen $ text "non_null"
kwNullable = dullgreen $ text "nullable"
kwOwner = dullgreen $ text "owner"
kwReturn = dullred $ text "return"
kwSizeof = dullred $ text "sizeof"
kwStaticAssert = dullred $ text "static_assert"
Expand Down Expand Up @@ -408,6 +409,7 @@ ppNode = foldFix go
TyForce ty -> kwForce <+> ty
TyPointer ty -> ty <> char '*'
TyConst ty -> ty <+> kwConst
TyOwner ty -> ty <+> kwOwner
TyUserDefined l -> dullgreen $ ppLexeme l
TyStd l -> dullgreen $ ppLexeme l
TyFunc l -> dullgreen $ ppLexeme l
Expand Down
1 change: 1 addition & 0 deletions src/Language/Cimple/Tokens.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data LexemeClass
| KwIf
| KwNonNull
| KwNullable
| KwOwner
| KwReturn
| KwSizeof
| KwStatic
Expand Down
2 changes: 2 additions & 0 deletions src/Language/Cimple/TraverseAst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ instance TraverseAst text (Node (Lexeme text)) where
recurse ty
TyConst ty ->
recurse ty
TyOwner ty ->
recurse ty
TyPointer ty ->
recurse ty
TyStruct name ->
Expand Down

0 comments on commit f7489fd

Please sign in to comment.