dhscanner-kbgen 2.8.0 → 2.9.0
raw patch · 3 files changed
+63/−2 lines, 3 filesdep ~dhscanner-bitcodePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: dhscanner-bitcode
API changes (from Hackage documentation)
+ Kbgen: CallMethodOfReturnValue :: Call -> MethodName -> ReturnValue -> CallMethodOfReturnValue
+ Kbgen: CallMethodOfReturnValueCtor :: CallMethodOfReturnValue -> Fact
+ Kbgen: data CallMethodOfReturnValue
+ Kbgen: instance Data.Aeson.Types.FromJSON.FromJSON Kbgen.CallMethodOfReturnValue
+ Kbgen: instance Data.Aeson.Types.ToJSON.ToJSON Kbgen.CallMethodOfReturnValue
+ Kbgen: instance GHC.Internal.Classes.Eq Kbgen.CallMethodOfReturnValue
+ Kbgen: instance GHC.Internal.Classes.Ord Kbgen.CallMethodOfReturnValue
+ Kbgen: instance GHC.Internal.Generics.Generic Kbgen.CallMethodOfReturnValue
+ Kbgen: instance GHC.Internal.Show.Show Kbgen.CallMethodOfReturnValue
Files
- dhscanner-kbgen.cabal +2/−2
- src/Kbgen.hs +43/−0
- test/SmokeTests.hs +18/−0
dhscanner-kbgen.cabal view
@@ -33,7 +33,7 @@ * explain in plain English your query's purpose * et voilà ! -version: 2.8.0+version: 2.9.0 license: GPL-3.0-only license-file: LICENSE author: OrenGitHub@@ -63,7 +63,7 @@ containers >= 0.8 && < 0.9, text >= 2.0 && < 2.2, dhscanner-ast >= 1.6.0,- dhscanner-bitcode >= 2.4.0+ dhscanner-bitcode >= 2.5.0 hs-source-dirs: src
src/Kbgen.hs view
@@ -62,6 +62,7 @@ CallMethodOf1stPartyImportedName(..), FieldReadOf1stPartyImportedName(..), ReturnValueOfCall(..),+ CallMethodOfReturnValue(..), ImportedName(..), ImportedFromFile(..), ParamName(..),@@ -530,6 +531,41 @@ Call -- ^ deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON ) +-- |+--+-- __Name__+--+-- This is how the fact will look inside the Prolog file+--+-- @+-- kb_call_method_of_return_value( Call, Method, ReturnValue ).+-- @+--+-- __When should I use this fact__+--+-- A method called on the value another call returns, a chained call+-- @a()->m()@ : @Call@ is the call of @m@, @ReturnValue@ the value @a()@+-- returns ( the location of the call @a()@ ). It tells a receiver from an+-- argument, which a dataflow edge alone does not.+--+-- __Writing a predicate with this fact and others__+--+-- @+-- chained_method_of_1st_party_imported_name( Call, Method, First, Name ) :-+-- kb_call_method_of_return_value( Call, Method, ReturnValue ),+-- kb_call_method_of_1st_party_imported_name( ReturnValue, First, Name, _ ).+-- @+--+-- Other facts combined in this predicate:+--+-- * 'CallMethodOf1stPartyImportedName'+--+data CallMethodOfReturnValue = CallMethodOfReturnValue+ Call -- ^+ MethodName -- ^+ ReturnValue -- ^+ deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON )+ data AssignValueToToplevelVarName = AssignValueToToplevelVarName AssignedValue -- ^ Token.VarName -- ^@@ -1568,6 +1604,7 @@ | CallMethodOf1stPartyImportedNameCtor CallMethodOf1stPartyImportedName | FieldReadOf1stPartyImportedNameCtor FieldReadOf1stPartyImportedName | ReturnValueOfCallCtor ReturnValueOfCall+ | CallMethodOfReturnValueCtor CallMethodOfReturnValue | CallMethodOfUntypedNamedParamCtor CallMethodOfUntypedNamedParam deriving ( Show, Eq, Ord, Generic, ToJSON, FromJSON ) @@ -1618,6 +1655,7 @@ prologify (CallMethodOf1stPartyImportedNameCtor content) = prologify_CallMethodOf1stPartyImportedName content prologify (FieldReadOf1stPartyImportedNameCtor content) = prologify_FieldReadOf1stPartyImportedName content prologify (ReturnValueOfCallCtor content) = prologify_ReturnValueOfCall content+prologify (CallMethodOfReturnValueCtor content) = prologify_CallMethodOfReturnValue content prologify (CallMethodOfUntypedNamedParamCtor content) = prologify_CallMethodOfUntypedNamedParam content prologify_ParamResolvedType' :: Location -> String -> String@@ -1813,6 +1851,10 @@ prologify_ReturnValueOfCall (ReturnValueOfCall (ReturnValue v) (Call c)) = printf "kb_return_value_of_call( %s, %s )." (locationify v) (locationify c) +prologify_CallMethodOfReturnValue :: CallMethodOfReturnValue -> String+prologify_CallMethodOfReturnValue (CallMethodOfReturnValue (Call c) (MethodName m) (ReturnValue v)) =+ printf "kb_call_method_of_return_value( %s, '%s', %s )." (locationify c) (quoted m) (locationify v)+ prologify_Call1stPartyFuncDefinedInDir :: Call1stPartyFuncDefinedInDir -> String prologify_Call1stPartyFuncDefinedInDir (Call1stPartyFuncDefinedInDir call func d) = prologify_Call1stPartyFuncDefinedInDir' call func d @@ -1928,6 +1970,7 @@ prologifyFqn (Fqn.CallMethodOfUntypedNamedParam _ m (Token.ParamName (Token.Named p _))) = tagged "param" p ++ "." ++ m prologifyFqn (Fqn.CallFuncFromImportedDir _ f d) = tagged "1st-party-dir" d ++ "." ++ f prologifyFqn (Fqn.CallFuncFromImportedFile _ f file) = tagged "1st-party" file ++ "." ++ f+prologifyFqn (Fqn.ReturnTypeOf _ fqn) = prologifyFqn fqn prologifyFqn (Fqn.FirstPartyImport (Fqn.FirstPartyImportContent file name)) = tagged "1st-party" file ++ maybe "" ("." ++) name prologifyFqn (Fqn.FirstPartyDirImport (Fqn.FirstPartyDirImportContent d alias)) = tagged "1st-party-dir" d ++ maybe "" ("." ++) alias prologifyFqn Fqn.Unknown = "Unknown"
test/SmokeTests.hs view
@@ -6,6 +6,7 @@ , FieldReadOf1stPartyImportedName (..) , FieldName (..) , ReturnValueOfCall (..)+ , CallMethodOfReturnValue (..) , ReturnValue (..) , CallResolved (..) , ImportedFromFile (..)@@ -199,6 +200,21 @@ expected = "kb_return_value_of_call( " ++ locationify valueLoc ++ ", " ++ locationify callLoc ++ " )." in prologify (ReturnValueOfCallCtor r) `shouldBe` expected +testPrologifyCallMethodOfReturnValue :: IO ()+testPrologifyCallMethodOfReturnValue =+ let callLoc = sampleLoc 1+ valueLoc = sampleLoc 2+ c = CallMethodOfReturnValue (Call callLoc) (MethodName "normalize") (ReturnValue valueLoc)+ expected = "kb_call_method_of_return_value( " ++ locationify callLoc ++ ", 'normalize', " ++ locationify valueLoc ++ " )."+ in prologify (CallMethodOfReturnValueCtor c) `shouldBe` expected++-- the value a call returns spells as its callee+testPrologifyFqnReturnTypeOf :: IO ()+testPrologifyFqnReturnTypeOf =+ let util = Fqn.FirstPartyImport (Fqn.FirstPartyImportContent "src/Util/PathUtil.php" (Just "PathUtil"))+ fqn = Fqn.FieldedAccess (Fqn.ReturnTypeOf (sampleLoc 1) (Fqn.FieldedAccess util (member "create"))) (member "normalize")+ in prologifyFqn fqn `shouldBe` "<1st-party>[src/Util/PathUtil.php].PathUtil.create.normalize"+ -- a capitalized method name ( C# ) must not read as a Prolog variable testPrologifyCallResolvedMethodOfClassQuoted :: IO () testPrologifyCallResolvedMethodOfClassQuoted =@@ -233,6 +249,8 @@ it' testPrologifyCallMethodOf1stPartyImportedName "prologify_CallMethodOf1stPartyImportedName should render kb_call_method_of_1st_party_imported_name( <call>, '<method>', '<name>', '<file>' )." it' testPrologifyFieldReadOf1stPartyImportedName "prologify_FieldReadOf1stPartyImportedName should render kb_field_read_of_1st_party_imported_name( <field read>, '<field>', '<name>', '<file>' )." it' testPrologifyReturnValueOfCall "prologify_ReturnValueOfCall should render kb_return_value_of_call( <return value>, <call> )."+ it' testPrologifyCallMethodOfReturnValue "prologify_CallMethodOfReturnValue should render kb_call_method_of_return_value( <call>, '<method>', <return value> )."+ it' testPrologifyFqnReturnTypeOf "prologifyFqn spells ReturnTypeOf as its callee" it' testPrologifyCallResolvedMethodOfClassQuoted "kb_call_method_of_class quotes the method name" it' testPrologifyCallResolvedEscapesQuote "kb_call_resolved escapes a quote in the fqn" it' testCompletelyInvalidLocationString "completelyInvalidLocationString should return Nothing"