Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for owner qualifiers on pointers. #109

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 8 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,11 @@ 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))) }

LeafType :: { NonTerm }
LeafType
Expand Down Expand Up @@ -762,9 +768,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
4 changes: 3 additions & 1 deletion src/Language/Cimple/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
UnaryOp (..), lexemeLine,
lexemeText)
import Prelude hiding ((<$>))
import Text.PrettyPrint.ANSI.Leijen

Check warning on line 25 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

Module ‘Text.PrettyPrint.ANSI.Leijen’ is deprecated:

indentWidth :: Int
indentWidth = 2

kwBitwise = dullgreen $ text "bitwise"

Check warning on line 30 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘dullgreen’

Check warning on line 30 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘text’ (imported from Text.PrettyPrint.ANSI.Leijen):
kwBreak = dullred $ text "break"

Check warning on line 31 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘dullred’

Check warning on line 31 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘text’ (imported from Text.PrettyPrint.ANSI.Leijen):
kwCase = dullred $ text "case"

Check warning on line 32 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘dullred’

Check warning on line 32 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘text’ (imported from Text.PrettyPrint.ANSI.Leijen):
kwConst = dullgreen $ text "const"

Check warning on line 33 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘dullgreen’

Check warning on line 33 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘text’ (imported from Text.PrettyPrint.ANSI.Leijen):
kwContinue = dullred $ text "continue"

Check warning on line 34 in src/Language/Cimple/Pretty.hs

View workflow job for this annotation

GitHub Actions / publish / Publish to Hackage

In the use of ‘dullred’
kwDefault = dullred $ text "default"
kwDo = dullred $ text "do"
kwElse = dullred $ text "else"
Expand All @@ -44,6 +44,7 @@
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 @@ -153,7 +154,7 @@

spaceWords = \case
(L c p s:ws) -> L c p (" "<>s):continue ws
[] -> []
[] -> []
where
continue [] = []
continue (w@(L _ CmtEnd _):ws) = w:continue ws
Expand Down Expand Up @@ -408,6 +409,7 @@
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
1 change: 1 addition & 0 deletions test/Language/CimpleSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sampleToken c = case c of
KwIf -> "if"
KwNonNull -> "non_null"
KwNullable -> "nullable"
KwOwner -> "owner"
KwReturn -> "return"
KwSizeof -> "sizeof"
KwStatic -> "static"
Expand Down
Loading