From 056a47ab5a7c24495d6e1ebe9da1b6c7173a0527 Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Wed, 19 Feb 2020 15:57:42 -0500 Subject: [PATCH] Tag functions, methods, and their calls. --- semantic-php/src/Language/PHP/Tags.hs | 34 ++++++++++++++++++++++++--- test/fixtures/php/analysis/foo.php | 2 ++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/semantic-php/src/Language/PHP/Tags.hs b/semantic-php/src/Language/PHP/Tags.hs index 1c98b0814..0fe8dbb26 100644 --- a/semantic-php/src/Language/PHP/Tags.hs +++ b/semantic-php/src/Language/PHP/Tags.hs @@ -2,6 +2,7 @@ {-# LANGUAGE DisambiguateRecordFields #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE OverloadedLists #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} module Language.PHP.Tags (tags) where @@ -57,10 +58,40 @@ yieldTag name kind loc range = do instance ToTags PHP.FunctionDefinition where tags t@PHP.FunctionDefinition + { PHP.ann = loc@Loc { byteRange } + , PHP.name = PHP.Name { text } + } = yieldTag text Method loc byteRange >> gtags t + +instance ToTags PHP.MethodDeclaration where + tags t@PHP.MethodDeclaration { PHP.ann = loc@Loc { byteRange } , PHP.name = PHP.Name { text } } = yieldTag text Function loc byteRange >> gtags t +instance ToTags PHP.FunctionCallExpression where + tags t@PHP.FunctionCallExpression + { PHP.ann = loc@Loc { byteRange } + , PHP.function = func + } = match func + where + yield name = yieldTag name Call loc byteRange >> gtags t + match expr = case expr of + Prj (PHP.VariableName { extraChildren = PHP.Name { text } }) + -> yield text *> gtags t + Prj (PHP.QualifiedName { extraChildren = [Prj (PHP.Name { text })] }) + -> yield text *> gtags t + _ + -> gtags t + +instance ToTags PHP.MemberCallExpression where + tags t@PHP.MemberCallExpression + { PHP.ann = loc@Loc { byteRange } + , PHP.name = item + } = case item of + Prj (PHP.Name { text }) -> yieldTag text Call loc byteRange >> gtags t + _ -> gtags t + + instance ToTags PHP.AnonymousFunctionCreationExpression instance ToTags PHP.AnonymousFunctionUseClause instance ToTags PHP.Arguments @@ -105,7 +136,6 @@ instance ToTags PHP.Float instance ToTags PHP.ForStatement instance ToTags PHP.ForeachStatement instance ToTags PHP.FormalParameters -instance ToTags PHP.FunctionCallExpression instance ToTags PHP.FunctionStaticDeclaration instance ToTags PHP.GlobalDeclaration instance ToTags PHP.GotoStatement @@ -118,8 +148,6 @@ instance ToTags PHP.InterfaceDeclaration instance ToTags PHP.ListLiteral instance ToTags PHP.Literal instance ToTags PHP.MemberAccessExpression -instance ToTags PHP.MemberCallExpression -instance ToTags PHP.MethodDeclaration instance ToTags PHP.Name instance ToTags PHP.NamedLabelStatement instance ToTags PHP.NamespaceAliasingClause diff --git a/test/fixtures/php/analysis/foo.php b/test/fixtures/php/analysis/foo.php index 64c09f591..eeb94bc17 100644 --- a/test/fixtures/php/analysis/foo.php +++ b/test/fixtures/php/analysis/foo.php @@ -2,3 +2,5 @@ function foo() { return 1; } + +foo()