Skip to content

Commit

Permalink
fix: Adapt to nullptr now being a constant expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jan 23, 2024
1 parent f227200 commit 57baf99
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Tokstyle/Linter/MallocCall.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# OPTIONS_GHC -Wwarn #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE Strict #-}
Expand Down Expand Up @@ -56,16 +55,21 @@ lintAssign = astActions
_ -> act
}

pattern NullCheck :: Text -> Node (Lexeme Text)
pattern NullCheck ref <-
pattern NullCheck :: Text -> Node (Lexeme Text) -> Node (Lexeme Text)
pattern NullCheck ref nullptr <-
Fix (IfStmt
(Fix (BinaryExpr (Fix (VarExpr (L _ _ ref))) _ (Fix (VarExpr (L _ _ "nullptr")))))
(Fix (BinaryExpr (Fix (VarExpr (L _ _ ref))) _ nullptr))
(Fix (CompoundStmt _)) _)
pattern ConstNull, VarNull :: Node (Lexeme Text)
pattern ConstNull <- Fix (LiteralExpr _ (L _ _ "nullptr"))
pattern VarNull <- Fix (VarExpr (L _ _ "nullptr"))

lintCheck :: AstActions (State [Text]) Text
lintCheck = astActions
{ doNodes = \file nodes act -> case nodes of
(MallocVarDecl decl FunctionCast{}:ss@(NullCheck ref:_)) | decl == ref ->
(MallocVarDecl decl FunctionCast{}:ss@(NullCheck ref ConstNull:_)) | decl == ref ->
traverseAst lintCheck (file, ss)
(MallocVarDecl decl FunctionCast{}:ss@(NullCheck ref VarNull:_)) | decl == ref ->
traverseAst lintCheck (file, ss)
(MallocVarDecl decl (FunctionCast name):s:_) ->
warn file s $ "`" <> decl <> "`, assigned from `" <> name
Expand Down

0 comments on commit 57baf99

Please sign in to comment.