From e788ed9baabfc1adf0eadd3d45804563c3c2bb9c Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Wed, 5 Sep 2018 11:13:35 -0700 Subject: [PATCH 01/39] First pass at returning adjacency graphs (JSON) as an alternative to trees --- src/Data/Graph.hs | 12 ++++--- src/Data/Graph/Vertex.hs | 4 +++ src/Rendering/Graph.hs | 74 ++++++++++++++++++++++++++++----------- src/Rendering/JSON.hs | 10 ++++++ src/Rendering/Renderer.hs | 4 +++ src/Semantic/CLI.hs | 1 + src/Semantic/Parse.hs | 8 ++++- 7 files changed, 88 insertions(+), 25 deletions(-) diff --git a/src/Data/Graph.hs b/src/Data/Graph.hs index 8dba6d352..06e86c699 100644 --- a/src/Data/Graph.hs +++ b/src/Data/Graph.hs @@ -7,6 +7,7 @@ module Data.Graph , Lower(..) , simplify , topologicalSort +, JSONVertex(..) ) where import qualified Algebra.Graph as G @@ -106,12 +107,15 @@ instance Ord vertex => Ord (Graph vertex) where compare (Graph (G.Connect a1 a2)) (Graph (G.Connect b1 b2)) = (compare `on` Graph) a1 b1 <> (compare `on` Graph) a2 b2 -instance (Ord vertex, ToJSON vertex) => ToJSON (Graph vertex) where +class JSONVertex vertex where + jsonVertexId :: vertex -> Text + +instance (Ord vertex, ToJSON vertex, JSONVertex vertex) => ToJSON (Graph vertex) where toJSON (Graph graph) = object ["vertices" .= G.vertexList graph, "edges" .= (JSONEdge <$> G.edgeList graph)] toEncoding (Graph graph) = pairs ("vertices" .= G.vertexList graph <> "edges" .= (JSONEdge <$> G.edgeList graph)) newtype JSONEdge vertex = JSONEdge (vertex, vertex) -instance ToJSON vertex => ToJSON (JSONEdge vertex) where - toJSON (JSONEdge (a, b)) = object ["source" .= a, "target" .= b] - toEncoding (JSONEdge (a, b)) = pairs ("source" .= a <> "target" .= b) +instance (ToJSON vertex, JSONVertex vertex) => ToJSON (JSONEdge vertex) where + toJSON (JSONEdge (a, b)) = object ["source" .= jsonVertexId a, "target" .= jsonVertexId b] + toEncoding (JSONEdge (a, b)) = pairs ("source" .= jsonVertexId a <> "target" .= jsonVertexId b) diff --git a/src/Data/Graph/Vertex.hs b/src/Data/Graph/Vertex.hs index 613042c01..31ca59218 100644 --- a/src/Data/Graph/Vertex.hs +++ b/src/Data/Graph/Vertex.hs @@ -22,6 +22,7 @@ import Data.Abstract.Package (PackageInfo (..)) import Data.Aeson import Data.Record import Data.Span +import Data.Graph (JSONVertex(..)) import qualified Data.Syntax as Syntax import qualified Data.Syntax.Declaration as Declaration import qualified Data.Syntax.Expression as Expression @@ -83,6 +84,9 @@ vertexToType Function{} = "Function" instance Lower Vertex where lowerBound = Package "" +instance JSONVertex Vertex where + jsonVertexId = vertexIdentifier + class VertexDeclaration syntax where toVertex :: (Declarations1 syntax, Foldable syntax, HasField fields Span) => Record fields diff --git a/src/Rendering/Graph.hs b/src/Rendering/Graph.hs index 294b3deca..ebd463279 100644 --- a/src/Rendering/Graph.hs +++ b/src/Rendering/Graph.hs @@ -8,13 +8,19 @@ module Rendering.Graph , DiffTag(..) ) where +import Data.Aeson +import Data.JSON.Fields import Algebra.Graph.Export.Dot import Analysis.ConstructorName import Control.Monad.Effect import Control.Monad.Effect.Fresh import Control.Monad.Effect.Reader +import qualified Data.Text as T import Data.Diff import Data.Graph +import Data.Range +import Data.Span +import Data.Record import Data.Patch import Data.String (IsString(..)) import Data.Term @@ -27,14 +33,21 @@ runGraph :: Eff '[Reader (Graph vertex), Fresh] (Graph vertex) -> Graph vertex runGraph = run . runFresh 0 . runReader mempty -termAlgebra :: (ConstructorName syntax, Foldable syntax, Member Fresh effs, Member (Reader (Graph (TaggedVertex tag))) effs) - => tag - -> TermF syntax ann (Eff effs (Graph (TaggedVertex tag))) - -> Eff effs (Graph (TaggedVertex tag)) -termAlgebra t (In _ syntax) = do +termAlgebra :: + ( ConstructorName syntax + , HasField fields Range + , HasField fields Span + , Foldable syntax + , Member Fresh effs + , Member (Reader (Graph (TaggedVertex tag))) effs + ) + => tag + -> TermF syntax (Record fields) (Eff effs (Graph (TaggedVertex tag))) + -> Eff effs (Graph (TaggedVertex tag)) +termAlgebra t (In ann syntax) = do i <- fresh parent <- ask - let root = vertex (TaggedVertex i t (constructorName syntax)) + let root = vertex (TaggedVertex i t (constructorName syntax) (getField ann) (getField ann)) subGraph <- foldl' (\acc x -> overlay <$> acc <*> local (const root) x) (pure mempty) syntax pure (parent `connect` root `overlay` subGraph) @@ -43,7 +56,7 @@ style name tagAttributes = (defaultStyle (fromString . show . vertexId)) { graphName = fromString (quote name) , vertexAttributes = vertexAttributes } where quote a = "\"" <> a <> "\"" - vertexAttributes TaggedVertex{..} = "label" := fromString vertexName : tagAttributes vertexTag + vertexAttributes TaggedVertex{..} = "label" := fromString vertexTermName : tagAttributes vertexTag termStyle :: (IsString string, Monoid string) => String -> Style (TaggedVertex ()) string termStyle name = style name (const []) @@ -55,8 +68,28 @@ diffStyle name = style name diffTagAttributes diffTagAttributes Replaced = ["color" := "orange", "style" := "dashed"] diffTagAttributes _ = [] -data TaggedVertex tag = TaggedVertex { vertexId :: Int, vertexTag :: tag, vertexName :: String } - deriving (Eq, Ord, Show) +data TaggedVertex tag + = TaggedVertex + { vertexId :: Int + , vertexTag :: tag + , vertexTermName :: String + , vertexRange :: Range + , vertexSpan :: Span + } deriving (Eq, Ord, Show) + +instance ToJSON (TaggedVertex ()) where + toJSON TaggedVertex{..} + = object $ [ "id" .= T.pack (show vertexId) + , "term" .= vertexTermName ] + <> toJSONFields vertexRange + <> toJSONFields vertexSpan + -- toEncoding TaggedVertex{..} + -- = pairs ( "id" .= T.pack (show vertexId) + -- <> "name" .= vertexTermName + -- <> toJSONFields vertexRange ) + +instance JSONVertex (TaggedVertex ()) where + jsonVertexId = T.pack . show . vertexId data DiffTag = Deleted | Inserted | Replaced | Merged deriving (Eq, Ord, Show) @@ -65,17 +98,18 @@ data DiffTag = Deleted | Inserted | Replaced | Merged class ToTreeGraph vertex t | t -> vertex where toTreeGraph :: (Member Fresh effs, Member (Reader (Graph vertex)) effs) => t (Eff effs (Graph vertex)) -> Eff effs (Graph vertex) -instance (ConstructorName syntax, Foldable syntax) => ToTreeGraph (TaggedVertex ()) (TermF syntax ann) where +instance (ConstructorName syntax, Foldable syntax, HasField fields Range, HasField fields Span) => ToTreeGraph (TaggedVertex ()) (TermF syntax (Record fields)) where toTreeGraph = termAlgebra () instance (ConstructorName syntax, Foldable syntax) => ToTreeGraph (TaggedVertex DiffTag) (DiffF syntax ann1 ann2) where - toTreeGraph d = case d of - Merge t -> termAlgebra Merged t - Patch (Delete t1) -> termAlgebra Deleted t1 - Patch (Insert t2) -> termAlgebra Inserted t2 - Patch (Replace t1 t2) -> do - i <- fresh - parent <- ask - let replace = vertex (TaggedVertex i Replaced "Replacement") - graph <- local (const replace) (overlay <$> termAlgebra Deleted t1 <*> termAlgebra Inserted t2) - pure (parent `connect` replace `overlay` graph) + toTreeGraph = undefined + -- toTreeGraph d = case d of + -- Merge t -> termAlgebra Merged t + -- Patch (Delete t1) -> termAlgebra Deleted t1 + -- Patch (Insert t2) -> termAlgebra Inserted t2 + -- Patch (Replace t1 t2) -> do + -- i <- fresh + -- parent <- ask + -- let replace = vertex (TaggedVertex i Replaced "Replacement") + -- graph <- local (const replace) (overlay <$> termAlgebra Deleted t1 <*> termAlgebra Inserted t2) + -- pure (parent `connect` replace `overlay` graph) diff --git a/src/Rendering/JSON.hs b/src/Rendering/JSON.hs index c8a2b090d..a4343111e 100644 --- a/src/Rendering/JSON.hs +++ b/src/Rendering/JSON.hs @@ -3,6 +3,7 @@ module Rendering.JSON ( JSON(..) , renderJSONDiff , renderJSONTerm +, renderJSONAdjGraph , renderJSONAST , renderSymbolTerms , renderJSONError @@ -55,6 +56,15 @@ instance ToJSON a => ToJSON (JSONTerm a) where toJSON JSONTerm{..} = object ("tree" .= jsonTerm : toJSONFields jsonTermBlob) toEncoding JSONTerm{..} = pairs (fold ("tree" .= jsonTerm : toJSONFields jsonTermBlob)) +renderJSONAdjGraph :: ToJSON a => Blob -> a -> JSON "graphs" SomeJSON +renderJSONAdjGraph blob content = JSON [ SomeJSON (JSONAdjTerm blob content) ] + +data JSONAdjTerm a = JSONAdjTerm { jsonAdjTermBlob :: Blob, jsonAdjTerm :: a } + deriving (Eq, Show) + +instance ToJSON a => ToJSON (JSONAdjTerm a) where + toJSON JSONAdjTerm{..} = object ("graph" .= jsonAdjTerm : toJSONFields jsonAdjTermBlob) + toEncoding JSONAdjTerm{..} = pairs (fold ("graph" .= jsonAdjTerm : toJSONFields jsonAdjTermBlob)) renderJSONAST :: ToJSON a => Blob -> a -> JSON "trees" SomeJSON renderJSONAST blob content = JSON [ SomeJSON (JSONAST blob content) ] diff --git a/src/Rendering/Renderer.hs b/src/Rendering/Renderer.hs index 3884a7e9c..7eafe867d 100644 --- a/src/Rendering/Renderer.hs +++ b/src/Rendering/Renderer.hs @@ -4,6 +4,7 @@ module Rendering.Renderer , TermRenderer(..) , renderJSONDiff , renderJSONTerm +, renderJSONAdjGraph , renderJSONAST , renderToCDiff , renderRPCToCDiff @@ -46,6 +47,9 @@ deriving instance Show (DiffRenderer output) data TermRenderer output where -- | Render to JSON with the format documented in docs/json-format.md under “Term.” JSONTermRenderer :: TermRenderer (JSON "trees" SomeJSON) + + JSONAdjTermRenderer :: TermRenderer (JSON "trees" SomeJSON) + -- | Render to a 'ByteString' formatted as nested s-expressions. SExpressionTermRenderer :: TermRenderer Builder -- | Render to a list of symbols. diff --git a/src/Semantic/CLI.hs b/src/Semantic/CLI.hs index a24d4e7f9..4967d3883 100644 --- a/src/Semantic/CLI.hs +++ b/src/Semantic/CLI.hs @@ -72,6 +72,7 @@ parseCommand = command "parse" (info parseArgumentsParser (progDesc "Generate pa parseArgumentsParser = do renderer <- flag (Parse.runParse SExpressionTermRenderer) (Parse.runParse SExpressionTermRenderer) (long "sexpression" <> help "Output s-expression parse trees (default)") <|> flag' (Parse.runParse JSONTermRenderer) (long "json" <> help "Output JSON parse trees") + <|> flag' (Parse.runParse JSONAdjTermRenderer) (long "json-adj" <> help "Output JSON adjacency list") <|> flag' (Parse.runParse . SymbolsTermRenderer) (long "symbols" <> help "Output JSON symbol list") <*> (option symbolFieldsReader ( long "fields" <> help "Comma delimited list of specific fields to return (symbols output only)." diff --git a/src/Semantic/Parse.hs b/src/Semantic/Parse.hs index bdda0155a..df1a106b3 100644 --- a/src/Semantic/Parse.hs +++ b/src/Semantic/Parse.hs @@ -29,8 +29,14 @@ import qualified Language.TypeScript.Assignment as TypeScript import qualified Language.JSON.Assignment as JSON import qualified Language.Python.Assignment as Python +import Rendering.JSON (SomeJSON(..)) +import qualified Rendering.JSON as JSON + runParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) => TermRenderer output -> [Blob] -> Eff effs Builder -runParse JSONTermRenderer = withParsedBlobs renderJSONError (render . renderJSONTerm) >=> serialize JSON +runParse JSONTermRenderer = withParsedBlobs renderJSONError (render . renderJSONTerm) >=> serialize JSON +runParse JSONAdjTermRenderer = withParsedBlobs (\_ _ -> mempty) (render . renderAdjGraph) >=> serialize JSON + where renderAdjGraph :: (Recursive t, ToTreeGraph (TaggedVertex ()) (Base t)) => Blob -> t -> JSON.JSON "graphs" SomeJSON + renderAdjGraph blob term = renderJSONAdjGraph blob (renderTreeGraph term) runParse SExpressionTermRenderer = withParsedBlobs (\_ _ -> mempty) (const (serialize (SExpression ByConstructorName))) runParse ShowTermRenderer = withParsedBlobs (\_ _ -> mempty) (const (serialize Show . quieterm)) runParse (SymbolsTermRenderer fields) = withParsedBlobs (\_ _ -> mempty) (\ blob -> decorate (declarationAlgebra blob) >=> render (renderSymbolTerms . renderToSymbols fields blob)) >=> serialize JSON From 018f78bd42d02256ebeb3d8953af065215f07f0a Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Wed, 5 Sep 2018 12:28:44 -0700 Subject: [PATCH 02/39] Enable toEncoding as well --- src/Rendering/Graph.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Rendering/Graph.hs b/src/Rendering/Graph.hs index ebd463279..ec2b35354 100644 --- a/src/Rendering/Graph.hs +++ b/src/Rendering/Graph.hs @@ -83,10 +83,10 @@ instance ToJSON (TaggedVertex ()) where , "term" .= vertexTermName ] <> toJSONFields vertexRange <> toJSONFields vertexSpan - -- toEncoding TaggedVertex{..} - -- = pairs ( "id" .= T.pack (show vertexId) - -- <> "name" .= vertexTermName - -- <> toJSONFields vertexRange ) + toEncoding TaggedVertex{..} + = pairs ( fold ( "id" .= T.pack (show vertexId) + : "name" .= vertexTermName + : toJSONFields vertexRange ) ) instance JSONVertex (TaggedVertex ()) where jsonVertexId = T.pack . show . vertexId From 7ccabb06ed3618bc06f094faad4715d8d9e1bc70 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Wed, 5 Sep 2018 12:29:04 -0700 Subject: [PATCH 03/39] Use trees key to get error messages working for free --- src/Rendering/JSON.hs | 2 +- src/Semantic/Parse.hs | 47 +++++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/Rendering/JSON.hs b/src/Rendering/JSON.hs index a4343111e..60f753abd 100644 --- a/src/Rendering/JSON.hs +++ b/src/Rendering/JSON.hs @@ -56,7 +56,7 @@ instance ToJSON a => ToJSON (JSONTerm a) where toJSON JSONTerm{..} = object ("tree" .= jsonTerm : toJSONFields jsonTermBlob) toEncoding JSONTerm{..} = pairs (fold ("tree" .= jsonTerm : toJSONFields jsonTermBlob)) -renderJSONAdjGraph :: ToJSON a => Blob -> a -> JSON "graphs" SomeJSON +renderJSONAdjGraph :: ToJSON a => Blob -> a -> JSON "trees" SomeJSON renderJSONAdjGraph blob content = JSON [ SomeJSON (JSONAdjTerm blob content) ] data JSONAdjTerm a = JSONAdjTerm { jsonAdjTermBlob :: Blob, jsonAdjTerm :: a } diff --git a/src/Semantic/Parse.hs b/src/Semantic/Parse.hs index df1a106b3..e42e2427b 100644 --- a/src/Semantic/Parse.hs +++ b/src/Semantic/Parse.hs @@ -7,35 +7,34 @@ module Semantic.Parse , runJSONParse ) where -import Analysis.ConstructorName (ConstructorName) -import Analysis.Declaration (HasDeclaration, declarationAlgebra) -import Analysis.PackageDef (HasPackageDef) -import Control.Monad.Effect.Exception -import Data.AST -import Data.Blob -import Data.JSON.Fields -import Data.Quieterm -import Data.Record -import Data.Term -import Parsing.Parser -import Prologue hiding (MonadError(..)) -import Rendering.Graph -import Rendering.Renderer -import Semantic.IO (noLanguageForBlob) -import Semantic.Task -import Serializing.Format -import qualified Language.Ruby.Assignment as Ruby -import qualified Language.TypeScript.Assignment as TypeScript +import Analysis.ConstructorName (ConstructorName) +import Analysis.Declaration (HasDeclaration, declarationAlgebra) +import Analysis.PackageDef (HasPackageDef) +import Control.Monad.Effect.Exception +import Data.AST +import Data.Blob +import Data.JSON.Fields +import Data.Quieterm +import Data.Record +import Data.Term import qualified Language.JSON.Assignment as JSON import qualified Language.Python.Assignment as Python - -import Rendering.JSON (SomeJSON(..)) +import qualified Language.Ruby.Assignment as Ruby +import qualified Language.TypeScript.Assignment as TypeScript +import Parsing.Parser +import Prologue hiding (MonadError (..)) +import Rendering.Graph +import Rendering.JSON (SomeJSON (..)) import qualified Rendering.JSON as JSON +import Rendering.Renderer +import Semantic.IO (noLanguageForBlob) +import Semantic.Task +import Serializing.Format runParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) => TermRenderer output -> [Blob] -> Eff effs Builder -runParse JSONTermRenderer = withParsedBlobs renderJSONError (render . renderJSONTerm) >=> serialize JSON -runParse JSONAdjTermRenderer = withParsedBlobs (\_ _ -> mempty) (render . renderAdjGraph) >=> serialize JSON - where renderAdjGraph :: (Recursive t, ToTreeGraph (TaggedVertex ()) (Base t)) => Blob -> t -> JSON.JSON "graphs" SomeJSON +runParse JSONTermRenderer = withParsedBlobs renderJSONError (render . renderJSONTerm) >=> serialize JSON +runParse JSONAdjTermRenderer = withParsedBlobs renderJSONError (render . renderAdjGraph) >=> serialize JSON + where renderAdjGraph :: (Recursive t, ToTreeGraph (TaggedVertex ()) (Base t)) => Blob -> t -> JSON.JSON "trees" SomeJSON renderAdjGraph blob term = renderJSONAdjGraph blob (renderTreeGraph term) runParse SExpressionTermRenderer = withParsedBlobs (\_ _ -> mempty) (const (serialize (SExpression ByConstructorName))) runParse ShowTermRenderer = withParsedBlobs (\_ _ -> mempty) (const (serialize Show . quieterm)) From 18c0554864b6ac150e8050ddf60579f4e50986fe Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Wed, 5 Sep 2018 12:29:08 -0700 Subject: [PATCH 04/39] Docs --- src/Rendering/Renderer.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Rendering/Renderer.hs b/src/Rendering/Renderer.hs index 7eafe867d..a50cfa216 100644 --- a/src/Rendering/Renderer.hs +++ b/src/Rendering/Renderer.hs @@ -47,9 +47,8 @@ deriving instance Show (DiffRenderer output) data TermRenderer output where -- | Render to JSON with the format documented in docs/json-format.md under “Term.” JSONTermRenderer :: TermRenderer (JSON "trees" SomeJSON) - + -- | Render to JSON as an adjacency list represenation. JSONAdjTermRenderer :: TermRenderer (JSON "trees" SomeJSON) - -- | Render to a 'ByteString' formatted as nested s-expressions. SExpressionTermRenderer :: TermRenderer Builder -- | Render to a list of symbols. From e3f20f6903ce6be29c6cef657e00ca698140612c Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Wed, 5 Sep 2018 15:08:58 -0700 Subject: [PATCH 05/39] Implement adj list diff tree JSON responses Co-Authored-By: Rick Winfrey --- src/Rendering/Graph.hs | 214 +++++++++++++++++++++++++++----------- src/Rendering/JSON.hs | 18 +++- src/Rendering/Renderer.hs | 9 +- src/Semantic/CLI.hs | 1 + src/Semantic/Diff.hs | 5 + src/Semantic/Parse.hs | 4 +- 6 files changed, 182 insertions(+), 69 deletions(-) diff --git a/src/Rendering/Graph.hs b/src/Rendering/Graph.hs index ec2b35354..9a78f9924 100644 --- a/src/Rendering/Graph.hs +++ b/src/Rendering/Graph.hs @@ -4,8 +4,8 @@ module Rendering.Graph , termStyle , diffStyle , ToTreeGraph(..) -, TaggedVertex(..) -, DiffTag(..) +, TermVertex(..) +, DiffVertex(..) ) where import Data.Aeson @@ -32,84 +32,176 @@ renderTreeGraph = simplify . runGraph . cata toTreeGraph runGraph :: Eff '[Reader (Graph vertex), Fresh] (Graph vertex) -> Graph vertex runGraph = run . runFresh 0 . runReader mempty - -termAlgebra :: - ( ConstructorName syntax - , HasField fields Range - , HasField fields Span - , Foldable syntax - , Member Fresh effs - , Member (Reader (Graph (TaggedVertex tag))) effs - ) - => tag - -> TermF syntax (Record fields) (Eff effs (Graph (TaggedVertex tag))) - -> Eff effs (Graph (TaggedVertex tag)) -termAlgebra t (In ann syntax) = do - i <- fresh - parent <- ask - let root = vertex (TaggedVertex i t (constructorName syntax) (getField ann) (getField ann)) - subGraph <- foldl' (\acc x -> overlay <$> acc <*> local (const root) x) (pure mempty) syntax - pure (parent `connect` root `overlay` subGraph) - -style :: (IsString string, Monoid string) => String -> (tag -> [Attribute string]) -> Style (TaggedVertex tag) string -style name tagAttributes = (defaultStyle (fromString . show . vertexId)) +-- | GraphViz styling for terms +termStyle :: (IsString string, Monoid string) => String -> Style TermVertex string +termStyle name = (defaultStyle (fromString . show . vertexId)) { graphName = fromString (quote name) , vertexAttributes = vertexAttributes } where quote a = "\"" <> a <> "\"" - vertexAttributes TaggedVertex{..} = "label" := fromString vertexTermName : tagAttributes vertexTag + vertexAttributes TermVertex{..} = ["label" := fromString vertexTermName] -termStyle :: (IsString string, Monoid string) => String -> Style (TaggedVertex ()) string -termStyle name = style name (const []) +-- | Graphviz styling for diffs +diffStyle :: (IsString string, Monoid string) => String -> Style DiffVertex string +diffStyle name = (defaultStyle (fromString . show . diffVertexId)) + { graphName = fromString (quote name) + , vertexAttributes = vertexAttributes } + where quote a = "\"" <> a <> "\"" + vertexAttributes (DiffVertex _ (Deleted DeletedTerm{..})) = [ "label" := fromString deletedTermName, "color" := "red" ] + vertexAttributes (DiffVertex _ (Inserted InsertedTerm{..})) = [ "label" := fromString insertedTermName, "color" := "green" ] + vertexAttributes (DiffVertex _ (Replaced ReplacedTerm{..})) = [ "label" := "Replacement", "color" := "orange", "style" := "dashed" ] + vertexAttributes (DiffVertex _ (Merged MergedTerm{..})) = [ "label" := fromString mergedTermName ] -diffStyle :: (IsString string, Monoid string) => String -> Style (TaggedVertex DiffTag) string -diffStyle name = style name diffTagAttributes - where diffTagAttributes Deleted = ["color" := "red"] - diffTagAttributes Inserted = ["color" := "green"] - diffTagAttributes Replaced = ["color" := "orange", "style" := "dashed"] - diffTagAttributes _ = [] - -data TaggedVertex tag - = TaggedVertex +data TermVertex + = TermVertex { vertexId :: Int - , vertexTag :: tag , vertexTermName :: String , vertexRange :: Range , vertexSpan :: Span } deriving (Eq, Ord, Show) -instance ToJSON (TaggedVertex ()) where - toJSON TaggedVertex{..} - = object $ [ "id" .= T.pack (show vertexId) - , "term" .= vertexTermName ] +data TermAnnotation + = TermAnnotation + { range :: Range + , span :: Span + } deriving (Eq, Ord, Show) + +instance ToJSON TermAnnotation where + toJSON TermAnnotation{..} = object $ toJSONFields range <> toJSONFields span + +instance ToJSONFields TermAnnotation where + toJSONFields TermAnnotation{..} = toJSONFields range <> toJSONFields span + +data MergedTerm + = MergedTerm + { mergedTermName :: String + , mergedTermBefore :: TermAnnotation + , mergedTermAfter :: TermAnnotation + } deriving (Eq, Ord, Show) + +instance ToJSON MergedTerm where + toJSON MergedTerm{..} = object [ "term" .= mergedTermName, "before" .= mergedTermBefore, "after" .= mergedTermAfter ] + +data DeletedTerm + = DeletedTerm + { deletedTermName :: String + , deletedTermBefore :: TermAnnotation + } deriving (Eq, Ord, Show) + +instance ToJSON DeletedTerm where + toJSON DeletedTerm{..} = object [ "term" .= deletedTermName, "before" .= deletedTermBefore ] + +data InsertedTerm + = InsertedTerm + { insertedTermName :: String + , insertedTermAfter :: TermAnnotation + } deriving (Eq, Ord, Show) + +instance ToJSON InsertedTerm where + toJSON InsertedTerm{..} = object [ "term" .= insertedTermName, "after" .= insertedTermAfter ] + +data ReplacedTerm + = ReplacedTerm + { replacedTermBefore :: DeletedTerm + , replacedTermAfter :: InsertedTerm + } deriving (Eq, Ord, Show) + +instance ToJSON ReplacedTerm where + toJSON (ReplacedTerm DeletedTerm{..} InsertedTerm{..}) + = object [ "before" .= deleted, "after" .= inserted ] + where deleted = object $ [ "term" .= deletedTermName ] <> toJSONFields deletedTermBefore + inserted = object $ [ "term" .= insertedTermName ] <> toJSONFields insertedTermAfter + +data DiffVertexTerm + = Deleted DeletedTerm + | Inserted InsertedTerm + | Replaced ReplacedTerm + | Merged MergedTerm + deriving (Eq, Ord, Show) + +data DiffVertex + = DiffVertex + { diffVertexId :: Int + , diffVertexTerm :: DiffVertexTerm + } deriving (Eq, Ord, Show) + +instance ToJSON TermVertex where + toJSON TermVertex{..} + = object $ [ "id" .= T.pack (show vertexId) + , "term" .= vertexTermName ] <> toJSONFields vertexRange <> toJSONFields vertexSpan - toEncoding TaggedVertex{..} - = pairs ( fold ( "id" .= T.pack (show vertexId) - : "name" .= vertexTermName - : toJSONFields vertexRange ) ) + toEncoding TermVertex{..} + = pairs ( fold ( "id" .= T.pack (show vertexId) + : "name" .= vertexTermName + : toJSONFields vertexRange + <> toJSONFields vertexSpan )) -instance JSONVertex (TaggedVertex ()) where + +instance JSONVertex TermVertex where jsonVertexId = T.pack . show . vertexId -data DiffTag = Deleted | Inserted | Replaced | Merged - deriving (Eq, Ord, Show) +instance ToJSON DiffVertex where + toJSON (DiffVertex i (Deleted t)) = object [ "id" .= T.pack (show i), "deleted" .= t ] + toJSON (DiffVertex i (Inserted t)) = object [ "id" .= T.pack (show i), "inserted" .= t ] + toJSON (DiffVertex i (Replaced t)) = object [ "id" .= T.pack (show i), "replaced" .= t ] + toJSON (DiffVertex i (Merged t)) = object [ "id" .= T.pack (show i), "merged" .= t ] + -- TODO + -- toEncoding = undefined + + +instance JSONVertex DiffVertex where + jsonVertexId = T.pack . show . diffVertexId class ToTreeGraph vertex t | t -> vertex where toTreeGraph :: (Member Fresh effs, Member (Reader (Graph vertex)) effs) => t (Eff effs (Graph vertex)) -> Eff effs (Graph vertex) -instance (ConstructorName syntax, Foldable syntax, HasField fields Range, HasField fields Span) => ToTreeGraph (TaggedVertex ()) (TermF syntax (Record fields)) where - toTreeGraph = termAlgebra () +instance (ConstructorName syntax, Foldable syntax, HasField fields Range, HasField fields Span) => + ToTreeGraph TermVertex (TermF syntax (Record fields)) where + toTreeGraph = termAlgebra where + termAlgebra :: + ( ConstructorName syntax + , HasField fields Range + , HasField fields Span + , Foldable syntax + , Member Fresh effs + , Member (Reader (Graph TermVertex)) effs + ) + => TermF syntax (Record fields) (Eff effs (Graph TermVertex)) + -> Eff effs (Graph TermVertex) + termAlgebra (In ann syntax) = do + i <- fresh + parent <- ask + let root = vertex (TermVertex i (constructorName syntax) (getField ann) (getField ann)) + subGraph <- foldl' (\acc x -> overlay <$> acc <*> local (const root) x) (pure mempty) syntax + pure (parent `connect` root `overlay` subGraph) -instance (ConstructorName syntax, Foldable syntax) => ToTreeGraph (TaggedVertex DiffTag) (DiffF syntax ann1 ann2) where - toTreeGraph = undefined - -- toTreeGraph d = case d of - -- Merge t -> termAlgebra Merged t - -- Patch (Delete t1) -> termAlgebra Deleted t1 - -- Patch (Insert t2) -> termAlgebra Inserted t2 - -- Patch (Replace t1 t2) -> do - -- i <- fresh - -- parent <- ask - -- let replace = vertex (TaggedVertex i Replaced "Replacement") - -- graph <- local (const replace) (overlay <$> termAlgebra Deleted t1 <*> termAlgebra Inserted t2) - -- pure (parent `connect` replace `overlay` graph) +instance (ConstructorName syntax, Foldable syntax, HasField fields1 Range, HasField fields1 Span, HasField fields2 Range, HasField fields2 Span) => + ToTreeGraph DiffVertex (DiffF syntax (Record fields1) (Record fields2)) where + toTreeGraph d = case d of + Merge t@(In (a1, a2) syntax) -> diffAlgebra t (Merged (MergedTerm (constructorName syntax) (ann a1) (ann a2))) + Patch (Delete t1@(In a1 syntax)) -> diffAlgebra t1 (Deleted (DeletedTerm (constructorName syntax) (ann a1))) + Patch (Insert t2@(In a2 syntax)) -> diffAlgebra t2 (Inserted (InsertedTerm (constructorName syntax) (ann a2))) + Patch (Replace t1@(In a1 syntax1) t2@(In a2 syntax2)) -> do + i <- fresh + parent <- ask + let a = DeletedTerm (constructorName syntax1) (ann a1) + let b = InsertedTerm (constructorName syntax2) (ann a2) + let replace = vertex (DiffVertex i (Replaced (ReplacedTerm a b))) + graph <- local (const replace) (overlay <$> diffAlgebra t1 (Deleted a) <*> diffAlgebra t2 (Inserted b)) + pure (parent `connect` replace `overlay` graph) + where + ann a = TermAnnotation (getField a) (getField a) + diffAlgebra :: + ( Foldable f + , Member Fresh effs + , Member (Reader (Graph DiffVertex)) effs + ) => f (Eff effs (Graph DiffVertex)) -> DiffVertexTerm -> Eff effs (Graph DiffVertex) + diffAlgebra syntax a = do + i <- fresh + parent <- ask + let root = vertex (DiffVertex i a) + subGraph <- foldl' (\acc x -> overlay <$> acc <*> local (const root) x) (pure mempty) syntax + pure (parent `connect` root `overlay` subGraph) + + -- flatTerm (n, r, s) = FlatTerm n r s diff --git a/src/Rendering/JSON.hs b/src/Rendering/JSON.hs index 60f753abd..2f59986c5 100644 --- a/src/Rendering/JSON.hs +++ b/src/Rendering/JSON.hs @@ -2,8 +2,9 @@ module Rendering.JSON ( JSON(..) , renderJSONDiff +, renderJSONAdjDiff , renderJSONTerm -, renderJSONAdjGraph +, renderJSONAdjTerm , renderJSONAST , renderSymbolTerms , renderJSONError @@ -38,6 +39,17 @@ instance ToJSON a => ToJSON (JSONDiff a) where toJSON JSONDiff{..} = object [ "diff" .= jsonDiff, "stat" .= jsonDiffStat ] toEncoding JSONDiff{..} = pairs ("diff" .= jsonDiff <> "stat" .= jsonDiffStat) +-- | Render a diff to a value representing its JSON. +renderJSONAdjDiff :: ToJSON a => BlobPair -> a -> JSON "diffs" SomeJSON +renderJSONAdjDiff blobs diff = JSON [ SomeJSON (JSONAdjDiff (JSONStat blobs) diff) ] + +data JSONAdjDiff a = JSONAdjDiff { jsonAdjDiffStat :: JSONStat, jsonAdjDiff :: a } + deriving (Eq, Show) + +instance ToJSON a => ToJSON (JSONAdjDiff a) where + toJSON JSONAdjDiff{..} = object [ "graph" .= jsonAdjDiff, "stat" .= jsonAdjDiffStat ] + toEncoding JSONAdjDiff{..} = pairs ("graph" .= jsonAdjDiff <> "stat" .= jsonAdjDiffStat) + newtype JSONStat = JSONStat { jsonStatBlobs :: BlobPair } deriving (Eq, Show) @@ -56,8 +68,8 @@ instance ToJSON a => ToJSON (JSONTerm a) where toJSON JSONTerm{..} = object ("tree" .= jsonTerm : toJSONFields jsonTermBlob) toEncoding JSONTerm{..} = pairs (fold ("tree" .= jsonTerm : toJSONFields jsonTermBlob)) -renderJSONAdjGraph :: ToJSON a => Blob -> a -> JSON "trees" SomeJSON -renderJSONAdjGraph blob content = JSON [ SomeJSON (JSONAdjTerm blob content) ] +renderJSONAdjTerm :: ToJSON a => Blob -> a -> JSON "trees" SomeJSON +renderJSONAdjTerm blob content = JSON [ SomeJSON (JSONAdjTerm blob content) ] data JSONAdjTerm a = JSONAdjTerm { jsonAdjTermBlob :: Blob, jsonAdjTerm :: a } deriving (Eq, Show) diff --git a/src/Rendering/Renderer.hs b/src/Rendering/Renderer.hs index a50cfa216..fce9de643 100644 --- a/src/Rendering/Renderer.hs +++ b/src/Rendering/Renderer.hs @@ -3,8 +3,9 @@ module Rendering.Renderer ( DiffRenderer(..) , TermRenderer(..) , renderJSONDiff +, renderJSONAdjDiff , renderJSONTerm -, renderJSONAdjGraph +, renderJSONAdjTerm , renderJSONAST , renderToCDiff , renderRPCToCDiff @@ -33,10 +34,12 @@ data DiffRenderer output where ToCDiffRenderer :: DiffRenderer Summaries -- | Render to JSON with the format documented in docs/json-format.md JSONDiffRenderer :: DiffRenderer (JSON "diffs" SomeJSON) + -- | Render to JSON as an adjacency list. + JSONAdjDiffRenderer :: DiffRenderer (JSON "diffs" SomeJSON) -- | Render to a 'ByteString' formatted as nested s-expressions with patches indicated. SExpressionDiffRenderer :: DiffRenderer Builder -- | Render to a 'ByteString' formatted as a DOT description of the diff. - DOTDiffRenderer :: DiffRenderer (Graph (TaggedVertex DiffTag)) + DOTDiffRenderer :: DiffRenderer (Graph DiffVertex) -- | Render to a 'ByteString' formatted using the 'Show' instance. ShowDiffRenderer :: DiffRenderer Builder @@ -54,7 +57,7 @@ data TermRenderer output where -- | Render to a list of symbols. SymbolsTermRenderer :: SymbolFields -> TermRenderer (JSON "files" SomeJSON) -- | Render to a 'ByteString' formatted as a DOT description of the term. - DOTTermRenderer :: TermRenderer (Graph (TaggedVertex ())) + DOTTermRenderer :: TermRenderer (Graph TermVertex) -- | Render to a 'ByteString' formatted using the 'Show' instance. ShowTermRenderer :: TermRenderer Builder diff --git a/src/Semantic/CLI.hs b/src/Semantic/CLI.hs index 4967d3883..909d7f176 100644 --- a/src/Semantic/CLI.hs +++ b/src/Semantic/CLI.hs @@ -60,6 +60,7 @@ diffCommand = command "diff" (info diffArgumentsParser (progDesc "Compute change diffArgumentsParser = do renderer <- flag (Diff.runDiff SExpressionDiffRenderer) (Diff.runDiff SExpressionDiffRenderer) (long "sexpression" <> help "Output s-expression diff tree (default)") <|> flag' (Diff.runDiff JSONDiffRenderer) (long "json" <> help "Output JSON diff trees") + <|> flag' (Diff.runDiff JSONAdjDiffRenderer) (long "json-adj" <> help "Output JSON diff trees") <|> flag' (Diff.runDiff ToCDiffRenderer) (long "toc" <> help "Output JSON table of contents diff summary") <|> flag' (Diff.runDiff DOTDiffRenderer) (long "dot" <> help "Output the diff as a DOT graph") <|> flag' (Diff.runDiff ShowDiffRenderer) (long "show" <> help "Output using the Show instance (debug only, format subject to change without notice)") diff --git a/src/Semantic/Diff.hs b/src/Semantic/Diff.hs index 7d9c7cb91..47382b4fe 100644 --- a/src/Semantic/Diff.hs +++ b/src/Semantic/Diff.hs @@ -25,6 +25,8 @@ import Semantic.IO (noLanguageForBlob) import Semantic.Telemetry as Stat import Semantic.Task as Task import Serializing.Format +import Rendering.JSON (SomeJSON (..)) +import qualified Rendering.JSON as JSON import qualified Language.TypeScript.Assignment as TypeScript import qualified Language.Ruby.Assignment as Ruby import qualified Language.JSON.Assignment as JSON @@ -33,6 +35,9 @@ import qualified Language.Python.Assignment as Python runDiff :: (Member Distribute effs, Member (Exc SomeException) effs, Member (Lift IO) effs, Member Task effs, Member Telemetry effs) => DiffRenderer output -> [BlobPair] -> Eff effs Builder runDiff ToCDiffRenderer = withParsedBlobPairs (decorate . declarationAlgebra) (render . renderToCDiff) >=> serialize JSON runDiff JSONDiffRenderer = withParsedBlobPairs (const pure) (render . renderJSONDiff) >=> serialize JSON +runDiff JSONAdjDiffRenderer = withParsedBlobPairs (const pure) (render . renderAdjGraph) >=> serialize JSON + where renderAdjGraph :: (Recursive t, ToTreeGraph DiffVertex (Base t)) => BlobPair -> t -> JSON.JSON "diffs" SomeJSON + renderAdjGraph blob diff = renderJSONAdjDiff blob (renderTreeGraph diff) runDiff SExpressionDiffRenderer = withParsedBlobPairs (const pure) (const (serialize (SExpression ByConstructorName))) runDiff ShowDiffRenderer = withParsedBlobPairs (const pure) (const (serialize Show)) runDiff DOTDiffRenderer = withParsedBlobPairs (const pure) (const (render renderTreeGraph)) >=> serialize (DOT (diffStyle "diffs")) diff --git a/src/Semantic/Parse.hs b/src/Semantic/Parse.hs index e42e2427b..0d8f682df 100644 --- a/src/Semantic/Parse.hs +++ b/src/Semantic/Parse.hs @@ -34,8 +34,8 @@ import Serializing.Format runParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) => TermRenderer output -> [Blob] -> Eff effs Builder runParse JSONTermRenderer = withParsedBlobs renderJSONError (render . renderJSONTerm) >=> serialize JSON runParse JSONAdjTermRenderer = withParsedBlobs renderJSONError (render . renderAdjGraph) >=> serialize JSON - where renderAdjGraph :: (Recursive t, ToTreeGraph (TaggedVertex ()) (Base t)) => Blob -> t -> JSON.JSON "trees" SomeJSON - renderAdjGraph blob term = renderJSONAdjGraph blob (renderTreeGraph term) + where renderAdjGraph :: (Recursive t, ToTreeGraph TermVertex (Base t)) => Blob -> t -> JSON.JSON "trees" SomeJSON + renderAdjGraph blob term = renderJSONAdjTerm blob (renderTreeGraph term) runParse SExpressionTermRenderer = withParsedBlobs (\_ _ -> mempty) (const (serialize (SExpression ByConstructorName))) runParse ShowTermRenderer = withParsedBlobs (\_ _ -> mempty) (const (serialize Show . quieterm)) runParse (SymbolsTermRenderer fields) = withParsedBlobs (\_ _ -> mempty) (\ blob -> decorate (declarationAlgebra blob) >=> render (renderSymbolTerms . renderToSymbols fields blob)) >=> serialize JSON From f0d164f95220797052fa299046f97737bcc4875e Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 6 Sep 2018 15:12:12 -0700 Subject: [PATCH 06/39] Rework control flow graph data types --- semantic.cabal | 3 +- src/Analysis/Abstract/Graph.hs | 38 ++--- src/Data/Graph.hs | 42 +++-- src/Data/Graph/Adjacency.hs | 178 --------------------- src/Data/Graph/ControlFlowVertex.hs | 238 ++++++++++++++++++++++++++++ src/Data/Graph/Vertex.hs | 148 ----------------- src/Parsing/Parser.hs | 2 +- src/Rendering/Graph.hs | 8 +- src/Semantic/Graph.hs | 12 +- 9 files changed, 295 insertions(+), 374 deletions(-) delete mode 100644 src/Data/Graph/Adjacency.hs create mode 100644 src/Data/Graph/ControlFlowVertex.hs delete mode 100644 src/Data/Graph/Vertex.hs diff --git a/semantic.cabal b/semantic.cabal index 57cb04cbf..ff1f08c11 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -82,8 +82,7 @@ library , Data.Functor.Both , Data.Functor.Classes.Generic , Data.Graph - , Data.Graph.Adjacency - , Data.Graph.Vertex + , Data.Graph.ControlFlowVertex , Data.History , Data.JSON.Fields , Data.Language diff --git a/src/Analysis/Abstract/Graph.hs b/src/Analysis/Abstract/Graph.hs index 8dcedefc7..86bcd52a4 100644 --- a/src/Analysis/Abstract/Graph.hs +++ b/src/Analysis/Abstract/Graph.hs @@ -1,7 +1,7 @@ {-# LANGUAGE ScopedTypeVariables, TypeFamilies, TypeOperators #-} module Analysis.Abstract.Graph ( Graph(..) -, Vertex(..) +, ControlFlowVertex(..) , moduleVertex , unknownModuleVertex , style @@ -28,14 +28,14 @@ import Data.Abstract.Module (Module (moduleInfo), ModuleInfo (..)) import Data.Abstract.Package (PackageInfo (..)) import Data.ByteString.Builder import Data.Graph -import Data.Graph.Vertex +import Data.Graph.ControlFlowVertex import Data.Record import Data.Term import qualified Data.Map as Map import qualified Data.Text.Encoding as T import Prologue hiding (project) -style :: Style Vertex Builder +style :: Style ControlFlowVertex Builder style = (defaultStyle (T.encodeUtf8Builder . vertexIdentifier)) { vertexAttributes = vertexAttributes , edgeAttributes = edgeAttributes @@ -65,11 +65,11 @@ style = (defaultStyle (T.encodeUtf8Builder . vertexIdentifier)) graphingTerms :: ( Member (Reader ModuleInfo) effects , Member (Reader Span) effects , Member (Env (Hole context (Located address))) effects - , Member (State (Graph Vertex)) effects - , Member (State (Map (Hole context (Located address)) Vertex)) effects + , Member (State (Graph ControlFlowVertex)) effects + , Member (State (Map (Hole context (Located address)) ControlFlowVertex)) effects , Member (Resumable (BaseError (EnvironmentError (Hole context (Located address))))) effects , AbstractValue (Hole context (Located address)) value effects - , Member (Reader Vertex) effects + , Member (Reader ControlFlowVertex) effects , HasField fields Span , VertexDeclaration syntax , Declarations1 syntax @@ -108,8 +108,8 @@ graphingTerms recur term@(In a syntax) = do -- | Add vertices to the graph for evaluated modules and the packages containing them. graphingPackages :: ( Member (Reader PackageInfo) effects - , Member (State (Graph Vertex)) effects - , Member (Reader Vertex) effects + , Member (State (Graph ControlFlowVertex)) effects + , Member (Reader ControlFlowVertex) effects ) => SubtermAlgebra Module term (TermEvaluator term address value effects a) -> SubtermAlgebra Module term (TermEvaluator term address value effects a) @@ -120,8 +120,8 @@ graphingPackages recur m = graphingModules :: forall term address value effects a . ( Member (Modules address) effects , Member (Reader ModuleInfo) effects - , Member (State (Graph Vertex)) effects - , Member (Reader Vertex) effects + , Member (State (Graph ControlFlowVertex)) effects + , Member (Reader ControlFlowVertex) effects , PureEffects effects ) => SubtermAlgebra Module term (TermEvaluator term address value effects a) @@ -160,10 +160,10 @@ graphingModuleInfo recur m = do -- | Add an edge from the current package to the passed vertex. packageInclusion :: ( Effectful m , Member (Reader PackageInfo) effects - , Member (State (Graph Vertex)) effects + , Member (State (Graph ControlFlowVertex)) effects , Monad (m effects) ) - => Vertex + => ControlFlowVertex -> m effects () packageInclusion v = do p <- currentPackage @@ -172,20 +172,20 @@ packageInclusion v = do -- | Add an edge from the current module to the passed vertex. moduleInclusion :: ( Effectful m , Member (Reader ModuleInfo) effects - , Member (State (Graph Vertex)) effects + , Member (State (Graph ControlFlowVertex)) effects , Monad (m effects) ) - => Vertex + => ControlFlowVertex -> m effects () moduleInclusion v = do m <- currentModule appendGraph (vertex (moduleVertex m) `connect` vertex v) -- | Add an edge from the passed variable name to the context it originated within. -variableDefinition :: ( Member (State (Graph Vertex)) effects - , Member (Reader Vertex) effects +variableDefinition :: ( Member (State (Graph ControlFlowVertex)) effects + , Member (Reader ControlFlowVertex) effects ) - => Vertex + => ControlFlowVertex -> TermEvaluator term (Hole context (Located address)) value effects () variableDefinition var = do context <- ask @@ -195,6 +195,6 @@ appendGraph :: (Effectful m, Member (State (Graph v)) effects) => Graph v -> m e appendGraph = modify' . (<>) -graphing :: (Effectful m, Effects effects, Functor (m (State (Graph Vertex) : effects))) - => m (State (Map (Hole context (Located address)) Vertex) ': State (Graph Vertex) ': effects) result -> m effects (Graph Vertex, result) +graphing :: (Effectful m, Effects effects, Functor (m (State (Graph ControlFlowVertex) : effects))) + => m (State (Map (Hole context (Located address)) ControlFlowVertex) ': State (Graph ControlFlowVertex) ': effects) result -> m effects (Graph ControlFlowVertex, result) graphing = runState mempty . fmap snd . runState lowerBound diff --git a/src/Data/Graph.hs b/src/Data/Graph.hs index 06e86c699..85212810c 100644 --- a/src/Data/Graph.hs +++ b/src/Data/Graph.hs @@ -7,18 +7,22 @@ module Data.Graph , Lower(..) , simplify , topologicalSort -, JSONVertex(..) +, VertexTag(..) +, Edge(..) +, vertexList +, edgeList ) where +import Prologue + import qualified Algebra.Graph as G import qualified Algebra.Graph.AdjacencyMap as A -import Algebra.Graph.Class (connect, overlay, vertex) +import Algebra.Graph.Class (connect, overlay, vertex) import qualified Algebra.Graph.Class as Class -import Control.Monad.Effect -import Control.Monad.Effect.State -import Data.Aeson +import Control.Monad.Effect +import Control.Monad.Effect.State +import Data.Aeson import qualified Data.Set as Set -import Prologue -- | An algebraic graph with 'Ord', 'Semigroup', and 'Monoid' instances. newtype Graph vertex = Graph { unGraph :: G.Graph vertex } @@ -79,10 +83,16 @@ extendVisited f (Visited a b) = Visited (f a) b extendOrder :: ([v] -> [v]) -> Visited v -> Visited v extendOrder f (Visited a b) = Visited a (f b) - toAdjacencyMap :: Ord v => G.Graph v -> A.AdjacencyMap v toAdjacencyMap = Class.toGraph +vertexList :: Ord v => Graph v -> [v] +vertexList = G.vertexList . unGraph + +edgeList :: Ord v => Graph v -> [Edge v] +edgeList = fmap Edge . G.edgeList . unGraph + +-- Instances instance Lower (Graph vertex) where lowerBound = Class.empty @@ -107,15 +117,15 @@ instance Ord vertex => Ord (Graph vertex) where compare (Graph (G.Connect a1 a2)) (Graph (G.Connect b1 b2)) = (compare `on` Graph) a1 b1 <> (compare `on` Graph) a2 b2 -class JSONVertex vertex where - jsonVertexId :: vertex -> Text +class VertexTag vertex where + uniqueTag :: vertex -> Text -instance (Ord vertex, ToJSON vertex, JSONVertex vertex) => ToJSON (Graph vertex) where - toJSON (Graph graph) = object ["vertices" .= G.vertexList graph, "edges" .= (JSONEdge <$> G.edgeList graph)] - toEncoding (Graph graph) = pairs ("vertices" .= G.vertexList graph <> "edges" .= (JSONEdge <$> G.edgeList graph)) +instance (Ord vertex, ToJSON vertex, VertexTag vertex) => ToJSON (Graph vertex) where + toJSON (Graph graph) = object ["vertices" .= G.vertexList graph, "edges" .= (Edge <$> G.edgeList graph)] + toEncoding (Graph graph) = pairs ("vertices" .= G.vertexList graph <> "edges" .= (Edge <$> G.edgeList graph)) -newtype JSONEdge vertex = JSONEdge (vertex, vertex) +newtype Edge vertex = Edge (vertex, vertex) -instance (ToJSON vertex, JSONVertex vertex) => ToJSON (JSONEdge vertex) where - toJSON (JSONEdge (a, b)) = object ["source" .= jsonVertexId a, "target" .= jsonVertexId b] - toEncoding (JSONEdge (a, b)) = pairs ("source" .= jsonVertexId a <> "target" .= jsonVertexId b) +instance (ToJSON vertex, VertexTag vertex) => ToJSON (Edge vertex) where + toJSON (Edge (a, b)) = object ["source" .= uniqueTag a, "target" .= uniqueTag b] + toEncoding (Edge (a, b)) = pairs ("source" .= uniqueTag a <> "target" .= uniqueTag b) diff --git a/src/Data/Graph/Adjacency.hs b/src/Data/Graph/Adjacency.hs deleted file mode 100644 index e7e12766e..000000000 --- a/src/Data/Graph/Adjacency.hs +++ /dev/null @@ -1,178 +0,0 @@ -{-# LANGUAGE DeriveAnyClass, LambdaCase, ScopedTypeVariables #-} - -module Data.Graph.Adjacency - ( AdjacencyList (..) - , Edge (..) - , Tag - , Vertex (..) - , VertexType (..) - , graphToAdjacencyList - , importGraphToGraph - , tagGraph - , isCoherent - ) where - -import Prologue - -import Algebra.Graph.AdjacencyMap (adjacencyMap) -import Algebra.Graph.Class (ToGraph (..), edges, vertices) -import Control.Monad.Effect -import Control.Monad.Effect.State -import Control.Monad.Effect.Fresh -import Data.Aeson -import Data.Coerce -import Data.HashMap.Strict (HashMap, (!)) -import qualified Data.HashMap.Strict as HashMap -import Data.HashSet (HashSet) -import qualified Data.HashSet as HashSet -import Data.Map (Map) -import qualified Data.Map as Map -import Data.Set (Set) -import qualified Data.Set as Set -import Data.Span -import qualified Data.Vector as Vec -import Data.Word -import GHC.Exts (fromList) -import qualified Proto3.Suite as PB - -import Data.Graph -import qualified Data.Graph.Vertex as V - --- | Sum type corresponding to a protobuf enum for vertex types. -data VertexType - = PACKAGE - | MODULE - | UNKNOWN_MODULE - | VARIABLE - | METHOD - | FUNCTION - deriving (Eq, Ord, Show, Enum, Bounded, Generic, ToJSON, FromJSON, PB.Named, PB.Finite, PB.MessageField) - --- | Defaults to 'PACKAGE'. -instance PB.HasDefault VertexType where def = PACKAGE - --- | Piggybacks on top of the 'Enumerated' instance, as the generated code would. --- This instance will get easier when we have DerivingVia, or a Generic instance --- that hooks into Enumerated. -instance PB.Primitive VertexType where - primType _ = PB.primType (Proxy @(PB.Enumerated VertexType)) - encodePrimitive f = PB.encodePrimitive f . PB.Enumerated . Right - decodePrimitive = PB.decodePrimitive >>= \case - (PB.Enumerated (Right r)) -> pure r - other -> Prelude.fail ("VertexType decodeMessageField: unexpected value" <> show other) - --- | A tag used on each vertext of a 'Graph' to convert to an 'AdjacencyList'. -type Tag = Word64 - --- | A protobuf-compatible vertex type, with a unique 'Tag' identifier. -data Vertex = Vertex - { vertexType :: VertexType - , vertexContents :: Text - , vertexTag :: Tag - } deriving (Eq, Ord, Show, Generic, PB.Message, PB.Named) - --- | A protobuf-compatible edge type. Only tag information is carried; --- consumers are expected to look up nodes in the vertex list when necessary. -data Edge = Edge { edgeFrom :: Tag, edgeTo :: Tag } - deriving (Eq, Ord, Show, Generic, Hashable, PB.Named, PB.Message) - --- | An adjacency list-representation of a graph. You generally build these by calling --- 'graphToAdjacencyList' on an algebraic 'Graph'. This representation is less efficient and --- fluent than an ordinary 'Graph', but is more amenable to serialization. -data AdjacencyList = AdjacencyList - { graphVertices :: PB.NestedVec Vertex - , graphEdges :: PB.NestedVec Edge - } deriving (Eq, Ord, Show, Generic, PB.Named, PB.Message) - --- | Convert an algebraic graph to an adjacency list. -graphToAdjacencyList :: Graph V.Vertex -> AdjacencyList -graphToAdjacencyList = taggedGraphToAdjacencyList . tagGraph . simplify - --- * Internal interface stuff - --- Using a PBGraph as the accumulator for the fold would incur --- significant overhead associated with Vector concatenation. --- We use this and then pay the O(v + e) to-Vector cost once. --- The fields are strict because we have StrictData on. -data Acc = Acc [Vertex] (HashSet Edge) - --- Convert a graph with tagged members to a protobuf-compatible adjacency list. --- The Tag is necessary to build a canonical adjacency list. --- Since import graphs can be very large, this is written with speed in mind, in --- that we convert the graph to algebraic-graphs's 'AdjacencyMap' and then fold --- to build a 'Graph', avoiding inefficient vector concatenation. --- Time complexity, given V vertices and E edges, is at least O(2V + 2E + (V * E * log E)), --- plus whatever overhead converting the graph to 'AdjacencyMap' may entail. -taggedGraphToAdjacencyList :: Graph (V.Vertex, Tag) -> AdjacencyList -taggedGraphToAdjacencyList = accumToAdj . adjMapToAccum . adjacencyMap . toGraph . simplify - where adjMapToAccum :: Map (V.Vertex, Tag) (Set (V.Vertex, Tag)) -> Acc - adjMapToAccum = Map.foldlWithKey go (Acc [] mempty) - - go :: Acc -> (V.Vertex, Tag) -> Set (V.Vertex, Tag) -> Acc - go (Acc vs es) (v, from) edges = Acc (vertexToPB v from : vs) (Set.foldr' (add . snd) es edges) - where add = HashSet.insert . Edge from - - accumToAdj :: Acc -> AdjacencyList - accumToAdj (Acc vs es) = AdjacencyList (fromList vs) (fromList (toList es)) - - vertexToPB :: V.Vertex -> Tag -> Vertex - vertexToPB s = Vertex t (V.vertexIdentifier s) where - t = case s of - V.Package{} -> PACKAGE - V.Module{} -> MODULE - V.UnknownModule{} -> UNKNOWN_MODULE - V.Variable{} -> VARIABLE - V.Method{} -> METHOD - V.Function{} -> FUNCTION - --- Annotate all vertices of a 'Graph' with a 'Tag', starting from 1. --- Two vertices @a@ and @b@ will share a 'Tag' iff @a == b@. -tagGraph :: forall a . (Eq a, Hashable a) => Graph a -> Graph (a, Tag) -tagGraph = unwrap . traverse go where - - unwrap :: Eff '[Fresh, State (HashMap a Tag)] (Graph (a, Tag)) -> Graph (a, Tag) - unwrap = run . fmap snd . runState HashMap.empty . runFresh 1 - - go :: a -> Eff '[Fresh, State (HashMap a Tag)] (a, Tag) - go v = gets (HashMap.lookup v) >>= \case - Just t -> pure (v, t) - Nothing -> do - next <- fromIntegral <$> fresh - modify' (HashMap.insert v next) - pure (v, next) - --- | This is the reverse of 'graphToAdjacencyList'. Don't use this outside of a testing context. --- N.B. @importGraphToGraph . graphToAdjacencyList@ is 'id', but @graphToAdjacencyList . importGraphToGraph@ is not. -importGraphToGraph :: AdjacencyList -> Graph V.Vertex -importGraphToGraph (AdjacencyList vs es) = simplify built - where built = allEdges <> vertices unreferencedVertices - - allEdges :: Graph V.Vertex - allEdges = fmap fst (edges (foldr addEdge [] es)) - addEdge (Edge f t) xs = ((adjMap ! f, f), (adjMap ! t, t)) : xs - adjMap = foldMap (\v -> HashMap.singleton (vertexTag v) (pbToVertex v)) vs - - unreferencedVertices :: [V.Vertex] - unreferencedVertices = pbToVertex <$> toList (Vec.filter isUnreferenced (coerce vs)) - - isUnreferenced :: Vertex -> Bool - isUnreferenced v = not (vertexTag v `HashSet.member` edgedTags) - - edgedTags :: HashSet Tag - edgedTags = HashSet.fromList $ concatMap unEdge es where unEdge (Edge f t) = [f, t] - - pbToVertex :: Vertex -> V.Vertex - pbToVertex (Vertex t c _) = case t of - PACKAGE -> V.Package c - MODULE -> V.Module c - UNKNOWN_MODULE -> V.UnknownModule c - VARIABLE -> V.Variable c "unknown" emptySpan - METHOD -> V.Method c "unknown" emptySpan - FUNCTION -> V.Function c "unknown" emptySpan - - --- | For debugging: returns True if all edges reference a valid vertex tag. -isCoherent :: AdjacencyList -> Bool -isCoherent (AdjacencyList vs es) = all edgeValid es where - edgeValid (Edge a b) = HashSet.member a allTags && HashSet.member b allTags - allTags = HashSet.fromList (toList (vertexTag <$> vs)) diff --git a/src/Data/Graph/ControlFlowVertex.hs b/src/Data/Graph/ControlFlowVertex.hs new file mode 100644 index 000000000..ec9206139 --- /dev/null +++ b/src/Data/Graph/ControlFlowVertex.hs @@ -0,0 +1,238 @@ +{-# LANGUAGE DeriveAnyClass, ScopedTypeVariables, TypeFamilies, TypeOperators, UndecidableInstances #-} +module Data.Graph.ControlFlowVertex +( ControlFlowVertex (..) +, packageVertex +, moduleVertex +, unknownModuleVertex +, variableVertex +, methodVertex +, functionVertex +, vertexIdentifier +, showSpan +, VertexDeclaration (..) +, VertexDeclaration' (..) +, VertexDeclarationStrategy +, VertexDeclarationWithStrategy +) where + +import Data.Abstract.Declarations +import Data.Abstract.Module (ModuleInfo (..)) +import Data.Abstract.Name +import Data.Abstract.Package (PackageInfo (..)) +import Data.Aeson +import Data.Record +import Data.Span +import Data.Graph (VertexTag(..)) +import qualified Data.Graph as G +import qualified Data.Syntax as Syntax +import qualified Data.Syntax.Declaration as Declaration +import qualified Data.Syntax.Expression as Expression +import Data.Term +import qualified Data.Text as T +import Prologue hiding (packageName) + +-- import Data.Word +import Proto3.Suite +import qualified Proto3.Suite as PB +import qualified Proto3.Suite.Types as PB +import qualified Proto3.Wire.Encode as Encode +import qualified Proto3.Wire.Decode as Decode +import qualified Algebra.Graph as Graph +import GHC.Exts (fromList) + +-- | A vertex of representing some node in a control flow graph. +data ControlFlowVertex + = Package { vertexName :: Text } + | Module { vertexName :: Text } + | UnknownModule { vertexName :: Text } + | Variable { vertexName :: Text, vertexModuleName :: Text, vertexSpan :: Span } + | Method { vertexName :: Text, vertexModuleName :: Text, vertexSpan :: Span } + | Function { vertexName :: Text, vertexModuleName :: Text, vertexSpan :: Span } + deriving (Eq, Ord, Show, Generic, Hashable, Named) + +-- | A tag used on each vertex of a 'Graph' to convert to an 'ControlFlowAdjacencyList'. +-- type Tag = Word64 + +-- -- | A serializable edge type for control flow graphs. Only tag information is +-- -- carried about vertices; consumers are expected to look up nodes in the vertex +-- -- list when necessary. +-- data ControlFlowEdge = ControlFlowEdge +-- { controlFlowEdgeFrom :: Tag +-- , controlFlowEdgeTo :: Tag +-- } deriving (Eq, Ord, Show, Generic, Hashable, PB.Named, Message) + +-- -- | An adjacency list-representation of a control flow graph. This +-- -- representation is less efficient and fluent than an ordinary 'Graph', but is +-- -- more amenable to serialization. +-- data ControlFlowAdjacencyList = ControlFlowAdjacencyList +-- { controlFlowVertices :: [ControlFlowVertex] +-- , controlFlowEdges :: [ControlFlowEdge] +-- } deriving (Eq, Ord, Show, Generic, Hashable, Named, Message) + + +packageVertex :: PackageInfo -> ControlFlowVertex +packageVertex (PackageInfo name _) = Package (formatName name) + +moduleVertex :: ModuleInfo -> ControlFlowVertex +moduleVertex = Module . T.pack . modulePath + +unknownModuleVertex :: ModuleInfo -> ControlFlowVertex +unknownModuleVertex = UnknownModule . T.pack . modulePath + +variableVertex :: Text -> ModuleInfo -> Span -> ControlFlowVertex +variableVertex name ModuleInfo{..} = Variable name (T.pack modulePath) + +methodVertex :: Text -> ModuleInfo -> Span -> ControlFlowVertex +methodVertex name ModuleInfo{..} = Method name (T.pack modulePath) + +functionVertex :: Text -> ModuleInfo -> Span -> ControlFlowVertex +functionVertex name ModuleInfo{..} = Function name (T.pack modulePath) + +vertexIdentifier :: ControlFlowVertex -> Text +vertexIdentifier v@Package{..} = vertexName <> " (" <> vertexToType v <> ")" +vertexIdentifier v@Module{..} = vertexName <> " (" <> vertexToType v <> ")" +vertexIdentifier v@UnknownModule{..} = vertexName <> " (" <> vertexToType v <> ")" +vertexIdentifier v = vertexModuleName v <> "::" <> vertexName v <> " (" <> vertexToType v <> " " <> showSpan (vertexSpan v) <> ")" + +showSpan :: Span -> Text +showSpan (Span (Pos a b) (Pos c d)) = T.pack $ + "[" <> show a <> ", " <> show b <> "]" + <> " - " + <> "[" <> show c <> ", " <> show d <> "]" + +vertexToType :: ControlFlowVertex -> Text +vertexToType Package{} = "Package" +vertexToType Module{} = "Module" +vertexToType UnknownModule{} = "Unknown Module" +vertexToType Variable{} = "Variable" +vertexToType Method{} = "Method" +vertexToType Function{} = "Function" + + +-- Instances + +instance Named (G.Graph ControlFlowVertex) where nameOf _ = "ControlFlowGraph" + +instance Message (G.Graph ControlFlowVertex) where + encodeMessage _ graph = encodeMessageField 1 (NestedVec (fromList (G.vertexList graph))) + <> encodeMessageField 2 (NestedVec (fromList (G.edgeList graph))) + decodeMessage = undefined + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Repeated . Named $ Single "ControlFlowVertex") (Single "vertices") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Repeated . Named $ Single "ControlFlowEdge") (Single "edges") [] Nothing + ] + +instance Lower ControlFlowVertex where lowerBound = Package "" +instance VertexTag ControlFlowVertex where uniqueTag = vertexIdentifier + +instance ToJSON ControlFlowVertex where + toJSON v = object [ "name" .= vertexIdentifier v, "type" .= vertexToType v ] + +instance Message ControlFlowVertex where + encodeMessage _ v@Package{..} = Encode.embedded 1 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName) + encodeMessage _ v@Module{..} = Encode.embedded 2 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName) + encodeMessage _ v@UnknownModule{..} = Encode.embedded 3 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName) + encodeMessage _ v@Variable{..} = Encode.embedded 4 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 vertexModuleName <> encodeMessage 4 vertexSpan) + encodeMessage _ v@Method{..} = Encode.embedded 5 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 vertexModuleName <> encodeMessage 4 vertexSpan) + encodeMessage _ v@Function{..} = Encode.embedded 6 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 vertexModuleName <> encodeMessage 4 vertexSpan) + decodeMessage = undefined + dotProto _ = + [ DotProtoMessageOneOf (Single "vertex") + [ DotProtoField 1 (Prim . Named $ Single "Package") (Single "package") [] Nothing + , DotProtoField 2 (Prim . Named $ Single "Module") (Single "module") [] Nothing + , DotProtoField 3 (Prim . Named $ Single "UnknownModule") (Single "unknownModule") [] Nothing + , DotProtoField 4 (Prim . Named $ Single "Variable") (Single "variable") [] Nothing + , DotProtoField 5 (Prim . Named $ Single "Method") (Single "method") [] Nothing + , DotProtoField 6 (Prim . Named $ Single "Function") (Single "function") [] Nothing + ] + ] + <> gen "Package" mempty + <> gen "Module" mempty + <> gen "UnknownModule" mempty + <> gen "Variable" [ genModuleName, genSpan ] + <> gen "Method" [ genModuleName, genSpan ] + <> gen "Function" [ genModuleName, genSpan ] + where + genModuleName = DotProtoMessageField $ DotProtoField 3 (Prim PB.String) (Single "moduleName") [] Nothing + genSpan = DotProtoMessageField $ DotProtoField 4 (Prim . Named $ Single (nameOf (Proxy @Span))) (Single "span") [] Nothing + gen name extras = + [ DotProtoMessageDefinition . DotProtoMessage (Single name) $ + (DotProtoMessageField $ DotProtoField 1 (Prim PB.String) (Single "id") [] Nothing) + : (DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "name") [] Nothing) + : extras + ] + + +instance Named (G.Edge ControlFlowVertex) where nameOf _ = "ControlFlowEdge" + +instance Message (G.Edge ControlFlowVertex) where + encodeMessage _ (G.Edge (from, to)) = encodePrimitive 1 (uniqueTag from) <> encodePrimitive 2 (uniqueTag to) + decodeMessage = undefined + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim PB.String) (Single "from") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "to") [] Nothing + ] + + +-- Typeclasses to create 'ControlFlowVertex's from 'Term's. Also extracts +-- 'Name's for terms with symbolic names like Identifiers and Declarations. + +class VertexDeclaration syntax where + toVertex :: (Declarations1 syntax, Foldable syntax, HasField fields Span) + => Record fields + -> ModuleInfo + -> syntax (Term syntax (Record fields)) + -> Maybe (ControlFlowVertex, Name) + +instance (VertexDeclaration' syntax syntax) => VertexDeclaration syntax where + toVertex = toVertex' + +class VertexDeclaration' whole syntax where + toVertex' :: (Declarations1 whole, Foldable whole, HasField fields Span) + => Record fields + -> ModuleInfo + -> syntax (Term whole (Record fields)) + -> Maybe (ControlFlowVertex, Name) + +instance (VertexDeclarationStrategy syntax ~ strategy, VertexDeclarationWithStrategy strategy whole syntax) => VertexDeclaration' whole syntax where + toVertex' = toVertexWithStrategy (Proxy :: Proxy strategy) + +data Strategy = Default | Custom + +type family VertexDeclarationStrategy syntax where + VertexDeclarationStrategy Syntax.Identifier = 'Custom + VertexDeclarationStrategy Declaration.Function = 'Custom + VertexDeclarationStrategy Declaration.Method = 'Custom + VertexDeclarationStrategy Expression.MemberAccess = 'Custom + VertexDeclarationStrategy (Sum _) = 'Custom + VertexDeclarationStrategy syntax = 'Default + +class VertexDeclarationWithStrategy (strategy :: Strategy) whole syntax where + toVertexWithStrategy :: (Declarations1 whole, Foldable whole, HasField fields Span) + => proxy strategy + -> Record fields + -> ModuleInfo + -> syntax (Term whole (Record fields)) + -> Maybe (ControlFlowVertex, Name) + +-- | The 'Default' strategy produces 'Nothing'. +instance VertexDeclarationWithStrategy 'Default whole syntax where + toVertexWithStrategy _ _ _ _ = Nothing + +instance Apply (VertexDeclaration' whole) fs => VertexDeclarationWithStrategy 'Custom whole (Sum fs) where + toVertexWithStrategy _ ann info = apply @(VertexDeclaration' whole) (toVertex' ann info) + +instance VertexDeclarationWithStrategy 'Custom whole Syntax.Identifier where + toVertexWithStrategy _ ann info (Syntax.Identifier name) = Just (variableVertex (formatName name) info (getField ann), name) + +instance VertexDeclarationWithStrategy 'Custom whole Declaration.Function where + toVertexWithStrategy _ ann info term@Declaration.Function{} = (\n -> (functionVertex (formatName n) info (getField ann), n)) <$> liftDeclaredName declaredName term + +instance VertexDeclarationWithStrategy 'Custom whole Declaration.Method where + toVertexWithStrategy _ ann info term@Declaration.Method{} = (\n -> (methodVertex (formatName n) info (getField ann), n)) <$> liftDeclaredName declaredName term + +instance VertexDeclarationWithStrategy 'Custom whole whole => VertexDeclarationWithStrategy 'Custom whole Expression.MemberAccess where + toVertexWithStrategy proxy ann info (Expression.MemberAccess (Term (In lhsAnn lhs)) name) = + case toVertexWithStrategy proxy lhsAnn info lhs of + Just (Variable n _ _, _) -> Just (variableVertex (n <> "." <> formatName name) info (getField ann), name) + _ -> Just (variableVertex (formatName name) info (getField ann), name) diff --git a/src/Data/Graph/Vertex.hs b/src/Data/Graph/Vertex.hs deleted file mode 100644 index 31ca59218..000000000 --- a/src/Data/Graph/Vertex.hs +++ /dev/null @@ -1,148 +0,0 @@ -{-# LANGUAGE DeriveAnyClass, ScopedTypeVariables, TypeFamilies, TypeOperators, UndecidableInstances #-} -module Data.Graph.Vertex -( Vertex (..) -, packageVertex -, moduleVertex -, unknownModuleVertex -, variableVertex -, methodVertex -, functionVertex -, vertexIdentifier -, showSpan -, VertexDeclaration (..) -, VertexDeclaration' (..) -, VertexDeclarationStrategy -, VertexDeclarationWithStrategy -) where - -import Data.Abstract.Declarations -import Data.Abstract.Module (ModuleInfo (..)) -import Data.Abstract.Name -import Data.Abstract.Package (PackageInfo (..)) -import Data.Aeson -import Data.Record -import Data.Span -import Data.Graph (JSONVertex(..)) -import qualified Data.Syntax as Syntax -import qualified Data.Syntax.Declaration as Declaration -import qualified Data.Syntax.Expression as Expression -import Data.Term -import qualified Data.Text as T -import Prologue hiding (packageName) - --- | A vertex of some specific type. -data Vertex - = Package { vertexName :: Text } - | Module { vertexName :: Text } - | UnknownModule { vertexName :: Text } - | Variable { vertexName :: Text, vertexModuleName :: Text, vertexSpan :: Span } - | Method { vertexName :: Text, vertexModuleName :: Text, vertexSpan :: Span } - | Function { vertexName :: Text, vertexModuleName :: Text, vertexSpan :: Span } - deriving (Eq, Ord, Show, Generic, Hashable) - -packageVertex :: PackageInfo -> Vertex -packageVertex (PackageInfo name _) = Package (formatName name) - -moduleVertex :: ModuleInfo -> Vertex -moduleVertex = Module . T.pack . modulePath - -unknownModuleVertex :: ModuleInfo -> Vertex -unknownModuleVertex = UnknownModule . T.pack . modulePath - -variableVertex :: Text -> ModuleInfo -> Span -> Vertex -variableVertex name ModuleInfo{..} = Variable name (T.pack modulePath) - -methodVertex :: Text -> ModuleInfo -> Span -> Vertex -methodVertex name ModuleInfo{..} = Method name (T.pack modulePath) - -functionVertex :: Text -> ModuleInfo -> Span -> Vertex -functionVertex name ModuleInfo{..} = Function name (T.pack modulePath) - -instance ToJSON Vertex where - toJSON v = object [ "name" .= vertexIdentifier v, "type" .= vertexToType v ] - -vertexIdentifier :: Vertex -> Text -vertexIdentifier v@Package{..} = vertexName <> " (" <> vertexToType v <> ")" -vertexIdentifier v@Module{..} = vertexName <> " (" <> vertexToType v <> ")" -vertexIdentifier v@UnknownModule{..} = vertexName <> " (" <> vertexToType v <> ")" -vertexIdentifier v = vertexModuleName v <> "::" <> vertexName v <> " (" <> vertexToType v <> " " <> showSpan (vertexSpan v) <> ")" - -showSpan :: Span -> Text -showSpan (Span (Pos a b) (Pos c d)) = T.pack $ - "[" <> show a <> ", " <> show b <> "]" - <> " - " - <> "[" <> show c <> ", " <> show d <> "]" - -vertexToType :: Vertex -> Text -vertexToType Package{} = "Package" -vertexToType Module{} = "Module" -vertexToType UnknownModule{} = "Unknown Module" -vertexToType Variable{} = "Variable" -vertexToType Method{} = "Method" -vertexToType Function{} = "Function" - -instance Lower Vertex where - lowerBound = Package "" - -instance JSONVertex Vertex where - jsonVertexId = vertexIdentifier - -class VertexDeclaration syntax where - toVertex :: (Declarations1 syntax, Foldable syntax, HasField fields Span) - => Record fields - -> ModuleInfo - -> syntax (Term syntax (Record fields)) - -> Maybe (Vertex, Name) - -instance (VertexDeclaration' syntax syntax) => VertexDeclaration syntax where - toVertex = toVertex' - -class VertexDeclaration' whole syntax where - toVertex' :: (Declarations1 whole, Foldable whole, HasField fields Span) - => Record fields - -> ModuleInfo - -> syntax (Term whole (Record fields)) - -> Maybe (Vertex, Name) - -instance (VertexDeclarationStrategy syntax ~ strategy, VertexDeclarationWithStrategy strategy whole syntax) => VertexDeclaration' whole syntax where - toVertex' = toVertexWithStrategy (Proxy :: Proxy strategy) - -data Strategy = Default | Custom - -type family VertexDeclarationStrategy syntax where - VertexDeclarationStrategy Syntax.Identifier = 'Custom - VertexDeclarationStrategy Declaration.Function = 'Custom - VertexDeclarationStrategy Declaration.Method = 'Custom - VertexDeclarationStrategy Expression.MemberAccess = 'Custom - VertexDeclarationStrategy (Sum _) = 'Custom - VertexDeclarationStrategy syntax = 'Default - -class VertexDeclarationWithStrategy (strategy :: Strategy) whole syntax where - toVertexWithStrategy :: (Declarations1 whole, Foldable whole, HasField fields Span) - => proxy strategy - -> Record fields - -> ModuleInfo - -> syntax (Term whole (Record fields)) - -> Maybe (Vertex, Name) - --- | The 'Default' strategy produces 'Nothing'. -instance VertexDeclarationWithStrategy 'Default whole syntax where - toVertexWithStrategy _ _ _ _ = Nothing - -instance Apply (VertexDeclaration' whole) fs => VertexDeclarationWithStrategy 'Custom whole (Sum fs) where - toVertexWithStrategy _ ann info = apply @(VertexDeclaration' whole) (toVertex' ann info) - -instance VertexDeclarationWithStrategy 'Custom whole Syntax.Identifier where - toVertexWithStrategy _ ann info (Syntax.Identifier name) = Just (variableVertex (formatName name) info (getField ann), name) - -instance VertexDeclarationWithStrategy 'Custom whole Declaration.Function where - toVertexWithStrategy _ ann info term@Declaration.Function{} = (\n -> (functionVertex (formatName n) info (getField ann), n)) <$> liftDeclaredName declaredName term - -instance VertexDeclarationWithStrategy 'Custom whole Declaration.Method where - toVertexWithStrategy _ ann info term@Declaration.Method{} = (\n -> (methodVertex (formatName n) info (getField ann), n)) <$> liftDeclaredName declaredName term - -instance VertexDeclarationWithStrategy 'Custom whole whole => VertexDeclarationWithStrategy 'Custom whole Expression.MemberAccess where - toVertexWithStrategy proxy ann info (Expression.MemberAccess (Term (In lhsAnn lhs)) name) = - case toVertexWithStrategy proxy lhsAnn info lhs of - Just (Variable n _ _, _) -> Just (variableVertex (n <> "." <> formatName name) info (getField ann), name) - _ -> Just (variableVertex (formatName name) info (getField ann), name) diff --git a/src/Parsing/Parser.hs b/src/Parsing/Parser.hs index 019e832fa..b394971f8 100644 --- a/src/Parsing/Parser.hs +++ b/src/Parsing/Parser.hs @@ -33,7 +33,7 @@ import qualified Assigning.Assignment.Deterministic as Deterministic import qualified CMarkGFM import Data.Abstract.Evaluatable (HasPostlude, HasPrelude) import Data.AST -import Data.Graph.Vertex (VertexDeclaration') +import Data.Graph.ControlFlowVertex (VertexDeclaration') import Data.Kind import Data.Language import Data.Record diff --git a/src/Rendering/Graph.hs b/src/Rendering/Graph.hs index 9a78f9924..0a442961b 100644 --- a/src/Rendering/Graph.hs +++ b/src/Rendering/Graph.hs @@ -137,8 +137,8 @@ instance ToJSON TermVertex where <> toJSONFields vertexSpan )) -instance JSONVertex TermVertex where - jsonVertexId = T.pack . show . vertexId +instance VertexTag TermVertex where + uniqueTag = T.pack . show . vertexId instance ToJSON DiffVertex where toJSON (DiffVertex i (Deleted t)) = object [ "id" .= T.pack (show i), "deleted" .= t ] @@ -149,8 +149,8 @@ instance ToJSON DiffVertex where -- toEncoding = undefined -instance JSONVertex DiffVertex where - jsonVertexId = T.pack . show . diffVertexId +instance VertexTag DiffVertex where + uniqueTag = T.pack . show . diffVertexId class ToTreeGraph vertex t | t -> vertex where diff --git a/src/Semantic/Graph.hs b/src/Semantic/Graph.hs index f4b588054..6e0e42614 100644 --- a/src/Semantic/Graph.hs +++ b/src/Semantic/Graph.hs @@ -7,7 +7,7 @@ module Semantic.Graph , runImportGraphToModuleInfos , GraphType(..) , Graph -, Vertex +, ControlFlowVertex , ConcreteEff(..) , style , parsePackage @@ -47,7 +47,7 @@ import Data.Abstract.Value.Type as Type import Data.Blob import Data.Coerce import Data.Graph -import Data.Graph.Vertex (VertexDeclarationStrategy, VertexDeclarationWithStrategy) +import Data.Graph.ControlFlowVertex (VertexDeclarationStrategy, VertexDeclarationWithStrategy) import Data.Language as Language import Data.List (isPrefixOf, isSuffixOf) import Data.Project @@ -70,7 +70,7 @@ runGraph :: forall effs. (Member Distribute effs, Member (Exc SomeException) eff => GraphType -> Bool -> Project - -> Eff effs (Graph Vertex) + -> Eff effs (Graph ControlFlowVertex) runGraph ImportGraph _ project | SomeAnalysisParser parser (lang' :: Proxy lang) <- someAnalysisParser (Proxy :: Proxy AnalysisClasses) (projectLanguage project) = do let parse = if projectLanguage project == Language.Python then parsePythonPackage parser else fmap (fmap snd) . parsePackage parser @@ -103,7 +103,7 @@ runCallGraph :: ( HasField fields Span -> Bool -> [Module term] -> Package term - -> Eff effs (Graph Vertex) + -> Eff effs (Graph ControlFlowVertex) runCallGraph lang includePackages modules package = do let analyzeTerm = withTermSpans . graphingTerms . cachingTerms analyzeModule = (if includePackages then graphingPackages else id) . convergingModules . graphingModules @@ -122,7 +122,7 @@ runCallGraph lang includePackages modules package = do . resumingAddressError . runReader (packageInfo package) . runReader (lowerBound @Span) - . runReader (lowerBound @Vertex) + . runReader (lowerBound @ControlFlowVertex) . providingLiveSet . runReader (lowerBound @(ModuleTable (NonEmpty (Module (ModuleResult (Hole (Maybe Name) (Located Monovariant))))))) . raiseHandler (runModules (ModuleTable.modulePaths (packageModules package))) @@ -142,7 +142,7 @@ runImportGraphToModuleInfos :: ( Declarations term ) => Proxy lang -> Package term - -> Eff effs (Graph Vertex) + -> Eff effs (Graph ControlFlowVertex) runImportGraphToModuleInfos lang (package :: Package term) = runImportGraph lang package allModuleInfos where allModuleInfos info = maybe (vertex (unknownModuleVertex info)) (foldMap (vertex . moduleVertex . moduleInfo)) (ModuleTable.lookup (modulePath info) (packageModules package)) From b29c3a57ae808318b052c94eddbe31a54f1ec3d3 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 6 Sep 2018 15:12:31 -0700 Subject: [PATCH 07/39] Fix Message instances for Span and Position --- src/Data/Span.hs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Data/Span.hs b/src/Data/Span.hs index 1bc4fd936..39747f616 100644 --- a/src/Data/Span.hs +++ b/src/Data/Span.hs @@ -24,12 +24,17 @@ data Pos = Pos { posLine :: !Int , posColumn :: !Int } - deriving (Show, Read, Eq, Ord, Generic, Hashable, Named, Message) + deriving (Show, Read, Eq, Ord, Generic, Hashable) -instance MessageField Pos where - encodeMessageField num = Encode.embedded num . encodeMessage (fieldNumber 1) - decodeMessageField = fromMaybe def <$> Decode.embedded (decodeMessage (fieldNumber 1)) - protoType pr = messageField (Prim $ Named (Single (nameOf pr))) Nothing +instance Named Pos where nameOf _ = "Position" +instance Message Pos where + encodeMessage num Pos{..} = Encode.embedded num (encodePrimitive 1 posLine <> encodePrimitive 2 posColumn) + -- TODO: FIXME + decodeMessage = undefined -- fromMaybe def <$> Decode.embedded (decodeMessage (fieldNumber 1)) + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim Int64) (Single "line") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim Int64) (Single "column") [] Nothing + ] instance HasDefault Pos where def = Pos 1 1 @@ -50,7 +55,16 @@ data Span = Span { spanStart :: Pos , spanEnd :: Pos } - deriving (Show, Read, Eq, Ord, Generic, Hashable, Named, Message) + deriving (Show, Read, Eq, Ord, Generic, Hashable, Named) + + +instance Message Span where + encodeMessage num Span{..} = Encode.embedded num (encodeMessage 1 spanStart <> encodeMessage 2 spanEnd) + decodeMessage = undefined + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim . Named $ Single (nameOf (Proxy @Pos))) (Single "start") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim . Named $ Single (nameOf (Proxy @Pos))) (Single "end") [] Nothing + ] spanFromSrcLoc :: SrcLoc -> Span spanFromSrcLoc = Span . (Pos . srcLocStartLine <*> srcLocStartCol) <*> (Pos . srcLocEndLine <*> srcLocEndCol) From 6269a64c5fc71703bb013d90eca74ac4d3bf34c6 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 6 Sep 2018 15:13:08 -0700 Subject: [PATCH 08/39] Re-gen protos and server generated code --- proto/code_analysis.proto | 4 +- proto/types.proto | 82 ++++++++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 30 deletions(-) diff --git a/proto/code_analysis.proto b/proto/code_analysis.proto index de7a55c58..41bc9e00e 100644 --- a/proto/code_analysis.proto +++ b/proto/code_analysis.proto @@ -119,7 +119,7 @@ message CallGraphRequest { } message CallGraphResponse { - AdjacencyList graph = 1; + ControlFlowGraph graph = 1; DebugInfo error_info = 2; } @@ -128,7 +128,7 @@ message ImportGraphRequest { } message ImportGraphResponse { - AdjacencyList graph = 1; + ControlFlowGraph graph = 1; DebugInfo error_info = 2; } diff --git a/proto/types.proto b/proto/types.proto index 55720da97..1cf155cff 100644 --- a/proto/types.proto +++ b/proto/types.proto @@ -21,15 +21,6 @@ enum Language { PHP = 11; } -enum VertexType { - PACKAGE = 0; - MODULE = 1; - UNKNOWN_MODULE = 2; - VARIABLE = 3; - METHOD = 4; - FUNCTION = 5; -} - message BlobPair { Blob before = 1; Blob after = 2; @@ -41,24 +32,14 @@ message Blob { Language blobLanguage = 3; } -message Edge { - uint64 edgeFrom = 1; - uint64 edgeTo = 2; -} - message ErrorSite { string errorMessage = 1; SrcLoc errorLocation = 2; } -message AdjacencyList { - repeated Vertex graphVertices = 1; - repeated Edge graphEdges = 2; -} - -message Pos { - int64 posLine = 1; - int64 posColumn = 2; +message Position { + int64 line = 1; + int64 column = 2; } message Project { @@ -69,8 +50,8 @@ message Project { } message Span { - Pos spanStart = 1; - Pos spanEnd = 2; + Position start = 1; + Position end = 2; } message SrcLoc { @@ -83,8 +64,53 @@ message SrcLoc { int64 srcLocEndCol = 7; } -message Vertex { - VertexType vertexType = 1; - string vertexContents = 2; - uint64 vertexTag = 3; +message ControlFlowGraph { + repeated ControlFlowVertex vertices = 1; + repeated ControlFlowEdge edges = 2; +} + +message ControlFlowEdge { + string from = 1; + string to = 2; +} + +message ControlFlowVertex { + oneof vertex { + Package package = 1; + Module module = 2; + UnknownModule unknownModule = 3; + Variable variable = 4; + Method method = 5; + Function function = 6; + } + message Package { + string id = 1; + string name = 2; + } + message Module { + string id = 1; + string name = 2; + } + message UnknownModule { + string id = 1; + string name = 2; + } + message Variable { + string id = 1; + string name = 2; + string moduleName = 3; + Span span = 4; + } + message Method { + string id = 1; + string name = 2; + string moduleName = 3; + Span span = 4; + } + message Function { + string id = 1; + string name = 2; + string moduleName = 3; + Span span = 4; + } } From 16b99b86346cc249f1e18bc6ad01ef3409ac2943 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 6 Sep 2018 16:29:32 -0700 Subject: [PATCH 09/39] One more roundtrip test --- test/Proto3/Roundtrip.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/Proto3/Roundtrip.hs b/test/Proto3/Roundtrip.hs index 7f8504906..c43f95fdb 100644 --- a/test/Proto3/Roundtrip.hs +++ b/test/Proto3/Roundtrip.hs @@ -43,7 +43,10 @@ spec = parallel $ do \sp -> shouldRoundtrip @BlobPair sp describe "spans" $ prop "roundtrips" $ - \sp -> shouldRoundtrip @Span sp + \x -> shouldRoundtrip @Span x + describe "pos" $ + prop "roundtrips" $ + \x -> shouldRoundtrip @Pos x describe "nulls" $ prop "roundtrips" $ From edc1b229dbe964f2500c998d33b5f0eaf019f7d9 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 6 Sep 2018 16:29:55 -0700 Subject: [PATCH 10/39] Sort out Span and Pos Message instances --- src/Data/Span.hs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Data/Span.hs b/src/Data/Span.hs index 39747f616..3dc9ba824 100644 --- a/src/Data/Span.hs +++ b/src/Data/Span.hs @@ -28,17 +28,13 @@ data Pos = Pos instance Named Pos where nameOf _ = "Position" instance Message Pos where - encodeMessage num Pos{..} = Encode.embedded num (encodePrimitive 1 posLine <> encodePrimitive 2 posColumn) - -- TODO: FIXME - decodeMessage = undefined -- fromMaybe def <$> Decode.embedded (decodeMessage (fieldNumber 1)) + encodeMessage _ Pos{..} = encodeMessageField 1 posLine <> encodeMessageField 2 posColumn + decodeMessage _ = Pos <$> Decode.at decodeMessageField 1 <*> Decode.at decodeMessageField 2 dotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim Int64) (Single "line") [] Nothing , DotProtoMessageField $ DotProtoField 2 (Prim Int64) (Single "column") [] Nothing ] -instance HasDefault Pos where - def = Pos 1 1 - instance A.ToJSON Pos where toJSON Pos{..} = A.toJSON [posLine, posColumn] @@ -51,6 +47,10 @@ instance A.FromJSON Pos where instance Lower Pos where lowerBound = Pos 1 1 +instance HasDefault Pos where + def = lowerBound @Pos + + data Span = Span { spanStart :: Pos , spanEnd :: Pos @@ -59,8 +59,9 @@ data Span = Span instance Message Span where - encodeMessage num Span{..} = Encode.embedded num (encodeMessage 1 spanStart <> encodeMessage 2 spanEnd) - decodeMessage = undefined + encodeMessage _ Span{..} = Encode.embedded 1 (encodeMessage 1 spanStart) <> Encode.embedded 2 (encodeMessage 1 spanEnd) + decodeMessage _ = Span <$> embeddedAt (decodeMessage 1) 1 <*> embeddedAt (decodeMessage 1) 2 + where embeddedAt parser = Decode.at (Decode.embedded'' parser) dotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim . Named $ Single (nameOf (Proxy @Pos))) (Single "start") [] Nothing , DotProtoMessageField $ DotProtoField 2 (Prim . Named $ Single (nameOf (Proxy @Pos))) (Single "end") [] Nothing @@ -91,4 +92,7 @@ instance ToJSONFields Span where toJSONFields sourceSpan = [ "sourceSpan" .= sourceSpan ] instance Lower Span where - lowerBound = Span lowerBound lowerBound + lowerBound = emptySpan + +instance HasDefault Span where + def = emptySpan From 31d093d1c9461b31625da9420387994fc829a3d5 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 6 Sep 2018 16:29:59 -0700 Subject: [PATCH 11/39] Fix tests --- test/Graphing/Calls/Spec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Graphing/Calls/Spec.hs b/test/Graphing/Calls/Spec.hs index fa6e51e13..942bba978 100644 --- a/test/Graphing/Calls/Spec.hs +++ b/test/Graphing/Calls/Spec.hs @@ -11,7 +11,7 @@ import Data.List (uncons) import Data.Abstract.Module import "semantic" Data.Graph (Graph (..), topologicalSort) -import Data.Graph.Vertex +import Data.Graph.ControlFlowVertex import Data.Span import qualified Data.Language as Language import Semantic.Config (defaultOptions) From 4bcd440c982dbc490c59aca701d585af8337d61e Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 6 Sep 2018 16:46:27 -0700 Subject: [PATCH 12/39] Dial in id vs description a bit, fix embedding of span --- proto/types.proto | 34 +++++++++++--------- src/Data/Graph.hs | 2 +- src/Data/Graph/ControlFlowVertex.hs | 48 +++++++++-------------------- src/Data/Span.hs | 19 +++++++----- src/Rendering/Graph.hs | 4 +-- 5 files changed, 48 insertions(+), 59 deletions(-) diff --git a/proto/types.proto b/proto/types.proto index 1cf155cff..87e0b42ea 100644 --- a/proto/types.proto +++ b/proto/types.proto @@ -70,8 +70,8 @@ message ControlFlowGraph { } message ControlFlowEdge { - string from = 1; - string to = 2; + int64 from = 1; + int64 to = 2; } message ControlFlowVertex { @@ -84,33 +84,39 @@ message ControlFlowVertex { Function function = 6; } message Package { - string id = 1; + int64 id = 1; string name = 2; + string description = 3; } message Module { - string id = 1; + int64 id = 1; string name = 2; + string description = 3; } message UnknownModule { - string id = 1; + int64 id = 1; string name = 2; + string description = 3; } message Variable { - string id = 1; + int64 id = 1; string name = 2; - string moduleName = 3; - Span span = 4; + string description = 3; + string moduleName = 4; + Span span = 5; } message Method { - string id = 1; + int64 id = 1; string name = 2; - string moduleName = 3; - Span span = 4; + string description = 3; + string moduleName = 4; + Span span = 5; } message Function { - string id = 1; + int64 id = 1; string name = 2; - string moduleName = 3; - Span span = 4; + string description = 3; + string moduleName = 4; + Span span = 5; } } diff --git a/src/Data/Graph.hs b/src/Data/Graph.hs index 85212810c..dd97b167e 100644 --- a/src/Data/Graph.hs +++ b/src/Data/Graph.hs @@ -118,7 +118,7 @@ instance Ord vertex => Ord (Graph vertex) where class VertexTag vertex where - uniqueTag :: vertex -> Text + uniqueTag :: vertex -> Int instance (Ord vertex, ToJSON vertex, VertexTag vertex) => ToJSON (Graph vertex) where toJSON (Graph graph) = object ["vertices" .= G.vertexList graph, "edges" .= (Edge <$> G.edgeList graph)] diff --git a/src/Data/Graph/ControlFlowVertex.hs b/src/Data/Graph/ControlFlowVertex.hs index ec9206139..b577e7807 100644 --- a/src/Data/Graph/ControlFlowVertex.hs +++ b/src/Data/Graph/ControlFlowVertex.hs @@ -34,10 +34,8 @@ import Prologue hiding (packageName) -- import Data.Word import Proto3.Suite import qualified Proto3.Suite as PB -import qualified Proto3.Suite.Types as PB import qualified Proto3.Wire.Encode as Encode import qualified Proto3.Wire.Decode as Decode -import qualified Algebra.Graph as Graph import GHC.Exts (fromList) -- | A vertex of representing some node in a control flow graph. @@ -50,26 +48,6 @@ data ControlFlowVertex | Function { vertexName :: Text, vertexModuleName :: Text, vertexSpan :: Span } deriving (Eq, Ord, Show, Generic, Hashable, Named) --- | A tag used on each vertex of a 'Graph' to convert to an 'ControlFlowAdjacencyList'. --- type Tag = Word64 - --- -- | A serializable edge type for control flow graphs. Only tag information is --- -- carried about vertices; consumers are expected to look up nodes in the vertex --- -- list when necessary. --- data ControlFlowEdge = ControlFlowEdge --- { controlFlowEdgeFrom :: Tag --- , controlFlowEdgeTo :: Tag --- } deriving (Eq, Ord, Show, Generic, Hashable, PB.Named, Message) - --- -- | An adjacency list-representation of a control flow graph. This --- -- representation is less efficient and fluent than an ordinary 'Graph', but is --- -- more amenable to serialization. --- data ControlFlowAdjacencyList = ControlFlowAdjacencyList --- { controlFlowVertices :: [ControlFlowVertex] --- , controlFlowEdges :: [ControlFlowEdge] --- } deriving (Eq, Ord, Show, Generic, Hashable, Named, Message) - - packageVertex :: PackageInfo -> ControlFlowVertex packageVertex (PackageInfo name _) = Package (formatName name) @@ -123,18 +101,18 @@ instance Message (G.Graph ControlFlowVertex) where ] instance Lower ControlFlowVertex where lowerBound = Package "" -instance VertexTag ControlFlowVertex where uniqueTag = vertexIdentifier +instance VertexTag ControlFlowVertex where uniqueTag = hash . vertexIdentifier instance ToJSON ControlFlowVertex where toJSON v = object [ "name" .= vertexIdentifier v, "type" .= vertexToType v ] instance Message ControlFlowVertex where - encodeMessage _ v@Package{..} = Encode.embedded 1 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName) - encodeMessage _ v@Module{..} = Encode.embedded 2 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName) - encodeMessage _ v@UnknownModule{..} = Encode.embedded 3 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName) - encodeMessage _ v@Variable{..} = Encode.embedded 4 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 vertexModuleName <> encodeMessage 4 vertexSpan) - encodeMessage _ v@Method{..} = Encode.embedded 5 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 vertexModuleName <> encodeMessage 4 vertexSpan) - encodeMessage _ v@Function{..} = Encode.embedded 6 (encodePrimitive 1 (vertexIdentifier v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 vertexModuleName <> encodeMessage 4 vertexSpan) + encodeMessage _ v@Package{..} = Encode.embedded 1 (encodePrimitive 1 (uniqueTag v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 (vertexIdentifier v)) + encodeMessage _ v@Module{..} = Encode.embedded 2 (encodePrimitive 1 (uniqueTag v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 (vertexIdentifier v)) + encodeMessage _ v@UnknownModule{..} = Encode.embedded 3 (encodePrimitive 1 (uniqueTag v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 (vertexIdentifier v)) + encodeMessage _ v@Variable{..} = Encode.embedded 4 (encodePrimitive 1 (uniqueTag v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 (vertexIdentifier v) <> encodePrimitive 4 vertexModuleName <> Encode.embedded 5 (encodeMessage 1 vertexSpan)) + encodeMessage _ v@Method{..} = Encode.embedded 5 (encodePrimitive 1 (uniqueTag v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 (vertexIdentifier v) <> encodePrimitive 4 vertexModuleName <> Encode.embedded 5 (encodeMessage 1 vertexSpan)) + encodeMessage _ v@Function{..} = Encode.embedded 6 (encodePrimitive 1 (uniqueTag v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 (vertexIdentifier v) <> encodePrimitive 4 vertexModuleName <> Encode.embedded 5 (encodeMessage 1 vertexSpan)) decodeMessage = undefined dotProto _ = [ DotProtoMessageOneOf (Single "vertex") @@ -153,12 +131,13 @@ instance Message ControlFlowVertex where <> gen "Method" [ genModuleName, genSpan ] <> gen "Function" [ genModuleName, genSpan ] where - genModuleName = DotProtoMessageField $ DotProtoField 3 (Prim PB.String) (Single "moduleName") [] Nothing - genSpan = DotProtoMessageField $ DotProtoField 4 (Prim . Named $ Single (nameOf (Proxy @Span))) (Single "span") [] Nothing + genModuleName = DotProtoMessageField $ DotProtoField 4 (Prim PB.String) (Single "moduleName") [] Nothing + genSpan = DotProtoMessageField $ DotProtoField 5 (Prim . Named $ Single (nameOf (Proxy @Span))) (Single "span") [] Nothing gen name extras = [ DotProtoMessageDefinition . DotProtoMessage (Single name) $ - (DotProtoMessageField $ DotProtoField 1 (Prim PB.String) (Single "id") [] Nothing) + (DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "id") [] Nothing) : (DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "name") [] Nothing) + : (DotProtoMessageField $ DotProtoField 3 (Prim PB.String) (Single "description") [] Nothing) : extras ] @@ -169,11 +148,12 @@ instance Message (G.Edge ControlFlowVertex) where encodeMessage _ (G.Edge (from, to)) = encodePrimitive 1 (uniqueTag from) <> encodePrimitive 2 (uniqueTag to) decodeMessage = undefined dotProto _ = - [ DotProtoMessageField $ DotProtoField 1 (Prim PB.String) (Single "from") [] Nothing - , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "to") [] Nothing + [ DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "from") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.Int64) (Single "to") [] Nothing ] +-- TODO: This is potentially valuable just to get name's out of declarable things. -- Typeclasses to create 'ControlFlowVertex's from 'Term's. Also extracts -- 'Name's for terms with symbolic names like Identifiers and Declarations. diff --git a/src/Data/Span.hs b/src/Data/Span.hs index 3dc9ba824..d40b300f9 100644 --- a/src/Data/Span.hs +++ b/src/Data/Span.hs @@ -19,13 +19,23 @@ import Data.JSON.Fields import GHC.Stack import Prologue --- | Source position information +-- | Source position information (1 indexed) data Pos = Pos { posLine :: !Int , posColumn :: !Int } deriving (Show, Read, Eq, Ord, Generic, Hashable) +-- | A Span of position information +data Span = Span + { spanStart :: Pos + , spanEnd :: Pos + } + deriving (Show, Read, Eq, Ord, Generic, Hashable, Named) + + +-- Instances + instance Named Pos where nameOf _ = "Position" instance Message Pos where encodeMessage _ Pos{..} = encodeMessageField 1 posLine <> encodeMessageField 2 posColumn @@ -51,13 +61,6 @@ instance HasDefault Pos where def = lowerBound @Pos -data Span = Span - { spanStart :: Pos - , spanEnd :: Pos - } - deriving (Show, Read, Eq, Ord, Generic, Hashable, Named) - - instance Message Span where encodeMessage _ Span{..} = Encode.embedded 1 (encodeMessage 1 spanStart) <> Encode.embedded 2 (encodeMessage 1 spanEnd) decodeMessage _ = Span <$> embeddedAt (decodeMessage 1) 1 <*> embeddedAt (decodeMessage 1) 2 diff --git a/src/Rendering/Graph.hs b/src/Rendering/Graph.hs index 0a442961b..8bc45dfac 100644 --- a/src/Rendering/Graph.hs +++ b/src/Rendering/Graph.hs @@ -138,7 +138,7 @@ instance ToJSON TermVertex where instance VertexTag TermVertex where - uniqueTag = T.pack . show . vertexId + uniqueTag = vertexId instance ToJSON DiffVertex where toJSON (DiffVertex i (Deleted t)) = object [ "id" .= T.pack (show i), "deleted" .= t ] @@ -150,7 +150,7 @@ instance ToJSON DiffVertex where instance VertexTag DiffVertex where - uniqueTag = T.pack . show . diffVertexId + uniqueTag = diffVertexId class ToTreeGraph vertex t | t -> vertex where From a15155c4da429a55a1dd1f2c60d23745730bb41c Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 6 Sep 2018 17:27:13 -0700 Subject: [PATCH 13/39] Basics of TermVertex in grpc --- proto/types.proto | 25 +++++++ semantic.cabal | 2 + src/Data/Graph/ControlFlowVertex.hs | 12 ++- src/Data/Graph/DiffVertex.hs | 98 +++++++++++++++++++++++++ src/Data/Graph/TermVertex.hs | 97 +++++++++++++++++++++++++ src/Data/Range.hs | 20 ++++- src/Rendering/Graph.hs | 109 +--------------------------- src/Rendering/Renderer.hs | 1 + src/Semantic/Diff.hs | 1 + src/Semantic/Parse.hs | 1 + 10 files changed, 250 insertions(+), 116 deletions(-) create mode 100644 src/Data/Graph/DiffVertex.hs create mode 100644 src/Data/Graph/TermVertex.hs diff --git a/proto/types.proto b/proto/types.proto index 87e0b42ea..584d82967 100644 --- a/proto/types.proto +++ b/proto/types.proto @@ -54,6 +54,11 @@ message Span { Position end = 2; } +message Range { + int64 start = 1; + int64 end = 2; +} + message SrcLoc { string srcLocPackage = 1; string srcLocModule = 2; @@ -120,3 +125,23 @@ message ControlFlowVertex { Span span = 5; } } + +message TermGraph { + repeated TermVertex vertices = 1; + repeated TermEdge edges = 2; +} + +message TermEdge { + int64 from = 1; + int64 to = 2; +} + +message TermVertex { + int64 id = 1; + string name = 2; +} + +message TermAnnotation { + Range range = 1; + Span span = 2; +} diff --git a/semantic.cabal b/semantic.cabal index ff1f08c11..0dc82938a 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -83,6 +83,8 @@ library , Data.Functor.Classes.Generic , Data.Graph , Data.Graph.ControlFlowVertex + , Data.Graph.TermVertex + , Data.Graph.DiffVertex , Data.History , Data.JSON.Fields , Data.Language diff --git a/src/Data/Graph/ControlFlowVertex.hs b/src/Data/Graph/ControlFlowVertex.hs index b577e7807..ea7b3cae1 100644 --- a/src/Data/Graph/ControlFlowVertex.hs +++ b/src/Data/Graph/ControlFlowVertex.hs @@ -20,23 +20,21 @@ import Data.Abstract.Module (ModuleInfo (..)) import Data.Abstract.Name import Data.Abstract.Package (PackageInfo (..)) import Data.Aeson +import Data.Graph (VertexTag (..)) +import qualified Data.Graph as G import Data.Record import Data.Span -import Data.Graph (VertexTag(..)) -import qualified Data.Graph as G import qualified Data.Syntax as Syntax import qualified Data.Syntax.Declaration as Declaration import qualified Data.Syntax.Expression as Expression import Data.Term import qualified Data.Text as T +import GHC.Exts (fromList) import Prologue hiding (packageName) - --- import Data.Word -import Proto3.Suite +import Proto3.Suite import qualified Proto3.Suite as PB -import qualified Proto3.Wire.Encode as Encode import qualified Proto3.Wire.Decode as Decode -import GHC.Exts (fromList) +import qualified Proto3.Wire.Encode as Encode -- | A vertex of representing some node in a control flow graph. data ControlFlowVertex diff --git a/src/Data/Graph/DiffVertex.hs b/src/Data/Graph/DiffVertex.hs new file mode 100644 index 000000000..432a40767 --- /dev/null +++ b/src/Data/Graph/DiffVertex.hs @@ -0,0 +1,98 @@ +module Data.Graph.DiffVertex +( DiffVertex(..) +, DiffVertexTerm(..) +, DeletedTerm(..) +, InsertedTerm(..) +, ReplacedTerm(..) +, MergedTerm(..) + +-- rexport +, TermVertex(..) +, TermAnnotation(..) +) where + +import Prologue +import Data.Graph +import Data.Graph.TermVertex +import Data.Aeson +import Data.Range +import Data.Span +import Data.JSON.Fields +import qualified Data.Text as T + +-- Diffs + +data DiffVertex + = DiffVertex + { diffVertexId :: Int + , diffVertexTerm :: DiffVertexTerm + } deriving (Eq, Ord, Show) + +data DiffVertexTerm + = Deleted DeletedTerm + | Inserted InsertedTerm + | Replaced ReplacedTerm + | Merged MergedTerm + deriving (Eq, Ord, Show) + +data MergedTerm + = MergedTerm + { mergedTermName :: String + , mergedTermBefore :: TermAnnotation + , mergedTermAfter :: TermAnnotation + } deriving (Eq, Ord, Show) + +data DeletedTerm + = DeletedTerm + { deletedTermName :: String + , deletedTermBefore :: TermAnnotation + } deriving (Eq, Ord, Show) + +data InsertedTerm + = InsertedTerm + { insertedTermName :: String + , insertedTermAfter :: TermAnnotation + } deriving (Eq, Ord, Show) + +data ReplacedTerm + = ReplacedTerm + { replacedTermBefore :: DeletedTerm + , replacedTermAfter :: InsertedTerm + } deriving (Eq, Ord, Show) + +-- Instances + +instance ToJSON MergedTerm where + toJSON MergedTerm{..} = object + [ "term" .= mergedTermName + , "before" .= mergedTermBefore + , "after" .= mergedTermAfter + ] + +instance ToJSON DeletedTerm where + toJSON DeletedTerm{..} = object + [ "term" .= deletedTermName + , "before" .= deletedTermBefore + ] + +instance ToJSON InsertedTerm where + toJSON InsertedTerm{..} = object + [ "term" .= insertedTermName + , "after" .= insertedTermAfter + ] + +instance ToJSON ReplacedTerm where + toJSON (ReplacedTerm DeletedTerm{..} InsertedTerm{..}) + = object [ "before" .= deleted, "after" .= inserted ] + where deleted = object $ [ "term" .= deletedTermName ] <> toJSONFields deletedTermBefore + inserted = object $ [ "term" .= insertedTermName ] <> toJSONFields insertedTermAfter + +instance ToJSON DiffVertex where + toJSON (DiffVertex i (Deleted t)) = object [ "id" .= T.pack (show i), "deleted" .= t ] + toJSON (DiffVertex i (Inserted t)) = object [ "id" .= T.pack (show i), "inserted" .= t ] + toJSON (DiffVertex i (Replaced t)) = object [ "id" .= T.pack (show i), "replaced" .= t ] + toJSON (DiffVertex i (Merged t)) = object [ "id" .= T.pack (show i), "merged" .= t ] + -- TODO + -- toEncoding = undefined + +instance VertexTag DiffVertex where uniqueTag = diffVertexId diff --git a/src/Data/Graph/TermVertex.hs b/src/Data/Graph/TermVertex.hs new file mode 100644 index 000000000..d2dba9cc3 --- /dev/null +++ b/src/Data/Graph/TermVertex.hs @@ -0,0 +1,97 @@ +{-# LANGUAGE DeriveAnyClass, ScopedTypeVariables, TypeFamilies, TypeOperators, UndecidableInstances #-} +module Data.Graph.TermVertex +( TermVertex(..) +, TermAnnotation(..) +) where + +import Prologue + +import Data.Aeson +import Data.Graph +import Data.JSON.Fields +import Data.Range +import Data.Span +import GHC.Exts (fromList) +import Proto3.Suite +import qualified Proto3.Suite as PB +import Proto3.Wire.Decode as Decode +import Proto3.Wire.Encode as Encode + +-- Terms + +data TermVertex + = TermVertex + { vertexId :: Int + , vertexTermName :: String + , vertexRange :: Range + , vertexSpan :: Span + } deriving (Eq, Ord, Show, Generic, Named) + +data TermAnnotation + = TermAnnotation + { range :: Range + , span :: Span + } deriving (Eq, Ord, Show, Generic, Named) + + +-- Instances + +instance Named (Graph TermVertex) where nameOf _ = "TermGraph" +instance Message (Graph TermVertex) where + encodeMessage _ graph = encodeMessageField 1 (NestedVec (fromList (vertexList graph))) + <> encodeMessageField 2 (NestedVec (fromList (edgeList graph))) + decodeMessage = undefined + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Repeated . Named $ Single "TermVertex") (Single "vertices") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Repeated . Named $ Single "TermEdge") (Single "edges") [] Nothing + ] + +instance Named (Edge TermVertex) where nameOf _ = "TermEdge" +instance Message (Edge TermVertex) where + encodeMessage _ (Edge (from, to)) = encodePrimitive 1 (uniqueTag from) <> encodePrimitive 2 (uniqueTag to) + decodeMessage = undefined + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "from") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.Int64) (Single "to") [] Nothing + ] + +instance Message TermVertex where + encodeMessage _ TermVertex{..} = encodeMessageField 1 vertexId <> encodeMessageField 2 vertexTermName -- Encode.embedded 1 (encodeMessage 0 vertexId) <> Encode.embedded 2 (encodeMessage 0 vertexTermName) + decodeMessage _ = TermVertex <$> Decode.at decodeMessageField 1 <*> Decode.at decodeMessageField 2 <*> pure lowerBound <*> pure lowerBound -- TODO <*> embeddedAt (decodeMessage 0) 1 <*> embeddedAt (decodeMessage 0) 2 + where embeddedAt parser = Decode.at (Decode.embedded'' parser) + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "id") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "name") [] Nothing + ] + +instance VertexTag TermVertex where uniqueTag = vertexId + +instance ToJSON TermVertex where + toJSON TermVertex{..} = object $ + [ "id" .= vertexId + , "term" .= vertexTermName ] + <> toJSONFields vertexRange + <> toJSONFields vertexSpan + toEncoding TermVertex{..} = pairs . fold $ + "id" .= vertexId + : "name" .= vertexTermName + : toJSONFields vertexRange + <> toJSONFields vertexSpan + +instance Message TermAnnotation where + encodeMessage _ TermAnnotation{..} = Encode.embedded 1 (encodeMessage 0 range) <> Encode.embedded 2 (encodeMessage 0 span) + decodeMessage _ = TermAnnotation <$> embeddedAt (decodeMessage 0) 1 <*> embeddedAt (decodeMessage 0) 2 + where embeddedAt parser = Decode.at (Decode.embedded'' parser) + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim . Named $ Single (nameOf (Proxy @Range))) (Single "range") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim . Named $ Single (nameOf (Proxy @Span))) (Single "span") [] Nothing + ] + +instance HasDefault TermAnnotation where + def = TermAnnotation def def + +instance ToJSON TermAnnotation where + toJSON TermAnnotation{..} = object $ toJSONFields range <> toJSONFields span + +instance ToJSONFields TermAnnotation where + toJSONFields TermAnnotation{..} = toJSONFields range <> toJSONFields span diff --git a/src/Data/Range.hs b/src/Data/Range.hs index bd5a8b7ac..f47fcc7b3 100644 --- a/src/Data/Range.hs +++ b/src/Data/Range.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE DeriveAnyClass #-} module Data.Range ( Range(..) , emptyRange @@ -7,13 +8,17 @@ module Data.Range , subtractRange ) where +import Prologue + import Data.Aeson import Data.JSON.Fields -import Prologue +import Proto3.Suite +import Proto3.Wire.Decode as Decode +import Proto3.Wire.Encode as Encode -- | A half-open interval of integers, defined by start & end indices. data Range = Range { start :: {-# UNPACK #-} !Int, end :: {-# UNPACK #-} !Int } - deriving (Eq, Show, Generic) + deriving (Eq, Show, Generic, Named) emptyRange :: Range emptyRange = Range 0 0 @@ -54,3 +59,14 @@ instance ToJSONFields Range where instance Lower Range where lowerBound = Range 0 0 + +instance HasDefault Range where + def = lowerBound @Range + +instance Message Range where + encodeMessage _ Range{..} = encodeMessageField 1 start <> encodeMessageField 2 end + decodeMessage _ = Range <$> Decode.at decodeMessageField 1 <*> Decode.at decodeMessageField 2 + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim Int64) (Single "start") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim Int64) (Single "end") [] Nothing + ] diff --git a/src/Rendering/Graph.hs b/src/Rendering/Graph.hs index 8bc45dfac..bfb25cf6a 100644 --- a/src/Rendering/Graph.hs +++ b/src/Rendering/Graph.hs @@ -4,20 +4,17 @@ module Rendering.Graph , termStyle , diffStyle , ToTreeGraph(..) -, TermVertex(..) -, DiffVertex(..) ) where -import Data.Aeson -import Data.JSON.Fields import Algebra.Graph.Export.Dot import Analysis.ConstructorName import Control.Monad.Effect import Control.Monad.Effect.Fresh import Control.Monad.Effect.Reader -import qualified Data.Text as T import Data.Diff import Data.Graph +import Data.Graph.TermVertex +import Data.Graph.DiffVertex import Data.Range import Data.Span import Data.Record @@ -51,108 +48,6 @@ diffStyle name = (defaultStyle (fromString . show . diffVertexId)) vertexAttributes (DiffVertex _ (Replaced ReplacedTerm{..})) = [ "label" := "Replacement", "color" := "orange", "style" := "dashed" ] vertexAttributes (DiffVertex _ (Merged MergedTerm{..})) = [ "label" := fromString mergedTermName ] -data TermVertex - = TermVertex - { vertexId :: Int - , vertexTermName :: String - , vertexRange :: Range - , vertexSpan :: Span - } deriving (Eq, Ord, Show) - -data TermAnnotation - = TermAnnotation - { range :: Range - , span :: Span - } deriving (Eq, Ord, Show) - -instance ToJSON TermAnnotation where - toJSON TermAnnotation{..} = object $ toJSONFields range <> toJSONFields span - -instance ToJSONFields TermAnnotation where - toJSONFields TermAnnotation{..} = toJSONFields range <> toJSONFields span - -data MergedTerm - = MergedTerm - { mergedTermName :: String - , mergedTermBefore :: TermAnnotation - , mergedTermAfter :: TermAnnotation - } deriving (Eq, Ord, Show) - -instance ToJSON MergedTerm where - toJSON MergedTerm{..} = object [ "term" .= mergedTermName, "before" .= mergedTermBefore, "after" .= mergedTermAfter ] - -data DeletedTerm - = DeletedTerm - { deletedTermName :: String - , deletedTermBefore :: TermAnnotation - } deriving (Eq, Ord, Show) - -instance ToJSON DeletedTerm where - toJSON DeletedTerm{..} = object [ "term" .= deletedTermName, "before" .= deletedTermBefore ] - -data InsertedTerm - = InsertedTerm - { insertedTermName :: String - , insertedTermAfter :: TermAnnotation - } deriving (Eq, Ord, Show) - -instance ToJSON InsertedTerm where - toJSON InsertedTerm{..} = object [ "term" .= insertedTermName, "after" .= insertedTermAfter ] - -data ReplacedTerm - = ReplacedTerm - { replacedTermBefore :: DeletedTerm - , replacedTermAfter :: InsertedTerm - } deriving (Eq, Ord, Show) - -instance ToJSON ReplacedTerm where - toJSON (ReplacedTerm DeletedTerm{..} InsertedTerm{..}) - = object [ "before" .= deleted, "after" .= inserted ] - where deleted = object $ [ "term" .= deletedTermName ] <> toJSONFields deletedTermBefore - inserted = object $ [ "term" .= insertedTermName ] <> toJSONFields insertedTermAfter - -data DiffVertexTerm - = Deleted DeletedTerm - | Inserted InsertedTerm - | Replaced ReplacedTerm - | Merged MergedTerm - deriving (Eq, Ord, Show) - -data DiffVertex - = DiffVertex - { diffVertexId :: Int - , diffVertexTerm :: DiffVertexTerm - } deriving (Eq, Ord, Show) - -instance ToJSON TermVertex where - toJSON TermVertex{..} - = object $ [ "id" .= T.pack (show vertexId) - , "term" .= vertexTermName ] - <> toJSONFields vertexRange - <> toJSONFields vertexSpan - toEncoding TermVertex{..} - = pairs ( fold ( "id" .= T.pack (show vertexId) - : "name" .= vertexTermName - : toJSONFields vertexRange - <> toJSONFields vertexSpan )) - - -instance VertexTag TermVertex where - uniqueTag = vertexId - -instance ToJSON DiffVertex where - toJSON (DiffVertex i (Deleted t)) = object [ "id" .= T.pack (show i), "deleted" .= t ] - toJSON (DiffVertex i (Inserted t)) = object [ "id" .= T.pack (show i), "inserted" .= t ] - toJSON (DiffVertex i (Replaced t)) = object [ "id" .= T.pack (show i), "replaced" .= t ] - toJSON (DiffVertex i (Merged t)) = object [ "id" .= T.pack (show i), "merged" .= t ] - -- TODO - -- toEncoding = undefined - - -instance VertexTag DiffVertex where - uniqueTag = diffVertexId - - class ToTreeGraph vertex t | t -> vertex where toTreeGraph :: (Member Fresh effs, Member (Reader (Graph vertex)) effs) => t (Eff effs (Graph vertex)) -> Eff effs (Graph vertex) diff --git a/src/Rendering/Renderer.hs b/src/Rendering/Renderer.hs index fce9de643..d675f676e 100644 --- a/src/Rendering/Renderer.hs +++ b/src/Rendering/Renderer.hs @@ -23,6 +23,7 @@ module Rendering.Renderer import Data.ByteString.Builder import Data.Graph +import Data.Graph.DiffVertex import Rendering.Graph as R import Rendering.JSON as R import Rendering.Symbol as R diff --git a/src/Semantic/Diff.hs b/src/Semantic/Diff.hs index 47382b4fe..33d58b48d 100644 --- a/src/Semantic/Diff.hs +++ b/src/Semantic/Diff.hs @@ -16,6 +16,7 @@ import Data.Diff import Data.JSON.Fields import Data.Record import Data.Term +import Data.Graph.DiffVertex import Diffing.Algorithm (Diffable) import Parsing.Parser import Prologue hiding (MonadError(..)) diff --git a/src/Semantic/Parse.hs b/src/Semantic/Parse.hs index 0d8f682df..aa24a1116 100644 --- a/src/Semantic/Parse.hs +++ b/src/Semantic/Parse.hs @@ -13,6 +13,7 @@ import Analysis.PackageDef (HasPackageDef) import Control.Monad.Effect.Exception import Data.AST import Data.Blob +import Data.Graph.TermVertex import Data.JSON.Fields import Data.Quieterm import Data.Record From 2cca3875f6ecaea7bfa15a8791b41f129d57eeab Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Fri, 7 Sep 2018 08:59:41 -0700 Subject: [PATCH 14/39] First pass at working term adj graphs in grpc --- proto/code_analysis.proto | 7 +++++++ src/Rendering/Graph.hs | 1 + src/Semantic/Parse.hs | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/proto/code_analysis.proto b/proto/code_analysis.proto index 41bc9e00e..74fcf2b7e 100644 --- a/proto/code_analysis.proto +++ b/proto/code_analysis.proto @@ -21,6 +21,8 @@ option go_package = "github.com/semantic/analysis/;analysis"; service CodeAnalysis { // Parsing // + // Parse source code blobs and return abstract syntax trees as adjacency list graph. + rpc ParseTreeGraph (ParseTreeRequest) returns (ParseTreeGraphResponse); // Parse source code blobs and return abstract syntax trees. rpc ParseTree (ParseTreeRequest) returns (ParseTreeResponse); @@ -49,6 +51,11 @@ message ParseTreeRequest { repeated Blob blobs = 1; } +message ParseTreeGraphResponse { + repeated TermGraph graph = 1; + DebugInfo error_info = 2; +} + message ParseTreeResponse { oneof response_type { RubyResponse ruby = 1; diff --git a/src/Rendering/Graph.hs b/src/Rendering/Graph.hs index bfb25cf6a..d29d0170f 100644 --- a/src/Rendering/Graph.hs +++ b/src/Rendering/Graph.hs @@ -23,6 +23,7 @@ import Data.String (IsString(..)) import Data.Term import Prologue +-- TODO: rename as this isn't a render renderTreeGraph :: (Ord vertex, Recursive t, ToTreeGraph vertex (Base t)) => t -> Graph vertex renderTreeGraph = simplify . runGraph . cata toTreeGraph diff --git a/src/Semantic/Parse.hs b/src/Semantic/Parse.hs index aa24a1116..a7bcfb669 100644 --- a/src/Semantic/Parse.hs +++ b/src/Semantic/Parse.hs @@ -3,6 +3,7 @@ module Semantic.Parse ( runParse , runPythonParse , runRubyParse + , runRubyParse' , runTypeScriptParse , runJSONParse ) where @@ -50,6 +51,11 @@ runRubyParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member runRubyParse = flip distributeFor $ \blob -> (Right . (() <$) <$> parse rubyParser blob) `catchError` (pure . Left) +runRubyParse' :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) + => [Blob] -> Eff effs [Either SomeException (Term (Sum Ruby.Syntax) (Record Location))] +runRubyParse' = flip distributeFor $ \blob -> + (Right <$> parse rubyParser blob) `catchError` (pure . Left) + runTypeScriptParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) => [Blob] -> Eff effs [Either SomeException (Term (Sum TypeScript.Syntax) ())] runTypeScriptParse = flip distributeFor $ \blob -> do From 2c8df30476e93c92c63b8d358bde105d52e242de Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Fri, 7 Sep 2018 11:25:19 -0700 Subject: [PATCH 15/39] Move specialized parsing around, implement more of grpc handler --- proto/code_analysis.proto | 7 ++++++- src/Semantic/Parse.hs | 38 +------------------------------------- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/proto/code_analysis.proto b/proto/code_analysis.proto index 74fcf2b7e..dde0f3b00 100644 --- a/proto/code_analysis.proto +++ b/proto/code_analysis.proto @@ -52,10 +52,15 @@ message ParseTreeRequest { } message ParseTreeGraphResponse { - repeated TermGraph graph = 1; + ParseTreeGraph graph = 1; DebugInfo error_info = 2; } +message ParseTreeGraph { + repeated TermGraph graph = 1; + repeated DebugInfo error_info = 2; +} + message ParseTreeResponse { oneof response_type { RubyResponse ruby = 1; diff --git a/src/Semantic/Parse.hs b/src/Semantic/Parse.hs index a7bcfb669..1cc72ada1 100644 --- a/src/Semantic/Parse.hs +++ b/src/Semantic/Parse.hs @@ -1,12 +1,5 @@ {-# LANGUAGE GADTs, RankNTypes #-} -module Semantic.Parse - ( runParse - , runPythonParse - , runRubyParse - , runRubyParse' - , runTypeScriptParse - , runJSONParse - ) where +module Semantic.Parse ( runParse ) where import Analysis.ConstructorName (ConstructorName) import Analysis.Declaration (HasDeclaration, declarationAlgebra) @@ -21,7 +14,6 @@ import Data.Record import Data.Term import qualified Language.JSON.Assignment as JSON import qualified Language.Python.Assignment as Python -import qualified Language.Ruby.Assignment as Ruby import qualified Language.TypeScript.Assignment as TypeScript import Parsing.Parser import Prologue hiding (MonadError (..)) @@ -43,34 +35,6 @@ runParse ShowTermRenderer = withParsedBlobs (\_ _ -> mempty) (const runParse (SymbolsTermRenderer fields) = withParsedBlobs (\_ _ -> mempty) (\ blob -> decorate (declarationAlgebra blob) >=> render (renderSymbolTerms . renderToSymbols fields blob)) >=> serialize JSON runParse DOTTermRenderer = withParsedBlobs (\_ _ -> mempty) (const (render renderTreeGraph)) >=> serialize (DOT (termStyle "terms")) --- NB: Our gRPC interface requires concrete 'Term's for each language to know --- how to encode messages, so we have dedicated functions for parsing each --- supported language. -runRubyParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) - => [Blob] -> Eff effs [Either SomeException (Term (Sum Ruby.Syntax) ())] -runRubyParse = flip distributeFor $ \blob -> - (Right . (() <$) <$> parse rubyParser blob) `catchError` (pure . Left) - -runRubyParse' :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) - => [Blob] -> Eff effs [Either SomeException (Term (Sum Ruby.Syntax) (Record Location))] -runRubyParse' = flip distributeFor $ \blob -> - (Right <$> parse rubyParser blob) `catchError` (pure . Left) - -runTypeScriptParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) - => [Blob] -> Eff effs [Either SomeException (Term (Sum TypeScript.Syntax) ())] -runTypeScriptParse = flip distributeFor $ \blob -> do - (Right . (() <$) <$> parse typescriptParser blob) `catchError` (pure . Left) - -runPythonParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) - => [Blob] -> Eff effs [Either SomeException (Term (Sum Python.Syntax) ())] -runPythonParse = flip distributeFor $ \blob -> do - (Right . (() <$) <$> parse pythonParser blob) `catchError` (pure . Left) - -runJSONParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) - => [Blob] -> Eff effs [Either SomeException (Term (Sum JSON.Syntax) ())] -runJSONParse = flip distributeFor $ \blob -> do - (Right . (() <$) <$> parse jsonParser blob) `catchError` (pure . Left) - withParsedBlobs :: ( Member Distribute effs , Member (Exc SomeException) effs From 7905b0e26d535a3f1d127d4296023116c80054a4 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Fri, 7 Sep 2018 14:20:44 -0700 Subject: [PATCH 16/39] Do not need these anymore --- src/Semantic/Parse.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Semantic/Parse.hs b/src/Semantic/Parse.hs index 1cc72ada1..73bceed3a 100644 --- a/src/Semantic/Parse.hs +++ b/src/Semantic/Parse.hs @@ -12,9 +12,6 @@ import Data.JSON.Fields import Data.Quieterm import Data.Record import Data.Term -import qualified Language.JSON.Assignment as JSON -import qualified Language.Python.Assignment as Python -import qualified Language.TypeScript.Assignment as TypeScript import Parsing.Parser import Prologue hiding (MonadError (..)) import Rendering.Graph From 88c90521bee1692cddf6da87995dd86310cda1f1 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Fri, 7 Sep 2018 14:20:56 -0700 Subject: [PATCH 17/39] Cleanup --- src/Language/Ruby/Assignment.hs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Language/Ruby/Assignment.hs b/src/Language/Ruby/Assignment.hs index 5ab37060b..0bceddef6 100644 --- a/src/Language/Ruby/Assignment.hs +++ b/src/Language/Ruby/Assignment.hs @@ -7,6 +7,8 @@ module Language.Ruby.Assignment , Term ) where +import Prologue hiding (for) + import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment import Data.Abstract.Name (name) @@ -37,7 +39,6 @@ import qualified Data.Term as Term import qualified Data.Diff as Diff import Language.Ruby.Grammar as Grammar import qualified Language.Ruby.Syntax as Ruby.Syntax -import Prologue hiding (for) import Proto3.Suite (Named (..), Named1 (..)) -- | The type of Ruby syntax. @@ -133,14 +134,10 @@ type Syntax = '[ type Term = Term.Term (Sum Syntax) (Record Location) type Assignment = Assignment.Assignment [] Grammar -instance Named1 (Sum Syntax) where - nameOf1 _ = "RubySyntax" - -instance Named (Term.Term (Sum Syntax) ()) where - nameOf _ = "RubyTerm" - -instance Named (Diff.Diff (Sum Syntax) () ()) where - nameOf _ = "RubyDiff" +-- For Protobuf serialization +instance Named1 (Sum Syntax) where nameOf1 _ = "RubySyntax" +instance Named (Term.Term (Sum Syntax) ()) where nameOf _ = "RubyTerm" +instance Named (Diff.Diff (Sum Syntax) () ()) where nameOf _ = "RubyDiff" -- | Assignment from AST in Ruby’s grammar onto a program in Ruby’s syntax. assignment :: Assignment Term From 3ff2861fe5d45ececaf77d5068eab8252eb8cd36 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Fri, 7 Sep 2018 14:21:42 -0700 Subject: [PATCH 18/39] Record fields for syntaxes and needed PB deriving --- src/Data/Syntax/Expression.hs | 2 +- src/Data/Syntax/Literal.hs | 9 ++-- src/Data/Syntax/Statement.hs | 12 +++--- src/Data/Syntax/Type.hs | 24 ++++++----- src/Language/Go/Syntax.hs | 78 ++++++++++++++++++++++------------- src/Language/Java/Syntax.hs | 73 ++++++++++++++++---------------- 6 files changed, 112 insertions(+), 86 deletions(-) diff --git a/src/Data/Syntax/Expression.hs b/src/Data/Syntax/Expression.hs index d5655d313..d8628d406 100644 --- a/src/Data/Syntax/Expression.hs +++ b/src/Data/Syntax/Expression.hs @@ -543,7 +543,7 @@ instance Show1 Cast where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Cast data Super a = Super - deriving (Diffable, Eq, Foldable, Functor, Generic1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, Foldable, Functor, Generic1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Hashable1, Named1, Message1) instance Eq1 Super where liftEq = genericLiftEq instance Ord1 Super where liftCompare = genericLiftCompare diff --git a/src/Data/Syntax/Literal.hs b/src/Data/Syntax/Literal.hs index 1cb67378f..82e1524e6 100644 --- a/src/Data/Syntax/Literal.hs +++ b/src/Data/Syntax/Literal.hs @@ -2,14 +2,15 @@ {-# OPTIONS_GHC -Wno-missing-export-lists #-} module Data.Syntax.Literal where +import Prelude hiding (Float, null) +import Prologue hiding (Set, hash, null) + import Data.Abstract.Evaluatable as Eval import Data.JSON.Fields import Data.Scientific.Exts import qualified Data.Text as T import Diffing.Algorithm import Numeric.Exts -import Prelude hiding (Float, null) -import Prologue hiding (Set, hash, null) import Proto3.Suite.Class import Reprinting.Tokenize as Tok import Text.Read (readMaybe) @@ -265,7 +266,7 @@ instance Evaluatable Set -- Pointers -- | A declared pointer (e.g. var pointer *int in Go) -newtype Pointer a = Pointer a +newtype Pointer a = Pointer { value :: a } deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Pointer where liftEq = genericLiftEq @@ -277,7 +278,7 @@ instance Evaluatable Pointer -- | A reference to a pointer's address (e.g. &pointer in Go) -newtype Reference a = Reference a +newtype Reference a = Reference { value :: a } deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Reference where liftEq = genericLiftEq diff --git a/src/Data/Syntax/Statement.hs b/src/Data/Syntax/Statement.hs index d53828879..cf3e8af6d 100644 --- a/src/Data/Syntax/Statement.hs +++ b/src/Data/Syntax/Statement.hs @@ -145,7 +145,7 @@ instance Evaluatable Assignment where pure (Rval rhs) -- | Post increment operator (e.g. 1++ in Go, or i++ in C). -newtype PostIncrement a = PostIncrement a +newtype PostIncrement a = PostIncrement { value :: a } deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PostIncrement where liftEq = genericLiftEq @@ -157,7 +157,7 @@ instance Evaluatable PostIncrement -- | Post decrement operator (e.g. 1-- in Go, or i-- in C). -newtype PostDecrement a = PostDecrement a +newtype PostDecrement a = PostDecrement { value :: a } deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PostDecrement where liftEq = genericLiftEq @@ -168,8 +168,8 @@ instance Show1 PostDecrement where liftShowsPrec = genericLiftShowsPrec instance Evaluatable PostDecrement -- | Pre increment operator (e.g. ++1 in C or Java). -newtype PreIncrement a = PreIncrement a - deriving (Diffable, Eq, Foldable, Functor, Generic1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Hashable1) +newtype PreIncrement a = PreIncrement { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PreIncrement where liftEq = genericLiftEq instance Ord1 PreIncrement where liftCompare = genericLiftCompare @@ -180,8 +180,8 @@ instance Evaluatable PreIncrement -- | Pre decrement operator (e.g. --1 in C or Java). -newtype PreDecrement a = PreDecrement a - deriving (Diffable, Eq, Foldable, Functor, Generic1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Hashable1) +newtype PreDecrement a = PreDecrement { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PreDecrement where liftEq = genericLiftEq instance Ord1 PreDecrement where liftCompare = genericLiftCompare diff --git a/src/Data/Syntax/Type.hs b/src/Data/Syntax/Type.hs index edaf110cb..5585c86ed 100644 --- a/src/Data/Syntax/Type.hs +++ b/src/Data/Syntax/Type.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DataKinds, DeriveAnyClass, DeriveGeneric, MultiParamTypeClasses, UndecidableInstances #-} +{-# LANGUAGE DataKinds, DeriveAnyClass, DuplicateRecordFields, DeriveGeneric, MultiParamTypeClasses, UndecidableInstances #-} {-# OPTIONS_GHC -Wno-missing-export-lists #-} module Data.Syntax.Type where @@ -11,7 +11,9 @@ import Proto3.Suite.Class import Reprinting.Tokenize data Array a = Array { arraySize :: !(Maybe a), arrayElementType :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Message1) + +instance Named1 Array where nameOf1 _ = "TypeArray" instance Eq1 Array where liftEq = genericLiftEq instance Ord1 Array where liftCompare = genericLiftCompare @@ -50,7 +52,7 @@ instance Show1 Function where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Function -newtype Interface a = Interface [a] +newtype Interface a = Interface { values :: [a] } deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Interface where liftEq = genericLiftEq @@ -72,7 +74,7 @@ instance Show1 Map where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Map -newtype Parenthesized a = Parenthesized a +newtype Parenthesized a = Parenthesized { value :: a } deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Parenthesized where liftEq = genericLiftEq @@ -83,7 +85,7 @@ instance Show1 Parenthesized where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Parenthesized -newtype Pointer a = Pointer a +newtype Pointer a = Pointer { value :: a } deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Pointer where liftEq = genericLiftEq @@ -94,7 +96,7 @@ instance Show1 Pointer where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Pointer -newtype Product a = Product [a] +newtype Product a = Product { values :: [a] } deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Product where liftEq = genericLiftEq @@ -139,7 +141,7 @@ instance Evaluatable TypeParameters -- data instead of newtype because no payload data Void a = Void - deriving (Diffable, Eq, Foldable, Functor, Generic1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Hashable1) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Void where liftEq = genericLiftEq instance Ord1 Void where liftCompare = genericLiftCompare @@ -150,7 +152,7 @@ instance Evaluatable Void -- data instead of newtype because no payload data Int a = Int - deriving (Diffable, Eq, Foldable, Functor, Generic1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Hashable1) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Int where liftEq = genericLiftEq instance Ord1 Int where liftCompare = genericLiftCompare @@ -160,7 +162,7 @@ instance Show1 Int where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Int data Float a = Float - deriving (Diffable, Eq, Foldable, Functor, Generic1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Hashable1) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Float where liftEq = genericLiftEq instance Ord1 Float where liftCompare = genericLiftCompare @@ -170,7 +172,7 @@ instance Show1 Float where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Float data Double a = Double - deriving (Diffable, Eq, Foldable, Functor, Generic1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Hashable1) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Double where liftEq = genericLiftEq instance Ord1 Double where liftCompare = genericLiftCompare @@ -180,7 +182,7 @@ instance Show1 Double where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Double data Bool a = Bool - deriving (Diffable, Eq, Foldable, Functor, Generic1, Ord, Show, Traversable, FreeVariables1, Declarations1, ToJSONFields1, Hashable1) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Bool where liftEq = genericLiftEq instance Ord1 Bool where liftCompare = genericLiftCompare diff --git a/src/Language/Go/Syntax.hs b/src/Language/Go/Syntax.hs index 5baf87579..dcd3d329b 100644 --- a/src/Language/Go/Syntax.hs +++ b/src/Language/Go/Syntax.hs @@ -2,6 +2,8 @@ {-# OPTIONS_GHC -Wno-missing-export-lists #-} module Language.Go.Syntax where +import Prologue + import Data.Abstract.BaseError import Data.Abstract.Evaluatable import Data.Abstract.Module @@ -11,14 +13,33 @@ import Data.Aeson import Data.JSON.Fields import qualified Data.Text as T import Diffing.Algorithm -import Prologue +import Proto3.Suite.Class +import Proto3.Suite +import qualified Proto3.Wire.Encode as Encode +import qualified Proto3.Wire.Decode as Decode import System.FilePath.Posix -data Relative = Relative | NonRelative - deriving (Eq, Generic, Hashable, Ord, Show, ToJSON) +data Relative = Unknown | Relative | NonRelative + deriving (Bounded, Enum, Eq, Generic, Hashable, Ord, Show, ToJSON, Named, MessageField) + +instance Primitive Relative where + encodePrimitive = Encode.enum + decodePrimitive = either (const def) id <$> Decode.enum + primType _ = Named (Single (nameOf (Proxy @Relative))) + +instance HasDefault Relative where + def = Unknown data ImportPath = ImportPath { unPath :: FilePath, pathIsRelative :: Relative } - deriving (Eq, Generic, Hashable, Ord, Show, ToJSON) + deriving (Eq, Generic, Hashable, Ord, Show, ToJSON, Named, Message) + +instance MessageField ImportPath where + encodeMessageField num = Encode.embedded num . encodeMessage (fieldNumber 1) + decodeMessageField = fromMaybe def <$> Decode.embedded (decodeMessage (fieldNumber 1)) + protoType _ = messageField (Prim $ Named (Single (nameOf (Proxy @ImportPath)))) Nothing + +instance HasDefault ImportPath where + def = ImportPath mempty Unknown importPath :: Text -> ImportPath importPath str = let path = stripQuotes str in ImportPath (T.unpack path) (pathType path) @@ -38,6 +59,7 @@ resolveGoImport :: ( Member (Modules address) effects ) => ImportPath -> Evaluator address value effects [ModulePath] +resolveGoImport (ImportPath path Unknown) = throwResolutionError $ GoImportError path resolveGoImport (ImportPath path Relative) = do ModuleInfo{..} <- currentModule paths <- listModulesInDir (joinPaths (takeDirectory modulePath) path) @@ -58,7 +80,7 @@ resolveGoImport (ImportPath path NonRelative) = do -- -- If the list of symbols is empty copy everything to the calling environment. data Import a = Import { importFrom :: ImportPath, importWildcardToken :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Import where liftEq = genericLiftEq instance Ord1 Import where liftCompare = genericLiftCompare @@ -78,7 +100,7 @@ instance Evaluatable Import where -- -- If the list of symbols is empty copy and qualify everything to the calling environment. data QualifiedImport a = QualifiedImport { qualifiedImportFrom :: !ImportPath, qualifiedImportAlias :: !a} - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 QualifiedImport where liftEq = genericLiftEq instance Ord1 QualifiedImport where liftCompare = genericLiftCompare @@ -97,7 +119,7 @@ instance Evaluatable QualifiedImport where -- | Side effect only imports (no symbols made available to the calling environment). data SideEffectImport a = SideEffectImport { sideEffectImportFrom :: !ImportPath, sideEffectImportToken :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 SideEffectImport where liftEq = genericLiftEq instance Ord1 SideEffectImport where liftCompare = genericLiftCompare @@ -112,7 +134,7 @@ instance Evaluatable SideEffectImport where -- A composite literal in Go data Composite a = Composite { compositeType :: !a, compositeElement :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Composite where liftEq = genericLiftEq instance Ord1 Composite where liftCompare = genericLiftCompare @@ -123,7 +145,7 @@ instance Evaluatable Composite -- | A default pattern in a Go select or switch statement (e.g. `switch { default: s() }`). newtype DefaultPattern a = DefaultPattern { defaultPatternBody :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 DefaultPattern where liftEq = genericLiftEq instance Ord1 DefaultPattern where liftCompare = genericLiftCompare @@ -134,7 +156,7 @@ instance Evaluatable DefaultPattern -- | A defer statement in Go (e.g. `defer x()`). newtype Defer a = Defer { deferBody :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Defer where liftEq = genericLiftEq instance Ord1 Defer where liftCompare = genericLiftCompare @@ -145,7 +167,7 @@ instance Evaluatable Defer -- | A go statement (i.e. go routine) in Go (e.g. `go x()`). newtype Go a = Go { goBody :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Go where liftEq = genericLiftEq instance Ord1 Go where liftCompare = genericLiftCompare @@ -155,8 +177,8 @@ instance Show1 Go where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Go -- | A label statement in Go (e.g. `label:continue`). -data Label a = Label { _labelName :: !a, labelStatement :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data Label a = Label { labelName :: !a, labelStatement :: !a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Label where liftEq = genericLiftEq instance Ord1 Label where liftCompare = genericLiftCompare @@ -166,8 +188,8 @@ instance Show1 Label where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Label -- | A rune literal in Go (e.g. `'⌘'`). -newtype Rune a = Rune { _runeLiteral :: Text } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Rune a = Rune { runeLiteral :: Text } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) -- TODO: Implement Eval instance for Rune instance Evaluatable Rune @@ -178,7 +200,7 @@ instance Show1 Rune where liftShowsPrec = genericLiftShowsPrec -- | A select statement in Go (e.g. `select { case x := <-c: x() }` where each case is a send or receive operation on channels). newtype Select a = Select { selectCases :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) -- TODO: Implement Eval instance for Select instance Evaluatable Select @@ -189,7 +211,7 @@ instance Show1 Select where liftShowsPrec = genericLiftShowsPrec -- | A send statement in Go (e.g. `channel <- value`). data Send a = Send { sendReceiver :: !a, sendValue :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Send where liftEq = genericLiftEq instance Ord1 Send where liftCompare = genericLiftCompare @@ -200,7 +222,7 @@ instance Evaluatable Send -- | A slice expression in Go (e.g. `a[1:4:3]` where a is a list, 1 is the low bound, 4 is the high bound, and 3 is the max capacity). data Slice a = Slice { sliceName :: !a, sliceLow :: !a, sliceHigh :: !a, sliceCapacity :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Slice where liftEq = genericLiftEq instance Ord1 Slice where liftCompare = genericLiftCompare @@ -211,7 +233,7 @@ instance Evaluatable Slice -- | A type switch statement in Go (e.g. `switch x.(type) { // cases }`). data TypeSwitch a = TypeSwitch { typeSwitchSubject :: !a, typeSwitchCases :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 TypeSwitch where liftEq = genericLiftEq instance Ord1 TypeSwitch where liftCompare = genericLiftCompare @@ -222,7 +244,7 @@ instance Evaluatable TypeSwitch -- | A type switch guard statement in a Go type switch statement (e.g. `switch i := x.(type) { // cases}`). newtype TypeSwitchGuard a = TypeSwitchGuard { typeSwitchGuardSubject :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 TypeSwitchGuard where liftEq = genericLiftEq instance Ord1 TypeSwitchGuard where liftCompare = genericLiftCompare @@ -233,7 +255,7 @@ instance Evaluatable TypeSwitchGuard -- | A receive statement in a Go select statement (e.g. `case value := <-channel` ) data Receive a = Receive { receiveSubject :: !a, receiveExpression :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Receive where liftEq = genericLiftEq instance Ord1 Receive where liftCompare = genericLiftCompare @@ -243,8 +265,8 @@ instance Show1 Receive where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Receive -- | A receive operator unary expression in Go (e.g. `<-channel` ) -newtype ReceiveOperator a = ReceiveOperator a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ReceiveOperator a = ReceiveOperator { value :: a} + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 ReceiveOperator where liftEq = genericLiftEq instance Ord1 ReceiveOperator where liftCompare = genericLiftCompare @@ -255,7 +277,7 @@ instance Evaluatable ReceiveOperator -- | A field declaration in a Go struct type declaration. data Field a = Field { fieldContext :: ![a], fieldName :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Field where liftEq = genericLiftEq instance Ord1 Field where liftCompare = genericLiftCompare @@ -266,7 +288,7 @@ instance Evaluatable Field data Package a = Package { packageName :: !a, packageContents :: ![a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Package where liftEq = genericLiftEq instance Ord1 Package where liftCompare = genericLiftCompare @@ -278,7 +300,7 @@ instance Evaluatable Package where -- | A type assertion in Go (e.g. `x.(T)` where the value of `x` is not nil and is of type `T`). data TypeAssertion a = TypeAssertion { typeAssertionSubject :: !a, typeAssertionType :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 TypeAssertion where liftEq = genericLiftEq instance Ord1 TypeAssertion where liftCompare = genericLiftCompare @@ -289,7 +311,7 @@ instance Evaluatable TypeAssertion -- | A type conversion expression in Go (e.g. `T(x)` where `T` is a type and `x` is an expression that can be converted to type `T`). data TypeConversion a = TypeConversion { typeConversionType :: !a, typeConversionSubject :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 TypeConversion where liftEq = genericLiftEq instance Ord1 TypeConversion where liftCompare = genericLiftCompare @@ -300,7 +322,7 @@ instance Evaluatable TypeConversion -- | Variadic arguments and parameters in Go (e.g. parameter: `param ...Type`, argument: `Type...`). data Variadic a = Variadic { variadicContext :: [a], variadicIdentifier :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Variadic where liftEq = genericLiftEq instance Ord1 Variadic where liftCompare = genericLiftCompare diff --git a/src/Language/Java/Syntax.hs b/src/Language/Java/Syntax.hs index 3cecf9cac..31e2025ad 100644 --- a/src/Language/Java/Syntax.hs +++ b/src/Language/Java/Syntax.hs @@ -3,12 +3,13 @@ module Language.Java.Syntax where import Data.Abstract.Evaluatable +import Data.JSON.Fields import Diffing.Algorithm import Prologue hiding (Constructor) -import Data.JSON.Fields +import Proto3.Suite.Class -newtype Import a = Import [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Import a = Import { imports :: [a]} + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Import where liftEq = genericLiftEq @@ -19,7 +20,7 @@ instance Show1 Import where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Import data Module a = Module { moduleIdentifier :: !a, moduleStatements :: ![a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Module where liftEq = genericLiftEq @@ -28,8 +29,8 @@ instance Show1 Module where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Module -newtype Package a = Package [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Package a = Package { packages :: [a]} + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Package where liftEq = genericLiftEq @@ -40,7 +41,7 @@ instance Show1 Package where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Package data EnumDeclaration a = EnumDeclaration { enumDeclarationModifier :: ![a], enumDeclarationIdentifier :: !a, enumDeclarationSuperInterfaces :: ![a], enumDeclarationConstant :: ![a], enumDeclarationBody :: ![a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 EnumDeclaration where liftEq = genericLiftEq instance Ord1 EnumDeclaration where liftCompare = genericLiftCompare @@ -49,7 +50,7 @@ instance Evaluatable EnumDeclaration data Variable a = Variable { variableModifiers :: ![a], variableType :: !a, variableName :: !a} - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Variable where liftEq = genericLiftEq instance Ord1 Variable where liftCompare = genericLiftCompare @@ -59,7 +60,7 @@ instance Show1 Variable where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Variable data Synchronized a = Synchronized { synchronizedSubject :: !a, synchronizedBody :: !a} - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Synchronized where liftEq = genericLiftEq instance Ord1 Synchronized where liftCompare = genericLiftCompare @@ -69,7 +70,7 @@ instance Show1 Synchronized where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Synchronized data New a = New { newType :: !a, newArgs :: ![a], newClassBody :: Maybe a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 New where liftEq = genericLiftEq instance Ord1 New where liftCompare = genericLiftCompare @@ -79,7 +80,7 @@ instance Show1 New where liftShowsPrec = genericLiftShowsPrec instance Evaluatable New data Asterisk a = Asterisk - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Asterisk where liftEq = genericLiftEq instance Ord1 Asterisk where liftCompare = genericLiftCompare @@ -90,7 +91,7 @@ instance Evaluatable Asterisk data Constructor a = Constructor { constructorModifiers :: ![a], constructorTypeParams :: ![a], constructorIdentifier :: !a, constructorParams :: ![a], constructorThrows :: ![a], constructorBody :: a} - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Constructor where liftEq = genericLiftEq instance Ord1 Constructor where liftCompare = genericLiftCompare @@ -100,7 +101,7 @@ instance Show1 Constructor where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Constructor data TypeParameter a = TypeParameter { typeParamAnnotation :: ![a], typeParamIdentifier :: !a, typeParamTypeBound :: ![a]} - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 TypeParameter where liftEq = genericLiftEq instance Ord1 TypeParameter where liftCompare = genericLiftCompare @@ -110,7 +111,7 @@ instance Show1 TypeParameter where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeParameter data Annotation a = Annotation { annotationName :: !a, annotationField :: [a]} - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Annotation where liftEq = genericLiftEq instance Ord1 Annotation where liftCompare = genericLiftCompare @@ -120,7 +121,7 @@ instance Show1 Annotation where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Annotation data AnnotationField a = AnnotationField { annotationFieldName :: a, annotationFieldValue :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 AnnotationField where liftEq = genericLiftEq instance Ord1 AnnotationField where liftCompare = genericLiftCompare @@ -130,7 +131,7 @@ instance Show1 AnnotationField where liftShowsPrec = genericLiftShowsPrec instance Evaluatable AnnotationField data GenericType a = GenericType { genericTypeIdentifier :: a, genericTypeArguments :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 GenericType where liftEq = genericLiftEq instance Ord1 GenericType where liftCompare = genericLiftCompare @@ -140,7 +141,7 @@ instance Show1 GenericType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable GenericType data AnnotatedType a = AnnotatedType { annotationes :: [a], annotatedType :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 AnnotatedType where liftEq = genericLiftEq instance Ord1 AnnotatedType where liftCompare = genericLiftCompare @@ -150,7 +151,7 @@ instance Show1 AnnotatedType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable AnnotatedType newtype CatchType a = CatchType { types :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 CatchType where liftEq = genericLiftEq instance Ord1 CatchType where liftCompare = genericLiftCompare @@ -159,8 +160,8 @@ instance Show1 CatchType where liftShowsPrec = genericLiftShowsPrec -- TODO: Implement Eval instance for CatchType instance Evaluatable CatchType -data TypeWithModifiers a = TypeWithModifiers [a] a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data TypeWithModifiers a = TypeWithModifiers { types :: [a], modifier :: a} + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 TypeWithModifiers where liftEq = genericLiftEq instance Ord1 TypeWithModifiers where liftCompare = genericLiftCompare @@ -170,7 +171,7 @@ instance Show1 TypeWithModifiers where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeWithModifiers data Wildcard a = Wildcard { wildcardAnnotation :: [a], wildcardBounds :: Maybe a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Wildcard where liftEq = genericLiftEq instance Ord1 Wildcard where liftCompare = genericLiftCompare @@ -180,7 +181,7 @@ instance Show1 Wildcard where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Wildcard data WildcardBounds a = WildcardBoundExtends { wildcardBoundType :: a} | WildcardBoundSuper { wildcardBoundType :: a} - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 WildcardBounds where liftEq = genericLiftEq instance Ord1 WildcardBounds where liftCompare = genericLiftCompare @@ -190,7 +191,7 @@ instance Show1 WildcardBounds where liftShowsPrec = genericLiftShowsPrec instance Evaluatable WildcardBounds newtype SpreadParameter a = SpreadParameter { spreadParameterVariableDeclarator :: a} - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 SpreadParameter where liftEq = genericLiftEq instance Ord1 SpreadParameter where liftCompare = genericLiftCompare @@ -200,7 +201,7 @@ instance Show1 SpreadParameter where liftShowsPrec = genericLiftShowsPrec instance Evaluatable SpreadParameter newtype StaticInitializer a = StaticInitializer { staticInitializerBlock :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 StaticInitializer where liftEq = genericLiftEq @@ -210,7 +211,7 @@ instance Show1 StaticInitializer where liftShowsPrec = genericLiftShowsPrec instance Evaluatable StaticInitializer data MethodReference a = MethodReference { methodReferenceType :: !a, methodReferenceTypeArgs :: ![a], methodReferenceIdentifier :: !a} - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 MethodReference where liftEq = genericLiftEq instance Ord1 MethodReference where liftCompare = genericLiftCompare @@ -220,7 +221,7 @@ instance Show1 MethodReference where liftShowsPrec = genericLiftShowsPrec instance Evaluatable MethodReference data NewKeyword a = NewKeyword - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 NewKeyword where liftEq = genericLiftEq instance Ord1 NewKeyword where liftCompare = genericLiftCompare @@ -230,7 +231,7 @@ instance Show1 NewKeyword where liftShowsPrec = genericLiftShowsPrec instance Evaluatable NewKeyword data Lambda a = Lambda { lambdaParams :: ![a], lambdaBody :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 Lambda where liftEq = genericLiftEq instance Ord1 Lambda where liftCompare = genericLiftCompare @@ -239,7 +240,7 @@ instance Show1 Lambda where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Lambda newtype LambdaBody a = LambdaBody { lambdaBodyExpression :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 LambdaBody where liftEq = genericLiftEq instance Ord1 LambdaBody where liftCompare = genericLiftCompare @@ -248,7 +249,7 @@ instance Show1 LambdaBody where liftShowsPrec = genericLiftShowsPrec instance Evaluatable LambdaBody data ArrayCreationExpression a = ArrayCreationExpression { arrayCreationExpressionType :: !a, arrayCreationExpressionDims :: ![a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 ArrayCreationExpression where liftEq = genericLiftEq instance Ord1 ArrayCreationExpression where liftCompare = genericLiftCompare @@ -257,7 +258,7 @@ instance Show1 ArrayCreationExpression where liftShowsPrec = genericLiftShowsPre instance Evaluatable ArrayCreationExpression data DimsExpr a = DimsExpr { dimsExprAnnotation :: ![a], dimsExprExpression :: ![a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 DimsExpr where liftEq = genericLiftEq instance Ord1 DimsExpr where liftCompare = genericLiftCompare @@ -266,7 +267,7 @@ instance Show1 DimsExpr where liftShowsPrec = genericLiftShowsPrec instance Evaluatable DimsExpr newtype ClassBody a = ClassBody { classBodyExpression :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 ClassBody where liftEq = genericLiftEq instance Ord1 ClassBody where liftCompare = genericLiftCompare @@ -275,7 +276,7 @@ instance Show1 ClassBody where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ClassBody newtype ClassLiteral a = ClassLiteral { classLiteralType :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 ClassLiteral where liftEq = genericLiftEq instance Ord1 ClassLiteral where liftCompare = genericLiftCompare @@ -284,7 +285,7 @@ instance Show1 ClassLiteral where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ClassLiteral data TryWithResources a = TryWithResources { tryResources :: ![a], tryBody :: !a, tryCatch :: ![a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 TryWithResources where liftEq = genericLiftEq instance Ord1 TryWithResources where liftCompare = genericLiftCompare @@ -294,7 +295,7 @@ instance Show1 TryWithResources where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TryWithResources data AssertStatement a = AssertStatement { assertLHS :: !a, assertRHS :: !(Maybe a) } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 AssertStatement where liftEq = genericLiftEq instance Ord1 AssertStatement where liftCompare = genericLiftCompare @@ -304,7 +305,7 @@ instance Show1 AssertStatement where liftShowsPrec = genericLiftShowsPrec instance Evaluatable AssertStatement newtype DefaultValue a = DefaultValue { defaultValueElement :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 DefaultValue where liftEq = genericLiftEq instance Ord1 DefaultValue where liftCompare = genericLiftCompare @@ -313,7 +314,7 @@ instance Show1 DefaultValue where liftShowsPrec = genericLiftShowsPrec instance Evaluatable DefaultValue data AnnotationTypeElement a = AnnotationTypeElement { modifiers :: ![a], annotationType :: a, identifier :: !a, dims :: ![a], defaultValue :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 AnnotationTypeElement where liftEq = genericLiftEq instance Ord1 AnnotationTypeElement where liftCompare = genericLiftCompare From 636b393b801870aa09000a3ae95eb3d348081a54 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Fri, 7 Sep 2018 15:12:47 -0700 Subject: [PATCH 19/39] Sort out inclusion of Java and Go in grpc --- proto/code_analysis.proto | 57 ++- proto/go_term.proto | 601 ++++++++++++++++++++++++++++++ proto/java_term.proto | 642 ++++++++++++++++++++++++++++++++ src/Data/Syntax/Type.hs | 13 +- src/Language/Go/Assignment.hs | 32 +- src/Language/Go/Syntax.hs | 23 +- src/Language/Go/Type.hs | 16 +- src/Language/Java/Assignment.hs | 41 +- src/Language/Java/Syntax.hs | 5 +- 9 files changed, 1363 insertions(+), 67 deletions(-) create mode 100644 proto/go_term.proto create mode 100644 proto/java_term.proto diff --git a/proto/code_analysis.proto b/proto/code_analysis.proto index dde0f3b00..c3f77f89e 100644 --- a/proto/code_analysis.proto +++ b/proto/code_analysis.proto @@ -2,13 +2,15 @@ syntax = "proto3"; package github.semantic; -import "ruby_term.proto"; -import "ruby_diff.proto"; +import "go_term.proto"; +import "java_term.proto"; import "json_term.proto"; -import "typescript_term.proto"; -import "typescript_diff.proto"; -import "python_term.proto"; import "python_diff.proto"; +import "python_term.proto"; +import "ruby_diff.proto"; +import "ruby_term.proto"; +import "typescript_diff.proto"; +import "typescript_term.proto"; import "types.proto"; import "error_details.proto"; @@ -47,32 +49,42 @@ service CodeAnalysis { rpc CheckHealth (HealthCheckRequest) returns (HealthCheckResponse); } +// Term Requests and Responses +// message ParseTreeRequest { repeated Blob blobs = 1; } message ParseTreeGraphResponse { - ParseTreeGraph graph = 1; + ParseTreeGraph response = 1; DebugInfo error_info = 2; } message ParseTreeGraph { - repeated TermGraph graph = 1; + repeated TermGraph graphs = 1; repeated DebugInfo error_info = 2; } + message ParseTreeResponse { + DebugInfo error_info = 1; oneof response_type { - RubyResponse ruby = 1; - JSONResponse json = 2; - TypeScriptResponse typescript = 3; - PythonResponse python = 4; + GoResponse go = 2; + JavaResponse java = 3; + JSONResponse json = 4; + PythonResponse python = 5; + RubyResponse ruby = 6; + TypeScriptResponse typescript = 7; } - DebugInfo error_info = 5; } -message RubyResponse { - repeated rubyterm.RubyTerm terms = 1; +message GoResponse { + repeated goterm.GoTerm terms = 1; + repeated DebugInfo errors = 2; +} + +message JavaResponse { + repeated javaterm.JavaTerm terms = 1; repeated DebugInfo errors = 2; } @@ -81,16 +93,23 @@ message JSONResponse { repeated DebugInfo errors = 2; } -message TypeScriptResponse { - repeated typescriptterm.TypeScriptTerm terms = 1; - repeated DebugInfo errors = 2; -} - message PythonResponse { repeated pythonterm.PythonTerm terms = 1; repeated DebugInfo errors = 2; } +message RubyResponse { + repeated rubyterm.RubyTerm terms = 1; + repeated DebugInfo errors = 2; +} + +message TypeScriptResponse { + repeated typescriptterm.TypeScriptTerm terms = 1; + repeated DebugInfo errors = 2; +} + +// Diff Request & Responses +// message SummarizeDiffRequest { repeated BlobPair blobPairs = 1; } diff --git a/proto/go_term.proto b/proto/go_term.proto new file mode 100644 index 000000000..2bf3f1e22 --- /dev/null +++ b/proto/go_term.proto @@ -0,0 +1,601 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.goterm; + +import "types.proto"; + +option java_package = "com.github.semantic.goterm"; +option go_package = "github.com/semantic/goterm;go"; + +message GoTerm { + GoSyntax syntax = 1; +} + +message GoSyntax { + oneof syntax { + Comment comment = 1; + Constructor constructor = 2; + Function function = 3; + Method method = 4; + MethodSignature methodSignature = 5; + Type type = 6; + TypeAlias typeAlias = 7; + Plus plus = 8; + Minus minus = 9; + Times times = 10; + DividedBy dividedBy = 11; + Modulo modulo = 12; + Power power = 13; + Negate negate = 14; + FloorDivision floorDivision = 15; + BOr bOr = 16; + BAnd bAnd = 17; + BXOr bXOr = 18; + LShift lShift = 19; + RShift rShift = 20; + UnsignedRShift unsignedRShift = 21; + Complement complement = 22; + Call call = 23; + LessThan lessThan = 24; + LessThanEqual lessThanEqual = 25; + GreaterThan greaterThan = 26; + GreaterThanEqual greaterThanEqual = 27; + Equal equal = 28; + StrictEqual strictEqual = 29; + Comparison comparison = 30; + Subscript subscript = 31; + Member member = 32; + PostDecrement postDecrement = 33; + PostIncrement postIncrement = 34; + MemberAccess memberAccess = 35; + And and = 36; + Not not = 37; + Or or = 38; + XOr xOr = 39; + Composite composite = 40; + DefaultPattern defaultPattern = 41; + Defer defer = 42; + Field field = 43; + Go go = 44; + Label label = 45; + Package package = 46; + Receive receive = 47; + ReceiveOperator receiveOperator = 48; + Rune rune = 49; + Select select = 50; + Send send = 51; + Slice slice = 52; + TypeAssertion typeAssertion = 53; + TypeConversion typeConversion = 54; + TypeSwitch typeSwitch = 55; + TypeSwitchGuard typeSwitchGuard = 56; + Variadic variadic = 57; + BidirectionalChannel bidirectionalChannel = 58; + ReceiveChannel receiveChannel = 59; + SendChannel sendChannel = 60; + Import import = 61; + QualifiedImport qualifiedImport = 62; + SideEffectImport sideEffectImport = 63; + Array array = 64; + Complex complex = 65; + Float float = 66; + Hash hash = 67; + Integer integer = 68; + KeyValue keyValue = 69; + Pointer pointer = 70; + Reference reference = 71; + TextElement textElement = 72; + Assignment assignment = 73; + Break break = 74; + Continue continue = 75; + For for = 76; + ForEach forEach = 77; + Goto goto = 78; + If if = 79; + Match match = 80; + NoOp noOp = 81; + Pattern pattern = 82; + Return return = 83; + Statements statements = 84; + Context context = 85; + Error error = 86; + Empty empty = 87; + Identifier identifier = 88; + Annotation annotation = 89; + TypeArray typeArray = 90; + TypeFunction typeFunction = 91; + Interface interface = 92; + Map map = 93; + Parenthesized parenthesized = 94; + TypePointer typePointer = 95; + TypeSlice typeSlice = 96; + List list = 97; + String string = 98; + EscapeSequence escapeSequence = 99; + } +} + +message Comment { + string commentContent = 1; +} + +message Constructor { + repeated GoTerm constructorContext = 1; + GoTerm constructorName = 2; + GoTerm constructorFields = 3; +} + +message Function { + repeated GoTerm functionContext = 1; + GoTerm functionName = 2; + repeated GoTerm functionParameters = 3; + GoTerm functionBody = 4; +} + +message Method { + repeated GoTerm methodContext = 1; + GoTerm methodReceiver = 2; + GoTerm methodName = 3; + repeated GoTerm methodParameters = 4; + GoTerm methodBody = 5; +} + +message MethodSignature { + repeated GoTerm methodSignatureContext = 1; + GoTerm methodSignatureName = 2; + repeated GoTerm methodSignatureParameters = 3; +} + +message Type { + GoTerm typeName = 1; + GoTerm typeKind = 2; +} + +message TypeAlias { + repeated GoTerm typeAliasContext = 1; + GoTerm typeAliasIdentifier = 2; + GoTerm typeAliasKind = 3; +} + +message Plus { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message Minus { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message Times { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message DividedBy { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message Modulo { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message Power { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message Negate { + GoTerm value = 1; +} + +message FloorDivision { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message BOr { + GoTerm left = 1; + GoTerm right = 2; +} + +message BAnd { + GoTerm left = 1; + GoTerm right = 2; +} + +message BXOr { + GoTerm left = 1; + GoTerm right = 2; +} + +message LShift { + GoTerm left = 1; + GoTerm right = 2; +} + +message RShift { + GoTerm left = 1; + GoTerm right = 2; +} + +message UnsignedRShift { + GoTerm left = 1; + GoTerm right = 2; +} + +message Complement { + GoTerm value = 1; +} + +message Call { + repeated GoTerm callContext = 1; + GoTerm callFunction = 2; + repeated GoTerm callParams = 3; + GoTerm callBlock = 4; +} + +message LessThan { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message LessThanEqual { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message GreaterThan { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message GreaterThanEqual { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message Equal { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message StrictEqual { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message Comparison { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message Subscript { + GoTerm lhs = 1; + repeated GoTerm rhs = 2; +} + +message Member { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message PostDecrement { + GoTerm value = 1; +} + +message PostIncrement { + GoTerm value = 1; +} + +message MemberAccess { + GoTerm lhs = 1; + bytes rhs = 2; +} + +message And { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message Not { + GoTerm value = 1; +} + +message Or { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message XOr { + GoTerm lhs = 1; + GoTerm rhs = 2; +} + +message Composite { + GoTerm compositeType = 1; + GoTerm compositeElement = 2; +} + +message DefaultPattern { + GoTerm defaultPatternBody = 1; +} + +message Defer { + GoTerm deferBody = 1; +} + +message Field { + repeated GoTerm fieldContext = 1; + GoTerm fieldName = 2; +} + +message Go { + GoTerm goBody = 1; +} + +message Label { + GoTerm labelName = 1; + GoTerm labelStatement = 2; +} + +message Package { + GoTerm packageName = 1; + repeated GoTerm packageContents = 2; +} + +message Receive { + GoTerm receiveSubject = 1; + GoTerm receiveExpression = 2; +} + +message ReceiveOperator { + GoTerm value = 1; +} + +message Rune { + string runeLiteral = 1; +} + +message Select { + GoTerm selectCases = 1; +} + +message Send { + GoTerm sendReceiver = 1; + GoTerm sendValue = 2; +} + +message Slice { + GoTerm sliceName = 1; + GoTerm sliceLow = 2; + GoTerm sliceHigh = 3; + GoTerm sliceCapacity = 4; +} + +message TypeAssertion { + GoTerm typeAssertionSubject = 1; + GoTerm typeAssertionType = 2; +} + +message TypeConversion { + GoTerm typeConversionType = 1; + GoTerm typeConversionSubject = 2; +} + +message TypeSwitch { + GoTerm typeSwitchSubject = 1; + GoTerm typeSwitchCases = 2; +} + +message TypeSwitchGuard { + GoTerm typeSwitchGuardSubject = 1; +} + +message Variadic { + repeated GoTerm variadicContext = 1; + GoTerm variadicIdentifier = 2; +} + +message BidirectionalChannel { + GoTerm value = 1; +} + +message ReceiveChannel { + GoTerm value = 1; +} + +message SendChannel { + GoTerm value = 1; +} + +message Import { + ImportPath importFrom = 1; + GoTerm importWildcardToken = 2; +} + +message QualifiedImport { + ImportPath qualifiedImportFrom = 1; + GoTerm qualifiedImportAlias = 2; +} + +message SideEffectImport { + ImportPath sideEffectImportFrom = 1; + GoTerm sideEffectImportToken = 2; +} + +message Array { + repeated GoTerm arrayElements = 1; +} + +message Complex { + string value = 1; +} + +message Float { + string floatContent = 1; +} + +message Hash { + repeated GoTerm hashElements = 1; +} + +message Integer { + string integerContent = 1; +} + +message KeyValue { + GoTerm key = 1; + GoTerm value = 2; +} + +message Pointer { + GoTerm value = 1; +} + +message Reference { + GoTerm value = 1; +} + +message TextElement { + string textElementContent = 1; +} + +message Assignment { + repeated GoTerm assignmentContext = 1; + GoTerm assignmentTarget = 2; + GoTerm assignmentValue = 3; +} + +message Break { + GoTerm value = 1; +} + +message Continue { + GoTerm value = 1; +} + +message For { + GoTerm forBefore = 1; + GoTerm forCondition = 2; + GoTerm forStep = 3; + GoTerm forBody = 4; +} + +message ForEach { + GoTerm forEachBinding = 1; + GoTerm forEachSubject = 2; + GoTerm forEachBody = 3; +} + +message Goto { + GoTerm gotoLocation = 1; +} + +message If { + GoTerm ifCondition = 1; + GoTerm ifThenBody = 2; + GoTerm ifElseBody = 3; +} + +message Match { + GoTerm matchSubject = 1; + GoTerm matchPatterns = 2; +} + +message NoOp { + GoTerm value = 1; +} + +message Pattern { + GoTerm value = 1; + GoTerm patternBody = 2; +} + +message Return { + GoTerm value = 1; +} + +message Statements { + repeated GoTerm statements = 1; +} + +message Context { + repeated GoTerm contextTerms = 1; + GoTerm contextSubject = 2; +} + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated GoTerm errorChildren = 4; +} + +message Empty { } + +message Identifier { + bytes name = 1; +} + +message Annotation { + GoTerm annotationSubject = 1; + GoTerm annotationType = 2; +} + +message TypeArray { + repeated GoTerm arraySize = 1; + GoTerm arrayElementType = 2; +} + +message TypeFunction { + repeated GoTerm functionParameters = 1; + GoTerm functionReturn = 2; +} + +message Interface { + repeated GoTerm values = 1; +} + +message Map { + GoTerm mapKeyType = 1; + GoTerm mapElementType = 2; +} + +message Parenthesized { + GoTerm value = 1; +} + +message TypePointer { + GoTerm value = 1; +} + +message TypeSlice { + GoTerm value = 1; +} + +message List { + repeated GoTerm listContent = 1; +} + +message String { + repeated GoTerm stringElements = 1; +} + +message EscapeSequence { + string value = 1; +} + +message ImportPath { + string unPath = 1; + IsRelative pathIsRelative = 2; +} + +enum IsRelative { + Unknown = 0; + Relative = 1; + NonRelative = 2; +} diff --git a/proto/java_term.proto b/proto/java_term.proto new file mode 100644 index 000000000..ffbcdae92 --- /dev/null +++ b/proto/java_term.proto @@ -0,0 +1,642 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.javaterm; + +import "types.proto"; + +option java_package = "com.github.semantic.javaterm"; +option go_package = "github.com/semantic/javaterm;java"; + +message JavaTerm { + JavaSyntax syntax = 1; +} + +message JavaSyntax { + oneof syntax { + Comment comment = 1; + Class class = 2; + InterfaceDeclaration interfaceDeclaration = 3; + Method method = 4; + VariableDeclaration variableDeclaration = 5; + Plus plus = 6; + Minus minus = 7; + Times times = 8; + DividedBy dividedBy = 9; + Modulo modulo = 10; + Power power = 11; + Negate negate = 12; + FloorDivision floorDivision = 13; + Call call = 14; + LessThan lessThan = 15; + LessThanEqual lessThanEqual = 16; + GreaterThan greaterThan = 17; + GreaterThanEqual greaterThanEqual = 18; + Equal equal = 19; + StrictEqual strictEqual = 20; + Comparison comparison = 21; + BOr bOr = 22; + BXOr bXOr = 23; + BAnd bAnd = 24; + LShift lShift = 25; + RShift rShift = 26; + UnsignedRShift unsignedRShift = 27; + Complement complement = 28; + And and = 29; + Not not = 30; + Or or = 31; + XOr xOr = 32; + InstanceOf instanceOf = 33; + MemberAccess memberAccess = 34; + Subscript subscript = 35; + Member member = 36; + Super super = 37; + This this = 38; + AnnotatedType annotatedType = 39; + JavaAnnotation javaAnnotation = 40; + AnnotationField annotationField = 41; + AnnotationTypeElement annotationTypeElement = 42; + ArrayCreationExpression arrayCreationExpression = 43; + AssertStatement assertStatement = 44; + Asterisk asterisk = 45; + CatchType catchType = 46; + Constructor constructor = 47; + ClassBody classBody = 48; + ClassLiteral classLiteral = 49; + DefaultValue defaultValue = 50; + DimsExpr dimsExpr = 51; + EnumDeclaration enumDeclaration = 52; + GenericType genericType = 53; + Import import = 54; + Lambda lambda = 55; + LambdaBody lambdaBody = 56; + MethodReference methodReference = 57; + Module module = 58; + New new = 59; + NewKeyword newKeyword = 60; + Package package = 61; + SpreadParameter spreadParameter = 62; + StaticInitializer staticInitializer = 63; + Synchronized synchronized = 64; + TryWithResources tryWithResources = 65; + TypeParameter typeParameter = 66; + TypeWithModifiers typeWithModifiers = 67; + Variable variable = 68; + Wildcard wildcard = 69; + WildcardBounds wildcardBounds = 70; + Array array = 71; + Boolean boolean = 72; + Integer integer = 73; + Float float = 74; + Null null = 75; + String string = 76; + TextElement textElement = 77; + Assignment assignment = 78; + Break break = 79; + Catch catch = 80; + Continue continue = 81; + DoWhile doWhile = 82; + Finally finally = 83; + For for = 84; + ForEach forEach = 85; + If if = 86; + Match match = 87; + Pattern pattern = 88; + PostIncrement postIncrement = 89; + PostDecrement postDecrement = 90; + PreIncrement preIncrement = 91; + PreDecrement preDecrement = 92; + While while = 93; + Statements statements = 94; + Throw throw = 95; + Try try = 96; + Context context = 97; + Empty empty = 98; + Error error = 99; + Identifier identifier = 100; + AccessibilityModifier accessibilityModifier = 101; + TypeArray typeArray = 102; + Bool bool = 103; + Int int = 104; + Void void = 105; + TypeFloat typeFloat = 106; + Annotation annotation = 107; + Return return = 108; + List list = 109; + } +} + +message Comment { + string commentContent = 1; +} + +message Class { + repeated JavaTerm classContext = 1; + JavaTerm classIdentifier = 2; + repeated JavaTerm classSuperclasses = 3; + JavaTerm classBody = 4; +} + +message InterfaceDeclaration { + repeated JavaTerm interfaceDeclarationContext = 1; + JavaTerm interfaceDeclarationIdentifier = 2; + repeated JavaTerm interfaceDeclarationSuperInterfaces = 3; + JavaTerm interfaceDeclarationBody = 4; +} + +message Method { + repeated JavaTerm methodContext = 1; + JavaTerm methodReceiver = 2; + JavaTerm methodName = 3; + repeated JavaTerm methodParameters = 4; + JavaTerm methodBody = 5; +} + +message VariableDeclaration { + repeated JavaTerm variableDeclarations = 1; +} + +message Plus { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message Minus { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message Times { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message DividedBy { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message Modulo { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message Power { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message Negate { + JavaTerm value = 1; +} + +message FloorDivision { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message Call { + repeated JavaTerm callContext = 1; + JavaTerm callFunction = 2; + repeated JavaTerm callParams = 3; + JavaTerm callBlock = 4; +} + +message LessThan { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message LessThanEqual { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message GreaterThan { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message GreaterThanEqual { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message Equal { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message StrictEqual { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message Comparison { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message BOr { + JavaTerm left = 1; + JavaTerm right = 2; +} + +message BXOr { + JavaTerm left = 1; + JavaTerm right = 2; +} + +message BAnd { + JavaTerm left = 1; + JavaTerm right = 2; +} + +message LShift { + JavaTerm left = 1; + JavaTerm right = 2; +} + +message RShift { + JavaTerm left = 1; + JavaTerm right = 2; +} + +message UnsignedRShift { + JavaTerm left = 1; + JavaTerm right = 2; +} + +message Complement { + JavaTerm value = 1; +} + +message And { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message Not { + JavaTerm value = 1; +} + +message Or { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message XOr { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message InstanceOf { + JavaTerm instanceOfSubject = 1; + JavaTerm instanceOfObject = 2; +} + +message MemberAccess { + JavaTerm lhs = 1; + bytes rhs = 2; +} + +message Subscript { + JavaTerm lhs = 1; + repeated JavaTerm rhs = 2; +} + +message Member { + JavaTerm lhs = 1; + JavaTerm rhs = 2; +} + +message Super { } + +message This { } + +message AnnotatedType { + repeated JavaTerm annotationes = 1; + JavaTerm annotatedType = 2; +} + +message JavaAnnotation { + JavaTerm annotationName = 1; + repeated JavaTerm annotationField = 2; +} + +message AnnotationField { + JavaTerm annotationFieldName = 1; + JavaTerm annotationFieldValue = 2; +} + +message AnnotationTypeElement { + repeated JavaTerm modifiers = 1; + JavaTerm annotationType = 2; + JavaTerm identifier = 3; + repeated JavaTerm dims = 4; + JavaTerm defaultValue = 5; +} + +message ArrayCreationExpression { + JavaTerm arrayCreationExpressionType = 1; + repeated JavaTerm arrayCreationExpressionDims = 2; +} + +message AssertStatement { + JavaTerm assertLHS = 1; + repeated JavaTerm assertRHS = 2; +} + +message Asterisk { } + +message CatchType { + repeated JavaTerm types = 1; +} + +message Constructor { + repeated JavaTerm constructorModifiers = 1; + repeated JavaTerm constructorTypeParams = 2; + JavaTerm constructorIdentifier = 3; + repeated JavaTerm constructorParams = 4; + repeated JavaTerm constructorThrows = 5; + JavaTerm constructorBody = 6; +} + +message ClassBody { + repeated JavaTerm classBodyExpression = 1; +} + +message ClassLiteral { + JavaTerm classLiteralType = 1; +} + +message DefaultValue { + JavaTerm defaultValueElement = 1; +} + +message DimsExpr { + repeated JavaTerm dimsExprAnnotation = 1; + repeated JavaTerm dimsExprExpression = 2; +} + +message EnumDeclaration { + repeated JavaTerm enumDeclarationModifier = 1; + JavaTerm enumDeclarationIdentifier = 2; + repeated JavaTerm enumDeclarationSuperInterfaces = 3; + repeated JavaTerm enumDeclarationConstant = 4; + repeated JavaTerm enumDeclarationBody = 5; +} + +message GenericType { + JavaTerm genericTypeIdentifier = 1; + repeated JavaTerm genericTypeArguments = 2; +} + +message Import { + repeated JavaTerm imports = 1; +} + +message Lambda { + repeated JavaTerm lambdaParams = 1; + JavaTerm lambdaBody = 2; +} + +message LambdaBody { + repeated JavaTerm lambdaBodyExpression = 1; +} + +message MethodReference { + JavaTerm methodReferenceType = 1; + repeated JavaTerm methodReferenceTypeArgs = 2; + JavaTerm methodReferenceIdentifier = 3; +} + +message Module { + JavaTerm moduleIdentifier = 1; + repeated JavaTerm moduleStatements = 2; +} + +message New { + JavaTerm newType = 1; + repeated JavaTerm newArgs = 2; + repeated JavaTerm newClassBody = 3; +} + +message NewKeyword { } + +message Package { + repeated JavaTerm packages = 1; +} + +message SpreadParameter { + JavaTerm spreadParameterVariableDeclarator = 1; +} + +message StaticInitializer { + JavaTerm staticInitializerBlock = 1; +} + +message Synchronized { + JavaTerm synchronizedSubject = 1; + JavaTerm synchronizedBody = 2; +} + +message TryWithResources { + repeated JavaTerm tryResources = 1; + JavaTerm tryBody = 2; + repeated JavaTerm tryCatch = 3; +} + +message TypeParameter { + repeated JavaTerm typeParamAnnotation = 1; + JavaTerm typeParamIdentifier = 2; + repeated JavaTerm typeParamTypeBound = 3; +} + +message TypeWithModifiers { + repeated JavaTerm types = 1; + JavaTerm modifier = 2; +} + +message Variable { + repeated JavaTerm variableModifiers = 1; + JavaTerm variableType = 2; + JavaTerm variableName = 3; +} + +message Wildcard { + repeated JavaTerm wildcardAnnotation = 1; + repeated JavaTerm wildcardBounds = 2; +} + +message WildcardBounds { + oneof sum { + JavaTerm wildcardBoundExtendsType = 1; + JavaTerm wildcardBoundSuperType = 2; + } +} + +message Array { + repeated JavaTerm arrayElements = 1; +} + +message Boolean { + bool booleanContent = 1; +} + +message Integer { + string integerContent = 1; +} + +message Float { + string floatContent = 1; +} + +message Null { } + +message String { + repeated JavaTerm stringElements = 1; +} + +message TextElement { + string textElementContent = 1; +} + +message Assignment { + repeated JavaTerm assignmentContext = 1; + JavaTerm assignmentTarget = 2; + JavaTerm assignmentValue = 3; +} + +message Break { + JavaTerm value = 1; +} + +message Catch { + JavaTerm catchException = 1; + JavaTerm catchBody = 2; +} + +message Continue { + JavaTerm value = 1; +} + +message DoWhile { + JavaTerm doWhileCondition = 1; + JavaTerm doWhileBody = 2; +} + +message Finally { + JavaTerm value = 1; +} + +message For { + JavaTerm forBefore = 1; + JavaTerm forCondition = 2; + JavaTerm forStep = 3; + JavaTerm forBody = 4; +} + +message ForEach { + JavaTerm forEachBinding = 1; + JavaTerm forEachSubject = 2; + JavaTerm forEachBody = 3; +} + +message If { + JavaTerm ifCondition = 1; + JavaTerm ifThenBody = 2; + JavaTerm ifElseBody = 3; +} + +message Match { + JavaTerm matchSubject = 1; + JavaTerm matchPatterns = 2; +} + +message Pattern { + JavaTerm value = 1; + JavaTerm patternBody = 2; +} + +message PostIncrement { + JavaTerm value = 1; +} + +message PostDecrement { + JavaTerm value = 1; +} + +message PreIncrement { + JavaTerm value = 1; +} + +message PreDecrement { + JavaTerm value = 1; +} + +message While { + JavaTerm whileCondition = 1; + JavaTerm whileBody = 2; +} + +message Statements { + repeated JavaTerm statements = 1; +} + +message Throw { + JavaTerm value = 1; +} + +message Try { + JavaTerm tryBody = 1; + repeated JavaTerm tryCatch = 2; +} + +message Context { + repeated JavaTerm contextTerms = 1; + JavaTerm contextSubject = 2; +} + +message Empty { } + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated JavaTerm errorChildren = 4; +} + +message Identifier { + bytes name = 1; +} + +message AccessibilityModifier { + string contents = 1; +} + +message TypeArray { + repeated JavaTerm arraySize = 1; + JavaTerm arrayElementType = 2; +} + +message Bool { } + +message Int { } + +message Void { } + +message TypeFloat { } + +message Annotation { + JavaTerm annotationSubject = 1; + JavaTerm annotationType = 2; +} + +message Return { + JavaTerm value = 1; +} + +message List { + repeated JavaTerm listContent = 1; +} diff --git a/src/Data/Syntax/Type.hs b/src/Data/Syntax/Type.hs index 5585c86ed..bf16a448d 100644 --- a/src/Data/Syntax/Type.hs +++ b/src/Data/Syntax/Type.hs @@ -42,8 +42,9 @@ instance Tokenize Annotation where data Function a = Function { functionParameters :: ![a], functionReturn :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Message1) +instance Named1 Function where nameOf1 _ = "TypeFunction" instance Eq1 Function where liftEq = genericLiftEq instance Ord1 Function where liftCompare = genericLiftCompare instance Show1 Function where liftShowsPrec = genericLiftShowsPrec @@ -86,8 +87,9 @@ instance Evaluatable Parenthesized newtype Pointer a = Pointer { value :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Message1) +instance Named1 Pointer where nameOf1 _ = "TypePointer" instance Eq1 Pointer where liftEq = genericLiftEq instance Ord1 Pointer where liftCompare = genericLiftCompare instance Show1 Pointer where liftShowsPrec = genericLiftShowsPrec @@ -119,8 +121,9 @@ instance Evaluatable Readonly newtype Slice a = Slice { value :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Message1) +instance Named1 Slice where nameOf1 _ = "TypeSlice" instance Eq1 Slice where liftEq = genericLiftEq instance Ord1 Slice where liftCompare = genericLiftCompare instance Show1 Slice where liftShowsPrec = genericLiftShowsPrec @@ -162,7 +165,9 @@ instance Show1 Int where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Int data Float a = Float - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Message1) + +instance Named1 Float where nameOf1 _ = "TypeFloat" instance Eq1 Float where liftEq = genericLiftEq instance Ord1 Float where liftCompare = genericLiftCompare diff --git a/src/Language/Go/Assignment.hs b/src/Language/Go/Assignment.hs index bff7856a1..1e51b7f7f 100644 --- a/src/Language/Go/Assignment.hs +++ b/src/Language/Go/Assignment.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds, RankNTypes, TypeOperators #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} -- FIXME module Language.Go.Assignment ( assignment , Syntax @@ -6,14 +7,14 @@ module Language.Go.Assignment , Term ) where -import Assigning.Assignment hiding (Assignment, Error) -import Data.Abstract.Name (Name, name) -import Data.Record -import Data.Syntax (contextualize, emptyTerm, parseError, handleError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1) -import Language.Go.Grammar as Grammar -import Language.Go.Syntax as Go.Syntax -import Language.Go.Type as Go.Type +import Prologue + +import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment +import Data.Abstract.Name (Name, name) +import Data.Record +import Data.Syntax + (contextualize, emptyTerm, handleError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1, parseError) import qualified Data.Syntax as Syntax import qualified Data.Syntax.Comment as Comment import qualified Data.Syntax.Declaration as Declaration @@ -21,9 +22,12 @@ import qualified Data.Syntax.Expression as Expression import qualified Data.Syntax.Literal as Literal import qualified Data.Syntax.Statement as Statement import qualified Data.Syntax.Type as Type -import Data.Sum import qualified Data.Term as Term -import Prologue +import qualified Data.Diff as Diff +import Language.Go.Grammar as Grammar +import Language.Go.Syntax as Go.Syntax hiding (runeLiteral, labelName) +import Language.Go.Type as Go.Type +import Proto3.Suite (Named (..), Named1 (..)) type Syntax = '[ Comment.Comment @@ -65,12 +69,6 @@ type Syntax = , Expression.Not , Expression.Or , Expression.XOr - , Expression.Call - , Expression.Comparison - , Expression.Subscript - , Statement.PostDecrement - , Statement.PostIncrement - , Expression.MemberAccess , Go.Syntax.Composite , Go.Syntax.DefaultPattern , Go.Syntax.Defer @@ -136,6 +134,10 @@ type Syntax = type Term = Term.Term (Sum Syntax) (Record Location) type Assignment = Assignment.Assignment [] Grammar +-- For Protobuf serialization +instance Named1 (Sum Syntax) where nameOf1 _ = "GoSyntax" +instance Named (Term.Term (Sum Syntax) ()) where nameOf _ = "GoTerm" +instance Named (Diff.Diff (Sum Syntax) () ()) where nameOf _ = "GoDiff" -- | Assignment from AST in Go's grammar onto a program in Go's syntax. assignment :: Assignment Term diff --git a/src/Language/Go/Syntax.hs b/src/Language/Go/Syntax.hs index dcd3d329b..00b966db8 100644 --- a/src/Language/Go/Syntax.hs +++ b/src/Language/Go/Syntax.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveAnyClass, LambdaCase #-} {-# OPTIONS_GHC -Wno-missing-export-lists #-} module Language.Go.Syntax where @@ -19,18 +19,23 @@ import qualified Proto3.Wire.Encode as Encode import qualified Proto3.Wire.Decode as Decode import System.FilePath.Posix -data Relative = Unknown | Relative | NonRelative - deriving (Bounded, Enum, Eq, Generic, Hashable, Ord, Show, ToJSON, Named, MessageField) +data IsRelative = Unknown | Relative | NonRelative + deriving (Bounded, Enum, Finite, Eq, Generic, Hashable, Ord, Show, ToJSON, Named, MessageField) -instance Primitive Relative where - encodePrimitive = Encode.enum - decodePrimitive = either (const def) id <$> Decode.enum - primType _ = Named (Single (nameOf (Proxy @Relative))) +instance Primitive IsRelative where + -- encodePrimitive = Encode.enum + -- decodePrimitive = either (const def) id <$> Decode.enum + -- primType _ = Named (Single (nameOf (Proxy @IsRelative))) + primType _ = primType (Proxy @(Enumerated IsRelative)) + encodePrimitive f = encodePrimitive f . Enumerated . Right + decodePrimitive = decodePrimitive >>= \case + (Enumerated (Right r)) -> pure r + other -> Prelude.fail ("IsRelative decodeMessageField: unexpected value" <> show other) -instance HasDefault Relative where +instance HasDefault IsRelative where def = Unknown -data ImportPath = ImportPath { unPath :: FilePath, pathIsRelative :: Relative } +data ImportPath = ImportPath { unPath :: FilePath, pathIsRelative :: IsRelative } deriving (Eq, Generic, Hashable, Ord, Show, ToJSON, Named, Message) instance MessageField ImportPath where diff --git a/src/Language/Go/Type.hs b/src/Language/Go/Type.hs index c17ba4f36..037a7a016 100644 --- a/src/Language/Go/Type.hs +++ b/src/Language/Go/Type.hs @@ -1,15 +1,17 @@ -{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveAnyClass, DuplicateRecordFields #-} {-# OPTIONS_GHC -Wno-missing-export-lists #-} module Language.Go.Type where import Prologue + import Data.Abstract.Evaluatable import Data.JSON.Fields import Diffing.Algorithm +import Proto3.Suite.Class -- | A Bidirectional channel in Go (e.g. `chan`). -newtype BidirectionalChannel a = BidirectionalChannel a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype BidirectionalChannel a = BidirectionalChannel { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 BidirectionalChannel where liftEq = genericLiftEq instance Ord1 BidirectionalChannel where liftCompare = genericLiftCompare @@ -19,8 +21,8 @@ instance Show1 BidirectionalChannel where liftShowsPrec = genericLiftShowsPrec instance Evaluatable BidirectionalChannel -- | A Receive channel in Go (e.g. `<-chan`). -newtype ReceiveChannel a = ReceiveChannel a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ReceiveChannel a = ReceiveChannel { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 ReceiveChannel where liftEq = genericLiftEq instance Ord1 ReceiveChannel where liftCompare = genericLiftCompare @@ -30,8 +32,8 @@ instance Show1 ReceiveChannel where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ReceiveChannel -- | A Send channel in Go (e.g. `chan<-`). -newtype SendChannel a = SendChannel a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype SendChannel a = SendChannel { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 SendChannel where liftEq = genericLiftEq instance Ord1 SendChannel where liftCompare = genericLiftCompare diff --git a/src/Language/Java/Assignment.hs b/src/Language/Java/Assignment.hs index 4b6f02276..6d8b3216b 100644 --- a/src/Language/Java/Assignment.hs +++ b/src/Language/Java/Assignment.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds, RankNTypes, TypeOperators #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} -- FIXME module Language.Java.Assignment ( assignment , Syntax @@ -6,16 +7,27 @@ module Language.Java.Assignment , Term ) where -import Assigning.Assignment hiding (Assignment, Error, try) -import Data.Abstract.Name -import Data.Functor (($>)) -import Data.List.NonEmpty (some1) -import Data.Record -import Data.Syntax (contextualize, emptyTerm, handleError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1, parseError, postContextualize) -import Data.Sum -import Language.Java.Grammar as Grammar -import qualified Language.Java.Syntax as Java.Syntax +import Prelude hiding (break) +import Prologue hiding (for, try, This, catches, finally) + +import Assigning.Assignment hiding (Assignment, Error, try) import qualified Assigning.Assignment as Assignment +import Data.Abstract.Name +import Data.Functor (($>)) +import Data.List.NonEmpty (some1) +import Data.Record +import Data.Syntax + ( contextualize + , emptyTerm + , handleError + , infixContext + , makeTerm + , makeTerm' + , makeTerm'' + , makeTerm1 + , parseError + , postContextualize + ) import qualified Data.Syntax as Syntax import qualified Data.Syntax.Comment as Comment import qualified Data.Syntax.Declaration as Declaration @@ -24,8 +36,10 @@ import qualified Data.Syntax.Literal as Literal import qualified Data.Syntax.Statement as Statement import qualified Data.Syntax.Type as Type import qualified Data.Term as Term -import Prelude hiding (break) -import Prologue hiding (for, try, This, catches, finally) +import qualified Data.Diff as Diff +import Language.Java.Grammar as Grammar +import qualified Language.Java.Syntax as Java.Syntax +import Proto3.Suite (Named (..), Named1 (..)) type Syntax = '[ Comment.Comment @@ -142,6 +156,11 @@ type Syntax = type Term = Term.Term (Sum Syntax) (Record Location) type Assignment = Assignment.Assignment [] Grammar +-- For Protobuf serialization +instance Named1 (Sum Syntax) where nameOf1 _ = "JavaSyntax" +instance Named (Term.Term (Sum Syntax) ()) where nameOf _ = "JavaTerm" +instance Named (Diff.Diff (Sum Syntax) () ()) where nameOf _ = "JavaDiff" + -- | Assignment from AST in Java's grammar onto a program in Java's syntax. assignment :: Assignment Term assignment = handleError $ makeTerm <$> symbol Grammar.Program <*> children (Statement.Statements <$> manyTerm expression) <|> parseError diff --git a/src/Language/Java/Syntax.hs b/src/Language/Java/Syntax.hs index 31e2025ad..7e6570458 100644 --- a/src/Language/Java/Syntax.hs +++ b/src/Language/Java/Syntax.hs @@ -111,8 +111,9 @@ instance Show1 TypeParameter where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeParameter data Annotation a = Annotation { annotationName :: !a, annotationField :: [a]} - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Message1, Traversable) +instance Named1 Annotation where nameOf1 _ = "JavaAnnotation" instance Eq1 Annotation where liftEq = genericLiftEq instance Ord1 Annotation where liftCompare = genericLiftCompare instance Show1 Annotation where liftShowsPrec = genericLiftShowsPrec @@ -180,7 +181,7 @@ instance Show1 Wildcard where liftShowsPrec = genericLiftShowsPrec -- TODO: Implement Eval instance for TypeWithModifiers instance Evaluatable Wildcard -data WildcardBounds a = WildcardBoundExtends { wildcardBoundType :: a} | WildcardBoundSuper { wildcardBoundType :: a} +data WildcardBounds a = WildcardBoundExtends { wildcardBoundExtendsType :: a} | WildcardBoundSuper { wildcardBoundSuperType :: a} deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Named1, Message1, Traversable) instance Eq1 WildcardBounds where liftEq = genericLiftEq From 8d4eab66b9bd977025afe021aa9c9e178cc07684 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Fri, 7 Sep 2018 17:10:18 -0700 Subject: [PATCH 20/39] Remove comment --- src/Language/Go/Syntax.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Language/Go/Syntax.hs b/src/Language/Go/Syntax.hs index 00b966db8..c4a9e6bbe 100644 --- a/src/Language/Go/Syntax.hs +++ b/src/Language/Go/Syntax.hs @@ -23,9 +23,6 @@ data IsRelative = Unknown | Relative | NonRelative deriving (Bounded, Enum, Finite, Eq, Generic, Hashable, Ord, Show, ToJSON, Named, MessageField) instance Primitive IsRelative where - -- encodePrimitive = Encode.enum - -- decodePrimitive = either (const def) id <$> Decode.enum - -- primType _ = Named (Single (nameOf (Proxy @IsRelative))) primType _ = primType (Proxy @(Enumerated IsRelative)) encodePrimitive f = encodePrimitive f . Enumerated . Right decodePrimitive = decodePrimitive >>= \case From ceed3b0ae4c76aff25e86b7bbce89391412ef5a4 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 10 Sep 2018 11:15:34 -0700 Subject: [PATCH 21/39] Fix a few test fixtures due to structure changes --- .../go/corpus/slice-expressions.diffA-B.txt | 71 ++++++++++-------- .../go/corpus/slice-expressions.diffB-A.txt | 72 +++++++++++-------- .../go/corpus/unary-expressions.diffA-B.txt | 54 ++++++++------ .../go/corpus/unary-expressions.diffB-A.txt | 54 ++++++++------ 4 files changed, 149 insertions(+), 102 deletions(-) diff --git a/test/fixtures/go/corpus/slice-expressions.diffA-B.txt b/test/fixtures/go/corpus/slice-expressions.diffA-B.txt index 44ccf8cf3..1b3474cdd 100644 --- a/test/fixtures/go/corpus/slice-expressions.diffA-B.txt +++ b/test/fixtures/go/corpus/slice-expressions.diffA-B.txt @@ -4,36 +4,49 @@ (Function (Identifier) (Statements - (Slice - (Identifier) - { (Integer) - ->(Integer) } - (Empty) - (Empty)) - (Slice - (Identifier) - (Empty) - { (Integer) - ->(Integer) } - (Empty)) - (Slice - (Identifier) - { (Empty) - ->(Integer) } - { (Empty) - ->(Integer) } - (Empty)) - (Slice - (Identifier) - { (Integer) - ->(Integer) } - { (Integer) - ->(Integer) } - { (Integer) - ->(Integer) }) + {+(Slice + {+(Identifier)+} + {+(Integer)+} + {+(Empty)+} + {+(Empty)+})+} + {+(Slice + {+(Identifier)+} + {+(Empty)+} + {+(Integer)+} + {+(Empty)+})+} + {+(Slice + {+(Identifier)+} + {+(Integer)+} + {+(Integer)+} + {+(Empty)+})+} (Slice { (Identifier) ->(Identifier) } (Integer) - (Integer) - (Empty))))) + { (Empty) + ->(Integer) } + { (Empty) + ->(Integer) }) + (Slice + { (Identifier) + ->(Identifier) } + { (Empty) + ->(Integer) } + { (Integer) + ->(Integer) } + (Empty)) + {-(Slice + {-(Identifier)-} + {-(Empty)-} + {-(Empty)-} + {-(Empty)-})-} + {-(Slice + {-(Identifier)-} + {-(Integer)-} + {-(Integer)-} + {-(Integer)-})-} + {-(Slice + {-(Identifier)-} + {-(Integer)-} + {-(Integer)-} + {-(Empty)-})-}))) diff --git a/test/fixtures/go/corpus/slice-expressions.diffB-A.txt b/test/fixtures/go/corpus/slice-expressions.diffB-A.txt index e4c55a60b..cc6efa0bd 100644 --- a/test/fixtures/go/corpus/slice-expressions.diffB-A.txt +++ b/test/fixtures/go/corpus/slice-expressions.diffB-A.txt @@ -4,36 +4,50 @@ (Function (Identifier) (Statements - (Slice - (Identifier) - { (Integer) - ->(Integer) } - (Empty) - (Empty)) - (Slice - (Identifier) - (Empty) - { (Integer) - ->(Integer) } - (Empty)) - (Slice - (Identifier) - { (Integer) - ->(Empty) } - { (Integer) - ->(Empty) } - (Empty)) - (Slice - (Identifier) - { (Integer) - ->(Integer) } - { (Integer) - ->(Integer) } - { (Integer) - ->(Integer) }) + {+(Slice + {+(Identifier)+} + {+(Integer)+} + {+(Empty)+} + {+(Empty)+})+} + {+(Slice + {+(Identifier)+} + {+(Empty)+} + {+(Integer)+} + {+(Empty)+})+} + {+(Slice + {+(Identifier)+} + {+(Empty)+} + {+(Empty)+} + {+(Empty)+})+} + {+(Slice + {+(Identifier)+} + {+(Integer)+} + {+(Integer)+} + {+(Integer)+})+} (Slice { (Identifier) ->(Identifier) } (Integer) - (Integer) - (Empty))))) + { (Empty) + ->(Integer) } + (Empty)) + {-(Slice + {-(Identifier)-} + {-(Empty)-} + {-(Integer)-} + {-(Empty)-})-} + {-(Slice + {-(Identifier)-} + {-(Integer)-} + {-(Integer)-} + {-(Empty)-})-} + {-(Slice + {-(Identifier)-} + {-(Integer)-} + {-(Integer)-} + {-(Integer)-})-} + {-(Slice + {-(Identifier)-} + {-(Integer)-} + {-(Integer)-} + {-(Empty)-})-}))) diff --git a/test/fixtures/go/corpus/unary-expressions.diffA-B.txt b/test/fixtures/go/corpus/unary-expressions.diffA-B.txt index 9bbb33121..139f4530d 100644 --- a/test/fixtures/go/corpus/unary-expressions.diffA-B.txt +++ b/test/fixtures/go/corpus/unary-expressions.diffA-B.txt @@ -6,25 +6,35 @@ (Statements { (Identifier) ->(Identifier) } - (Negate - { (Identifier) - ->(Identifier) }) - (Not - (ReceiveOperator - { (Identifier) - ->(Identifier) })) - (Pointer - (Call - { (Identifier) - ->(Identifier) } - (Statements) - (Empty))) - (Complement - { (Identifier) - ->(Identifier) }) - (Reference - { (Identifier) - ->(Identifier) }) - (ReceiveOperator - { (Identifier) - ->(Identifier) })))) + {+(Negate + {+(Identifier)+})+} + {+(Not + {+(ReceiveOperator + {+(Identifier)+})+})+} + {+(Pointer + {+(Call + {+(Identifier)+} + {+(Statements)+} + {+(Empty)+})+})+} + {+(Complement + {+(Identifier)+})+} + {+(Reference + {+(Identifier)+})+} + {+(ReceiveOperator + {+(Identifier)+})+} + {-(Negate + {-(Identifier)-})-} + {-(Not + {-(ReceiveOperator + {-(Identifier)-})-})-} + {-(Pointer + {-(Call + {-(Identifier)-} + {-(Statements)-} + {-(Empty)-})-})-} + {-(Complement + {-(Identifier)-})-} + {-(Reference + {-(Identifier)-})-} + {-(ReceiveOperator + {-(Identifier)-})-}))) diff --git a/test/fixtures/go/corpus/unary-expressions.diffB-A.txt b/test/fixtures/go/corpus/unary-expressions.diffB-A.txt index 9bbb33121..139f4530d 100644 --- a/test/fixtures/go/corpus/unary-expressions.diffB-A.txt +++ b/test/fixtures/go/corpus/unary-expressions.diffB-A.txt @@ -6,25 +6,35 @@ (Statements { (Identifier) ->(Identifier) } - (Negate - { (Identifier) - ->(Identifier) }) - (Not - (ReceiveOperator - { (Identifier) - ->(Identifier) })) - (Pointer - (Call - { (Identifier) - ->(Identifier) } - (Statements) - (Empty))) - (Complement - { (Identifier) - ->(Identifier) }) - (Reference - { (Identifier) - ->(Identifier) }) - (ReceiveOperator - { (Identifier) - ->(Identifier) })))) + {+(Negate + {+(Identifier)+})+} + {+(Not + {+(ReceiveOperator + {+(Identifier)+})+})+} + {+(Pointer + {+(Call + {+(Identifier)+} + {+(Statements)+} + {+(Empty)+})+})+} + {+(Complement + {+(Identifier)+})+} + {+(Reference + {+(Identifier)+})+} + {+(ReceiveOperator + {+(Identifier)+})+} + {-(Negate + {-(Identifier)-})-} + {-(Not + {-(ReceiveOperator + {-(Identifier)-})-})-} + {-(Pointer + {-(Call + {-(Identifier)-} + {-(Statements)-} + {-(Empty)-})-})-} + {-(Complement + {-(Identifier)-})-} + {-(Reference + {-(Identifier)-})-} + {-(ReceiveOperator + {-(Identifier)-})-}))) From 38e3cba57ae8c55d2410b656f840ea25b57fda46 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 10 Sep 2018 11:15:52 -0700 Subject: [PATCH 22/39] Messy, but working multi-lang grpc parsing --- proto/apitypes.proto | 21 ++++++++++ proto/code_analysis.proto | 84 +++++++++++++++++++++------------------ semantic.cabal | 1 + src/Data/ParseTree.hs | 47 ++++++++++++++++++++++ src/Data/Term.hs | 22 +++++++++- 5 files changed, 134 insertions(+), 41 deletions(-) create mode 100644 proto/apitypes.proto create mode 100644 src/Data/ParseTree.hs diff --git a/proto/apitypes.proto b/proto/apitypes.proto new file mode 100644 index 000000000..ad6597eaa --- /dev/null +++ b/proto/apitypes.proto @@ -0,0 +1,21 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic; + +import "java_term.proto"; +import "ruby_term.proto"; +import "types.proto"; + +option java_package = "com.github.semantic.apitypes"; +option go_package = "github.com/semantic/apitypes;types"; + +message ParseTree { + Language language = 1; + string path = 2; + string error = 3; + oneof response_type { + javaterm.JavaTerm java_tree = 4; + rubyterm.RubyTerm ruby_tree = 5; + } +} diff --git a/proto/code_analysis.proto b/proto/code_analysis.proto index c3f77f89e..87f21836e 100644 --- a/proto/code_analysis.proto +++ b/proto/code_analysis.proto @@ -11,9 +11,11 @@ import "ruby_diff.proto"; import "ruby_term.proto"; import "typescript_diff.proto"; import "typescript_term.proto"; -import "types.proto"; import "error_details.proto"; +import "types.proto"; +import "apitypes.proto"; + option java_package = "com.github.semantic.analysis"; option go_package = "github.com/semantic/analysis/;analysis"; @@ -65,48 +67,52 @@ message ParseTreeGraph { repeated DebugInfo error_info = 2; } - message ParseTreeResponse { - DebugInfo error_info = 1; - oneof response_type { - GoResponse go = 2; - JavaResponse java = 3; - JSONResponse json = 4; - PythonResponse python = 5; - RubyResponse ruby = 6; - TypeScriptResponse typescript = 7; - } + repeated ParseTree trees = 1; + DebugInfo error_info = 2; // Top level failure for things like timeouts } -message GoResponse { - repeated goterm.GoTerm terms = 1; - repeated DebugInfo errors = 2; -} +// message ParseTree { +// Language language = 1; +// string path = 2; +// +// // Parse failure for an individual path or language not supported +// DebugInfo error_info = 3; +// +// oneof response_type { +// // GoResponse go = 4; +// // JavaResponse java = 5; +// javaterm.JavaTerm term = 5; +// // JSONResponse json = 6; +// // PythonResponse python = 7; +// // RubyResponse ruby = 8; +// // TypeScriptResponse typescript = 9; +// } +// } -message JavaResponse { - repeated javaterm.JavaTerm terms = 1; - repeated DebugInfo errors = 2; -} - -message JSONResponse { - repeated jsonterm.JSONTerm terms = 1; - repeated DebugInfo errors = 2; -} - -message PythonResponse { - repeated pythonterm.PythonTerm terms = 1; - repeated DebugInfo errors = 2; -} - -message RubyResponse { - repeated rubyterm.RubyTerm terms = 1; - repeated DebugInfo errors = 2; -} - -message TypeScriptResponse { - repeated typescriptterm.TypeScriptTerm terms = 1; - repeated DebugInfo errors = 2; -} +// message GoResponse { +// goterm.GoTerm term = 1; +// } +// +// message JavaResponse { +// javaterm.JavaTerm term = 1; +// } +// +// message JSONResponse { +// jsonterm.JSONTerm term = 1; +// } +// +// message PythonResponse { +// pythonterm.PythonTerm term = 1; +// } +// +// message RubyResponse { +// rubyterm.RubyTerm term = 1; +// } +// +// message TypeScriptResponse { +// typescriptterm.TypeScriptTerm term = 1; +// } // Diff Request & Responses // diff --git a/semantic.cabal b/semantic.cabal index 0dc82938a..492fc8fe7 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -89,6 +89,7 @@ library , Data.JSON.Fields , Data.Language , Data.Map.Monoidal + , Data.ParseTree , Data.Patch , Data.Project , Data.Quieterm diff --git a/src/Data/ParseTree.hs b/src/Data/ParseTree.hs new file mode 100644 index 000000000..2fa015b83 --- /dev/null +++ b/src/Data/ParseTree.hs @@ -0,0 +1,47 @@ +{-# LANGUAGE DeriveAnyClass #-} +module Data.ParseTree (ParseTree(..), ResponseType(..)) where + +import Prologue +import Data.Language +import Data.Term +import qualified Language.Java.Assignment as Java +import qualified Language.Ruby.Assignment as Ruby +import Proto3.Suite +import qualified Proto3.Wire.Encode as Encode +import qualified Proto3.Suite as PB + +type JavaTerm = Term (Sum Java.Syntax) () +type RubyTerm = Term (Sum Ruby.Syntax) () + +data ParseTree + = ParseTree + { language :: Language + , path :: FilePath + , error :: String + , responseType :: Maybe ResponseType + } deriving (Eq, Show, Generic, Named) + +instance Message ParseTree where + encodeMessage _ ParseTree{..} + = encodeMessageField 1 language + <> encodeMessageField 2 path + <> encodeMessageField 3 error + <> case responseType of + Just (JavaResponse x) -> Encode.embedded 4 (encodeMessage 1 x) + Just (RubyResponse x) -> Encode.embedded 5 (encodeMessage 1 x) + _ -> mempty + decodeMessage = undefined + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim . Named $ Single "Language") (Single "language") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "path") [] Nothing + , DotProtoMessageField $ DotProtoField 3 (Prim PB.String) (Single "error") [] Nothing + , DotProtoMessageOneOf (Single "response_type") + [ DotProtoField 4 (Prim . Named $ Dots (Path ["javaterm", "JavaTerm"])) (Single "java_tree") [] Nothing + , DotProtoField 5 (Prim . Named $ Dots (Path ["rubyterm", "RubyTerm"])) (Single "ruby_tree") [] Nothing + ] + ] + +data ResponseType + = JavaResponse JavaTerm + | RubyResponse RubyTerm + deriving (Eq, Show) diff --git a/src/Data/Term.hs b/src/Data/Term.hs index 22faabefb..f00d5947c 100644 --- a/src/Data/Term.hs +++ b/src/Data/Term.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE RankNTypes, TypeFamilies, TypeOperators, ScopedTypeVariables, FunctionalDependencies #-} +{-# LANGUAGE DeriveAnyClass, RankNTypes, TypeFamilies, TypeOperators, ScopedTypeVariables, FunctionalDependencies #-} module Data.Term ( Term(..) , termIn @@ -103,10 +103,28 @@ instance (Show1 f, Show a) => Show (Term f a) where showsPrec = showsPrec1 instance (Named1 f, Message1 f) => Message (Term f ()) where - encodeMessage num (Term (In _ f)) = Encode.embedded num (liftEncodeMessage encodeMessage 1 f) + encodeMessage num (Term (In _ f)) = Encode.embedded num (liftEncodeMessage encodeMessage 1 f) decodeMessage num = termIn () . fromMaybe undefined <$> Decode.at (Decode.embedded (liftDecodeMessage decodeMessage 1)) num dotProto (_ :: Proxy (Term f ())) = [ DotProtoMessageField (DotProtoField 1 (Prim . Named $ Single (nameOf1 (Proxy @f))) (Single "syntax") [] Nothing) ] +-- -- TODO: Implement these +-- instance (Named1 f, Message1 f, Foldable f, Message a) => MessageField (Term f a) where +-- encodeMessageField num = foldMap (Encode.embedded num . encodeMessage 1) +-- -- encodeMessageField num (Term (In _ f)) = Encode.embedded num (liftEncodeMessage encodeMessageField 1 f) +-- -- encodeMessageField num (Term (In _ f)) = liftEncodeMessage encodeMessageField num f +-- decodeMessageField = undefined +-- protoType = undefined +-- +-- instance (Eq1 f) => HasDefault (Term f ()) where +-- def = undefined +-- +-- deriving instance Message () +-- +-- instance Primitive (Term f ()) where +-- primType = undefined +-- encodePrimitive = undefined +-- decodePrimitive = undefined + instance Ord1 f => Ord1 (Term f) where liftCompare comp = go where go t1 t2 = liftCompare2 comp go (unTerm t1) (unTerm t2) From c806be4cfc5b84b342fe80aa35380555e2fd28b7 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 10 Sep 2018 11:43:42 -0700 Subject: [PATCH 23/39] Clean up, expand grpc support to larger language list --- proto/apitypes.proto | 21 ------------ proto/code_analysis.proto | 58 ++++---------------------------- proto/terms.proto | 29 ++++++++++++++++ semantic.cabal | 2 +- src/Data/ParseTree.hs | 47 -------------------------- src/Data/Proto/ParseTree.hs | 67 +++++++++++++++++++++++++++++++++++++ src/Data/Term.hs | 18 ---------- 7 files changed, 104 insertions(+), 138 deletions(-) delete mode 100644 proto/apitypes.proto create mode 100644 proto/terms.proto delete mode 100644 src/Data/ParseTree.hs create mode 100644 src/Data/Proto/ParseTree.hs diff --git a/proto/apitypes.proto b/proto/apitypes.proto deleted file mode 100644 index ad6597eaa..000000000 --- a/proto/apitypes.proto +++ /dev/null @@ -1,21 +0,0 @@ -// This file was generated by proto-gen. Do not edit by hand. -syntax = "proto3"; - -package github.semantic; - -import "java_term.proto"; -import "ruby_term.proto"; -import "types.proto"; - -option java_package = "com.github.semantic.apitypes"; -option go_package = "github.com/semantic/apitypes;types"; - -message ParseTree { - Language language = 1; - string path = 2; - string error = 3; - oneof response_type { - javaterm.JavaTerm java_tree = 4; - rubyterm.RubyTerm ruby_tree = 5; - } -} diff --git a/proto/code_analysis.proto b/proto/code_analysis.proto index 87f21836e..569504ab5 100644 --- a/proto/code_analysis.proto +++ b/proto/code_analysis.proto @@ -2,19 +2,13 @@ syntax = "proto3"; package github.semantic; -import "go_term.proto"; -import "java_term.proto"; -import "json_term.proto"; import "python_diff.proto"; -import "python_term.proto"; import "ruby_diff.proto"; -import "ruby_term.proto"; import "typescript_diff.proto"; -import "typescript_term.proto"; -import "error_details.proto"; import "types.proto"; -import "apitypes.proto"; +import "terms.proto"; +import "error_details.proto"; option java_package = "com.github.semantic.analysis"; option go_package = "github.com/semantic/analysis/;analysis"; @@ -67,53 +61,15 @@ message ParseTreeGraph { repeated DebugInfo error_info = 2; } +// A ParseTreeResponse contains a list of syntax trees, one for each blob passed +// in the request. message ParseTreeResponse { + // The list of trees. repeated ParseTree trees = 1; - DebugInfo error_info = 2; // Top level failure for things like timeouts + // Entire response failed (e.g. a timeout) + DebugInfo error_info = 2; } -// message ParseTree { -// Language language = 1; -// string path = 2; -// -// // Parse failure for an individual path or language not supported -// DebugInfo error_info = 3; -// -// oneof response_type { -// // GoResponse go = 4; -// // JavaResponse java = 5; -// javaterm.JavaTerm term = 5; -// // JSONResponse json = 6; -// // PythonResponse python = 7; -// // RubyResponse ruby = 8; -// // TypeScriptResponse typescript = 9; -// } -// } - -// message GoResponse { -// goterm.GoTerm term = 1; -// } -// -// message JavaResponse { -// javaterm.JavaTerm term = 1; -// } -// -// message JSONResponse { -// jsonterm.JSONTerm term = 1; -// } -// -// message PythonResponse { -// pythonterm.PythonTerm term = 1; -// } -// -// message RubyResponse { -// rubyterm.RubyTerm term = 1; -// } -// -// message TypeScriptResponse { -// typescriptterm.TypeScriptTerm term = 1; -// } - // Diff Request & Responses // message SummarizeDiffRequest { diff --git a/proto/terms.proto b/proto/terms.proto new file mode 100644 index 000000000..fa82aadee --- /dev/null +++ b/proto/terms.proto @@ -0,0 +1,29 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic; + +import "go_term.proto"; +import "java_term.proto"; +import "json_term.proto"; +import "python_term.proto"; +import "ruby_term.proto"; +import "typescript_term.proto"; +import "types.proto"; + +option java_package = "com.github.semantic.terms"; +option go_package = "github.com/semantic/terms;types"; + +message ParseTree { + Language language = 1; + string path = 2; + string error = 3; + oneof response_type { + goterm.GoTerm go_tree = 4; + javaterm.JavaTerm java_tree = 5; + jsonterm.JSONTerm json_tree = 6; + pythonterm.PythonTerm python_tree = 7; + rubyterm.RubyTerm ruby_tree = 8; + typescriptterm.TypeScriptTerm typescript_tree = 9; + } +} diff --git a/semantic.cabal b/semantic.cabal index 492fc8fe7..09969beea 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -89,7 +89,7 @@ library , Data.JSON.Fields , Data.Language , Data.Map.Monoidal - , Data.ParseTree + , Data.Proto.ParseTree , Data.Patch , Data.Project , Data.Quieterm diff --git a/src/Data/ParseTree.hs b/src/Data/ParseTree.hs deleted file mode 100644 index 2fa015b83..000000000 --- a/src/Data/ParseTree.hs +++ /dev/null @@ -1,47 +0,0 @@ -{-# LANGUAGE DeriveAnyClass #-} -module Data.ParseTree (ParseTree(..), ResponseType(..)) where - -import Prologue -import Data.Language -import Data.Term -import qualified Language.Java.Assignment as Java -import qualified Language.Ruby.Assignment as Ruby -import Proto3.Suite -import qualified Proto3.Wire.Encode as Encode -import qualified Proto3.Suite as PB - -type JavaTerm = Term (Sum Java.Syntax) () -type RubyTerm = Term (Sum Ruby.Syntax) () - -data ParseTree - = ParseTree - { language :: Language - , path :: FilePath - , error :: String - , responseType :: Maybe ResponseType - } deriving (Eq, Show, Generic, Named) - -instance Message ParseTree where - encodeMessage _ ParseTree{..} - = encodeMessageField 1 language - <> encodeMessageField 2 path - <> encodeMessageField 3 error - <> case responseType of - Just (JavaResponse x) -> Encode.embedded 4 (encodeMessage 1 x) - Just (RubyResponse x) -> Encode.embedded 5 (encodeMessage 1 x) - _ -> mempty - decodeMessage = undefined - dotProto _ = - [ DotProtoMessageField $ DotProtoField 1 (Prim . Named $ Single "Language") (Single "language") [] Nothing - , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "path") [] Nothing - , DotProtoMessageField $ DotProtoField 3 (Prim PB.String) (Single "error") [] Nothing - , DotProtoMessageOneOf (Single "response_type") - [ DotProtoField 4 (Prim . Named $ Dots (Path ["javaterm", "JavaTerm"])) (Single "java_tree") [] Nothing - , DotProtoField 5 (Prim . Named $ Dots (Path ["rubyterm", "RubyTerm"])) (Single "ruby_tree") [] Nothing - ] - ] - -data ResponseType - = JavaResponse JavaTerm - | RubyResponse RubyTerm - deriving (Eq, Show) diff --git a/src/Data/Proto/ParseTree.hs b/src/Data/Proto/ParseTree.hs new file mode 100644 index 000000000..7e0580e2c --- /dev/null +++ b/src/Data/Proto/ParseTree.hs @@ -0,0 +1,67 @@ +{-# LANGUAGE DeriveAnyClass #-} +module Data.Proto.ParseTree (ParseTree(..), ResponseType(..)) where + +import Prologue +import Data.Language +import Data.Term +import qualified Language.Go.Assignment as Go +import qualified Language.Java.Assignment as Java +import qualified Language.JSON.Assignment as JSON +import qualified Language.Python.Assignment as Python +import qualified Language.Ruby.Assignment as Ruby +import qualified Language.TypeScript.Assignment as TypeScript +import Proto3.Suite +import qualified Proto3.Wire.Encode as Encode +import qualified Proto3.Suite as PB + +type GoTerm = Term (Sum Go.Syntax) () +type JavaTerm = Term (Sum Java.Syntax) () +type JSONTerm = Term (Sum JSON.Syntax) () +type PythonTerm = Term (Sum Python.Syntax) () +type RubyTerm = Term (Sum Ruby.Syntax) () +type TypeScriptTerm = Term (Sum TypeScript.Syntax) () + +data ParseTree + = ParseTree + { language :: Language + , path :: FilePath + , error :: String + , responseType :: Maybe ResponseType + } deriving (Eq, Show, Generic, Named) + +instance Message ParseTree where + encodeMessage _ ParseTree{..} + = encodeMessageField 1 language + <> encodeMessageField 2 path + <> encodeMessageField 3 error + <> case responseType of + Just (GoResponse x) -> Encode.embedded 4 (encodeMessage 1 x) + Just (JavaResponse x) -> Encode.embedded 5 (encodeMessage 1 x) + Just (JSONResponse x) -> Encode.embedded 6 (encodeMessage 1 x) + Just (PythonResponse x) -> Encode.embedded 7 (encodeMessage 1 x) + Just (RubyResponse x) -> Encode.embedded 8 (encodeMessage 1 x) + Just (TypeScriptResponse x) -> Encode.embedded 9 (encodeMessage 1 x) + _ -> mempty + decodeMessage = undefined + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim . Named $ Single "Language") (Single "language") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "path") [] Nothing + , DotProtoMessageField $ DotProtoField 3 (Prim PB.String) (Single "error") [] Nothing + , DotProtoMessageOneOf (Single "response_type") + [ DotProtoField 4 (Prim . Named $ Dots (Path ["goterm", "GoTerm"])) (Single "go_tree") [] Nothing + , DotProtoField 5 (Prim . Named $ Dots (Path ["javaterm", "JavaTerm"])) (Single "java_tree") [] Nothing + , DotProtoField 6 (Prim . Named $ Dots (Path ["jsonterm", "JSONTerm"])) (Single "json_tree") [] Nothing + , DotProtoField 7 (Prim . Named $ Dots (Path ["pythonterm", "PythonTerm"])) (Single "python_tree") [] Nothing + , DotProtoField 8 (Prim . Named $ Dots (Path ["rubyterm", "RubyTerm"])) (Single "ruby_tree") [] Nothing + , DotProtoField 9 (Prim . Named $ Dots (Path ["typescriptterm", "TypeScriptTerm"])) (Single "typescript_tree") [] Nothing + ] + ] + +data ResponseType + = GoResponse GoTerm + | JavaResponse JavaTerm + | JSONResponse JSONTerm + | PythonResponse PythonTerm + | RubyResponse RubyTerm + | TypeScriptResponse TypeScriptTerm + deriving (Eq, Show) diff --git a/src/Data/Term.hs b/src/Data/Term.hs index f00d5947c..f872ab364 100644 --- a/src/Data/Term.hs +++ b/src/Data/Term.hs @@ -107,24 +107,6 @@ instance (Named1 f, Message1 f) => Message (Term f ()) where decodeMessage num = termIn () . fromMaybe undefined <$> Decode.at (Decode.embedded (liftDecodeMessage decodeMessage 1)) num dotProto (_ :: Proxy (Term f ())) = [ DotProtoMessageField (DotProtoField 1 (Prim . Named $ Single (nameOf1 (Proxy @f))) (Single "syntax") [] Nothing) ] --- -- TODO: Implement these --- instance (Named1 f, Message1 f, Foldable f, Message a) => MessageField (Term f a) where --- encodeMessageField num = foldMap (Encode.embedded num . encodeMessage 1) --- -- encodeMessageField num (Term (In _ f)) = Encode.embedded num (liftEncodeMessage encodeMessageField 1 f) --- -- encodeMessageField num (Term (In _ f)) = liftEncodeMessage encodeMessageField num f --- decodeMessageField = undefined --- protoType = undefined --- --- instance (Eq1 f) => HasDefault (Term f ()) where --- def = undefined --- --- deriving instance Message () --- --- instance Primitive (Term f ()) where --- primType = undefined --- encodePrimitive = undefined --- decodePrimitive = undefined - instance Ord1 f => Ord1 (Term f) where liftCompare comp = go where go t1 t2 = liftCompare2 comp go (unTerm t1) (unTerm t2) From 2c9407757f73794670976c142afe620e4b0b341c Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 10 Sep 2018 15:38:37 -0700 Subject: [PATCH 24/39] Turn on the rest of our langauges for grpc parse trees --- proto/haskell_term.proto | 782 ++++++++++++++++++++++++++++ proto/markdown_term.proto | 127 +++++ proto/php_term.proto | 721 +++++++++++++++++++++++++ proto/terms.proto | 16 +- src/Data/Proto/ParseTree.hs | 46 +- src/Language/Haskell/Assignment.hs | 35 +- src/Language/Haskell/Syntax.hs | 378 +++++++------- src/Language/Markdown/Assignment.hs | 21 +- src/Language/Markdown/Syntax.hs | 100 ++-- src/Language/PHP/Assignment.hs | 28 +- src/Language/PHP/Syntax.hs | 213 ++++---- 11 files changed, 2087 insertions(+), 380 deletions(-) create mode 100644 proto/haskell_term.proto create mode 100644 proto/markdown_term.proto create mode 100644 proto/php_term.proto diff --git a/proto/haskell_term.proto b/proto/haskell_term.proto new file mode 100644 index 000000000..3871c305f --- /dev/null +++ b/proto/haskell_term.proto @@ -0,0 +1,782 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.haskellterm; + +import "types.proto"; + +option java_package = "com.github.semantic.haskellterm"; +option go_package = "github.com/semantic/haskellterm;haskell"; + +message HaskellTerm { + HaskellSyntax syntax = 1; +} + +message HaskellSyntax { + oneof syntax { + Comment comment = 1; + Constructor constructor = 2; + Datatype datatype = 3; + Function function = 4; + Array array = 5; + Character character = 6; + Float float = 7; + Integer integer = 8; + TextElement textElement = 9; + Tuple tuple = 10; + If if = 11; + Match match = 12; + Pattern pattern = 13; + AllConstructors allConstructors = 14; + AnnotatedTypeVariable annotatedTypeVariable = 15; + App app = 16; + ArithmeticSequence arithmeticSequence = 17; + AsPattern asPattern = 18; + BindPattern bindPattern = 19; + CaseGuardPattern caseGuardPattern = 20; + Class class = 21; + ConstructorIdentifier constructorIdentifier = 22; + ConstructorOperator constructorOperator = 23; + ConstructorPattern constructorPattern = 24; + ConstructorSymbol constructorSymbol = 25; + Context context = 26; + ContextAlt contextAlt = 27; + CPPDirective cPPDirective = 28; + DefaultDeclaration defaultDeclaration = 29; + DefaultSignature defaultSignature = 30; + Deriving deriving = 31; + Do do = 32; + Empty empty = 33; + Error error = 34; + EqualityConstraint equalityConstraint = 35; + Export export = 36; + ExpressionTypeSignature expressionTypeSignature = 37; + Field field = 38; + FieldBind fieldBind = 39; + FieldPattern fieldPattern = 40; + FixityAlt fixityAlt = 41; + FunctionalDependency functionalDependency = 42; + FunctionConstructor functionConstructor = 43; + FunctionGuardPattern functionGuardPattern = 44; + FunctionType functionType = 45; + GADT gADT = 46; + GADTConstructor gADTConstructor = 47; + Generator generator = 48; + Guard guard = 49; + HiddenImport hiddenImport = 50; + Identifier identifier = 51; + InfixConstructorIdentifier infixConstructorIdentifier = 52; + InfixOperatorApp infixOperatorApp = 53; + InfixVariableIdentifier infixVariableIdentifier = 54; + ImplicitParameterIdentifier implicitParameterIdentifier = 55; + Import import = 56; + ImportAlias importAlias = 57; + ImportDeclaration importDeclaration = 58; + InfixDataConstructor infixDataConstructor = 59; + InfixOperatorPattern infixOperatorPattern = 60; + Instance instance = 61; + IrrefutablePattern irrefutablePattern = 62; + Kind kind = 63; + KindFunctionType kindFunctionType = 64; + KindListType kindListType = 65; + KindParenthesizedConstructor kindParenthesizedConstructor = 66; + KindSignature kindSignature = 67; + KindTupleType kindTupleType = 68; + LabeledConstruction labeledConstruction = 69; + LabeledPattern labeledPattern = 70; + LabeledUpdate labeledUpdate = 71; + Lambda lambda = 72; + LambdaCase lambdaCase = 73; + LeftOperatorSection leftOperatorSection = 74; + Let let = 75; + ListComprehension listComprehension = 76; + ListConstructor listConstructor = 77; + ListPattern listPattern = 78; + Module module = 79; + ModuleExport moduleExport = 80; + ModuleIdentifier moduleIdentifier = 81; + NamedFieldPun namedFieldPun = 82; + NegativeLiteral negativeLiteral = 83; + NewType newType = 84; + PatternGuard patternGuard = 85; + Pragma pragma = 86; + PrefixNegation prefixNegation = 87; + PrimitiveConstructorIdentifier primitiveConstructorIdentifier = 88; + PrimitiveVariableIdentifier primitiveVariableIdentifier = 89; + PromotedTypeOperator promotedTypeOperator = 90; + QualifiedConstructorIdentifier qualifiedConstructorIdentifier = 91; + QualifiedInfixVariableIdentifier qualifiedInfixVariableIdentifier = 92; + QualifiedModuleIdentifier qualifiedModuleIdentifier = 93; + QualifiedImportDeclaration qualifiedImportDeclaration = 94; + QualifiedTypeClassIdentifier qualifiedTypeClassIdentifier = 95; + QualifiedTypeConstructorIdentifier qualifiedTypeConstructorIdentifier = 96; + QualifiedVariableIdentifier qualifiedVariableIdentifier = 97; + QuasiQuotation quasiQuotation = 98; + QuasiQuotationDeclaration quasiQuotationDeclaration = 99; + QuasiQuotationExpression quasiQuotationExpression = 100; + QuasiQuotationExpressionBody quasiQuotationExpressionBody = 101; + QuasiQuotationPattern quasiQuotationPattern = 102; + QuasiQuotationQuoter quasiQuotationQuoter = 103; + QuasiQuotationType quasiQuotationType = 104; + QuotedName quotedName = 105; + RecordDataConstructor recordDataConstructor = 106; + RecordWildCards recordWildCards = 107; + RightOperatorSection rightOperatorSection = 108; + ScopedTypeVariables scopedTypeVariables = 109; + Splice splice = 110; + StandaloneDerivingInstance standaloneDerivingInstance = 111; + Star star = 112; + StrictPattern strictPattern = 113; + StrictType strictType = 114; + StrictTypeVariable strictTypeVariable = 115; + TupleConstructor tupleConstructor = 116; + TupleExpression tupleExpression = 117; + TuplePattern tuplePattern = 118; + Type type = 119; + TypeApp typeApp = 120; + TypeClass typeClass = 121; + TypeClassIdentifier typeClassIdentifier = 122; + TypeClassInstance typeClassInstance = 123; + TypeConstructorExport typeConstructorExport = 124; + TypeConstructorIdentifier typeConstructorIdentifier = 125; + TypeFamily typeFamily = 126; + TypeInstance typeInstance = 127; + TypeOperator typeOperator = 128; + TypePattern typePattern = 129; + TypeSignature typeSignature = 130; + TypeSynonym typeSynonym = 131; + TypeVariableIdentifier typeVariableIdentifier = 132; + UnitConstructor unitConstructor = 133; + VariableIdentifier variableIdentifier = 134; + VariableOperator variableOperator = 135; + VariableSymbol variableSymbol = 136; + ViewPattern viewPattern = 137; + Wildcard wildcard = 138; + TypeParameters typeParameters = 139; + List list = 140; + } +} + +message Comment { + string commentContent = 1; +} + +message Constructor { + repeated HaskellTerm constructorContext = 1; + HaskellTerm constructorName = 2; + HaskellTerm constructorFields = 3; +} + +message Datatype { + HaskellTerm datatypeContext = 1; + HaskellTerm datatypeName = 2; + repeated HaskellTerm datatypeConstructors = 3; + HaskellTerm datatypeDeriving = 4; +} + +message Function { + repeated HaskellTerm functionContext = 1; + HaskellTerm functionName = 2; + repeated HaskellTerm functionParameters = 3; + HaskellTerm functionBody = 4; +} + +message Array { + repeated HaskellTerm arrayElements = 1; +} + +message Character { + string characterContent = 1; +} + +message Float { + string floatContent = 1; +} + +message Integer { + string integerContent = 1; +} + +message TextElement { + string textElementContent = 1; +} + +message Tuple { + repeated HaskellTerm tupleContents = 1; +} + +message If { + HaskellTerm ifCondition = 1; + HaskellTerm ifThenBody = 2; + HaskellTerm ifElseBody = 3; +} + +message Match { + HaskellTerm matchSubject = 1; + HaskellTerm matchPatterns = 2; +} + +message Pattern { + HaskellTerm value = 1; + HaskellTerm patternBody = 2; +} + +message AllConstructors { } + +message AnnotatedTypeVariable { + HaskellTerm annotatedTypeVariableIdentifier = 1; + HaskellTerm annotatedTypeVariableannotation = 2; +} + +message App { + HaskellTerm appLeft = 1; + HaskellTerm appLeftTypeApp = 2; + HaskellTerm appRight = 3; +} + +message ArithmeticSequence { + HaskellTerm from = 1; + repeated HaskellTerm next = 2; + repeated HaskellTerm to = 3; +} + +message AsPattern { + HaskellTerm asPatternLeft = 1; + HaskellTerm asPatternRight = 2; +} + +message BindPattern { + repeated HaskellTerm bindPatternLeft = 1; + HaskellTerm bindPatternRight = 2; +} + +message CaseGuardPattern { + repeated HaskellTerm values = 1; +} + +message Class { + repeated HaskellTerm classContent = 1; +} + +message ConstructorIdentifier { + bytes name = 1; +} + +message ConstructorOperator { + HaskellTerm value = 1; +} + +message ConstructorPattern { + HaskellTerm value = 1; +} + +message ConstructorSymbol { + bytes constructorSymbolName = 1; +} + +message Context { + repeated HaskellTerm contextTerms = 1; + HaskellTerm contextSubject = 2; +} + +message ContextAlt { + HaskellTerm value = 1; +} + +message CPPDirective { + string value = 1; +} + +message DefaultDeclaration { + repeated HaskellTerm defaultDeclarationContent = 1; +} + +message DefaultSignature { + repeated HaskellTerm defaultSignatureName = 1; + repeated HaskellTerm defaultSignatureContext = 2; + HaskellTerm defaultSignatureContent = 3; +} + +message Deriving { + repeated HaskellTerm values = 1; +} + +message Do { + repeated HaskellTerm values = 1; +} + +message Empty { } + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated HaskellTerm errorChildren = 4; +} + +message EqualityConstraint { + HaskellTerm equalityConstraintLeft = 1; + HaskellTerm equalityConstraintRight = 2; +} + +message Export { + HaskellTerm exportContent = 1; +} + +message ExpressionTypeSignature { + repeated HaskellTerm expressionTypeSignatureName = 1; + repeated HaskellTerm expressionTypeSignatureContext = 2; + HaskellTerm expressionTypeSignatureContent = 3; +} + +message Field { + HaskellTerm fieldName = 1; + HaskellTerm fieldBody = 2; +} + +message FieldBind { + HaskellTerm fieldBindLeft = 1; + HaskellTerm fieldBindRight = 2; +} + +message FieldPattern { + HaskellTerm fieldPatternLeft = 1; + HaskellTerm fieldPatternRight = 2; +} + +message FixityAlt { + HaskellTerm fixityPrecedence = 1; + repeated HaskellTerm fixityIdentifier = 2; +} + +message FunctionalDependency { + HaskellTerm functionalDependencyContent = 1; +} + +message FunctionConstructor { } + +message FunctionGuardPattern { + repeated HaskellTerm values = 1; +} + +message FunctionType { + HaskellTerm functionTypeLeft = 1; + HaskellTerm functionTypeRight = 2; +} + +message GADT { + HaskellTerm gadtContext = 1; + HaskellTerm gadtName = 2; + HaskellTerm gadtConstructors = 3; +} + +message GADTConstructor { + HaskellTerm gadtConstructorContext = 1; + HaskellTerm gadtConstructorName = 2; + HaskellTerm gadtConstructorTypeSignature = 3; +} + +message Generator { + HaskellTerm generatorValue = 1; + HaskellTerm generatorSource = 2; +} + +message Guard { + HaskellTerm value = 1; +} + +message HiddenImport { + HaskellTerm hiddenimportContent = 1; +} + +message Identifier { + bytes name = 1; +} + +message InfixConstructorIdentifier { + bytes name = 1; +} + +message InfixOperatorApp { + HaskellTerm infixOperatorAppLeft = 1; + HaskellTerm infixOperatorAppLeftTypeApp = 2; + HaskellTerm infixOperatorAppOperator = 3; + HaskellTerm infixOperatorAppRight = 4; +} + +message InfixVariableIdentifier { + bytes name = 1; +} + +message ImplicitParameterIdentifier { + bytes name = 1; +} + +message Import { + HaskellTerm importContent = 1; +} + +message ImportAlias { + HaskellTerm importAliasSource = 1; + HaskellTerm importAliasName = 2; +} + +message ImportDeclaration { + HaskellTerm importPackageQualifiedContent = 1; + HaskellTerm importModule = 2; + repeated HaskellTerm importSpec = 3; +} + +message InfixDataConstructor { + repeated HaskellTerm infixDataConstructorContext = 1; + HaskellTerm infixDataConstructorLeft = 2; + HaskellTerm infixDataConstructorOperator = 3; + HaskellTerm infixDataConstructorRight = 4; +} + +message InfixOperatorPattern { + HaskellTerm infixOperatorPatternLeft = 1; + HaskellTerm infixOperatorPatternOperator = 2; + HaskellTerm infixOperatorPatternRight = 3; +} + +message Instance { + HaskellTerm value = 1; +} + +message IrrefutablePattern { + HaskellTerm value = 1; +} + +message Kind { + HaskellTerm kindKind = 1; +} + +message KindFunctionType { + HaskellTerm kindFunctionTypeLeft = 1; + HaskellTerm kindFunctionTypeRight = 2; +} + +message KindListType { + HaskellTerm kindListTypeKind = 1; +} + +message KindParenthesizedConstructor { + HaskellTerm kindParenthesizedConstructorContent = 1; +} + +message KindSignature { + HaskellTerm kindSignatureContent = 1; +} + +message KindTupleType { + repeated HaskellTerm kindTupleType = 1; +} + +message LabeledConstruction { + HaskellTerm labeledConstructionConstructor = 1; + repeated HaskellTerm labeledConstructionFields = 2; +} + +message LabeledPattern { + HaskellTerm value = 1; +} + +message LabeledUpdate { + repeated HaskellTerm values = 1; +} + +message Lambda { + HaskellTerm lambdaHead = 1; + HaskellTerm lambdaBody = 2; +} + +message LambdaCase { + repeated HaskellTerm values = 1; +} + +message LeftOperatorSection { + HaskellTerm lhs = 1; + HaskellTerm rhs = 2; +} + +message Let { + repeated HaskellTerm letStatements = 1; + HaskellTerm letInClause = 2; +} + +message ListComprehension { + HaskellTerm comprehensionValue = 1; + repeated HaskellTerm comprehensionSource = 2; +} + +message ListConstructor { } + +message ListPattern { + HaskellTerm value = 1; +} + +message Module { + repeated HaskellTerm moduleContext = 1; + HaskellTerm moduleIdentifier = 2; + repeated HaskellTerm moduleExports = 3; + HaskellTerm moduleStatements = 4; +} + +message ModuleExport { + HaskellTerm moduleExportContent = 1; +} + +message ModuleIdentifier { + bytes name = 1; +} + +message NamedFieldPun { + HaskellTerm value = 1; +} + +message NegativeLiteral { + HaskellTerm value = 1; +} + +message NewType { + repeated HaskellTerm newTypeContext = 1; + HaskellTerm newTypeLeft = 2; + HaskellTerm newTypeRight = 3; + HaskellTerm newTypeDeriving = 4; +} + +message PatternGuard { + HaskellTerm patternGuardPattern = 1; + HaskellTerm patternGuardExpression = 2; +} + +message Pragma { + string value = 1; +} + +message PrefixNegation { + HaskellTerm value = 1; +} + +message PrimitiveConstructorIdentifier { + bytes name = 1; +} + +message PrimitiveVariableIdentifier { + bytes name = 1; +} + +message PromotedTypeOperator { + HaskellTerm value = 1; +} + +message QualifiedConstructorIdentifier { + repeated HaskellTerm values = 1; +} + +message QualifiedInfixVariableIdentifier { + repeated HaskellTerm values = 1; +} + +message QualifiedModuleIdentifier { + repeated HaskellTerm values = 1; +} + +message QualifiedImportDeclaration { + HaskellTerm qualifiedImportPackageQualifiedContent = 1; + HaskellTerm qualifiedImportModule = 2; + repeated HaskellTerm qualifiedImportSpec = 3; +} + +message QualifiedTypeClassIdentifier { + repeated HaskellTerm values = 1; +} + +message QualifiedTypeConstructorIdentifier { + repeated HaskellTerm values = 1; +} + +message QualifiedVariableIdentifier { + repeated HaskellTerm values = 1; +} + +message QuasiQuotation { + HaskellTerm quasiQuotationHead = 1; + HaskellTerm quasiQuotationBody = 2; +} + +message QuasiQuotationDeclaration { } + +message QuasiQuotationExpression { } + +message QuasiQuotationExpressionBody { + bytes name = 1; +} + +message QuasiQuotationPattern { } + +message QuasiQuotationQuoter { + bytes name = 1; +} + +message QuasiQuotationType { } + +message QuotedName { + HaskellTerm quotedNameContent = 1; +} + +message RecordDataConstructor { + repeated HaskellTerm recordDataConstructorContext = 1; + HaskellTerm recordDataConstructorName = 2; + HaskellTerm recordDataConstructorFields = 3; +} + +message RecordWildCards { } + +message RightOperatorSection { + HaskellTerm lhs = 1; + HaskellTerm rhs = 2; +} + +message ScopedTypeVariables { + HaskellTerm scopedTypeVariablesContent = 1; +} + +message Splice { + HaskellTerm value = 1; +} + +message StandaloneDerivingInstance { + repeated HaskellTerm standaloneDerivingInstanceContext = 1; + HaskellTerm standaloneDerivingInstanceClass = 2; + HaskellTerm standaloneDerivingInstanceInstance = 3; +} + +message Star { } + +message StrictPattern { + HaskellTerm value = 1; +} + +message StrictType { + HaskellTerm strictTypeIdentifier = 1; + HaskellTerm strictTypeParameters = 2; +} + +message StrictTypeVariable { + HaskellTerm value = 1; +} + +message TupleConstructor { + int64 tupleConstructorArity = 1; +} + +message TupleExpression { + repeated HaskellTerm values = 1; +} + +message TuplePattern { + repeated HaskellTerm value = 1; +} + +message Type { + HaskellTerm typeIdentifier = 1; + HaskellTerm typeParameters = 2; + HaskellTerm typeKindSignature = 3; +} + +message TypeApp { + HaskellTerm typeAppType = 1; +} + +message TypeClass { + HaskellTerm typeClassContext = 1; + HaskellTerm typeClassIdentifier = 2; + repeated HaskellTerm typeClassParameters = 3; + HaskellTerm typeClassBody = 4; +} + +message TypeClassIdentifier { + bytes name = 1; +} + +message TypeClassInstance { + repeated HaskellTerm typeClassInstanceContext = 1; + HaskellTerm typeClassInstanceIdentifier = 2; + HaskellTerm typeClassInstanceInstance = 3; + HaskellTerm typeClassInstanceBody = 4; +} + +message TypeConstructorExport { + HaskellTerm typeConstructorExportContent = 1; +} + +message TypeConstructorIdentifier { + bytes name = 1; +} + +message TypeFamily { + HaskellTerm typeFamilyIdentifier = 1; + repeated HaskellTerm typeFamilyParameters = 2; + HaskellTerm typeFamilySignature = 3; + HaskellTerm typeFamilyBody = 4; +} + +message TypeInstance { + HaskellTerm typeInstanceType = 1; + HaskellTerm typeInstanceBody = 2; +} + +message TypeOperator { + bytes name = 1; +} + +message TypePattern { + HaskellTerm typePatternContent = 1; +} + +message TypeSignature { + repeated HaskellTerm typeSignatureName = 1; + repeated HaskellTerm typeSignatureContext = 2; + HaskellTerm typeSignatureContent = 3; +} + +message TypeSynonym { + HaskellTerm typeSynonymLeft = 1; + repeated HaskellTerm typeSynonymContext = 2; + HaskellTerm typeSynonymRight = 3; +} + +message TypeVariableIdentifier { + bytes name = 1; +} + +message UnitConstructor { } + +message VariableIdentifier { + bytes name = 1; +} + +message VariableOperator { + HaskellTerm value = 1; +} + +message VariableSymbol { + bytes variableSymbolName = 1; +} + +message ViewPattern { + HaskellTerm viewPatternLeft = 1; + HaskellTerm viewPatternRight = 2; +} + +message Wildcard { } + +message TypeParameters { + repeated HaskellTerm terms = 1; +} + +message List { + repeated HaskellTerm listContent = 1; +} diff --git a/proto/markdown_term.proto b/proto/markdown_term.proto new file mode 100644 index 000000000..4ee6bcb9f --- /dev/null +++ b/proto/markdown_term.proto @@ -0,0 +1,127 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.markdownterm; + +import "types.proto"; + +option java_package = "com.github.semantic.markdownterm"; +option go_package = "github.com/semantic/markdownterm;markdown"; + +message MarkdownTerm { + MarkdownSyntax syntax = 1; +} + +message MarkdownSyntax { + oneof syntax { + Document document = 1; + BlockQuote blockQuote = 2; + Heading heading = 3; + HTMLBlock hTMLBlock = 4; + OrderedList orderedList = 5; + Paragraph paragraph = 6; + ThematicBreak thematicBreak = 7; + UnorderedList unorderedList = 8; + Table table = 9; + TableRow tableRow = 10; + TableCell tableCell = 11; + Code code = 12; + Emphasis emphasis = 13; + Image image = 14; + LineBreak lineBreak = 15; + Link link = 16; + Strong strong = 17; + Text text = 18; + Strikethrough strikethrough = 19; + Error error = 20; + List list = 21; + } +} + +message Document { + repeated MarkdownTerm values = 1; +} + +message BlockQuote { + repeated MarkdownTerm values = 1; +} + +message Heading { + int64 headingLevel = 1; + repeated MarkdownTerm headingContent = 2; + repeated MarkdownTerm sectionContent = 3; +} + +message HTMLBlock { + string value = 1; +} + +message OrderedList { + repeated MarkdownTerm values = 1; +} + +message Paragraph { + repeated MarkdownTerm values = 1; +} + +message ThematicBreak { } + +message UnorderedList { + repeated MarkdownTerm values = 1; +} + +message Table { + repeated MarkdownTerm values = 1; +} + +message TableRow { + repeated MarkdownTerm values = 1; +} + +message TableCell { + repeated MarkdownTerm values = 1; +} + +message Code { + string codeLanguage = 1; + string codeContent = 2; +} + +message Emphasis { + repeated MarkdownTerm values = 1; +} + +message Image { + string imageURL = 1; + string imageTitle = 2; +} + +message LineBreak { } + +message Link { + string linkUrl = 1; + string linkTitle = 2; +} + +message Strong { + repeated MarkdownTerm values = 1; +} + +message Text { + string value = 1; +} + +message Strikethrough { + repeated MarkdownTerm values = 1; +} + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated MarkdownTerm errorChildren = 4; +} + +message List { + repeated MarkdownTerm listContent = 1; +} diff --git a/proto/php_term.proto b/proto/php_term.proto new file mode 100644 index 000000000..80b1d4b60 --- /dev/null +++ b/proto/php_term.proto @@ -0,0 +1,721 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.phpterm; + +import "types.proto"; + +option java_package = "com.github.semantic.phpterm"; +option go_package = "github.com/semantic/phpterm;php"; + +message PHPTerm { + PHPSyntax syntax = 1; +} + +message PHPSyntax { + oneof syntax { + Comment comment = 1; + Class class = 2; + Function function = 3; + Method method = 4; + VariableDeclaration variableDeclaration = 5; + Plus plus = 6; + Minus minus = 7; + Times times = 8; + DividedBy dividedBy = 9; + Modulo modulo = 10; + Power power = 11; + Negate negate = 12; + FloorDivision floorDivision = 13; + BAnd bAnd = 14; + BOr bOr = 15; + BXOr bXOr = 16; + LShift lShift = 17; + RShift rShift = 18; + And and = 19; + Not not = 20; + Or or = 21; + XOr xOr = 22; + Call call = 23; + Cast cast = 24; + LessThan lessThan = 25; + LessThanEqual lessThanEqual = 26; + GreaterThan greaterThan = 27; + GreaterThanEqual greaterThanEqual = 28; + Equal equal = 29; + StrictEqual strictEqual = 30; + Comparison comparison = 31; + InstanceOf instanceOf = 32; + MemberAccess memberAccess = 33; + New new = 34; + SequenceExpression sequenceExpression = 35; + Subscript subscript = 36; + Member member = 37; + Array array = 38; + Float float = 39; + Integer integer = 40; + KeyValue keyValue = 41; + TextElement textElement = 42; + Assignment assignment = 43; + Break break = 44; + Catch catch = 45; + Continue continue = 46; + DoWhile doWhile = 47; + Else else = 48; + Finally finally = 49; + For for = 50; + ForEach forEach = 51; + Goto goto = 52; + If if = 53; + Match match = 54; + Pattern pattern = 55; + Return return = 56; + Statements statements = 57; + Throw throw = 58; + Try try = 59; + While while = 60; + Yield yield = 61; + AliasAs aliasAs = 62; + ArrayElement arrayElement = 63; + BaseTypeDeclaration baseTypeDeclaration = 64; + CastType castType = 65; + ClassBaseClause classBaseClause = 66; + ClassConstDeclaration classConstDeclaration = 67; + ClassInterfaceClause classInterfaceClause = 68; + ClassModifier classModifier = 69; + Clone clone = 70; + ConstDeclaration constDeclaration = 71; + ConstructorDeclaration constructorDeclaration = 72; + Context context = 73; + Declare declare = 74; + DeclareDirective declareDirective = 75; + DestructorDeclaration destructorDeclaration = 76; + Echo echo = 77; + Empty empty = 78; + EmptyIntrinsic emptyIntrinsic = 79; + Error error = 80; + ErrorControl errorControl = 81; + EvalIntrinsic evalIntrinsic = 82; + ExitIntrinsic exitIntrinsic = 83; + GlobalDeclaration globalDeclaration = 84; + Identifier identifier = 85; + Include include = 86; + IncludeOnce includeOnce = 87; + InsteadOf insteadOf = 88; + InterfaceBaseClause interfaceBaseClause = 89; + InterfaceDeclaration interfaceDeclaration = 90; + IssetIntrinsic issetIntrinsic = 91; + LabeledStatement labeledStatement = 92; + Namespace namespace = 93; + NamespaceAliasingClause namespaceAliasingClause = 94; + NamespaceName namespaceName = 95; + NamespaceUseClause namespaceUseClause = 96; + NamespaceUseDeclaration namespaceUseDeclaration = 97; + NamespaceUseGroupClause namespaceUseGroupClause = 98; + NewVariable newVariable = 99; + PrintIntrinsic printIntrinsic = 100; + PropertyDeclaration propertyDeclaration = 101; + PropertyModifier propertyModifier = 102; + QualifiedName qualifiedName = 103; + RelativeScope relativeScope = 104; + Require require = 105; + RequireOnce requireOnce = 106; + ReturnType returnType = 107; + ScalarType scalarType = 108; + ShellCommand shellCommand = 109; + SimpleVariable simpleVariable = 110; + Static static = 111; + Text text = 112; + TraitDeclaration traitDeclaration = 113; + TraitUseClause traitUseClause = 114; + TraitUseSpecification traitUseSpecification = 115; + TypeDeclaration typeDeclaration = 116; + Unset unset = 117; + Update update = 118; + UseClause useClause = 119; + VariableName variableName = 120; + Annotation annotation = 121; + List list = 122; + } +} + +message Comment { + string commentContent = 1; +} + +message Class { + repeated PHPTerm classContext = 1; + PHPTerm classIdentifier = 2; + repeated PHPTerm classSuperclasses = 3; + PHPTerm classBody = 4; +} + +message Function { + repeated PHPTerm functionContext = 1; + PHPTerm functionName = 2; + repeated PHPTerm functionParameters = 3; + PHPTerm functionBody = 4; +} + +message Method { + repeated PHPTerm methodContext = 1; + PHPTerm methodReceiver = 2; + PHPTerm methodName = 3; + repeated PHPTerm methodParameters = 4; + PHPTerm methodBody = 5; +} + +message VariableDeclaration { + repeated PHPTerm variableDeclarations = 1; +} + +message Plus { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message Minus { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message Times { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message DividedBy { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message Modulo { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message Power { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message Negate { + PHPTerm value = 1; +} + +message FloorDivision { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message BAnd { + PHPTerm left = 1; + PHPTerm right = 2; +} + +message BOr { + PHPTerm left = 1; + PHPTerm right = 2; +} + +message BXOr { + PHPTerm left = 1; + PHPTerm right = 2; +} + +message LShift { + PHPTerm left = 1; + PHPTerm right = 2; +} + +message RShift { + PHPTerm left = 1; + PHPTerm right = 2; +} + +message And { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message Not { + PHPTerm value = 1; +} + +message Or { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message XOr { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message Call { + repeated PHPTerm callContext = 1; + PHPTerm callFunction = 2; + repeated PHPTerm callParams = 3; + PHPTerm callBlock = 4; +} + +message Cast { + PHPTerm castSubject = 1; + PHPTerm castType = 2; +} + +message LessThan { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message LessThanEqual { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message GreaterThan { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message GreaterThanEqual { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message Equal { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message StrictEqual { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message Comparison { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message InstanceOf { + PHPTerm instanceOfSubject = 1; + PHPTerm instanceOfObject = 2; +} + +message MemberAccess { + PHPTerm lhs = 1; + bytes rhs = 2; +} + +message New { + repeated PHPTerm newSubject = 1; +} + +message SequenceExpression { + PHPTerm firstExpression = 1; + PHPTerm secondExpression = 2; +} + +message Subscript { + PHPTerm lhs = 1; + repeated PHPTerm rhs = 2; +} + +message Member { + PHPTerm lhs = 1; + PHPTerm rhs = 2; +} + +message Array { + repeated PHPTerm arrayElements = 1; +} + +message Float { + string floatContent = 1; +} + +message Integer { + string integerContent = 1; +} + +message KeyValue { + PHPTerm key = 1; + PHPTerm value = 2; +} + +message TextElement { + string textElementContent = 1; +} + +message Assignment { + repeated PHPTerm assignmentContext = 1; + PHPTerm assignmentTarget = 2; + PHPTerm assignmentValue = 3; +} + +message Break { + PHPTerm value = 1; +} + +message Catch { + PHPTerm catchException = 1; + PHPTerm catchBody = 2; +} + +message Continue { + PHPTerm value = 1; +} + +message DoWhile { + PHPTerm doWhileCondition = 1; + PHPTerm doWhileBody = 2; +} + +message Else { + PHPTerm elseCondition = 1; + PHPTerm elseBody = 2; +} + +message Finally { + PHPTerm value = 1; +} + +message For { + PHPTerm forBefore = 1; + PHPTerm forCondition = 2; + PHPTerm forStep = 3; + PHPTerm forBody = 4; +} + +message ForEach { + PHPTerm forEachBinding = 1; + PHPTerm forEachSubject = 2; + PHPTerm forEachBody = 3; +} + +message Goto { + PHPTerm gotoLocation = 1; +} + +message If { + PHPTerm ifCondition = 1; + PHPTerm ifThenBody = 2; + PHPTerm ifElseBody = 3; +} + +message Match { + PHPTerm matchSubject = 1; + PHPTerm matchPatterns = 2; +} + +message Pattern { + PHPTerm value = 1; + PHPTerm patternBody = 2; +} + +message Return { + PHPTerm value = 1; +} + +message Statements { + repeated PHPTerm statements = 1; +} + +message Throw { + PHPTerm value = 1; +} + +message Try { + PHPTerm tryBody = 1; + repeated PHPTerm tryCatch = 2; +} + +message While { + PHPTerm whileCondition = 1; + PHPTerm whileBody = 2; +} + +message Yield { + PHPTerm value = 1; +} + +message AliasAs { + PHPTerm aliasAsName = 1; + PHPTerm aliasAsModifier = 2; + PHPTerm aliasAsClause = 3; +} + +message ArrayElement { + PHPTerm value = 1; +} + +message BaseTypeDeclaration { + PHPTerm value = 1; +} + +message CastType { + string _castType = 1; +} + +message ClassBaseClause { + PHPTerm value = 1; +} + +message ClassConstDeclaration { + PHPTerm visibility = 1; + repeated PHPTerm elements = 2; +} + +message ClassInterfaceClause { + repeated PHPTerm values = 1; +} + +message ClassModifier { + string value = 1; +} + +message Clone { + PHPTerm value = 1; +} + +message ConstDeclaration { + repeated PHPTerm values = 1; +} + +message ConstructorDeclaration { + repeated PHPTerm modifiers = 1; + repeated PHPTerm parameters = 2; + PHPTerm body = 3; +} + +message Context { + repeated PHPTerm contextTerms = 1; + PHPTerm contextSubject = 2; +} + +message Declare { + PHPTerm left = 1; + PHPTerm right = 2; +} + +message DeclareDirective { + PHPTerm value = 1; +} + +message DestructorDeclaration { + repeated PHPTerm body = 1; + PHPTerm name = 2; +} + +message Echo { + PHPTerm value = 1; +} + +message Empty { } + +message EmptyIntrinsic { + PHPTerm value = 1; +} + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated PHPTerm errorChildren = 4; +} + +message ErrorControl { + PHPTerm value = 1; +} + +message EvalIntrinsic { + PHPTerm value = 1; +} + +message ExitIntrinsic { + PHPTerm value = 1; +} + +message GlobalDeclaration { + repeated PHPTerm values = 1; +} + +message Identifier { + bytes name = 1; +} + +message Include { + PHPTerm value = 1; +} + +message IncludeOnce { + PHPTerm value = 1; +} + +message InsteadOf { + PHPTerm left = 1; + PHPTerm right = 2; +} + +message InterfaceBaseClause { + repeated PHPTerm values = 1; +} + +message InterfaceDeclaration { + PHPTerm name = 1; + PHPTerm base = 2; + repeated PHPTerm declarations = 3; +} + +message IssetIntrinsic { + PHPTerm value = 1; +} + +message LabeledStatement { + PHPTerm _labeledStatementIdentifier = 1; +} + +message Namespace { + repeated PHPTerm namespaceName = 1; + PHPTerm namespaceBody = 2; +} + +message NamespaceAliasingClause { + PHPTerm value = 1; +} + +message NamespaceName { + repeated PHPTerm names = 1; +} + +message NamespaceUseClause { + repeated PHPTerm values = 1; +} + +message NamespaceUseDeclaration { + repeated PHPTerm values = 1; +} + +message NamespaceUseGroupClause { + repeated PHPTerm values = 1; +} + +message NewVariable { + repeated PHPTerm values = 1; +} + +message PrintIntrinsic { + PHPTerm value = 1; +} + +message PropertyDeclaration { + PHPTerm modifier = 1; + repeated PHPTerm elements = 2; +} + +message PropertyModifier { + PHPTerm visibility = 1; + PHPTerm static = 2; +} + +message QualifiedName { + PHPTerm name = 1; + PHPTerm identifier = 2; +} + +message RelativeScope { + string value = 1; +} + +message Require { + PHPTerm value = 1; +} + +message RequireOnce { + PHPTerm value = 1; +} + +message ReturnType { + PHPTerm value = 1; +} + +message ScalarType { + string value = 1; +} + +message ShellCommand { + string value = 1; +} + +message SimpleVariable { + PHPTerm value = 1; +} + +message Static { + string value = 1; +} + +message Text { + string value = 1; +} + +message TraitDeclaration { + PHPTerm traitName = 1; + repeated PHPTerm traitStatements = 2; +} + +message TraitUseClause { + repeated PHPTerm namespace = 1; + PHPTerm alias = 2; +} + +message TraitUseSpecification { + repeated PHPTerm values = 1; +} + +message TypeDeclaration { + PHPTerm value = 1; +} + +message Unset { + PHPTerm value = 1; +} + +message Update { + PHPTerm _updateSubject = 1; +} + +message UseClause { + repeated PHPTerm values = 1; +} + +message VariableName { + PHPTerm value = 1; +} + +message Annotation { + PHPTerm annotationSubject = 1; + PHPTerm annotationType = 2; +} + +message List { + repeated PHPTerm listContent = 1; +} + +message Alias { + bytes aliasValue = 1; + bytes aliasName = 2; +} + +message ImportPath { + string unPath = 1; + IsRelative pathIsRelative = 2; +} + +enum IsRelative { + Unknown = 0; + Relative = 1; + NonRelative = 2; +} diff --git a/proto/terms.proto b/proto/terms.proto index fa82aadee..b13b0e7f1 100644 --- a/proto/terms.proto +++ b/proto/terms.proto @@ -4,11 +4,14 @@ syntax = "proto3"; package github.semantic; import "go_term.proto"; +import "haskell_term.proto"; import "java_term.proto"; import "json_term.proto"; +import "markdown_term.proto"; import "python_term.proto"; import "ruby_term.proto"; import "typescript_term.proto"; +import "php_term.proto"; import "types.proto"; option java_package = "com.github.semantic.terms"; @@ -20,10 +23,13 @@ message ParseTree { string error = 3; oneof response_type { goterm.GoTerm go_tree = 4; - javaterm.JavaTerm java_tree = 5; - jsonterm.JSONTerm json_tree = 6; - pythonterm.PythonTerm python_tree = 7; - rubyterm.RubyTerm ruby_tree = 8; - typescriptterm.TypeScriptTerm typescript_tree = 9; + haskellterm.HaskellTerm haskell_tree = 5; + javaterm.JavaTerm java_tree = 6; + jsonterm.JSONTerm json_tree = 7; + markdownterm.MarkdownTerm markdown_tree = 8; + pythonterm.PythonTerm python_tree = 9; + rubyterm.RubyTerm ruby_tree = 10; + typescriptterm.TypeScriptTerm typescript_tree = 11; + phpterm.PHPTerm php_tree = 12; } } diff --git a/src/Data/Proto/ParseTree.hs b/src/Data/Proto/ParseTree.hs index 7e0580e2c..3b8f94193 100644 --- a/src/Data/Proto/ParseTree.hs +++ b/src/Data/Proto/ParseTree.hs @@ -2,30 +2,37 @@ module Data.Proto.ParseTree (ParseTree(..), ResponseType(..)) where import Prologue -import Data.Language -import Data.Term + +import Data.Language +import Data.Term import qualified Language.Go.Assignment as Go +import qualified Language.Haskell.Assignment as Haskell import qualified Language.Java.Assignment as Java import qualified Language.JSON.Assignment as JSON +import qualified Language.Markdown.Assignment as Markdown +import qualified Language.PHP.Assignment as PHP import qualified Language.Python.Assignment as Python import qualified Language.Ruby.Assignment as Ruby import qualified Language.TypeScript.Assignment as TypeScript -import Proto3.Suite -import qualified Proto3.Wire.Encode as Encode +import Proto3.Suite import qualified Proto3.Suite as PB +import qualified Proto3.Wire.Encode as Encode type GoTerm = Term (Sum Go.Syntax) () +type HaskellTerm = Term (Sum Haskell.Syntax) () type JavaTerm = Term (Sum Java.Syntax) () type JSONTerm = Term (Sum JSON.Syntax) () +type MarkdownTerm = Term (Sum Markdown.Syntax) () type PythonTerm = Term (Sum Python.Syntax) () type RubyTerm = Term (Sum Ruby.Syntax) () type TypeScriptTerm = Term (Sum TypeScript.Syntax) () +type PHPTerm = Term (Sum PHP.Syntax) () data ParseTree = ParseTree { language :: Language , path :: FilePath - , error :: String + , error :: String -- TODO: make parse of oneof error , responseType :: Maybe ResponseType } deriving (Eq, Show, Generic, Named) @@ -36,11 +43,14 @@ instance Message ParseTree where <> encodeMessageField 3 error <> case responseType of Just (GoResponse x) -> Encode.embedded 4 (encodeMessage 1 x) - Just (JavaResponse x) -> Encode.embedded 5 (encodeMessage 1 x) - Just (JSONResponse x) -> Encode.embedded 6 (encodeMessage 1 x) - Just (PythonResponse x) -> Encode.embedded 7 (encodeMessage 1 x) - Just (RubyResponse x) -> Encode.embedded 8 (encodeMessage 1 x) - Just (TypeScriptResponse x) -> Encode.embedded 9 (encodeMessage 1 x) + Just (HaskellResponse x) -> Encode.embedded 5 (encodeMessage 1 x) + Just (JavaResponse x) -> Encode.embedded 6 (encodeMessage 1 x) + Just (JSONResponse x) -> Encode.embedded 7 (encodeMessage 1 x) + Just (MarkdownResponse x) -> Encode.embedded 8 (encodeMessage 1 x) + Just (PythonResponse x) -> Encode.embedded 9 (encodeMessage 1 x) + Just (RubyResponse x) -> Encode.embedded 10 (encodeMessage 1 x) + Just (TypeScriptResponse x) -> Encode.embedded 11 (encodeMessage 1 x) + Just (PHPResponse x) -> Encode.embedded 12 (encodeMessage 1 x) _ -> mempty decodeMessage = undefined dotProto _ = @@ -49,19 +59,25 @@ instance Message ParseTree where , DotProtoMessageField $ DotProtoField 3 (Prim PB.String) (Single "error") [] Nothing , DotProtoMessageOneOf (Single "response_type") [ DotProtoField 4 (Prim . Named $ Dots (Path ["goterm", "GoTerm"])) (Single "go_tree") [] Nothing - , DotProtoField 5 (Prim . Named $ Dots (Path ["javaterm", "JavaTerm"])) (Single "java_tree") [] Nothing - , DotProtoField 6 (Prim . Named $ Dots (Path ["jsonterm", "JSONTerm"])) (Single "json_tree") [] Nothing - , DotProtoField 7 (Prim . Named $ Dots (Path ["pythonterm", "PythonTerm"])) (Single "python_tree") [] Nothing - , DotProtoField 8 (Prim . Named $ Dots (Path ["rubyterm", "RubyTerm"])) (Single "ruby_tree") [] Nothing - , DotProtoField 9 (Prim . Named $ Dots (Path ["typescriptterm", "TypeScriptTerm"])) (Single "typescript_tree") [] Nothing + , DotProtoField 5 (Prim . Named $ Dots (Path ["haskellterm", "HaskellTerm"])) (Single "haskell_tree") [] Nothing + , DotProtoField 6 (Prim . Named $ Dots (Path ["javaterm", "JavaTerm"])) (Single "java_tree") [] Nothing + , DotProtoField 7 (Prim . Named $ Dots (Path ["jsonterm", "JSONTerm"])) (Single "json_tree") [] Nothing + , DotProtoField 8 (Prim . Named $ Dots (Path ["markdownterm", "MarkdownTerm"])) (Single "markdown_tree") [] Nothing + , DotProtoField 9 (Prim . Named $ Dots (Path ["pythonterm", "PythonTerm"])) (Single "python_tree") [] Nothing + , DotProtoField 10 (Prim . Named $ Dots (Path ["rubyterm", "RubyTerm"])) (Single "ruby_tree") [] Nothing + , DotProtoField 11 (Prim . Named $ Dots (Path ["typescriptterm", "TypeScriptTerm"])) (Single "typescript_tree") [] Nothing + , DotProtoField 12 (Prim . Named $ Dots (Path ["phpterm", "PHPTerm"])) (Single "php_tree") [] Nothing ] ] data ResponseType = GoResponse GoTerm + | HaskellResponse HaskellTerm | JavaResponse JavaTerm | JSONResponse JSONTerm + | MarkdownResponse MarkdownTerm | PythonResponse PythonTerm | RubyResponse RubyTerm | TypeScriptResponse TypeScriptTerm + | PHPResponse PHPTerm deriving (Eq, Show) diff --git a/src/Language/Haskell/Assignment.hs b/src/Language/Haskell/Assignment.hs index 3153b30f3..38dded6ca 100644 --- a/src/Language/Haskell/Assignment.hs +++ b/src/Language/Haskell/Assignment.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds, RankNTypes, TypeOperators #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} -- FIXME module Language.Haskell.Assignment ( assignment , Syntax @@ -6,15 +7,16 @@ module Language.Haskell.Assignment , Term ) where -import Assigning.Assignment hiding (Assignment, Error, count) -import Data.ByteString.Char8 (count) -import Data.Record -import Data.Sum -import Data.Syntax (emptyTerm, handleError, parseError, makeTerm, makeTerm1, makeTerm', makeTerm'', contextualize, postContextualize) -import Language.Haskell.Grammar as Grammar +import Prologue + +import Assigning.Assignment hiding (Assignment, Error, count) import qualified Assigning.Assignment as Assignment import qualified Data.Abstract.Name as Name +import Data.ByteString.Char8 (count) import qualified Data.List.NonEmpty as NonEmpty +import Data.Record +import Data.Syntax + (contextualize, emptyTerm, handleError, makeTerm, makeTerm', makeTerm'', makeTerm1, parseError, postContextualize) import qualified Data.Syntax as Syntax import qualified Data.Syntax.Comment as Comment import qualified Data.Syntax.Declaration as Declaration @@ -22,8 +24,10 @@ import qualified Data.Syntax.Literal as Literal import qualified Data.Syntax.Statement as Statement import qualified Data.Syntax.Type as Type import qualified Data.Term as Term +import qualified Data.Diff as Diff +import Language.Haskell.Grammar as Grammar import qualified Language.Haskell.Syntax as Syntax -import Prologue +import Proto3.Suite (Named (..), Named1 (..)) type Syntax = '[ Comment.Comment @@ -52,7 +56,7 @@ type Syntax = '[ , Syntax.ConstructorPattern , Syntax.ConstructorSymbol , Syntax.Context - , Syntax.Context' + , Syntax.ContextAlt , Syntax.CPPDirective , Syntax.DefaultDeclaration , Syntax.DefaultSignature @@ -66,7 +70,7 @@ type Syntax = '[ , Syntax.Field , Syntax.FieldBind , Syntax.FieldPattern - , Syntax.Fixity' + , Syntax.FixityAlt , Syntax.FunctionalDependency , Syntax.FunctionConstructor , Syntax.FunctionGuardPattern @@ -141,8 +145,8 @@ type Syntax = '[ , Syntax.StrictPattern , Syntax.StrictType , Syntax.StrictTypeVariable - , Syntax.Tuple , Syntax.TupleConstructor + , Syntax.TupleExpression , Syntax.TuplePattern , Syntax.Type , Syntax.TypeApp @@ -171,6 +175,11 @@ type Syntax = '[ type Term = Term.Term (Sum Syntax) (Record Location) type Assignment = Assignment.Assignment [] Grammar +-- For Protobuf serialization +instance Named1 (Sum Syntax) where nameOf1 _ = "HaskellSyntax" +instance Named (Term.Term (Sum Syntax) ()) where nameOf _ = "HaskellTerm" +instance Named (Diff.Diff (Sum Syntax) () ()) where nameOf _ = "HaskellDiff" + assignment :: Assignment Term assignment = handleError $ module' <|> parseError @@ -250,7 +259,7 @@ constructorSymbol :: Assignment Term constructorSymbol = makeTerm <$> symbol ConstructorSymbol <*> (Syntax.ConstructorSymbol . Name.name <$> source) context' :: Assignment Term -context' = makeTerm <$> symbol Context <*> children (Syntax.Context' <$> expressions) +context' = makeTerm <$> symbol Context <*> children (Syntax.ContextAlt <$> expressions) contextPattern :: Assignment Term contextPattern = symbol ContextPattern *> children expressions @@ -453,7 +462,7 @@ fieldPattern :: Assignment Term fieldPattern = makeTerm <$> symbol FieldPattern <*> children (Syntax.FieldPattern <$> expression <*> expressions) fixityDeclaration :: Assignment Term -fixityDeclaration = makeTerm <$> symbol FixityDeclaration <*> children (Syntax.Fixity' <$> (integer <|> emptyTerm) <*> manyTerm expression) +fixityDeclaration = makeTerm <$> symbol FixityDeclaration <*> children (Syntax.FixityAlt <$> (integer <|> emptyTerm) <*> manyTerm expression) float :: Assignment Term float = makeTerm <$> symbol Float <*> (Literal.Float <$> source) @@ -781,7 +790,7 @@ string :: Assignment Term string = makeTerm <$> symbol String <*> (Literal.TextElement <$> source) tuple :: Assignment Term -tuple = makeTerm <$> symbol TupleExpression <*> children (Syntax.Tuple <$> manyTerm expression) +tuple = makeTerm <$> symbol TupleExpression <*> children (Syntax.TupleExpression <$> manyTerm expression) tuplePattern :: Assignment Term tuplePattern = makeTerm <$> symbol TuplePattern <*> children (Syntax.TuplePattern <$> manyTerm expression) diff --git a/src/Language/Haskell/Syntax.hs b/src/Language/Haskell/Syntax.hs index cce8141bb..0659d090f 100644 --- a/src/Language/Haskell/Syntax.hs +++ b/src/Language/Haskell/Syntax.hs @@ -1,19 +1,21 @@ -{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveAnyClass, DuplicateRecordFields #-} {-# OPTIONS_GHC -Wno-missing-export-lists #-} module Language.Haskell.Syntax where -import Data.Abstract.Evaluatable -import Data.JSON.Fields -import Diffing.Algorithm -import Prelude -import Prologue +import Prelude +import Prologue + +import Data.Abstract.Evaluatable +import Data.JSON.Fields +import Diffing.Algorithm +import Proto3.Suite.Class data Module a = Module { moduleContext :: [a] , moduleIdentifier :: a , moduleExports :: [a] , moduleStatements :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Module where liftEq = genericLiftEq instance Ord1 Module where liftCompare = genericLiftCompare @@ -21,8 +23,8 @@ instance Show1 Module where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Module -newtype StrictPattern a = StrictPattern a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype StrictPattern a = StrictPattern { value :: a} + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 StrictPattern where liftEq = genericLiftEq instance Ord1 StrictPattern where liftCompare = genericLiftCompare @@ -31,7 +33,7 @@ instance Show1 StrictPattern where liftShowsPrec = genericLiftShowsPrec instance Evaluatable StrictPattern data StrictType a = StrictType { strictTypeIdentifier :: a, strictTypeParameters :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 StrictType where liftEq = genericLiftEq instance Ord1 StrictType where liftCompare = genericLiftCompare @@ -39,8 +41,8 @@ instance Show1 StrictType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable StrictType -newtype StrictTypeVariable a = StrictTypeVariable a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype StrictTypeVariable a = StrictTypeVariable { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 StrictTypeVariable where liftEq = genericLiftEq instance Ord1 StrictTypeVariable where liftCompare = genericLiftCompare @@ -49,7 +51,7 @@ instance Show1 StrictTypeVariable where liftShowsPrec = genericLiftShowsPrec instance Evaluatable StrictTypeVariable data Type a = Type { typeIdentifier :: a, typeParameters :: a, typeKindSignature :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Type where liftEq = genericLiftEq instance Ord1 Type where liftCompare = genericLiftCompare @@ -58,7 +60,7 @@ instance Show1 Type where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Type data TypeSynonym a = TypeSynonym { typeSynonymLeft :: a, typeSynonymContext :: [a], typeSynonymRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeSynonym where liftEq = genericLiftEq instance Ord1 TypeSynonym where liftCompare = genericLiftCompare @@ -67,7 +69,7 @@ instance Show1 TypeSynonym where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeSynonym data UnitConstructor a = UnitConstructor - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 UnitConstructor where liftEq = genericLiftEq instance Ord1 UnitConstructor where liftCompare = genericLiftCompare @@ -76,7 +78,7 @@ instance Show1 UnitConstructor where liftShowsPrec = genericLiftShowsPrec instance Evaluatable UnitConstructor newtype TupleConstructor a = TupleConstructor { tupleConstructorArity :: Int } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TupleConstructor where liftEq = genericLiftEq instance Ord1 TupleConstructor where liftCompare = genericLiftCompare @@ -85,7 +87,7 @@ instance Show1 TupleConstructor where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TupleConstructor data ListConstructor a = ListConstructor - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ListConstructor where liftEq = genericLiftEq instance Ord1 ListConstructor where liftCompare = genericLiftCompare @@ -94,7 +96,7 @@ instance Show1 ListConstructor where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ListConstructor data FunctionConstructor a = FunctionConstructor - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 FunctionConstructor where liftEq = genericLiftEq instance Ord1 FunctionConstructor where liftCompare = genericLiftCompare @@ -103,7 +105,7 @@ instance Show1 FunctionConstructor where liftShowsPrec = genericLiftShowsPrec instance Evaluatable FunctionConstructor data RecordDataConstructor a = RecordDataConstructor { recordDataConstructorContext :: [a], recordDataConstructorName :: !a, recordDataConstructorFields :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 RecordDataConstructor where liftEq = genericLiftEq instance Ord1 RecordDataConstructor where liftCompare = genericLiftCompare @@ -112,7 +114,7 @@ instance Show1 RecordDataConstructor where liftShowsPrec = genericLiftShowsPrec instance Evaluatable RecordDataConstructor data Field a = Field { fieldName :: !a, fieldBody :: !a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Field where liftEq = genericLiftEq instance Ord1 Field where liftCompare = genericLiftCompare @@ -120,8 +122,8 @@ instance Show1 Field where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Field -newtype Pragma a = Pragma Text - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Pragma a = Pragma { value :: Text } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Pragma where liftEq = genericLiftEq instance Ord1 Pragma where liftCompare = genericLiftCompare @@ -129,25 +131,25 @@ instance Show1 Pragma where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Pragma -newtype Deriving a = Deriving [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Deriving a = Deriving { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Deriving where liftEq = genericLiftEq instance Ord1 Deriving where liftCompare = genericLiftCompare instance Show1 Deriving where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Deriving -newtype Context' a = Context' a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ContextAlt a = ContextAlt { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) -instance Eq1 Context' where liftEq = genericLiftEq -instance Ord1 Context' where liftCompare = genericLiftCompare -instance Show1 Context' where liftShowsPrec = genericLiftShowsPrec +instance Eq1 ContextAlt where liftEq = genericLiftEq +instance Ord1 ContextAlt where liftCompare = genericLiftCompare +instance Show1 ContextAlt where liftShowsPrec = genericLiftShowsPrec -instance Evaluatable Context' +instance Evaluatable ContextAlt newtype Class a = Class { classContent :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Class where liftEq = genericLiftEq instance Ord1 Class where liftCompare = genericLiftCompare @@ -156,7 +158,7 @@ instance Show1 Class where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Class data GADT a = GADT { gadtContext :: a, gadtName :: a, gadtConstructors :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 GADT where liftEq = genericLiftEq instance Ord1 GADT where liftCompare = genericLiftCompare @@ -165,7 +167,7 @@ instance Show1 GADT where liftShowsPrec = genericLiftShowsPrec instance Evaluatable GADT data GADTConstructor a = GADTConstructor { gadtConstructorContext :: a, gadtConstructorName :: a, gadtConstructorTypeSignature :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 GADTConstructor where liftEq = genericLiftEq instance Ord1 GADTConstructor where liftCompare = genericLiftCompare @@ -174,7 +176,7 @@ instance Show1 GADTConstructor where liftShowsPrec = genericLiftShowsPrec instance Evaluatable GADTConstructor data FunctionType a = FunctionType { functionTypeLeft :: a, functionTypeRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 FunctionType where liftEq = genericLiftEq instance Ord1 FunctionType where liftCompare = genericLiftCompare @@ -183,7 +185,7 @@ instance Show1 FunctionType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable FunctionType data TypeSignature a = TypeSignature { typeSignatureName :: [a], typeSignatureContext :: [a], typeSignatureContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeSignature where liftEq = genericLiftEq instance Ord1 TypeSignature where liftCompare = genericLiftCompare @@ -192,7 +194,7 @@ instance Show1 TypeSignature where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeSignature data ExpressionTypeSignature a = ExpressionTypeSignature { expressionTypeSignatureName :: [a], expressionTypeSignatureContext :: [a], expressionTypeSignatureContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ExpressionTypeSignature where liftEq = genericLiftEq instance Ord1 ExpressionTypeSignature where liftCompare = genericLiftCompare @@ -201,7 +203,7 @@ instance Show1 ExpressionTypeSignature where liftShowsPrec = genericLiftShowsPre instance Evaluatable ExpressionTypeSignature newtype KindSignature a = KindSignature { kindSignatureContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 KindSignature where liftEq = genericLiftEq instance Ord1 KindSignature where liftCompare = genericLiftCompare @@ -210,7 +212,7 @@ instance Show1 KindSignature where liftShowsPrec = genericLiftShowsPrec instance Evaluatable KindSignature data KindFunctionType a = KindFunctionType { kindFunctionTypeLeft :: a, kindFunctionTypeRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 KindFunctionType where liftEq = genericLiftEq instance Ord1 KindFunctionType where liftCompare = genericLiftCompare @@ -219,7 +221,7 @@ instance Show1 KindFunctionType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable KindFunctionType newtype Kind a = Kind { kindKind :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Kind where liftEq = genericLiftEq instance Ord1 Kind where liftCompare = genericLiftCompare @@ -228,7 +230,7 @@ instance Show1 Kind where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Kind newtype KindListType a = KindListType { kindListTypeKind :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 KindListType where liftEq = genericLiftEq instance Ord1 KindListType where liftCompare = genericLiftCompare @@ -237,7 +239,7 @@ instance Show1 KindListType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable KindListType data Star a = Star - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Star where liftEq = genericLiftEq instance Ord1 Star where liftCompare = genericLiftCompare @@ -245,8 +247,8 @@ instance Show1 Star where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Star -newtype QualifiedTypeClassIdentifier a = QualifiedTypeClassIdentifier (NonEmpty a) - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable) +newtype QualifiedTypeClassIdentifier a = QualifiedTypeClassIdentifier { values :: NonEmpty a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QualifiedTypeClassIdentifier where liftEq = genericLiftEq instance Ord1 QualifiedTypeClassIdentifier where liftCompare = genericLiftCompare @@ -255,8 +257,8 @@ instance Hashable1 QualifiedTypeClassIdentifier where liftHashWithSalt = foldl instance Evaluatable QualifiedTypeClassIdentifier -newtype QualifiedTypeConstructorIdentifier a = QualifiedTypeConstructorIdentifier (NonEmpty a) - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable) +newtype QualifiedTypeConstructorIdentifier a = QualifiedTypeConstructorIdentifier { values :: NonEmpty a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QualifiedTypeConstructorIdentifier where liftEq = genericLiftEq instance Ord1 QualifiedTypeConstructorIdentifier where liftCompare = genericLiftCompare @@ -265,8 +267,8 @@ instance Hashable1 QualifiedTypeConstructorIdentifier where liftHashWithSalt = f instance Evaluatable QualifiedTypeConstructorIdentifier -newtype QualifiedConstructorIdentifier a = QualifiedConstructorIdentifier (NonEmpty a) - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable) +newtype QualifiedConstructorIdentifier a = QualifiedConstructorIdentifier { values :: NonEmpty a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QualifiedConstructorIdentifier where liftEq = genericLiftEq instance Ord1 QualifiedConstructorIdentifier where liftCompare = genericLiftCompare @@ -275,8 +277,8 @@ instance Hashable1 QualifiedConstructorIdentifier where liftHashWithSalt = foldl instance Evaluatable QualifiedConstructorIdentifier -newtype QualifiedInfixVariableIdentifier a = QualifiedInfixVariableIdentifier (NonEmpty a) - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable) +newtype QualifiedInfixVariableIdentifier a = QualifiedInfixVariableIdentifier { values :: NonEmpty a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QualifiedInfixVariableIdentifier where liftEq = genericLiftEq instance Ord1 QualifiedInfixVariableIdentifier where liftCompare = genericLiftCompare @@ -285,8 +287,8 @@ instance Hashable1 QualifiedInfixVariableIdentifier where liftHashWithSalt = fol instance Evaluatable QualifiedInfixVariableIdentifier -newtype QualifiedModuleIdentifier a = QualifiedModuleIdentifier (NonEmpty a) - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable) +newtype QualifiedModuleIdentifier a = QualifiedModuleIdentifier { values :: NonEmpty a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QualifiedModuleIdentifier where liftEq = genericLiftEq instance Ord1 QualifiedModuleIdentifier where liftCompare = genericLiftCompare @@ -295,8 +297,8 @@ instance Hashable1 QualifiedModuleIdentifier where liftHashWithSalt = foldl instance Evaluatable QualifiedModuleIdentifier -newtype QualifiedVariableIdentifier a = QualifiedVariableIdentifier (NonEmpty a) - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable) +newtype QualifiedVariableIdentifier a = QualifiedVariableIdentifier { values :: NonEmpty a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QualifiedVariableIdentifier where liftEq = genericLiftEq instance Ord1 QualifiedVariableIdentifier where liftCompare = genericLiftCompare @@ -306,7 +308,7 @@ instance Hashable1 QualifiedVariableIdentifier where liftHashWithSalt = foldl instance Evaluatable QualifiedVariableIdentifier data AnnotatedTypeVariable a = AnnotatedTypeVariable { annotatedTypeVariableIdentifier :: a, annotatedTypeVariableannotation :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 AnnotatedTypeVariable where liftEq = genericLiftEq instance Ord1 AnnotatedTypeVariable where liftCompare = genericLiftCompare @@ -315,7 +317,7 @@ instance Show1 AnnotatedTypeVariable where liftShowsPrec = genericLiftShowsPrec instance Evaluatable AnnotatedTypeVariable newtype Export a = Export { exportContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Export where liftEq = genericLiftEq instance Ord1 Export where liftCompare = genericLiftCompare @@ -324,7 +326,7 @@ instance Show1 Export where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Export newtype ModuleExport a = ModuleExport { moduleExportContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ModuleExport where liftEq = genericLiftEq instance Ord1 ModuleExport where liftCompare = genericLiftCompare @@ -333,7 +335,7 @@ instance Show1 ModuleExport where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ModuleExport newtype TypeConstructorExport a = TypeConstructorExport { typeConstructorExportContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeConstructorExport where liftEq = genericLiftEq instance Ord1 TypeConstructorExport where liftCompare = genericLiftCompare @@ -342,7 +344,7 @@ instance Show1 TypeConstructorExport where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeConstructorExport data AllConstructors a = AllConstructors - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 AllConstructors where liftEq = genericLiftEq instance Ord1 AllConstructors where liftCompare = genericLiftCompare @@ -351,7 +353,7 @@ instance Show1 AllConstructors where liftShowsPrec = genericLiftShowsPrec instance Evaluatable AllConstructors data InfixOperatorPattern a = InfixOperatorPattern { infixOperatorPatternLeft :: a, infixOperatorPatternOperator :: a, infixOperatorPatternRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 InfixOperatorPattern where liftEq = genericLiftEq instance Ord1 InfixOperatorPattern where liftCompare = genericLiftCompare @@ -360,7 +362,7 @@ instance Show1 InfixOperatorPattern where liftShowsPrec = genericLiftShowsPrec instance Evaluatable InfixOperatorPattern newtype QuotedName a = QuotedName { quotedNameContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QuotedName where liftEq = genericLiftEq instance Ord1 QuotedName where liftCompare = genericLiftCompare @@ -369,7 +371,7 @@ instance Show1 QuotedName where liftShowsPrec = genericLiftShowsPrec instance Evaluatable QuotedName newtype TypePattern a = TypePattern { typePatternContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypePattern where liftEq = genericLiftEq instance Ord1 TypePattern where liftCompare = genericLiftCompare @@ -378,7 +380,7 @@ instance Show1 TypePattern where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypePattern newtype ScopedTypeVariables a = ScopedTypeVariables { scopedTypeVariablesContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ScopedTypeVariables where liftEq = genericLiftEq instance Ord1 ScopedTypeVariables where liftCompare = genericLiftCompare @@ -387,7 +389,7 @@ instance Show1 ScopedTypeVariables where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ScopedTypeVariables data NewType a = NewType { newTypeContext :: [a], newTypeLeft :: a, newTypeRight :: a, newTypeDeriving :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 NewType where liftEq = genericLiftEq instance Ord1 NewType where liftCompare = genericLiftCompare @@ -396,7 +398,7 @@ instance Show1 NewType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable NewType newtype DefaultDeclaration a = DefaultDeclaration { defaultDeclarationContent :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 DefaultDeclaration where liftEq = genericLiftEq instance Ord1 DefaultDeclaration where liftCompare = genericLiftCompare @@ -405,7 +407,7 @@ instance Show1 DefaultDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable DefaultDeclaration data EqualityConstraint a = EqualityConstraint { equalityConstraintLeft :: a, equalityConstraintRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 EqualityConstraint where liftEq = genericLiftEq instance Ord1 EqualityConstraint where liftCompare = genericLiftCompare @@ -413,8 +415,8 @@ instance Show1 EqualityConstraint where liftShowsPrec = genericLiftShowsPrec instance Evaluatable EqualityConstraint -newtype TypeVariableIdentifier a = TypeVariableIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype TypeVariableIdentifier a = TypeVariableIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeVariableIdentifier where liftEq = genericLiftEq instance Ord1 TypeVariableIdentifier where liftCompare = genericLiftCompare @@ -422,8 +424,8 @@ instance Show1 TypeVariableIdentifier where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeVariableIdentifier -newtype TypeConstructorIdentifier a = TypeConstructorIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype TypeConstructorIdentifier a = TypeConstructorIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeConstructorIdentifier where liftEq = genericLiftEq instance Ord1 TypeConstructorIdentifier where liftCompare = genericLiftCompare @@ -431,8 +433,8 @@ instance Show1 TypeConstructorIdentifier where liftShowsPrec = genericLiftShowsP instance Evaluatable TypeConstructorIdentifier -newtype ModuleIdentifier a = ModuleIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ModuleIdentifier a = ModuleIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ModuleIdentifier where liftEq = genericLiftEq instance Ord1 ModuleIdentifier where liftCompare = genericLiftCompare @@ -440,8 +442,8 @@ instance Show1 ModuleIdentifier where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ModuleIdentifier -newtype ConstructorIdentifier a = ConstructorIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ConstructorIdentifier a = ConstructorIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ConstructorIdentifier where liftEq = genericLiftEq instance Ord1 ConstructorIdentifier where liftCompare = genericLiftCompare @@ -449,8 +451,8 @@ instance Show1 ConstructorIdentifier where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ConstructorIdentifier -newtype ImplicitParameterIdentifier a = ImplicitParameterIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ImplicitParameterIdentifier a = ImplicitParameterIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ImplicitParameterIdentifier where liftEq = genericLiftEq instance Ord1 ImplicitParameterIdentifier where liftCompare = genericLiftCompare @@ -458,8 +460,8 @@ instance Show1 ImplicitParameterIdentifier where liftShowsPrec = genericLiftShow instance Evaluatable ImplicitParameterIdentifier -newtype InfixConstructorIdentifier a = InfixConstructorIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype InfixConstructorIdentifier a = InfixConstructorIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 InfixConstructorIdentifier where liftEq = genericLiftEq instance Ord1 InfixConstructorIdentifier where liftCompare = genericLiftCompare @@ -467,8 +469,8 @@ instance Show1 InfixConstructorIdentifier where liftShowsPrec = genericLiftShows instance Evaluatable InfixConstructorIdentifier -newtype InfixVariableIdentifier a = InfixVariableIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype InfixVariableIdentifier a = InfixVariableIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 InfixVariableIdentifier where liftEq = genericLiftEq instance Ord1 InfixVariableIdentifier where liftCompare = genericLiftCompare @@ -476,8 +478,8 @@ instance Show1 InfixVariableIdentifier where liftShowsPrec = genericLiftShowsPre instance Evaluatable InfixVariableIdentifier -newtype TypeClassIdentifier a = TypeClassIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype TypeClassIdentifier a = TypeClassIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeClassIdentifier where liftEq = genericLiftEq instance Ord1 TypeClassIdentifier where liftCompare = genericLiftCompare @@ -485,8 +487,8 @@ instance Show1 TypeClassIdentifier where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeClassIdentifier -newtype VariableIdentifier a = VariableIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype VariableIdentifier a = VariableIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 VariableIdentifier where liftEq = genericLiftEq instance Ord1 VariableIdentifier where liftCompare = genericLiftCompare @@ -494,8 +496,8 @@ instance Show1 VariableIdentifier where liftShowsPrec = genericLiftShowsPrec instance Evaluatable VariableIdentifier -newtype PrimitiveConstructorIdentifier a = PrimitiveConstructorIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype PrimitiveConstructorIdentifier a = PrimitiveConstructorIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PrimitiveConstructorIdentifier where liftEq = genericLiftEq instance Ord1 PrimitiveConstructorIdentifier where liftCompare = genericLiftCompare @@ -503,8 +505,8 @@ instance Show1 PrimitiveConstructorIdentifier where liftShowsPrec = genericLiftS instance Evaluatable PrimitiveConstructorIdentifier -newtype PrimitiveVariableIdentifier a = PrimitiveVariableIdentifier Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype PrimitiveVariableIdentifier a = PrimitiveVariableIdentifier { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PrimitiveVariableIdentifier where liftEq = genericLiftEq instance Ord1 PrimitiveVariableIdentifier where liftCompare = genericLiftCompare @@ -512,8 +514,8 @@ instance Show1 PrimitiveVariableIdentifier where liftShowsPrec = genericLiftShow instance Evaluatable PrimitiveVariableIdentifier -newtype VariableOperator a = VariableOperator a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype VariableOperator a = VariableOperator { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 VariableOperator where liftEq = genericLiftEq instance Ord1 VariableOperator where liftCompare = genericLiftCompare @@ -521,8 +523,8 @@ instance Show1 VariableOperator where liftShowsPrec = genericLiftShowsPrec instance Evaluatable VariableOperator -newtype ConstructorOperator a = ConstructorOperator a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ConstructorOperator a = ConstructorOperator { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ConstructorOperator where liftEq = genericLiftEq instance Ord1 ConstructorOperator where liftCompare = genericLiftCompare @@ -530,8 +532,8 @@ instance Show1 ConstructorOperator where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ConstructorOperator -newtype TypeOperator a = TypeOperator Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype TypeOperator a = TypeOperator { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeOperator where liftEq = genericLiftEq instance Ord1 TypeOperator where liftCompare = genericLiftCompare @@ -539,8 +541,8 @@ instance Show1 TypeOperator where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeOperator -newtype PromotedTypeOperator a = PromotedTypeOperator a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype PromotedTypeOperator a = PromotedTypeOperator { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PromotedTypeOperator where liftEq = genericLiftEq instance Ord1 PromotedTypeOperator where liftCompare = genericLiftCompare @@ -549,7 +551,7 @@ instance Show1 PromotedTypeOperator where liftShowsPrec = genericLiftShowsPrec instance Evaluatable PromotedTypeOperator newtype ConstructorSymbol a = ConstructorSymbol { constructorSymbolName :: Name } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ConstructorSymbol where liftEq = genericLiftEq instance Ord1 ConstructorSymbol where liftCompare = genericLiftCompare @@ -558,7 +560,7 @@ instance Show1 ConstructorSymbol where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ConstructorSymbol newtype VariableSymbol a = VariableSymbol { variableSymbolName :: Name } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 VariableSymbol where liftEq = genericLiftEq instance Ord1 VariableSymbol where liftCompare = genericLiftCompare @@ -567,7 +569,7 @@ instance Show1 VariableSymbol where liftShowsPrec = genericLiftShowsPrec instance Evaluatable VariableSymbol data StandaloneDerivingInstance a = StandaloneDerivingInstance { standaloneDerivingInstanceContext :: [a], standaloneDerivingInstanceClass :: a, standaloneDerivingInstanceInstance :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 StandaloneDerivingInstance where liftEq = genericLiftEq instance Ord1 StandaloneDerivingInstance where liftCompare = genericLiftCompare @@ -576,7 +578,7 @@ instance Show1 StandaloneDerivingInstance where liftShowsPrec = genericLiftShows instance Evaluatable StandaloneDerivingInstance data ImportDeclaration a = ImportDeclaration { importPackageQualifiedContent :: a, importModule :: a, importSpec :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ImportDeclaration where liftEq = genericLiftEq instance Ord1 ImportDeclaration where liftCompare = genericLiftCompare @@ -585,7 +587,7 @@ instance Show1 ImportDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ImportDeclaration data QualifiedImportDeclaration a = QualifiedImportDeclaration { qualifiedImportPackageQualifiedContent :: a, qualifiedImportModule :: a, qualifiedImportSpec :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QualifiedImportDeclaration where liftEq = genericLiftEq instance Ord1 QualifiedImportDeclaration where liftCompare = genericLiftCompare @@ -594,7 +596,7 @@ instance Show1 QualifiedImportDeclaration where liftShowsPrec = genericLiftShows instance Evaluatable QualifiedImportDeclaration newtype Import a = Import { importContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Import where liftEq = genericLiftEq instance Ord1 Import where liftCompare = genericLiftCompare @@ -603,7 +605,7 @@ instance Show1 Import where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Import newtype HiddenImport a = HiddenImport { hiddenimportContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 HiddenImport where liftEq = genericLiftEq instance Ord1 HiddenImport where liftCompare = genericLiftCompare @@ -612,7 +614,7 @@ instance Show1 HiddenImport where liftShowsPrec = genericLiftShowsPrec instance Evaluatable HiddenImport data ImportAlias a = ImportAlias { importAliasSource :: a, importAliasName :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ImportAlias where liftEq = genericLiftEq instance Ord1 ImportAlias where liftCompare = genericLiftCompare @@ -621,7 +623,7 @@ instance Show1 ImportAlias where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ImportAlias data App a = App { appLeft :: a, appLeftTypeApp :: a, appRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 App where liftEq = genericLiftEq instance Ord1 App where liftCompare = genericLiftCompare @@ -630,7 +632,7 @@ instance Show1 App where liftShowsPrec = genericLiftShowsPrec instance Evaluatable App data InfixOperatorApp a = InfixOperatorApp { infixOperatorAppLeft :: a, infixOperatorAppLeftTypeApp :: a, infixOperatorAppOperator :: a, infixOperatorAppRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 InfixOperatorApp where liftEq = genericLiftEq instance Ord1 InfixOperatorApp where liftCompare = genericLiftCompare @@ -639,7 +641,7 @@ instance Show1 InfixOperatorApp where liftShowsPrec = genericLiftShowsPrec instance Evaluatable InfixOperatorApp newtype TypeApp a = TypeApp { typeAppType :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeApp where liftEq = genericLiftEq instance Ord1 TypeApp where liftCompare = genericLiftCompare @@ -648,7 +650,7 @@ instance Show1 TypeApp where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeApp data ListComprehension a = ListComprehension { comprehensionValue :: a, comprehensionSource :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ListComprehension where liftEq = genericLiftEq instance Ord1 ListComprehension where liftCompare = genericLiftCompare @@ -657,7 +659,7 @@ instance Show1 ListComprehension where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ListComprehension data Generator a = Generator { generatorValue :: a, generatorSource :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Generator where liftEq = genericLiftEq instance Ord1 Generator where liftCompare = genericLiftCompare @@ -665,17 +667,17 @@ instance Show1 Generator where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Generator -newtype Tuple a = Tuple [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype TupleExpression a = TupleExpression { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) -instance Eq1 Tuple where liftEq = genericLiftEq -instance Ord1 Tuple where liftCompare = genericLiftCompare -instance Show1 Tuple where liftShowsPrec = genericLiftShowsPrec +instance Eq1 TupleExpression where liftEq = genericLiftEq +instance Ord1 TupleExpression where liftCompare = genericLiftCompare +instance Show1 TupleExpression where liftShowsPrec = genericLiftShowsPrec -instance Evaluatable Tuple +instance Evaluatable TupleExpression -newtype TuplePattern a = TuplePattern [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype TuplePattern a = TuplePattern { value :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TuplePattern where liftEq = genericLiftEq instance Ord1 TuplePattern where liftCompare = genericLiftCompare @@ -685,7 +687,7 @@ instance Evaluatable TuplePattern -- e.g. [1..], [1,2..], [1,2..10] data ArithmeticSequence a = ArithmeticSequence { from :: a, next :: Maybe a, to :: Maybe a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ArithmeticSequence where liftEq = genericLiftEq instance Ord1 ArithmeticSequence where liftCompare = genericLiftCompare @@ -693,8 +695,8 @@ instance Show1 ArithmeticSequence where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ArithmeticSequence -data RightOperatorSection a = RightOperatorSection a a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data RightOperatorSection a = RightOperatorSection { lhs :: a, rhs :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 RightOperatorSection where liftEq = genericLiftEq instance Ord1 RightOperatorSection where liftCompare = genericLiftCompare @@ -702,8 +704,8 @@ instance Show1 RightOperatorSection where liftShowsPrec = genericLiftShowsPrec instance Evaluatable RightOperatorSection -data LeftOperatorSection a = LeftOperatorSection a a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data LeftOperatorSection a = LeftOperatorSection { lhs :: a, rhs :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 LeftOperatorSection where liftEq = genericLiftEq instance Ord1 LeftOperatorSection where liftCompare = genericLiftCompare @@ -711,8 +713,8 @@ instance Show1 LeftOperatorSection where liftShowsPrec = genericLiftShowsPrec instance Evaluatable LeftOperatorSection -newtype ConstructorPattern a = ConstructorPattern a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ConstructorPattern a = ConstructorPattern { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ConstructorPattern where liftEq = genericLiftEq instance Ord1 ConstructorPattern where liftCompare = genericLiftCompare @@ -722,7 +724,7 @@ instance Evaluatable ConstructorPattern -- e.g. `a <- b` in a Haskell do block. data BindPattern a = BindPattern { bindPatternLeft :: [a], bindPatternRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 BindPattern where liftEq = genericLiftEq instance Ord1 BindPattern where liftCompare = genericLiftCompare @@ -730,8 +732,8 @@ instance Show1 BindPattern where liftShowsPrec = genericLiftShowsPrec instance Evaluatable BindPattern -newtype Do a = Do [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Do a = Do { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Do where liftEq = genericLiftEq instance Ord1 Do where liftCompare = genericLiftCompare @@ -740,7 +742,7 @@ instance Show1 Do where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Do data Lambda a = Lambda { lambdaHead :: a, lambdaBody :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Lambda where liftEq = genericLiftEq instance Ord1 Lambda where liftCompare = genericLiftCompare @@ -749,8 +751,8 @@ instance Show1 Lambda where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Lambda -- e.g. -1 or (-a) as an expression and not `-` as a variable operator. -newtype PrefixNegation a = PrefixNegation a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype PrefixNegation a = PrefixNegation { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PrefixNegation where liftEq = genericLiftEq instance Ord1 PrefixNegation where liftCompare = genericLiftCompare @@ -758,8 +760,8 @@ instance Show1 PrefixNegation where liftShowsPrec = genericLiftShowsPrec instance Evaluatable PrefixNegation -newtype CPPDirective a = CPPDirective Text - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype CPPDirective a = CPPDirective { value :: Text } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 CPPDirective where liftEq = genericLiftEq instance Ord1 CPPDirective where liftCompare = genericLiftCompare @@ -768,7 +770,7 @@ instance Show1 CPPDirective where liftShowsPrec = genericLiftShowsPrec instance Evaluatable CPPDirective data QuasiQuotation a = QuasiQuotation { quasiQuotationHead :: a, quasiQuotationBody :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QuasiQuotation where liftEq = genericLiftEq instance Ord1 QuasiQuotation where liftCompare = genericLiftCompare @@ -776,8 +778,8 @@ instance Show1 QuasiQuotation where liftShowsPrec = genericLiftShowsPrec instance Evaluatable QuasiQuotation -newtype QuasiQuotationExpressionBody a = QuasiQuotationExpressionBody Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype QuasiQuotationExpressionBody a = QuasiQuotationExpressionBody { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QuasiQuotationExpressionBody where liftEq = genericLiftEq instance Ord1 QuasiQuotationExpressionBody where liftCompare = genericLiftCompare @@ -786,7 +788,7 @@ instance Show1 QuasiQuotationExpressionBody where liftShowsPrec = genericLiftSho instance Evaluatable QuasiQuotationExpressionBody data QuasiQuotationPattern a = QuasiQuotationPattern - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QuasiQuotationPattern where liftEq = genericLiftEq instance Ord1 QuasiQuotationPattern where liftCompare = genericLiftCompare @@ -795,7 +797,7 @@ instance Show1 QuasiQuotationPattern where liftShowsPrec = genericLiftShowsPrec instance Evaluatable QuasiQuotationPattern data QuasiQuotationType a = QuasiQuotationType - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QuasiQuotationType where liftEq = genericLiftEq instance Ord1 QuasiQuotationType where liftCompare = genericLiftCompare @@ -804,7 +806,7 @@ instance Show1 QuasiQuotationType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable QuasiQuotationType data QuasiQuotationDeclaration a = QuasiQuotationDeclaration - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QuasiQuotationDeclaration where liftEq = genericLiftEq instance Ord1 QuasiQuotationDeclaration where liftCompare = genericLiftCompare @@ -812,8 +814,8 @@ instance Show1 QuasiQuotationDeclaration where liftShowsPrec = genericLiftShowsP instance Evaluatable QuasiQuotationDeclaration -newtype QuasiQuotationQuoter a = QuasiQuotationQuoter Name - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype QuasiQuotationQuoter a = QuasiQuotationQuoter { name :: Name } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QuasiQuotationQuoter where liftEq = genericLiftEq instance Ord1 QuasiQuotationQuoter where liftCompare = genericLiftCompare @@ -822,7 +824,7 @@ instance Show1 QuasiQuotationQuoter where liftShowsPrec = genericLiftShowsPrec instance Evaluatable QuasiQuotationQuoter data QuasiQuotationExpression a = QuasiQuotationExpression - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QuasiQuotationExpression where liftEq = genericLiftEq instance Ord1 QuasiQuotationExpression where liftCompare = genericLiftCompare @@ -830,8 +832,8 @@ instance Show1 QuasiQuotationExpression where liftShowsPrec = genericLiftShowsPr instance Evaluatable QuasiQuotationExpression -newtype Splice a = Splice a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Splice a = Splice { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Splice where liftEq = genericLiftEq instance Ord1 Splice where liftCompare = genericLiftCompare @@ -840,7 +842,7 @@ instance Show1 Splice where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Splice data TypeClass a = TypeClass { typeClassContext :: a, typeClassIdentifier :: a, typeClassParameters :: [a], typeClassBody :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeClass where liftEq = genericLiftEq instance Ord1 TypeClass where liftCompare = genericLiftCompare @@ -848,18 +850,18 @@ instance Show1 TypeClass where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeClass -data Fixity' a = Fixity' { fixityPrecedence :: a, fixityIdentifier :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data FixityAlt a = FixityAlt { fixityPrecedence :: a, fixityIdentifier :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) -instance Eq1 Fixity' where liftEq = genericLiftEq -instance Ord1 Fixity' where liftCompare = genericLiftCompare -instance Show1 Fixity' where liftShowsPrec = genericLiftShowsPrec +instance Eq1 FixityAlt where liftEq = genericLiftEq +instance Ord1 FixityAlt where liftCompare = genericLiftCompare +instance Show1 FixityAlt where liftShowsPrec = genericLiftShowsPrec -instance Evaluatable Fixity' +instance Evaluatable FixityAlt -- The default signature of a type class. The default signature has the same shape as a TypeSignature Assignment. data DefaultSignature a = DefaultSignature { defaultSignatureName :: [a], defaultSignatureContext :: [a], defaultSignatureContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 DefaultSignature where liftEq = genericLiftEq instance Ord1 DefaultSignature where liftCompare = genericLiftCompare @@ -868,7 +870,7 @@ instance Show1 DefaultSignature where liftShowsPrec = genericLiftShowsPrec instance Evaluatable DefaultSignature data TypeFamily a = TypeFamily { typeFamilyIdentifier :: a, typeFamilyParameters :: [a], typeFamilySignature :: a, typeFamilyBody :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeFamily where liftEq = genericLiftEq instance Ord1 TypeFamily where liftCompare = genericLiftCompare @@ -877,7 +879,7 @@ instance Show1 TypeFamily where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeFamily newtype FunctionalDependency a = FunctionalDependency { functionalDependencyContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 FunctionalDependency where liftEq = genericLiftEq instance Ord1 FunctionalDependency where liftCompare = genericLiftCompare @@ -886,7 +888,7 @@ instance Show1 FunctionalDependency where liftShowsPrec = genericLiftShowsPrec instance Evaluatable FunctionalDependency data TypeClassInstance a = TypeClassInstance { typeClassInstanceContext :: [a], typeClassInstanceIdentifier :: a, typeClassInstanceInstance :: a, typeClassInstanceBody :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeClassInstance where liftEq = genericLiftEq instance Ord1 TypeClassInstance where liftCompare = genericLiftCompare @@ -894,8 +896,8 @@ instance Show1 TypeClassInstance where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeClassInstance -newtype Instance a = Instance a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Instance a = Instance { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Instance where liftEq = genericLiftEq instance Ord1 Instance where liftCompare = genericLiftCompare @@ -904,8 +906,8 @@ instance Show1 Instance where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Instance -- e.g. The `Bar{..}` in `foo Bar{..} = baz`. -newtype LabeledPattern a = LabeledPattern a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype LabeledPattern a = LabeledPattern { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 LabeledPattern where liftEq = genericLiftEq instance Ord1 LabeledPattern where liftCompare = genericLiftCompare @@ -915,7 +917,7 @@ instance Evaluatable LabeledPattern -- e.g. The `{..}` in `foo Bar{..} = baz` data RecordWildCards a = RecordWildCards - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 RecordWildCards where liftEq = genericLiftEq instance Ord1 RecordWildCards where liftCompare = genericLiftCompare @@ -925,7 +927,7 @@ instance Evaluatable RecordWildCards -- e.g. `type instance F [Int] = Int` where `F` is an open type family. data TypeInstance a = TypeInstance { typeInstanceType :: a, typeInstanceBody :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeInstance where liftEq = genericLiftEq instance Ord1 TypeInstance where liftCompare = genericLiftCompare @@ -934,7 +936,7 @@ instance Show1 TypeInstance where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeInstance newtype KindParenthesizedConstructor a = KindParenthesizedConstructor { kindParenthesizedConstructorContent :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 KindParenthesizedConstructor where liftEq = genericLiftEq instance Ord1 KindParenthesizedConstructor where liftCompare = genericLiftCompare @@ -943,7 +945,7 @@ instance Show1 KindParenthesizedConstructor where liftShowsPrec = genericLiftSho instance Evaluatable KindParenthesizedConstructor newtype KindTupleType a = KindTupleType { kindTupleType :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 KindTupleType where liftEq = genericLiftEq instance Ord1 KindTupleType where liftCompare = genericLiftCompare @@ -952,7 +954,7 @@ instance Show1 KindTupleType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable KindTupleType data Wildcard a = Wildcard - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Wildcard where liftEq = genericLiftEq instance Ord1 Wildcard where liftCompare = genericLiftCompare @@ -961,7 +963,7 @@ instance Show1 Wildcard where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Wildcard data Let a = Let { letStatements :: [a], letInClause :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Let where liftEq = genericLiftEq instance Ord1 Let where liftCompare = genericLiftCompare @@ -969,8 +971,8 @@ instance Show1 Let where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Let -newtype ListPattern a = ListPattern a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ListPattern a = ListPattern { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ListPattern where liftEq = genericLiftEq instance Ord1 ListPattern where liftCompare = genericLiftCompare @@ -980,7 +982,7 @@ instance Evaluatable ListPattern -- e.g. The `n@num1` in `f n@num1 x@num2 = x` data AsPattern a = AsPattern { asPatternLeft :: a, asPatternRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 AsPattern where liftEq = genericLiftEq instance Ord1 AsPattern where liftCompare = genericLiftCompare @@ -990,7 +992,7 @@ instance Evaluatable AsPattern -- e.g. The `a = 1` in `foo Bar{ a = 1 } = baz`. data FieldPattern a = FieldPattern { fieldPatternLeft :: a, fieldPatternRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 FieldPattern where liftEq = genericLiftEq instance Ord1 FieldPattern where liftCompare = genericLiftCompare @@ -999,8 +1001,8 @@ instance Show1 FieldPattern where liftShowsPrec = genericLiftShowsPrec instance Evaluatable FieldPattern -- e.g. The `start` or `end` in `f Blob{start, end} = [start, end]`. -newtype NamedFieldPun a = NamedFieldPun a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype NamedFieldPun a = NamedFieldPun { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 NamedFieldPun where liftEq = genericLiftEq instance Ord1 NamedFieldPun where liftCompare = genericLiftCompare @@ -1009,8 +1011,8 @@ instance Show1 NamedFieldPun where liftShowsPrec = genericLiftShowsPrec instance Evaluatable NamedFieldPun -- e.g. The `-(1)` in `f (-(1)) = 1`. -newtype NegativeLiteral a = NegativeLiteral a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype NegativeLiteral a = NegativeLiteral { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 NegativeLiteral where liftEq = genericLiftEq instance Ord1 NegativeLiteral where liftCompare = genericLiftCompare @@ -1019,8 +1021,8 @@ instance Show1 NegativeLiteral where liftShowsPrec = genericLiftShowsPrec instance Evaluatable NegativeLiteral -- e.g. The `~a` in `f ~a = 1` -newtype IrrefutablePattern a = IrrefutablePattern a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype IrrefutablePattern a = IrrefutablePattern { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 IrrefutablePattern where liftEq = genericLiftEq instance Ord1 IrrefutablePattern where liftCompare = genericLiftCompare @@ -1029,8 +1031,8 @@ instance Show1 IrrefutablePattern where liftShowsPrec = genericLiftShowsPrec instance Evaluatable IrrefutablePattern -- For handling guards in case alternative expressions. -newtype CaseGuardPattern a = CaseGuardPattern [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype CaseGuardPattern a = CaseGuardPattern { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 CaseGuardPattern where liftEq = genericLiftEq instance Ord1 CaseGuardPattern where liftCompare = genericLiftCompare @@ -1038,8 +1040,8 @@ instance Show1 CaseGuardPattern where liftShowsPrec = genericLiftShowsPrec instance Evaluatable CaseGuardPattern -newtype Guard a = Guard a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Guard a = Guard { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Guard where liftEq = genericLiftEq instance Ord1 Guard where liftCompare = genericLiftCompare @@ -1047,8 +1049,8 @@ instance Show1 Guard where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Guard -newtype LambdaCase a = LambdaCase [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype LambdaCase a = LambdaCase { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 LambdaCase where liftEq = genericLiftEq instance Ord1 LambdaCase where liftCompare = genericLiftCompare @@ -1057,8 +1059,8 @@ instance Show1 LambdaCase where liftShowsPrec = genericLiftShowsPrec instance Evaluatable LambdaCase -- For handling guards in function declarations. -newtype FunctionGuardPattern a = FunctionGuardPattern [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype FunctionGuardPattern a = FunctionGuardPattern { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 FunctionGuardPattern where liftEq = genericLiftEq instance Ord1 FunctionGuardPattern where liftCompare = genericLiftCompare @@ -1067,8 +1069,8 @@ instance Show1 FunctionGuardPattern where liftShowsPrec = genericLiftShowsPrec instance Evaluatable FunctionGuardPattern -- The `y { a = 1, b = 2} in `f y@Example = y { a = 1, b = 2 }`. -newtype LabeledUpdate a = LabeledUpdate [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype LabeledUpdate a = LabeledUpdate { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 LabeledUpdate where liftEq = genericLiftEq instance Ord1 LabeledUpdate where liftCompare = genericLiftCompare @@ -1078,7 +1080,7 @@ instance Evaluatable LabeledUpdate -- The `a = 1` in `f y@Example = y { a = 1, b = 2 }`. data FieldBind a = FieldBind { fieldBindLeft :: a, fieldBindRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 FieldBind where liftEq = genericLiftEq instance Ord1 FieldBind where liftCompare = genericLiftCompare @@ -1087,7 +1089,7 @@ instance Show1 FieldBind where liftShowsPrec = genericLiftShowsPrec instance Evaluatable FieldBind data ViewPattern a = ViewPattern { viewPatternLeft :: a, viewPatternRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ViewPattern where liftEq = genericLiftEq instance Ord1 ViewPattern where liftCompare = genericLiftCompare @@ -1097,7 +1099,7 @@ instance Evaluatable ViewPattern -- The `a <- b` in `f a | a <- b = c` of a function declaration. data PatternGuard a = PatternGuard { patternGuardPattern :: a, patternGuardExpression :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PatternGuard where liftEq = genericLiftEq instance Ord1 PatternGuard where liftCompare = genericLiftCompare @@ -1106,7 +1108,7 @@ instance Show1 PatternGuard where liftShowsPrec = genericLiftShowsPrec instance Evaluatable PatternGuard data LabeledConstruction a = LabeledConstruction { labeledConstructionConstructor :: a, labeledConstructionFields :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 LabeledConstruction where liftEq = genericLiftEq instance Ord1 LabeledConstruction where liftCompare = genericLiftCompare @@ -1115,7 +1117,7 @@ instance Show1 LabeledConstruction where liftShowsPrec = genericLiftShowsPrec instance Evaluatable LabeledConstruction data InfixDataConstructor a = InfixDataConstructor { infixDataConstructorContext :: [a], infixDataConstructorLeft :: a, infixDataConstructorOperator :: a, infixDataConstructorRight :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 InfixDataConstructor where liftEq = genericLiftEq instance Ord1 InfixDataConstructor where liftCompare = genericLiftCompare diff --git a/src/Language/Markdown/Assignment.hs b/src/Language/Markdown/Assignment.hs index 7ec744b69..c926ef77b 100644 --- a/src/Language/Markdown/Assignment.hs +++ b/src/Language/Markdown/Assignment.hs @@ -6,18 +6,21 @@ module Language.Markdown.Assignment , Language.Markdown.Assignment.Term ) where -import Assigning.Assignment hiding (Assignment, Error) -import Data.Record -import Data.Syntax (makeTerm) -import qualified Data.Term as Term -import Parsing.CMark as Grammar (Grammar(..)) +import Prologue + +import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment import qualified CMarkGFM -import Data.Sum +import Data.Record +import Data.Sum +import Data.Syntax (makeTerm) import qualified Data.Syntax as Syntax +import qualified Data.Term as Term +import qualified Data.Diff as Diff import qualified Data.Text as Text import qualified Language.Markdown.Syntax as Markup -import Prologue +import Parsing.CMark as Grammar (Grammar (..)) +import Proto3.Suite (Named (..), Named1 (..)) type Syntax = '[ Markup.Document @@ -49,6 +52,10 @@ type Syntax = type Term = Term.Term (Sum Syntax) (Record Location) type Assignment = Assignment.Assignment (Term.TermF [] CMarkGFM.NodeType) Grammar +-- For Protobuf serialization +instance Named1 (Sum Syntax) where nameOf1 _ = "MarkdownSyntax" +instance Named (Term.Term (Sum Syntax) ()) where nameOf _ = "MarkdownTerm" +instance Named (Diff.Diff (Sum Syntax) () ()) where nameOf _ = "MarkdownDiff" assignment :: Assignment Term assignment = Syntax.handleError $ makeTerm <$> symbol Document <*> children (Markup.Document <$> many blockElement) diff --git a/src/Language/Markdown/Syntax.hs b/src/Language/Markdown/Syntax.hs index 33bc3425d..5b006537f 100644 --- a/src/Language/Markdown/Syntax.hs +++ b/src/Language/Markdown/Syntax.hs @@ -1,14 +1,17 @@ -{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveAnyClass, DuplicateRecordFields #-} {-# OPTIONS_GHC -Wno-missing-export-lists #-} module Language.Markdown.Syntax where -import Prologue hiding (Text) -import Data.JSON.Fields +import Data.JSON.Fields import qualified Data.Text as T -import Diffing.Algorithm +import Diffing.Algorithm +import Prologue hiding (Text) +import Proto3.Suite +import qualified Proto3.Suite as PB +import qualified Proto3.Wire.Encode as Encode -newtype Document a = Document [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype Document a = Document { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 Document where liftEq = genericLiftEq instance Ord1 Document where liftCompare = genericLiftCompare @@ -17,71 +20,71 @@ instance Show1 Document where liftShowsPrec = genericLiftShowsPrec -- Block elements -newtype Paragraph a = Paragraph [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype Paragraph a = Paragraph { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 Paragraph where liftEq = genericLiftEq instance Ord1 Paragraph where liftCompare = genericLiftCompare instance Show1 Paragraph where liftShowsPrec = genericLiftShowsPrec data Heading a = Heading { headingLevel :: Int, headingContent :: [a], sectionContent :: [a] } - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 Heading where liftEq = genericLiftEq instance Ord1 Heading where liftCompare = genericLiftCompare instance Show1 Heading where liftShowsPrec = genericLiftShowsPrec -newtype UnorderedList a = UnorderedList [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype UnorderedList a = UnorderedList { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 UnorderedList where liftEq = genericLiftEq instance Ord1 UnorderedList where liftCompare = genericLiftCompare instance Show1 UnorderedList where liftShowsPrec = genericLiftShowsPrec -newtype OrderedList a = OrderedList [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype OrderedList a = OrderedList { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 OrderedList where liftEq = genericLiftEq instance Ord1 OrderedList where liftCompare = genericLiftCompare instance Show1 OrderedList where liftShowsPrec = genericLiftShowsPrec -newtype BlockQuote a = BlockQuote [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype BlockQuote a = BlockQuote { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 BlockQuote where liftEq = genericLiftEq instance Ord1 BlockQuote where liftCompare = genericLiftCompare instance Show1 BlockQuote where liftShowsPrec = genericLiftShowsPrec data ThematicBreak a = ThematicBreak - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 ThematicBreak where liftEq = genericLiftEq instance Ord1 ThematicBreak where liftCompare = genericLiftCompare instance Show1 ThematicBreak where liftShowsPrec = genericLiftShowsPrec -newtype HTMLBlock a = HTMLBlock T.Text - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype HTMLBlock a = HTMLBlock { value :: T.Text } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 HTMLBlock where liftEq = genericLiftEq instance Ord1 HTMLBlock where liftCompare = genericLiftCompare instance Show1 HTMLBlock where liftShowsPrec = genericLiftShowsPrec -newtype Table a = Table [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype Table a = Table { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 Table where liftEq = genericLiftEq instance Ord1 Table where liftCompare = genericLiftCompare instance Show1 Table where liftShowsPrec = genericLiftShowsPrec -newtype TableRow a = TableRow [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype TableRow a = TableRow { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 TableRow where liftEq = genericLiftEq instance Ord1 TableRow where liftCompare = genericLiftCompare instance Show1 TableRow where liftShowsPrec = genericLiftShowsPrec -newtype TableCell a = TableCell [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype TableCell a = TableCell { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 TableCell where liftEq = genericLiftEq instance Ord1 TableCell where liftCompare = genericLiftCompare @@ -90,57 +93,82 @@ instance Show1 TableCell where liftShowsPrec = genericLiftShowsPrec -- Inline elements -newtype Strong a = Strong [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype Strong a = Strong { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 Strong where liftEq = genericLiftEq instance Ord1 Strong where liftCompare = genericLiftCompare instance Show1 Strong where liftShowsPrec = genericLiftShowsPrec -newtype Emphasis a = Emphasis [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype Emphasis a = Emphasis { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 Emphasis where liftEq = genericLiftEq instance Ord1 Emphasis where liftCompare = genericLiftCompare instance Show1 Emphasis where liftShowsPrec = genericLiftShowsPrec -newtype Text a = Text T.Text - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype Text a = Text { value :: T.Text} + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 Text where liftEq = genericLiftEq instance Ord1 Text where liftCompare = genericLiftCompare instance Show1 Text where liftShowsPrec = genericLiftShowsPrec data Link a = Link { linkURL :: T.Text, linkTitle :: Maybe T.Text } - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1) + +instance Message1 Link where + liftEncodeMessage _ num Link{..} = encodeMessageField 1 linkURL <> maybe mempty (encodeMessageField 2) linkTitle + liftDecodeMessage = undefined + liftDotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim PB.String) (Single "linkUrl") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "linkTitle") [] Nothing + ] instance Eq1 Link where liftEq = genericLiftEq instance Ord1 Link where liftCompare = genericLiftCompare instance Show1 Link where liftShowsPrec = genericLiftShowsPrec data Image a = Image { imageURL :: T.Text, imageTitle :: Maybe T.Text } - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1) + +instance Message1 Image where + liftEncodeMessage _ num Image{..} = encodeMessageField 1 imageURL <> maybe mempty (encodeMessageField 2) imageTitle + liftDecodeMessage = undefined + liftDotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim PB.String) (Single "imageURL") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "imageTitle") [] Nothing + ] instance Eq1 Image where liftEq = genericLiftEq instance Ord1 Image where liftCompare = genericLiftCompare instance Show1 Image where liftShowsPrec = genericLiftShowsPrec data Code a = Code { codeLanguage :: Maybe T.Text, codeContent :: T.Text } - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1) + +instance Message1 Code where + liftEncodeMessage _ num Code{..} = maybe mempty (encodeMessageField 1) codeLanguage <> encodeMessageField 2 codeContent + liftDecodeMessage = undefined + liftDotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim PB.String) (Single "codeLanguage") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "codeContent") [] Nothing + ] + instance Eq1 Code where liftEq = genericLiftEq instance Ord1 Code where liftCompare = genericLiftCompare instance Show1 Code where liftShowsPrec = genericLiftShowsPrec data LineBreak a = LineBreak - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 LineBreak where liftEq = genericLiftEq instance Ord1 LineBreak where liftCompare = genericLiftCompare instance Show1 LineBreak where liftShowsPrec = genericLiftShowsPrec -newtype Strikethrough a = Strikethrough [a] - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1) +newtype Strikethrough a = Strikethrough { values :: [a] } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) instance Eq1 Strikethrough where liftEq = genericLiftEq instance Ord1 Strikethrough where liftCompare = genericLiftCompare diff --git a/src/Language/PHP/Assignment.hs b/src/Language/PHP/Assignment.hs index 222e0c3d4..29bc08431 100644 --- a/src/Language/PHP/Assignment.hs +++ b/src/Language/PHP/Assignment.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds, RankNTypes, TypeOperators #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} -- FIXME module Language.PHP.Assignment ( assignment , Syntax @@ -6,10 +7,16 @@ module Language.PHP.Assignment , Term ) where -import Assigning.Assignment hiding (Assignment, Error) -import Data.Record -import Data.Sum -import Data.Syntax +import Prologue + +import Assigning.Assignment hiding (Assignment, Error) +import qualified Assigning.Assignment as Assignment +import qualified Data.Abstract.Name as Name +import qualified Data.Diff as Diff +import qualified Data.List.NonEmpty as NonEmpty +import Data.Record +import Data.Sum +import Data.Syntax ( contextualize , emptyTerm , handleError @@ -20,10 +27,6 @@ import Data.Syntax , parseError , postContextualize ) -import Language.PHP.Grammar as Grammar -import qualified Assigning.Assignment as Assignment -import qualified Data.Abstract.Name as Name -import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Syntax as Syntax import qualified Data.Syntax.Comment as Comment import qualified Data.Syntax.Declaration as Declaration @@ -32,8 +35,9 @@ import qualified Data.Syntax.Literal as Literal import qualified Data.Syntax.Statement as Statement import qualified Data.Syntax.Type as Type import qualified Data.Term as Term +import Language.PHP.Grammar as Grammar import qualified Language.PHP.Syntax as Syntax -import Prologue +import Proto3.Suite (Named (..), Named1 (..)) type Syntax = '[ Comment.Comment @@ -89,7 +93,6 @@ type Syntax = '[ , Statement.ForEach , Statement.Goto , Statement.If - , Statement.If , Statement.Match , Statement.Pattern , Statement.Return @@ -163,6 +166,11 @@ type Syntax = '[ type Term = Term.Term (Sum Syntax) (Record Location) type Assignment = Assignment.Assignment [] Grammar +-- For Protobuf serialization +instance Named1 (Sum Syntax) where nameOf1 _ = "PHPSyntax" +instance Named (Term.Term (Sum Syntax) ()) where nameOf _ = "PHPTerm" +instance Named (Diff.Diff (Sum Syntax) () ()) where nameOf _ = "PHPDiff" + -- | Assignment from AST in PHP's grammar onto a program in PHP's syntax. assignment :: Assignment Term assignment = handleError $ makeTerm <$> symbol Program <*> children (Statement.Statements <$> (bookend <$> (text <|> emptyTerm) <*> manyTerm statement <*> (text <|> emptyTerm))) <|> parseError diff --git a/src/Language/PHP/Syntax.hs b/src/Language/PHP/Syntax.hs index 9cf201ef7..d30a79ef8 100644 --- a/src/Language/PHP/Syntax.hs +++ b/src/Language/PHP/Syntax.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveAnyClass, DuplicateRecordFields #-} {-# OPTIONS_GHC -Wno-missing-export-lists #-} module Language.PHP.Syntax where @@ -6,14 +6,15 @@ import Data.Abstract.BaseError import Data.Abstract.Evaluatable import Data.Abstract.Module import Data.Abstract.Path -import qualified Data.Text as T import Data.JSON.Fields import qualified Data.Language as Language +import qualified Data.Text as T import Diffing.Algorithm import Prologue hiding (Text) +import Proto3.Suite.Class -newtype Text a = Text T.Text - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Text a = Text { value :: T.Text } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Text where liftEq = genericLiftEq instance Ord1 Text where liftCompare = genericLiftCompare @@ -21,8 +22,8 @@ instance Show1 Text where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Text -newtype VariableName a = VariableName a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype VariableName a = VariableName { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 VariableName where liftEq = genericLiftEq instance Ord1 VariableName where liftCompare = genericLiftCompare @@ -74,8 +75,8 @@ include pathTerm f = do bindAll importedEnv pure (Rval v) -newtype Require a = Require a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Require a = Require { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Require where liftEq = genericLiftEq instance Ord1 Require where liftCompare = genericLiftCompare @@ -85,8 +86,8 @@ instance Evaluatable Require where eval (Require path) = include path load -newtype RequireOnce a = RequireOnce a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype RequireOnce a = RequireOnce { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 RequireOnce where liftEq = genericLiftEq instance Ord1 RequireOnce where liftCompare = genericLiftCompare @@ -96,8 +97,8 @@ instance Evaluatable RequireOnce where eval (RequireOnce path) = include path require -newtype Include a = Include a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Include a = Include { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Include where liftEq = genericLiftEq instance Ord1 Include where liftCompare = genericLiftCompare @@ -107,8 +108,8 @@ instance Evaluatable Include where eval (Include path) = include path load -newtype IncludeOnce a = IncludeOnce a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype IncludeOnce a = IncludeOnce { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 IncludeOnce where liftEq = genericLiftEq instance Ord1 IncludeOnce where liftCompare = genericLiftCompare @@ -118,24 +119,24 @@ instance Evaluatable IncludeOnce where eval (IncludeOnce path) = include path require -newtype ArrayElement a = ArrayElement a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ArrayElement a = ArrayElement { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ArrayElement where liftEq = genericLiftEq instance Ord1 ArrayElement where liftCompare = genericLiftCompare instance Show1 ArrayElement where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ArrayElement -newtype GlobalDeclaration a = GlobalDeclaration [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype GlobalDeclaration a = GlobalDeclaration { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 GlobalDeclaration where liftEq = genericLiftEq instance Ord1 GlobalDeclaration where liftCompare = genericLiftCompare instance Show1 GlobalDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable GlobalDeclaration -newtype SimpleVariable a = SimpleVariable a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype SimpleVariable a = SimpleVariable { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 SimpleVariable where liftEq = genericLiftEq instance Ord1 SimpleVariable where liftCompare = genericLiftCompare @@ -145,31 +146,31 @@ instance Evaluatable SimpleVariable -- | TODO: Unify with TypeScript's PredefinedType newtype CastType a = CastType { _castType :: T.Text } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 CastType where liftEq = genericLiftEq instance Ord1 CastType where liftCompare = genericLiftCompare instance Show1 CastType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable CastType -newtype ErrorControl a = ErrorControl a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ErrorControl a = ErrorControl { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ErrorControl where liftEq = genericLiftEq instance Ord1 ErrorControl where liftCompare = genericLiftCompare instance Show1 ErrorControl where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ErrorControl -newtype Clone a = Clone a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Clone a = Clone { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Clone where liftEq = genericLiftEq instance Ord1 Clone where liftCompare = genericLiftCompare instance Show1 Clone where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Clone -newtype ShellCommand a = ShellCommand T.Text - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ShellCommand a = ShellCommand { value :: T.Text } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ShellCommand where liftEq = genericLiftEq instance Ord1 ShellCommand where liftCompare = genericLiftCompare @@ -178,31 +179,31 @@ instance Evaluatable ShellCommand -- | TODO: Combine with TypeScript update expression. newtype Update a = Update { _updateSubject :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Update where liftEq = genericLiftEq instance Ord1 Update where liftCompare = genericLiftCompare instance Show1 Update where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Update -newtype NewVariable a = NewVariable [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype NewVariable a = NewVariable { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 NewVariable where liftEq = genericLiftEq instance Ord1 NewVariable where liftCompare = genericLiftCompare instance Show1 NewVariable where liftShowsPrec = genericLiftShowsPrec instance Evaluatable NewVariable -newtype RelativeScope a = RelativeScope T.Text - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype RelativeScope a = RelativeScope { value :: T.Text } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 RelativeScope where liftEq = genericLiftEq instance Ord1 RelativeScope where liftCompare = genericLiftCompare instance Show1 RelativeScope where liftShowsPrec = genericLiftShowsPrec instance Evaluatable RelativeScope -data QualifiedName a = QualifiedName !a !a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data QualifiedName a = QualifiedName { name :: a, identifier :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 QualifiedName where liftEq = genericLiftEq instance Ord1 QualifiedName where liftCompare = genericLiftCompare @@ -213,8 +214,8 @@ instance Evaluatable QualifiedName where namePtr <- subtermAddress name Rval <$> evaluateInScopedEnv namePtr (subtermAddress iden) -newtype NamespaceName a = NamespaceName (NonEmpty a) - deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Diffable, FreeVariables1, Declarations1, ToJSONFields1) +newtype NamespaceName a = NamespaceName { names :: NonEmpty a } + deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Diffable, FreeVariables1, Declarations1, ToJSONFields1, Named1, Message1) instance Hashable1 NamespaceName where liftHashWithSalt = foldl instance Eq1 NamespaceName where liftEq = genericLiftEq @@ -225,32 +226,32 @@ instance Evaluatable NamespaceName where eval (NamespaceName xs) = Rval <$> foldl1 f (fmap subtermAddress xs) where f ns id = ns >>= flip evaluateInScopedEnv id -newtype ConstDeclaration a = ConstDeclaration [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ConstDeclaration a = ConstDeclaration { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ConstDeclaration where liftEq = genericLiftEq instance Ord1 ConstDeclaration where liftCompare = genericLiftCompare instance Show1 ConstDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ConstDeclaration -data ClassConstDeclaration a = ClassConstDeclaration a [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data ClassConstDeclaration a = ClassConstDeclaration { visibility :: a, elements :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ClassConstDeclaration where liftEq = genericLiftEq instance Ord1 ClassConstDeclaration where liftCompare = genericLiftCompare instance Show1 ClassConstDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ClassConstDeclaration -newtype ClassInterfaceClause a = ClassInterfaceClause [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ClassInterfaceClause a = ClassInterfaceClause { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ClassInterfaceClause where liftEq = genericLiftEq instance Ord1 ClassInterfaceClause where liftCompare = genericLiftCompare instance Show1 ClassInterfaceClause where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ClassInterfaceClause -newtype ClassBaseClause a = ClassBaseClause a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ClassBaseClause a = ClassBaseClause { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ClassBaseClause where liftEq = genericLiftEq instance Ord1 ClassBaseClause where liftCompare = genericLiftCompare @@ -258,112 +259,112 @@ instance Show1 ClassBaseClause where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ClassBaseClause -newtype UseClause a = UseClause [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype UseClause a = UseClause { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 UseClause where liftEq = genericLiftEq instance Ord1 UseClause where liftCompare = genericLiftCompare instance Show1 UseClause where liftShowsPrec = genericLiftShowsPrec instance Evaluatable UseClause -newtype ReturnType a = ReturnType a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ReturnType a = ReturnType { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ReturnType where liftEq = genericLiftEq instance Ord1 ReturnType where liftCompare = genericLiftCompare instance Show1 ReturnType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ReturnType -newtype TypeDeclaration a = TypeDeclaration a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype TypeDeclaration a = TypeDeclaration { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TypeDeclaration where liftEq = genericLiftEq instance Ord1 TypeDeclaration where liftCompare = genericLiftCompare instance Show1 TypeDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeDeclaration -newtype BaseTypeDeclaration a = BaseTypeDeclaration a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype BaseTypeDeclaration a = BaseTypeDeclaration { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 BaseTypeDeclaration where liftEq = genericLiftEq instance Ord1 BaseTypeDeclaration where liftCompare = genericLiftCompare instance Show1 BaseTypeDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable BaseTypeDeclaration -newtype ScalarType a = ScalarType T.Text - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ScalarType a = ScalarType { value :: T.Text } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ScalarType where liftEq = genericLiftEq instance Ord1 ScalarType where liftCompare = genericLiftCompare instance Show1 ScalarType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ScalarType -newtype EmptyIntrinsic a = EmptyIntrinsic a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype EmptyIntrinsic a = EmptyIntrinsic { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 EmptyIntrinsic where liftEq = genericLiftEq instance Ord1 EmptyIntrinsic where liftCompare = genericLiftCompare instance Show1 EmptyIntrinsic where liftShowsPrec = genericLiftShowsPrec instance Evaluatable EmptyIntrinsic -newtype ExitIntrinsic a = ExitIntrinsic a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ExitIntrinsic a = ExitIntrinsic { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ExitIntrinsic where liftEq = genericLiftEq instance Ord1 ExitIntrinsic where liftCompare = genericLiftCompare instance Show1 ExitIntrinsic where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ExitIntrinsic -newtype IssetIntrinsic a = IssetIntrinsic a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype IssetIntrinsic a = IssetIntrinsic { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 IssetIntrinsic where liftEq = genericLiftEq instance Ord1 IssetIntrinsic where liftCompare = genericLiftCompare instance Show1 IssetIntrinsic where liftShowsPrec = genericLiftShowsPrec instance Evaluatable IssetIntrinsic -newtype EvalIntrinsic a = EvalIntrinsic a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype EvalIntrinsic a = EvalIntrinsic { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 EvalIntrinsic where liftEq = genericLiftEq instance Ord1 EvalIntrinsic where liftCompare = genericLiftCompare instance Show1 EvalIntrinsic where liftShowsPrec = genericLiftShowsPrec instance Evaluatable EvalIntrinsic -newtype PrintIntrinsic a = PrintIntrinsic a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype PrintIntrinsic a = PrintIntrinsic { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PrintIntrinsic where liftEq = genericLiftEq instance Ord1 PrintIntrinsic where liftCompare = genericLiftCompare instance Show1 PrintIntrinsic where liftShowsPrec = genericLiftShowsPrec instance Evaluatable PrintIntrinsic -newtype NamespaceAliasingClause a = NamespaceAliasingClause a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype NamespaceAliasingClause a = NamespaceAliasingClause { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 NamespaceAliasingClause where liftEq = genericLiftEq instance Ord1 NamespaceAliasingClause where liftCompare = genericLiftCompare instance Show1 NamespaceAliasingClause where liftShowsPrec = genericLiftShowsPrec instance Evaluatable NamespaceAliasingClause -newtype NamespaceUseDeclaration a = NamespaceUseDeclaration [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype NamespaceUseDeclaration a = NamespaceUseDeclaration { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 NamespaceUseDeclaration where liftEq = genericLiftEq instance Ord1 NamespaceUseDeclaration where liftCompare = genericLiftCompare instance Show1 NamespaceUseDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable NamespaceUseDeclaration -newtype NamespaceUseClause a = NamespaceUseClause [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype NamespaceUseClause a = NamespaceUseClause { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 NamespaceUseClause where liftEq = genericLiftEq instance Ord1 NamespaceUseClause where liftCompare = genericLiftCompare instance Show1 NamespaceUseClause where liftShowsPrec = genericLiftShowsPrec instance Evaluatable NamespaceUseClause -newtype NamespaceUseGroupClause a = NamespaceUseGroupClause [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype NamespaceUseGroupClause a = NamespaceUseGroupClause { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 NamespaceUseGroupClause where liftEq = genericLiftEq instance Ord1 NamespaceUseGroupClause where liftCompare = genericLiftCompare @@ -371,7 +372,7 @@ instance Show1 NamespaceUseGroupClause where liftShowsPrec = genericLiftShowsPre instance Evaluatable NamespaceUseGroupClause data Namespace a = Namespace { namespaceName :: [a], namespaceBody :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Namespace where liftEq = genericLiftEq instance Ord1 Namespace where liftCompare = genericLiftCompare @@ -394,7 +395,7 @@ instance Evaluatable Namespace where go [] = subtermAddress namespaceBody data TraitDeclaration a = TraitDeclaration { traitName :: a, traitStatements :: [a] } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TraitDeclaration where liftEq = genericLiftEq instance Ord1 TraitDeclaration where liftCompare = genericLiftCompare @@ -402,127 +403,127 @@ instance Show1 TraitDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TraitDeclaration data AliasAs a = AliasAs { aliasAsName :: a, aliasAsModifier :: a, aliasAsClause :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 AliasAs where liftEq = genericLiftEq instance Ord1 AliasAs where liftCompare = genericLiftCompare instance Show1 AliasAs where liftShowsPrec = genericLiftShowsPrec instance Evaluatable AliasAs -data InsteadOf a = InsteadOf a a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data InsteadOf a = InsteadOf { left :: a, right :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 InsteadOf where liftEq = genericLiftEq instance Ord1 InsteadOf where liftCompare = genericLiftCompare instance Show1 InsteadOf where liftShowsPrec = genericLiftShowsPrec instance Evaluatable InsteadOf -newtype TraitUseSpecification a = TraitUseSpecification [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype TraitUseSpecification a = TraitUseSpecification { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TraitUseSpecification where liftEq = genericLiftEq instance Ord1 TraitUseSpecification where liftCompare = genericLiftCompare instance Show1 TraitUseSpecification where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TraitUseSpecification -data TraitUseClause a = TraitUseClause [a] a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data TraitUseClause a = TraitUseClause { namespace :: [a], alias :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 TraitUseClause where liftEq = genericLiftEq instance Ord1 TraitUseClause where liftCompare = genericLiftCompare instance Show1 TraitUseClause where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TraitUseClause -data DestructorDeclaration a = DestructorDeclaration [a] a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data DestructorDeclaration a = DestructorDeclaration { body:: [a], name :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 DestructorDeclaration where liftEq = genericLiftEq instance Ord1 DestructorDeclaration where liftCompare = genericLiftCompare instance Show1 DestructorDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable DestructorDeclaration -newtype Static a = Static T.Text - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Static a = Static { value :: T.Text } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Static where liftEq = genericLiftEq instance Ord1 Static where liftCompare = genericLiftCompare instance Show1 Static where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Static -newtype ClassModifier a = ClassModifier T.Text - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype ClassModifier a = ClassModifier { value :: T.Text } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ClassModifier where liftEq = genericLiftEq instance Ord1 ClassModifier where liftCompare = genericLiftCompare instance Show1 ClassModifier where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ClassModifier -data ConstructorDeclaration a = ConstructorDeclaration [a] [a] a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data ConstructorDeclaration a = ConstructorDeclaration { modifiers :: [a], parameters :: [a], body :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 ConstructorDeclaration where liftEq = genericLiftEq instance Ord1 ConstructorDeclaration where liftCompare = genericLiftCompare instance Show1 ConstructorDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable ConstructorDeclaration -data PropertyDeclaration a = PropertyDeclaration a [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data PropertyDeclaration a = PropertyDeclaration { modifier :: a, elements :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PropertyDeclaration where liftEq = genericLiftEq instance Ord1 PropertyDeclaration where liftCompare = genericLiftCompare instance Show1 PropertyDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable PropertyDeclaration -data PropertyModifier a = PropertyModifier a a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data PropertyModifier a = PropertyModifier { visibility :: a , static :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 PropertyModifier where liftEq = genericLiftEq instance Ord1 PropertyModifier where liftCompare = genericLiftCompare instance Show1 PropertyModifier where liftShowsPrec = genericLiftShowsPrec instance Evaluatable PropertyModifier -data InterfaceDeclaration a = InterfaceDeclaration a a [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data InterfaceDeclaration a = InterfaceDeclaration { name :: a, base :: a, declarations :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 InterfaceDeclaration where liftEq = genericLiftEq instance Ord1 InterfaceDeclaration where liftCompare = genericLiftCompare instance Show1 InterfaceDeclaration where liftShowsPrec = genericLiftShowsPrec instance Evaluatable InterfaceDeclaration -newtype InterfaceBaseClause a = InterfaceBaseClause [a] - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype InterfaceBaseClause a = InterfaceBaseClause { values :: [a] } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 InterfaceBaseClause where liftEq = genericLiftEq instance Ord1 InterfaceBaseClause where liftCompare = genericLiftCompare instance Show1 InterfaceBaseClause where liftShowsPrec = genericLiftShowsPrec instance Evaluatable InterfaceBaseClause -newtype Echo a = Echo a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Echo a = Echo { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Echo where liftEq = genericLiftEq instance Ord1 Echo where liftCompare = genericLiftCompare instance Show1 Echo where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Echo -newtype Unset a = Unset a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype Unset a = Unset { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Unset where liftEq = genericLiftEq instance Ord1 Unset where liftCompare = genericLiftCompare instance Show1 Unset where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Unset -data Declare a = Declare a a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +data Declare a = Declare { left :: a, right :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Declare where liftEq = genericLiftEq instance Ord1 Declare where liftCompare = genericLiftCompare instance Show1 Declare where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Declare -newtype DeclareDirective a = DeclareDirective a - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) +newtype DeclareDirective a = DeclareDirective { value :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 DeclareDirective where liftEq = genericLiftEq instance Ord1 DeclareDirective where liftCompare = genericLiftCompare @@ -530,7 +531,7 @@ instance Show1 DeclareDirective where liftShowsPrec = genericLiftShowsPrec instance Evaluatable DeclareDirective newtype LabeledStatement a = LabeledStatement { _labeledStatementIdentifier :: a } - deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable) + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 LabeledStatement where liftEq = genericLiftEq instance Ord1 LabeledStatement where liftCompare = genericLiftCompare From addc6a6c6ff06864c66d84638807f60887fc4829 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 10 Sep 2018 15:41:16 -0700 Subject: [PATCH 25/39] Fix a few more go fixtures --- .../array-with-implicit-length.diffA-B.txt | 4 +- .../array-with-implicit-length.diffB-A.txt | 4 +- .../corpus/assignment-statements.diffB-A.txt | 34 +++---- .../go/corpus/channel-types.diffA-B.txt | 91 +++++++------------ .../go/corpus/channel-types.diffB-A.txt | 91 +++++++------------ .../const-with-implicit-values.diffA-B.txt | 30 +++--- .../const-with-implicit-values.diffB-A.txt | 21 ++--- .../grouped-import-declarations.diffB-A.txt | 8 +- .../type-conversion-expressions.diffA-B.txt | 36 ++++---- .../type-conversion-expressions.diffB-A.txt | 36 ++++---- 10 files changed, 156 insertions(+), 199 deletions(-) diff --git a/test/fixtures/go/corpus/array-with-implicit-length.diffA-B.txt b/test/fixtures/go/corpus/array-with-implicit-length.diffA-B.txt index 41f9afd5e..4ebc3437e 100644 --- a/test/fixtures/go/corpus/array-with-implicit-length.diffA-B.txt +++ b/test/fixtures/go/corpus/array-with-implicit-length.diffA-B.txt @@ -11,7 +11,7 @@ (Statements { (Integer) ->(Integer) } + {+(Integer)+} { (Integer) ->(Integer) } - { (Integer) - ->(Integer) }))))) + {-(Integer)-}))))) diff --git a/test/fixtures/go/corpus/array-with-implicit-length.diffB-A.txt b/test/fixtures/go/corpus/array-with-implicit-length.diffB-A.txt index 41f9afd5e..4ebc3437e 100644 --- a/test/fixtures/go/corpus/array-with-implicit-length.diffB-A.txt +++ b/test/fixtures/go/corpus/array-with-implicit-length.diffB-A.txt @@ -11,7 +11,7 @@ (Statements { (Integer) ->(Integer) } + {+(Integer)+} { (Integer) ->(Integer) } - { (Integer) - ->(Integer) }))))) + {-(Integer)-}))))) diff --git a/test/fixtures/go/corpus/assignment-statements.diffB-A.txt b/test/fixtures/go/corpus/assignment-statements.diffB-A.txt index 5766fa839..b74799cf7 100644 --- a/test/fixtures/go/corpus/assignment-statements.diffB-A.txt +++ b/test/fixtures/go/corpus/assignment-statements.diffB-A.txt @@ -33,24 +33,16 @@ {+(Plus {+(Identifier)+} {+(Integer)+})+})+} - (Assignment - { (Identifier) - ->(Identifier) } - { (Times - {-(Identifier)-} - {-(Integer)-}) - ->(LShift + {+(Assignment + {+(Identifier)+} + {+(LShift {+(Identifier)+} - {+(Integer)+}) }) - (Assignment - { (Identifier) - ->(Identifier) } - { (Plus - {-(Identifier)-} - {-(Integer)-}) - ->(RShift + {+(Integer)+})+})+} + {+(Assignment + {+(Identifier)+} + {+(RShift {+(Identifier)+} - {+(Integer)+}) }) + {+(Integer)+})+})+} {+(Assignment {+(Identifier)+} {+(DividedBy @@ -84,6 +76,16 @@ {+(KeyValue {+(Identifier)+} {+(Integer)+})+})+})+})+})+})+} + {-(Assignment + {-(Identifier)-} + {-(Times + {-(Identifier)-} + {-(Integer)-})-})-} + {-(Assignment + {-(Identifier)-} + {-(Plus + {-(Identifier)-} + {-(Integer)-})-})-} {-(Assignment {-(Identifier)-} {-(LShift diff --git a/test/fixtures/go/corpus/channel-types.diffA-B.txt b/test/fixtures/go/corpus/channel-types.diffA-B.txt index f68810532..fef850c14 100644 --- a/test/fixtures/go/corpus/channel-types.diffA-B.txt +++ b/test/fixtures/go/corpus/channel-types.diffA-B.txt @@ -4,59 +4,38 @@ (Function (Identifier) (Statements - {+(Type - {+(Identifier)+} - {+(BidirectionalChannel - {+(ReceiveChannel - {+(Identifier)+})+})+})+} - {+(Type - {+(Identifier)+} - {+(SendChannel - {+(SendChannel - {+(Constructor - {+(Empty)+} - {+(Statements)+})+})+})+})+} - {+(Type - {+(Identifier)+} - {+(SendChannel - {+(ReceiveChannel - {+(Identifier)+})+})+})+} - {+(Type - {+(Identifier)+} - {+(ReceiveChannel - {+(ReceiveChannel - {+(Identifier)+})+})+})+} - {+(Type - {+(Identifier)+} - {+(BidirectionalChannel - {+(Parenthesized - {+(ReceiveChannel - {+(Identifier)+})+})+})+})+} - {-(Type - {-(Identifier)-} - {-(BidirectionalChannel - {-(ReceiveChannel - {-(Identifier)-})-})-})-} - {-(Type - {-(Identifier)-} - {-(SendChannel - {-(SendChannel - {-(Constructor - {-(Empty)-} - {-(Statements)-})-})-})-})-} - {-(Type - {-(Identifier)-} - {-(SendChannel - {-(ReceiveChannel - {-(Identifier)-})-})-})-} - {-(Type - {-(Identifier)-} - {-(ReceiveChannel - {-(ReceiveChannel - {-(Identifier)-})-})-})-} - {-(Type - {-(Identifier)-} - {-(BidirectionalChannel - {-(Parenthesized - {-(ReceiveChannel - {-(Identifier)-})-})-})-})-}))) + (Type + { (Identifier) + ->(Identifier) } + (BidirectionalChannel + (ReceiveChannel + { (Identifier) + ->(Identifier) }))) + (Type + { (Identifier) + ->(Identifier) } + (SendChannel + (SendChannel + (Constructor + (Empty) + (Statements))))) + (Type + { (Identifier) + ->(Identifier) } + (SendChannel + (ReceiveChannel + { (Identifier) + ->(Identifier) }))) + (Type + (Identifier) + (ReceiveChannel + (ReceiveChannel + { (Identifier) + ->(Identifier) }))) + (Type + (Identifier) + (BidirectionalChannel + (Parenthesized + (ReceiveChannel + { (Identifier) + ->(Identifier) }))))))) diff --git a/test/fixtures/go/corpus/channel-types.diffB-A.txt b/test/fixtures/go/corpus/channel-types.diffB-A.txt index f68810532..fef850c14 100644 --- a/test/fixtures/go/corpus/channel-types.diffB-A.txt +++ b/test/fixtures/go/corpus/channel-types.diffB-A.txt @@ -4,59 +4,38 @@ (Function (Identifier) (Statements - {+(Type - {+(Identifier)+} - {+(BidirectionalChannel - {+(ReceiveChannel - {+(Identifier)+})+})+})+} - {+(Type - {+(Identifier)+} - {+(SendChannel - {+(SendChannel - {+(Constructor - {+(Empty)+} - {+(Statements)+})+})+})+})+} - {+(Type - {+(Identifier)+} - {+(SendChannel - {+(ReceiveChannel - {+(Identifier)+})+})+})+} - {+(Type - {+(Identifier)+} - {+(ReceiveChannel - {+(ReceiveChannel - {+(Identifier)+})+})+})+} - {+(Type - {+(Identifier)+} - {+(BidirectionalChannel - {+(Parenthesized - {+(ReceiveChannel - {+(Identifier)+})+})+})+})+} - {-(Type - {-(Identifier)-} - {-(BidirectionalChannel - {-(ReceiveChannel - {-(Identifier)-})-})-})-} - {-(Type - {-(Identifier)-} - {-(SendChannel - {-(SendChannel - {-(Constructor - {-(Empty)-} - {-(Statements)-})-})-})-})-} - {-(Type - {-(Identifier)-} - {-(SendChannel - {-(ReceiveChannel - {-(Identifier)-})-})-})-} - {-(Type - {-(Identifier)-} - {-(ReceiveChannel - {-(ReceiveChannel - {-(Identifier)-})-})-})-} - {-(Type - {-(Identifier)-} - {-(BidirectionalChannel - {-(Parenthesized - {-(ReceiveChannel - {-(Identifier)-})-})-})-})-}))) + (Type + { (Identifier) + ->(Identifier) } + (BidirectionalChannel + (ReceiveChannel + { (Identifier) + ->(Identifier) }))) + (Type + { (Identifier) + ->(Identifier) } + (SendChannel + (SendChannel + (Constructor + (Empty) + (Statements))))) + (Type + { (Identifier) + ->(Identifier) } + (SendChannel + (ReceiveChannel + { (Identifier) + ->(Identifier) }))) + (Type + (Identifier) + (ReceiveChannel + (ReceiveChannel + { (Identifier) + ->(Identifier) }))) + (Type + (Identifier) + (BidirectionalChannel + (Parenthesized + (ReceiveChannel + { (Identifier) + ->(Identifier) }))))))) diff --git a/test/fixtures/go/corpus/const-with-implicit-values.diffA-B.txt b/test/fixtures/go/corpus/const-with-implicit-values.diffA-B.txt index 5d02d46a5..3253e8afd 100644 --- a/test/fixtures/go/corpus/const-with-implicit-values.diffA-B.txt +++ b/test/fixtures/go/corpus/const-with-implicit-values.diffA-B.txt @@ -4,21 +4,15 @@ (Function (Identifier) (Statements - {+(Assignment - {+(Identifier)+} - {+(Identifier)+})+} - {+(Assignment - {+(Identifier)+} - {+(Statements)+})+} - {+(Assignment - {+(Identifier)+} - {+(Statements)+})+} - {-(Assignment - {-(Identifier)-} - {-(Identifier)-})-} - {-(Assignment - {-(Identifier)-} - {-(Statements)-})-} - {-(Assignment - {-(Identifier)-} - {-(Statements)-})-}))) + (Assignment + { (Identifier) + ->(Identifier) } + (Identifier)) + (Assignment + { (Identifier) + ->(Identifier) } + (Statements)) + (Assignment + { (Identifier) + ->(Identifier) } + (Statements))))) diff --git a/test/fixtures/go/corpus/const-with-implicit-values.diffB-A.txt b/test/fixtures/go/corpus/const-with-implicit-values.diffB-A.txt index 26c5920d5..3253e8afd 100644 --- a/test/fixtures/go/corpus/const-with-implicit-values.diffB-A.txt +++ b/test/fixtures/go/corpus/const-with-implicit-values.diffB-A.txt @@ -4,20 +4,15 @@ (Function (Identifier) (Statements - {+(Assignment - {+(Identifier)+} - {+(Identifier)+})+} - {+(Assignment - {+(Identifier)+} - {+(Statements)+})+} (Assignment { (Identifier) ->(Identifier) } + (Identifier)) + (Assignment { (Identifier) - ->(Statements) }) - {-(Assignment - {-(Identifier)-} - {-(Statements)-})-} - {-(Assignment - {-(Identifier)-} - {-(Statements)-})-}))) + ->(Identifier) } + (Statements)) + (Assignment + { (Identifier) + ->(Identifier) } + (Statements))))) diff --git a/test/fixtures/go/corpus/grouped-import-declarations.diffB-A.txt b/test/fixtures/go/corpus/grouped-import-declarations.diffB-A.txt index dec35ee70..30c0f56e6 100644 --- a/test/fixtures/go/corpus/grouped-import-declarations.diffB-A.txt +++ b/test/fixtures/go/corpus/grouped-import-declarations.diffB-A.txt @@ -6,10 +6,10 @@ {+(Identifier)+})+} {+(Import {+(TextElement)+})+} - { (QualifiedImport - {-(Identifier)-}) - ->(QualifiedImport - {+(Identifier)+}) } + {+(QualifiedImport + {+(Identifier)+})+} + {-(QualifiedImport + {-(Identifier)-})-} {-(Import {-(TextElement)-})-} {-(QualifiedImport diff --git a/test/fixtures/go/corpus/type-conversion-expressions.diffA-B.txt b/test/fixtures/go/corpus/type-conversion-expressions.diffA-B.txt index d10e5e339..eb3323ad2 100644 --- a/test/fixtures/go/corpus/type-conversion-expressions.diffA-B.txt +++ b/test/fixtures/go/corpus/type-conversion-expressions.diffA-B.txt @@ -70,19 +70,23 @@ {-(Identifier)-}) ->(MemberAccess {+(Identifier)+}) }) - (Call - { (MemberAccess - {-(Identifier)-}) - ->(MemberAccess - {+(Identifier)+}) } - { (Identifier) - ->(Identifier) } - (Empty)) - (Call - { (MemberAccess - {-(Identifier)-}) - ->(MemberAccess - {+(Identifier)+}) } - { (Identifier) - ->(Identifier) } - (Empty))))) + {+(Call + {+(MemberAccess + {+(Identifier)+})+} + {+(Identifier)+} + {+(Empty)+})+} + {+(Call + {+(MemberAccess + {+(Identifier)+})+} + {+(Identifier)+} + {+(Empty)+})+} + {-(Call + {-(MemberAccess + {-(Identifier)-})-} + {-(Identifier)-} + {-(Empty)-})-} + {-(Call + {-(MemberAccess + {-(Identifier)-})-} + {-(Identifier)-} + {-(Empty)-})-}))) diff --git a/test/fixtures/go/corpus/type-conversion-expressions.diffB-A.txt b/test/fixtures/go/corpus/type-conversion-expressions.diffB-A.txt index d10e5e339..eb3323ad2 100644 --- a/test/fixtures/go/corpus/type-conversion-expressions.diffB-A.txt +++ b/test/fixtures/go/corpus/type-conversion-expressions.diffB-A.txt @@ -70,19 +70,23 @@ {-(Identifier)-}) ->(MemberAccess {+(Identifier)+}) }) - (Call - { (MemberAccess - {-(Identifier)-}) - ->(MemberAccess - {+(Identifier)+}) } - { (Identifier) - ->(Identifier) } - (Empty)) - (Call - { (MemberAccess - {-(Identifier)-}) - ->(MemberAccess - {+(Identifier)+}) } - { (Identifier) - ->(Identifier) } - (Empty))))) + {+(Call + {+(MemberAccess + {+(Identifier)+})+} + {+(Identifier)+} + {+(Empty)+})+} + {+(Call + {+(MemberAccess + {+(Identifier)+})+} + {+(Identifier)+} + {+(Empty)+})+} + {-(Call + {-(MemberAccess + {-(Identifier)-})-} + {-(Identifier)-} + {-(Empty)-})-} + {-(Call + {-(MemberAccess + {-(Identifier)-})-} + {-(Identifier)-} + {-(Empty)-})-}))) From 6b3401eb9604e917bd6ae28908fb6ddb2a3bf5b8 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 10 Sep 2018 15:50:24 -0700 Subject: [PATCH 26/39] Lints --- src/Data/Term.hs | 2 +- src/Language/PHP/Assignment.hs | 1 - src/Language/Ruby/Assignment.hs | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Data/Term.hs b/src/Data/Term.hs index f872ab364..0c45e97ee 100644 --- a/src/Data/Term.hs +++ b/src/Data/Term.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DeriveAnyClass, RankNTypes, TypeFamilies, TypeOperators, ScopedTypeVariables, FunctionalDependencies #-} +{-# LANGUAGE RankNTypes, TypeFamilies, TypeOperators, ScopedTypeVariables, FunctionalDependencies #-} module Data.Term ( Term(..) , termIn diff --git a/src/Language/PHP/Assignment.hs b/src/Language/PHP/Assignment.hs index 29bc08431..164f9a538 100644 --- a/src/Language/PHP/Assignment.hs +++ b/src/Language/PHP/Assignment.hs @@ -15,7 +15,6 @@ import qualified Data.Abstract.Name as Name import qualified Data.Diff as Diff import qualified Data.List.NonEmpty as NonEmpty import Data.Record -import Data.Sum import Data.Syntax ( contextualize , emptyTerm diff --git a/src/Language/Ruby/Assignment.hs b/src/Language/Ruby/Assignment.hs index 0bceddef6..46ec60dd1 100644 --- a/src/Language/Ruby/Assignment.hs +++ b/src/Language/Ruby/Assignment.hs @@ -15,7 +15,6 @@ import Data.Abstract.Name (name) import Data.List (elem) import qualified Data.List.NonEmpty as NonEmpty import Data.Record -import Data.Sum import Data.Syntax ( contextualize , emptyTerm From 64ca4e2c67331789541f91198643de4edb9b3279 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 10 Sep 2018 17:15:46 -0700 Subject: [PATCH 27/39] Clean up the cleanup --- proto/code_analysis.proto | 10 +++++++--- proto/terms.proto | 2 +- src/Data/Proto/ParseTree.hs | 10 +++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/proto/code_analysis.proto b/proto/code_analysis.proto index 569504ab5..b0518b34d 100644 --- a/proto/code_analysis.proto +++ b/proto/code_analysis.proto @@ -51,14 +51,18 @@ message ParseTreeRequest { repeated Blob blobs = 1; } +// A ParseTreeResponse contains a list of syntax trees represented as adjacency +// graphs, one for each blob passed in the request. message ParseTreeGraphResponse { - ParseTreeGraph response = 1; + // The list of graphs. + repeated ParseTreeGraph graphs = 1; + // Entire response failed (e.g. a timeout) DebugInfo error_info = 2; } message ParseTreeGraph { - repeated TermGraph graphs = 1; - repeated DebugInfo error_info = 2; + TermGraph graph = 1; + string error = 2; } // A ParseTreeResponse contains a list of syntax trees, one for each blob passed diff --git a/proto/terms.proto b/proto/terms.proto index b13b0e7f1..7612ed33a 100644 --- a/proto/terms.proto +++ b/proto/terms.proto @@ -20,8 +20,8 @@ option go_package = "github.com/semantic/terms;types"; message ParseTree { Language language = 1; string path = 2; - string error = 3; oneof response_type { + string error = 3; goterm.GoTerm go_tree = 4; haskellterm.HaskellTerm haskell_tree = 5; javaterm.JavaTerm java_tree = 6; diff --git a/src/Data/Proto/ParseTree.hs b/src/Data/Proto/ParseTree.hs index 3b8f94193..04211e0bc 100644 --- a/src/Data/Proto/ParseTree.hs +++ b/src/Data/Proto/ParseTree.hs @@ -32,7 +32,6 @@ data ParseTree = ParseTree { language :: Language , path :: FilePath - , error :: String -- TODO: make parse of oneof error , responseType :: Maybe ResponseType } deriving (Eq, Show, Generic, Named) @@ -40,8 +39,8 @@ instance Message ParseTree where encodeMessage _ ParseTree{..} = encodeMessageField 1 language <> encodeMessageField 2 path - <> encodeMessageField 3 error <> case responseType of + Just (ParseError x) -> Encode.embedded 3 (encodeMessageField 1 x) Just (GoResponse x) -> Encode.embedded 4 (encodeMessage 1 x) Just (HaskellResponse x) -> Encode.embedded 5 (encodeMessage 1 x) Just (JavaResponse x) -> Encode.embedded 6 (encodeMessage 1 x) @@ -56,9 +55,9 @@ instance Message ParseTree where dotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim . Named $ Single "Language") (Single "language") [] Nothing , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "path") [] Nothing - , DotProtoMessageField $ DotProtoField 3 (Prim PB.String) (Single "error") [] Nothing , DotProtoMessageOneOf (Single "response_type") - [ DotProtoField 4 (Prim . Named $ Dots (Path ["goterm", "GoTerm"])) (Single "go_tree") [] Nothing + [ DotProtoField 3 (Prim PB.String) (Single "error") [] Nothing + , DotProtoField 4 (Prim . Named $ Dots (Path ["goterm", "GoTerm"])) (Single "go_tree") [] Nothing , DotProtoField 5 (Prim . Named $ Dots (Path ["haskellterm", "HaskellTerm"])) (Single "haskell_tree") [] Nothing , DotProtoField 6 (Prim . Named $ Dots (Path ["javaterm", "JavaTerm"])) (Single "java_tree") [] Nothing , DotProtoField 7 (Prim . Named $ Dots (Path ["jsonterm", "JSONTerm"])) (Single "json_tree") [] Nothing @@ -71,7 +70,8 @@ instance Message ParseTree where ] data ResponseType - = GoResponse GoTerm + = ParseError String + | GoResponse GoTerm | HaskellResponse HaskellTerm | JavaResponse JavaTerm | JSONResponse JSONTerm From 8096bfc8f7707f79a61cc97bb076330c9dc93154 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 10 Sep 2018 17:28:42 -0700 Subject: [PATCH 28/39] Annotations in adj list rep (grpc) --- proto/types.proto | 1 + src/Data/Graph/TermVertex.hs | 25 +++++++++++++++---------- src/Rendering/Graph.hs | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/proto/types.proto b/proto/types.proto index 584d82967..a4a97d1ec 100644 --- a/proto/types.proto +++ b/proto/types.proto @@ -139,6 +139,7 @@ message TermEdge { message TermVertex { int64 id = 1; string name = 2; + TermAnnotation annotation = 3; } message TermAnnotation { diff --git a/src/Data/Graph/TermVertex.hs b/src/Data/Graph/TermVertex.hs index d2dba9cc3..b33a62100 100644 --- a/src/Data/Graph/TermVertex.hs +++ b/src/Data/Graph/TermVertex.hs @@ -23,8 +23,7 @@ data TermVertex = TermVertex { vertexId :: Int , vertexTermName :: String - , vertexRange :: Range - , vertexSpan :: Span + , vertexAnnotation :: TermAnnotation } deriving (Eq, Ord, Show, Generic, Named) data TermAnnotation @@ -56,12 +55,20 @@ instance Message (Edge TermVertex) where ] instance Message TermVertex where - encodeMessage _ TermVertex{..} = encodeMessageField 1 vertexId <> encodeMessageField 2 vertexTermName -- Encode.embedded 1 (encodeMessage 0 vertexId) <> Encode.embedded 2 (encodeMessage 0 vertexTermName) - decodeMessage _ = TermVertex <$> Decode.at decodeMessageField 1 <*> Decode.at decodeMessageField 2 <*> pure lowerBound <*> pure lowerBound -- TODO <*> embeddedAt (decodeMessage 0) 1 <*> embeddedAt (decodeMessage 0) 2 + encodeMessage _ TermVertex{..} + = encodeMessageField 1 vertexId + <> encodeMessageField 2 vertexTermName + <> Encode.embedded 3 (encodeMessage 0 vertexAnnotation) + decodeMessage _ + = TermVertex + <$> Decode.at decodeMessageField 1 + <*> Decode.at decodeMessageField 2 + <*> embeddedAt (decodeMessage 0) 3 where embeddedAt parser = Decode.at (Decode.embedded'' parser) dotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "id") [] Nothing , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "name") [] Nothing + , DotProtoMessageField $ DotProtoField 3 (Prim . Named $ Single "TermAnnotation") (Single "annotation") [] Nothing ] instance VertexTag TermVertex where uniqueTag = vertexId @@ -69,14 +76,12 @@ instance VertexTag TermVertex where uniqueTag = vertexId instance ToJSON TermVertex where toJSON TermVertex{..} = object $ [ "id" .= vertexId - , "term" .= vertexTermName ] - <> toJSONFields vertexRange - <> toJSONFields vertexSpan + , "term" .= vertexTermName + ] <> toJSONFields vertexAnnotation toEncoding TermVertex{..} = pairs . fold $ "id" .= vertexId - : "name" .= vertexTermName - : toJSONFields vertexRange - <> toJSONFields vertexSpan + : "term" .= vertexTermName + : toJSONFields vertexAnnotation instance Message TermAnnotation where encodeMessage _ TermAnnotation{..} = Encode.embedded 1 (encodeMessage 0 range) <> Encode.embedded 2 (encodeMessage 0 span) diff --git a/src/Rendering/Graph.hs b/src/Rendering/Graph.hs index d29d0170f..db4526b22 100644 --- a/src/Rendering/Graph.hs +++ b/src/Rendering/Graph.hs @@ -68,7 +68,7 @@ instance (ConstructorName syntax, Foldable syntax, HasField fields Range, HasFie termAlgebra (In ann syntax) = do i <- fresh parent <- ask - let root = vertex (TermVertex i (constructorName syntax) (getField ann) (getField ann)) + let root = vertex (TermVertex i (constructorName syntax) (TermAnnotation (getField ann) (getField ann))) subGraph <- foldl' (\acc x -> overlay <$> acc <*> local (const root) x) (pure mempty) syntax pure (parent `connect` root `overlay` subGraph) From b985b155528fb72d2ebb0d066fcfec452241d976 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Mon, 10 Sep 2018 17:32:58 -0700 Subject: [PATCH 29/39] Always with the lints --- src/Data/Graph/DiffVertex.hs | 3 --- src/Language/Markdown/Syntax.hs | 7 +++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Data/Graph/DiffVertex.hs b/src/Data/Graph/DiffVertex.hs index 432a40767..7725ba826 100644 --- a/src/Data/Graph/DiffVertex.hs +++ b/src/Data/Graph/DiffVertex.hs @@ -11,12 +11,9 @@ module Data.Graph.DiffVertex , TermAnnotation(..) ) where -import Prologue import Data.Graph import Data.Graph.TermVertex import Data.Aeson -import Data.Range -import Data.Span import Data.JSON.Fields import qualified Data.Text as T diff --git a/src/Language/Markdown/Syntax.hs b/src/Language/Markdown/Syntax.hs index 5b006537f..2bcb68403 100644 --- a/src/Language/Markdown/Syntax.hs +++ b/src/Language/Markdown/Syntax.hs @@ -8,7 +8,6 @@ import Diffing.Algorithm import Prologue hiding (Text) import Proto3.Suite import qualified Proto3.Suite as PB -import qualified Proto3.Wire.Encode as Encode newtype Document a = Document { values :: [a] } deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1, Message1) @@ -118,7 +117,7 @@ data Link a = Link { linkURL :: T.Text, linkTitle :: Maybe T.Text } deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1) instance Message1 Link where - liftEncodeMessage _ num Link{..} = encodeMessageField 1 linkURL <> maybe mempty (encodeMessageField 2) linkTitle + liftEncodeMessage _ _ Link{..} = encodeMessageField 1 linkURL <> maybe mempty (encodeMessageField 2) linkTitle liftDecodeMessage = undefined liftDotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim PB.String) (Single "linkUrl") [] Nothing @@ -133,7 +132,7 @@ data Image a = Image { imageURL :: T.Text, imageTitle :: Maybe T.Text } deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1) instance Message1 Image where - liftEncodeMessage _ num Image{..} = encodeMessageField 1 imageURL <> maybe mempty (encodeMessageField 2) imageTitle + liftEncodeMessage _ _ Image{..} = encodeMessageField 1 imageURL <> maybe mempty (encodeMessageField 2) imageTitle liftDecodeMessage = undefined liftDotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim PB.String) (Single "imageURL") [] Nothing @@ -148,7 +147,7 @@ data Code a = Code { codeLanguage :: Maybe T.Text, codeContent :: T.Text } deriving (Eq, Ord, Show, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1, Named1) instance Message1 Code where - liftEncodeMessage _ num Code{..} = maybe mempty (encodeMessageField 1) codeLanguage <> encodeMessageField 2 codeContent + liftEncodeMessage _ _ Code{..} = maybe mempty (encodeMessageField 1) codeLanguage <> encodeMessageField 2 codeContent liftDecodeMessage = undefined liftDotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim PB.String) (Single "codeLanguage") [] Nothing From 2a0f69f2257fd6f6521ba8dd1ab1645c77dc1c50 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 11 Sep 2018 07:30:23 -0700 Subject: [PATCH 30/39] Extra import --- src/Data/Range.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Data/Range.hs b/src/Data/Range.hs index f47fcc7b3..7dba51c39 100644 --- a/src/Data/Range.hs +++ b/src/Data/Range.hs @@ -14,7 +14,6 @@ import Data.Aeson import Data.JSON.Fields import Proto3.Suite import Proto3.Wire.Decode as Decode -import Proto3.Wire.Encode as Encode -- | A half-open interval of integers, defined by start & end indices. data Range = Range { start :: {-# UNPACK #-} !Int, end :: {-# UNPACK #-} !Int } From f8f85d17f01cf18f0c145524fbf2b0d2818f296b Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 11 Sep 2018 07:53:18 -0700 Subject: [PATCH 31/39] Fix warnings --- src/Data/Graph/ControlFlowVertex.hs | 1 - src/Language/Markdown/Assignment.hs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Data/Graph/ControlFlowVertex.hs b/src/Data/Graph/ControlFlowVertex.hs index ea7b3cae1..0901dd363 100644 --- a/src/Data/Graph/ControlFlowVertex.hs +++ b/src/Data/Graph/ControlFlowVertex.hs @@ -33,7 +33,6 @@ import GHC.Exts (fromList) import Prologue hiding (packageName) import Proto3.Suite import qualified Proto3.Suite as PB -import qualified Proto3.Wire.Decode as Decode import qualified Proto3.Wire.Encode as Encode -- | A vertex of representing some node in a control flow graph. diff --git a/src/Language/Markdown/Assignment.hs b/src/Language/Markdown/Assignment.hs index c926ef77b..306bdc954 100644 --- a/src/Language/Markdown/Assignment.hs +++ b/src/Language/Markdown/Assignment.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds, RankNTypes, TypeOperators #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} -- FIXME module Language.Markdown.Assignment ( assignment , Syntax @@ -12,7 +13,6 @@ import Assigning.Assignment hiding (Assignment, Error) import qualified Assigning.Assignment as Assignment import qualified CMarkGFM import Data.Record -import Data.Sum import Data.Syntax (makeTerm) import qualified Data.Syntax as Syntax import qualified Data.Term as Term From 2e48678e6bd8d7a41a418e242df8ddc539e66228 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 11 Sep 2018 10:32:29 -0700 Subject: [PATCH 32/39] Rework diff grpc api as well, enable for all supported langauges --- proto/code_analysis.proto | 95 ++--- proto/go_diff.proto | 619 +++++++++++++++++++++++++++ proto/haskell_diff.proto | 800 +++++++++++++++++++++++++++++++++++ proto/java_diff.proto | 660 +++++++++++++++++++++++++++++ proto/json_diff.proto | 78 ++++ proto/markdown_diff.proto | 145 +++++++ proto/php_diff.proto | 723 +++++++++++++++++++++++++++++++ proto/terms.proto | 28 ++ semantic.cabal | 1 + src/Data/Graph/DiffVertex.hs | 2 - src/Data/Proto/DiffTree.hs | 93 ++++ src/Data/Proto/ParseTree.hs | 31 +- 12 files changed, 3204 insertions(+), 71 deletions(-) create mode 100644 proto/go_diff.proto create mode 100644 proto/haskell_diff.proto create mode 100644 proto/java_diff.proto create mode 100644 proto/json_diff.proto create mode 100644 proto/markdown_diff.proto create mode 100644 proto/php_diff.proto create mode 100644 src/Data/Proto/DiffTree.hs diff --git a/proto/code_analysis.proto b/proto/code_analysis.proto index b0518b34d..ca2f8eb7b 100644 --- a/proto/code_analysis.proto +++ b/proto/code_analysis.proto @@ -2,10 +2,6 @@ syntax = "proto3"; package github.semantic; -import "python_diff.proto"; -import "ruby_diff.proto"; -import "typescript_diff.proto"; - import "types.proto"; import "terms.proto"; import "error_details.proto"; @@ -51,6 +47,16 @@ message ParseTreeRequest { repeated Blob blobs = 1; } + +// A ParseTreeResponse contains a list of syntax trees, one for each blob passed +// in the request. +message ParseTreeResponse { + // The list of trees. + repeated ParseTree trees = 1; + // Entire response failed (e.g. a timeout) + DebugInfo error_info = 2; +} + // A ParseTreeResponse contains a list of syntax trees represented as adjacency // graphs, one for each blob passed in the request. message ParseTreeGraphResponse { @@ -65,17 +71,18 @@ message ParseTreeGraph { string error = 2; } -// A ParseTreeResponse contains a list of syntax trees, one for each blob passed -// in the request. -message ParseTreeResponse { - // The list of trees. - repeated ParseTree trees = 1; - // Entire response failed (e.g. a timeout) +// Diff Request & Responses +// +message DiffTreeRequest { + repeated BlobPair blobPairs = 1; +} + +message DiffTreeResponse { + repeated DiffTree diffs = 1; DebugInfo error_info = 2; } -// Diff Request & Responses -// +// Diff summaries message SummarizeDiffRequest { repeated BlobPair blobPairs = 1; } @@ -86,49 +93,6 @@ message SummarizeDiffResponse { DebugInfo error_info = 3; } -message DiffTreeRequest { - repeated BlobPair blobPairs = 1; -} - -message DiffTreeResponse { - oneof response_type { - RubyDiffResponse ruby = 1; - PythonDiffResponse python = 2; - TypeScriptDiffResponse typescript = 3; - } - DebugInfo error_info = 4; -} - -message RubyDiffResponse { - repeated rubydiff.RubyDiff diffs = 1; -} - -message PythonDiffResponse { - repeated pythondiff.PythonDiff diffs = 1; -} - -message TypeScriptDiffResponse { - repeated typescriptdiff.TypeScriptDiff diffs = 1; -} - -message CallGraphRequest { - Project project = 1; -} - -message CallGraphResponse { - ControlFlowGraph graph = 1; - DebugInfo error_info = 2; -} - -message ImportGraphRequest { - Project project = 1; -} - -message ImportGraphResponse { - ControlFlowGraph graph = 1; - DebugInfo error_info = 2; -} - message DiffSummary { string term = 1; string name = 2; @@ -142,6 +106,27 @@ message ParseError { string language = 3; } +// Call Graphs +message CallGraphRequest { + Project project = 1; +} + +message CallGraphResponse { + ControlFlowGraph graph = 1; + DebugInfo error_info = 2; +} + +// Import Graphs +message ImportGraphRequest { + Project project = 1; +} + +message ImportGraphResponse { + ControlFlowGraph graph = 1; + DebugInfo error_info = 2; +} + +// Health Check message HealthCheckRequest { string service = 1; } diff --git a/proto/go_diff.proto b/proto/go_diff.proto new file mode 100644 index 000000000..44ed6e773 --- /dev/null +++ b/proto/go_diff.proto @@ -0,0 +1,619 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.godiff; + +import "types.proto"; + +option java_package = "com.github.semantic.godiff"; +option go_package = "github.com/semantic/godiff;go"; + +message GoDiff { + oneof diff { + Merge merge = 1; + Delete delete = 2; + Insert insert = 3; + Replace replace = 4; + } + message Merge { + GoSyntax syntax = 1; + } + message Delete { + GoSyntax before = 1; + } + message Insert { + GoSyntax after = 1; + } + message Replace { + GoSyntax before = 1; + GoSyntax after = 2; + } +} + +message GoSyntax { + oneof syntax { + Comment comment = 1; + Constructor constructor = 2; + Function function = 3; + Method method = 4; + MethodSignature methodSignature = 5; + Type type = 6; + TypeAlias typeAlias = 7; + Plus plus = 8; + Minus minus = 9; + Times times = 10; + DividedBy dividedBy = 11; + Modulo modulo = 12; + Power power = 13; + Negate negate = 14; + FloorDivision floorDivision = 15; + BOr bOr = 16; + BAnd bAnd = 17; + BXOr bXOr = 18; + LShift lShift = 19; + RShift rShift = 20; + UnsignedRShift unsignedRShift = 21; + Complement complement = 22; + Call call = 23; + LessThan lessThan = 24; + LessThanEqual lessThanEqual = 25; + GreaterThan greaterThan = 26; + GreaterThanEqual greaterThanEqual = 27; + Equal equal = 28; + StrictEqual strictEqual = 29; + Comparison comparison = 30; + Subscript subscript = 31; + Member member = 32; + PostDecrement postDecrement = 33; + PostIncrement postIncrement = 34; + MemberAccess memberAccess = 35; + And and = 36; + Not not = 37; + Or or = 38; + XOr xOr = 39; + Composite composite = 40; + DefaultPattern defaultPattern = 41; + Defer defer = 42; + Field field = 43; + Go go = 44; + Label label = 45; + Package package = 46; + Receive receive = 47; + ReceiveOperator receiveOperator = 48; + Rune rune = 49; + Select select = 50; + Send send = 51; + Slice slice = 52; + TypeAssertion typeAssertion = 53; + TypeConversion typeConversion = 54; + TypeSwitch typeSwitch = 55; + TypeSwitchGuard typeSwitchGuard = 56; + Variadic variadic = 57; + BidirectionalChannel bidirectionalChannel = 58; + ReceiveChannel receiveChannel = 59; + SendChannel sendChannel = 60; + Import import = 61; + QualifiedImport qualifiedImport = 62; + SideEffectImport sideEffectImport = 63; + Array array = 64; + Complex complex = 65; + Float float = 66; + Hash hash = 67; + Integer integer = 68; + KeyValue keyValue = 69; + Pointer pointer = 70; + Reference reference = 71; + TextElement textElement = 72; + Assignment assignment = 73; + Break break = 74; + Continue continue = 75; + For for = 76; + ForEach forEach = 77; + Goto goto = 78; + If if = 79; + Match match = 80; + NoOp noOp = 81; + Pattern pattern = 82; + Return return = 83; + Statements statements = 84; + Context context = 85; + Error error = 86; + Empty empty = 87; + Identifier identifier = 88; + Annotation annotation = 89; + TypeArray typeArray = 90; + TypeFunction typeFunction = 91; + Interface interface = 92; + Map map = 93; + Parenthesized parenthesized = 94; + TypePointer typePointer = 95; + TypeSlice typeSlice = 96; + List list = 97; + String string = 98; + EscapeSequence escapeSequence = 99; + } +} + +message Comment { + string commentContent = 1; +} + +message Constructor { + repeated GoDiff constructorContext = 1; + GoDiff constructorName = 2; + GoDiff constructorFields = 3; +} + +message Function { + repeated GoDiff functionContext = 1; + GoDiff functionName = 2; + repeated GoDiff functionParameters = 3; + GoDiff functionBody = 4; +} + +message Method { + repeated GoDiff methodContext = 1; + GoDiff methodReceiver = 2; + GoDiff methodName = 3; + repeated GoDiff methodParameters = 4; + GoDiff methodBody = 5; +} + +message MethodSignature { + repeated GoDiff methodSignatureContext = 1; + GoDiff methodSignatureName = 2; + repeated GoDiff methodSignatureParameters = 3; +} + +message Type { + GoDiff typeName = 1; + GoDiff typeKind = 2; +} + +message TypeAlias { + repeated GoDiff typeAliasContext = 1; + GoDiff typeAliasIdentifier = 2; + GoDiff typeAliasKind = 3; +} + +message Plus { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message Minus { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message Times { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message DividedBy { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message Modulo { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message Power { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message Negate { + GoDiff value = 1; +} + +message FloorDivision { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message BOr { + GoDiff left = 1; + GoDiff right = 2; +} + +message BAnd { + GoDiff left = 1; + GoDiff right = 2; +} + +message BXOr { + GoDiff left = 1; + GoDiff right = 2; +} + +message LShift { + GoDiff left = 1; + GoDiff right = 2; +} + +message RShift { + GoDiff left = 1; + GoDiff right = 2; +} + +message UnsignedRShift { + GoDiff left = 1; + GoDiff right = 2; +} + +message Complement { + GoDiff value = 1; +} + +message Call { + repeated GoDiff callContext = 1; + GoDiff callFunction = 2; + repeated GoDiff callParams = 3; + GoDiff callBlock = 4; +} + +message LessThan { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message LessThanEqual { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message GreaterThan { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message GreaterThanEqual { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message Equal { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message StrictEqual { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message Comparison { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message Subscript { + GoDiff lhs = 1; + repeated GoDiff rhs = 2; +} + +message Member { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message PostDecrement { + GoDiff value = 1; +} + +message PostIncrement { + GoDiff value = 1; +} + +message MemberAccess { + GoDiff lhs = 1; + bytes rhs = 2; +} + +message And { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message Not { + GoDiff value = 1; +} + +message Or { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message XOr { + GoDiff lhs = 1; + GoDiff rhs = 2; +} + +message Composite { + GoDiff compositeType = 1; + GoDiff compositeElement = 2; +} + +message DefaultPattern { + GoDiff defaultPatternBody = 1; +} + +message Defer { + GoDiff deferBody = 1; +} + +message Field { + repeated GoDiff fieldContext = 1; + GoDiff fieldName = 2; +} + +message Go { + GoDiff goBody = 1; +} + +message Label { + GoDiff labelName = 1; + GoDiff labelStatement = 2; +} + +message Package { + GoDiff packageName = 1; + repeated GoDiff packageContents = 2; +} + +message Receive { + GoDiff receiveSubject = 1; + GoDiff receiveExpression = 2; +} + +message ReceiveOperator { + GoDiff value = 1; +} + +message Rune { + string runeLiteral = 1; +} + +message Select { + GoDiff selectCases = 1; +} + +message Send { + GoDiff sendReceiver = 1; + GoDiff sendValue = 2; +} + +message Slice { + GoDiff sliceName = 1; + GoDiff sliceLow = 2; + GoDiff sliceHigh = 3; + GoDiff sliceCapacity = 4; +} + +message TypeAssertion { + GoDiff typeAssertionSubject = 1; + GoDiff typeAssertionType = 2; +} + +message TypeConversion { + GoDiff typeConversionType = 1; + GoDiff typeConversionSubject = 2; +} + +message TypeSwitch { + GoDiff typeSwitchSubject = 1; + GoDiff typeSwitchCases = 2; +} + +message TypeSwitchGuard { + GoDiff typeSwitchGuardSubject = 1; +} + +message Variadic { + repeated GoDiff variadicContext = 1; + GoDiff variadicIdentifier = 2; +} + +message BidirectionalChannel { + GoDiff value = 1; +} + +message ReceiveChannel { + GoDiff value = 1; +} + +message SendChannel { + GoDiff value = 1; +} + +message Import { + ImportPath importFrom = 1; + GoDiff importWildcardToken = 2; +} + +message QualifiedImport { + ImportPath qualifiedImportFrom = 1; + GoDiff qualifiedImportAlias = 2; +} + +message SideEffectImport { + ImportPath sideEffectImportFrom = 1; + GoDiff sideEffectImportToken = 2; +} + +message Array { + repeated GoDiff arrayElements = 1; +} + +message Complex { + string value = 1; +} + +message Float { + string floatContent = 1; +} + +message Hash { + repeated GoDiff hashElements = 1; +} + +message Integer { + string integerContent = 1; +} + +message KeyValue { + GoDiff key = 1; + GoDiff value = 2; +} + +message Pointer { + GoDiff value = 1; +} + +message Reference { + GoDiff value = 1; +} + +message TextElement { + string textElementContent = 1; +} + +message Assignment { + repeated GoDiff assignmentContext = 1; + GoDiff assignmentTarget = 2; + GoDiff assignmentValue = 3; +} + +message Break { + GoDiff value = 1; +} + +message Continue { + GoDiff value = 1; +} + +message For { + GoDiff forBefore = 1; + GoDiff forCondition = 2; + GoDiff forStep = 3; + GoDiff forBody = 4; +} + +message ForEach { + GoDiff forEachBinding = 1; + GoDiff forEachSubject = 2; + GoDiff forEachBody = 3; +} + +message Goto { + GoDiff gotoLocation = 1; +} + +message If { + GoDiff ifCondition = 1; + GoDiff ifThenBody = 2; + GoDiff ifElseBody = 3; +} + +message Match { + GoDiff matchSubject = 1; + GoDiff matchPatterns = 2; +} + +message NoOp { + GoDiff value = 1; +} + +message Pattern { + GoDiff value = 1; + GoDiff patternBody = 2; +} + +message Return { + GoDiff value = 1; +} + +message Statements { + repeated GoDiff statements = 1; +} + +message Context { + repeated GoDiff contextTerms = 1; + GoDiff contextSubject = 2; +} + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated GoDiff errorChildren = 4; +} + +message Empty { } + +message Identifier { + bytes name = 1; +} + +message Annotation { + GoDiff annotationSubject = 1; + GoDiff annotationType = 2; +} + +message TypeArray { + repeated GoDiff arraySize = 1; + GoDiff arrayElementType = 2; +} + +message TypeFunction { + repeated GoDiff functionParameters = 1; + GoDiff functionReturn = 2; +} + +message Interface { + repeated GoDiff values = 1; +} + +message Map { + GoDiff mapKeyType = 1; + GoDiff mapElementType = 2; +} + +message Parenthesized { + GoDiff value = 1; +} + +message TypePointer { + GoDiff value = 1; +} + +message TypeSlice { + GoDiff value = 1; +} + +message List { + repeated GoDiff listContent = 1; +} + +message String { + repeated GoDiff stringElements = 1; +} + +message EscapeSequence { + string value = 1; +} + +message ImportPath { + string unPath = 1; + IsRelative pathIsRelative = 2; +} + +enum IsRelative { + Unknown = 0; + Relative = 1; + NonRelative = 2; +} diff --git a/proto/haskell_diff.proto b/proto/haskell_diff.proto new file mode 100644 index 000000000..884f46c97 --- /dev/null +++ b/proto/haskell_diff.proto @@ -0,0 +1,800 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.haskelldiff; + +import "types.proto"; + +option java_package = "com.github.semantic.haskelldiff"; +option go_package = "github.com/semantic/haskelldiff;haskell"; + +message HaskellDiff { + oneof diff { + Merge merge = 1; + Delete delete = 2; + Insert insert = 3; + Replace replace = 4; + } + message Merge { + HaskellSyntax syntax = 1; + } + message Delete { + HaskellSyntax before = 1; + } + message Insert { + HaskellSyntax after = 1; + } + message Replace { + HaskellSyntax before = 1; + HaskellSyntax after = 2; + } +} + +message HaskellSyntax { + oneof syntax { + Comment comment = 1; + Constructor constructor = 2; + Datatype datatype = 3; + Function function = 4; + Array array = 5; + Character character = 6; + Float float = 7; + Integer integer = 8; + TextElement textElement = 9; + Tuple tuple = 10; + If if = 11; + Match match = 12; + Pattern pattern = 13; + AllConstructors allConstructors = 14; + AnnotatedTypeVariable annotatedTypeVariable = 15; + App app = 16; + ArithmeticSequence arithmeticSequence = 17; + AsPattern asPattern = 18; + BindPattern bindPattern = 19; + CaseGuardPattern caseGuardPattern = 20; + Class class = 21; + ConstructorIdentifier constructorIdentifier = 22; + ConstructorOperator constructorOperator = 23; + ConstructorPattern constructorPattern = 24; + ConstructorSymbol constructorSymbol = 25; + Context context = 26; + ContextAlt contextAlt = 27; + CPPDirective cPPDirective = 28; + DefaultDeclaration defaultDeclaration = 29; + DefaultSignature defaultSignature = 30; + Deriving deriving = 31; + Do do = 32; + Empty empty = 33; + Error error = 34; + EqualityConstraint equalityConstraint = 35; + Export export = 36; + ExpressionTypeSignature expressionTypeSignature = 37; + Field field = 38; + FieldBind fieldBind = 39; + FieldPattern fieldPattern = 40; + FixityAlt fixityAlt = 41; + FunctionalDependency functionalDependency = 42; + FunctionConstructor functionConstructor = 43; + FunctionGuardPattern functionGuardPattern = 44; + FunctionType functionType = 45; + GADT gADT = 46; + GADTConstructor gADTConstructor = 47; + Generator generator = 48; + Guard guard = 49; + HiddenImport hiddenImport = 50; + Identifier identifier = 51; + InfixConstructorIdentifier infixConstructorIdentifier = 52; + InfixOperatorApp infixOperatorApp = 53; + InfixVariableIdentifier infixVariableIdentifier = 54; + ImplicitParameterIdentifier implicitParameterIdentifier = 55; + Import import = 56; + ImportAlias importAlias = 57; + ImportDeclaration importDeclaration = 58; + InfixDataConstructor infixDataConstructor = 59; + InfixOperatorPattern infixOperatorPattern = 60; + Instance instance = 61; + IrrefutablePattern irrefutablePattern = 62; + Kind kind = 63; + KindFunctionType kindFunctionType = 64; + KindListType kindListType = 65; + KindParenthesizedConstructor kindParenthesizedConstructor = 66; + KindSignature kindSignature = 67; + KindTupleType kindTupleType = 68; + LabeledConstruction labeledConstruction = 69; + LabeledPattern labeledPattern = 70; + LabeledUpdate labeledUpdate = 71; + Lambda lambda = 72; + LambdaCase lambdaCase = 73; + LeftOperatorSection leftOperatorSection = 74; + Let let = 75; + ListComprehension listComprehension = 76; + ListConstructor listConstructor = 77; + ListPattern listPattern = 78; + Module module = 79; + ModuleExport moduleExport = 80; + ModuleIdentifier moduleIdentifier = 81; + NamedFieldPun namedFieldPun = 82; + NegativeLiteral negativeLiteral = 83; + NewType newType = 84; + PatternGuard patternGuard = 85; + Pragma pragma = 86; + PrefixNegation prefixNegation = 87; + PrimitiveConstructorIdentifier primitiveConstructorIdentifier = 88; + PrimitiveVariableIdentifier primitiveVariableIdentifier = 89; + PromotedTypeOperator promotedTypeOperator = 90; + QualifiedConstructorIdentifier qualifiedConstructorIdentifier = 91; + QualifiedInfixVariableIdentifier qualifiedInfixVariableIdentifier = 92; + QualifiedModuleIdentifier qualifiedModuleIdentifier = 93; + QualifiedImportDeclaration qualifiedImportDeclaration = 94; + QualifiedTypeClassIdentifier qualifiedTypeClassIdentifier = 95; + QualifiedTypeConstructorIdentifier qualifiedTypeConstructorIdentifier = 96; + QualifiedVariableIdentifier qualifiedVariableIdentifier = 97; + QuasiQuotation quasiQuotation = 98; + QuasiQuotationDeclaration quasiQuotationDeclaration = 99; + QuasiQuotationExpression quasiQuotationExpression = 100; + QuasiQuotationExpressionBody quasiQuotationExpressionBody = 101; + QuasiQuotationPattern quasiQuotationPattern = 102; + QuasiQuotationQuoter quasiQuotationQuoter = 103; + QuasiQuotationType quasiQuotationType = 104; + QuotedName quotedName = 105; + RecordDataConstructor recordDataConstructor = 106; + RecordWildCards recordWildCards = 107; + RightOperatorSection rightOperatorSection = 108; + ScopedTypeVariables scopedTypeVariables = 109; + Splice splice = 110; + StandaloneDerivingInstance standaloneDerivingInstance = 111; + Star star = 112; + StrictPattern strictPattern = 113; + StrictType strictType = 114; + StrictTypeVariable strictTypeVariable = 115; + TupleConstructor tupleConstructor = 116; + TupleExpression tupleExpression = 117; + TuplePattern tuplePattern = 118; + Type type = 119; + TypeApp typeApp = 120; + TypeClass typeClass = 121; + TypeClassIdentifier typeClassIdentifier = 122; + TypeClassInstance typeClassInstance = 123; + TypeConstructorExport typeConstructorExport = 124; + TypeConstructorIdentifier typeConstructorIdentifier = 125; + TypeFamily typeFamily = 126; + TypeInstance typeInstance = 127; + TypeOperator typeOperator = 128; + TypePattern typePattern = 129; + TypeSignature typeSignature = 130; + TypeSynonym typeSynonym = 131; + TypeVariableIdentifier typeVariableIdentifier = 132; + UnitConstructor unitConstructor = 133; + VariableIdentifier variableIdentifier = 134; + VariableOperator variableOperator = 135; + VariableSymbol variableSymbol = 136; + ViewPattern viewPattern = 137; + Wildcard wildcard = 138; + TypeParameters typeParameters = 139; + List list = 140; + } +} + +message Comment { + string commentContent = 1; +} + +message Constructor { + repeated HaskellDiff constructorContext = 1; + HaskellDiff constructorName = 2; + HaskellDiff constructorFields = 3; +} + +message Datatype { + HaskellDiff datatypeContext = 1; + HaskellDiff datatypeName = 2; + repeated HaskellDiff datatypeConstructors = 3; + HaskellDiff datatypeDeriving = 4; +} + +message Function { + repeated HaskellDiff functionContext = 1; + HaskellDiff functionName = 2; + repeated HaskellDiff functionParameters = 3; + HaskellDiff functionBody = 4; +} + +message Array { + repeated HaskellDiff arrayElements = 1; +} + +message Character { + string characterContent = 1; +} + +message Float { + string floatContent = 1; +} + +message Integer { + string integerContent = 1; +} + +message TextElement { + string textElementContent = 1; +} + +message Tuple { + repeated HaskellDiff tupleContents = 1; +} + +message If { + HaskellDiff ifCondition = 1; + HaskellDiff ifThenBody = 2; + HaskellDiff ifElseBody = 3; +} + +message Match { + HaskellDiff matchSubject = 1; + HaskellDiff matchPatterns = 2; +} + +message Pattern { + HaskellDiff value = 1; + HaskellDiff patternBody = 2; +} + +message AllConstructors { } + +message AnnotatedTypeVariable { + HaskellDiff annotatedTypeVariableIdentifier = 1; + HaskellDiff annotatedTypeVariableannotation = 2; +} + +message App { + HaskellDiff appLeft = 1; + HaskellDiff appLeftTypeApp = 2; + HaskellDiff appRight = 3; +} + +message ArithmeticSequence { + HaskellDiff from = 1; + repeated HaskellDiff next = 2; + repeated HaskellDiff to = 3; +} + +message AsPattern { + HaskellDiff asPatternLeft = 1; + HaskellDiff asPatternRight = 2; +} + +message BindPattern { + repeated HaskellDiff bindPatternLeft = 1; + HaskellDiff bindPatternRight = 2; +} + +message CaseGuardPattern { + repeated HaskellDiff values = 1; +} + +message Class { + repeated HaskellDiff classContent = 1; +} + +message ConstructorIdentifier { + bytes name = 1; +} + +message ConstructorOperator { + HaskellDiff value = 1; +} + +message ConstructorPattern { + HaskellDiff value = 1; +} + +message ConstructorSymbol { + bytes constructorSymbolName = 1; +} + +message Context { + repeated HaskellDiff contextTerms = 1; + HaskellDiff contextSubject = 2; +} + +message ContextAlt { + HaskellDiff value = 1; +} + +message CPPDirective { + string value = 1; +} + +message DefaultDeclaration { + repeated HaskellDiff defaultDeclarationContent = 1; +} + +message DefaultSignature { + repeated HaskellDiff defaultSignatureName = 1; + repeated HaskellDiff defaultSignatureContext = 2; + HaskellDiff defaultSignatureContent = 3; +} + +message Deriving { + repeated HaskellDiff values = 1; +} + +message Do { + repeated HaskellDiff values = 1; +} + +message Empty { } + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated HaskellDiff errorChildren = 4; +} + +message EqualityConstraint { + HaskellDiff equalityConstraintLeft = 1; + HaskellDiff equalityConstraintRight = 2; +} + +message Export { + HaskellDiff exportContent = 1; +} + +message ExpressionTypeSignature { + repeated HaskellDiff expressionTypeSignatureName = 1; + repeated HaskellDiff expressionTypeSignatureContext = 2; + HaskellDiff expressionTypeSignatureContent = 3; +} + +message Field { + HaskellDiff fieldName = 1; + HaskellDiff fieldBody = 2; +} + +message FieldBind { + HaskellDiff fieldBindLeft = 1; + HaskellDiff fieldBindRight = 2; +} + +message FieldPattern { + HaskellDiff fieldPatternLeft = 1; + HaskellDiff fieldPatternRight = 2; +} + +message FixityAlt { + HaskellDiff fixityPrecedence = 1; + repeated HaskellDiff fixityIdentifier = 2; +} + +message FunctionalDependency { + HaskellDiff functionalDependencyContent = 1; +} + +message FunctionConstructor { } + +message FunctionGuardPattern { + repeated HaskellDiff values = 1; +} + +message FunctionType { + HaskellDiff functionTypeLeft = 1; + HaskellDiff functionTypeRight = 2; +} + +message GADT { + HaskellDiff gadtContext = 1; + HaskellDiff gadtName = 2; + HaskellDiff gadtConstructors = 3; +} + +message GADTConstructor { + HaskellDiff gadtConstructorContext = 1; + HaskellDiff gadtConstructorName = 2; + HaskellDiff gadtConstructorTypeSignature = 3; +} + +message Generator { + HaskellDiff generatorValue = 1; + HaskellDiff generatorSource = 2; +} + +message Guard { + HaskellDiff value = 1; +} + +message HiddenImport { + HaskellDiff hiddenimportContent = 1; +} + +message Identifier { + bytes name = 1; +} + +message InfixConstructorIdentifier { + bytes name = 1; +} + +message InfixOperatorApp { + HaskellDiff infixOperatorAppLeft = 1; + HaskellDiff infixOperatorAppLeftTypeApp = 2; + HaskellDiff infixOperatorAppOperator = 3; + HaskellDiff infixOperatorAppRight = 4; +} + +message InfixVariableIdentifier { + bytes name = 1; +} + +message ImplicitParameterIdentifier { + bytes name = 1; +} + +message Import { + HaskellDiff importContent = 1; +} + +message ImportAlias { + HaskellDiff importAliasSource = 1; + HaskellDiff importAliasName = 2; +} + +message ImportDeclaration { + HaskellDiff importPackageQualifiedContent = 1; + HaskellDiff importModule = 2; + repeated HaskellDiff importSpec = 3; +} + +message InfixDataConstructor { + repeated HaskellDiff infixDataConstructorContext = 1; + HaskellDiff infixDataConstructorLeft = 2; + HaskellDiff infixDataConstructorOperator = 3; + HaskellDiff infixDataConstructorRight = 4; +} + +message InfixOperatorPattern { + HaskellDiff infixOperatorPatternLeft = 1; + HaskellDiff infixOperatorPatternOperator = 2; + HaskellDiff infixOperatorPatternRight = 3; +} + +message Instance { + HaskellDiff value = 1; +} + +message IrrefutablePattern { + HaskellDiff value = 1; +} + +message Kind { + HaskellDiff kindKind = 1; +} + +message KindFunctionType { + HaskellDiff kindFunctionTypeLeft = 1; + HaskellDiff kindFunctionTypeRight = 2; +} + +message KindListType { + HaskellDiff kindListTypeKind = 1; +} + +message KindParenthesizedConstructor { + HaskellDiff kindParenthesizedConstructorContent = 1; +} + +message KindSignature { + HaskellDiff kindSignatureContent = 1; +} + +message KindTupleType { + repeated HaskellDiff kindTupleType = 1; +} + +message LabeledConstruction { + HaskellDiff labeledConstructionConstructor = 1; + repeated HaskellDiff labeledConstructionFields = 2; +} + +message LabeledPattern { + HaskellDiff value = 1; +} + +message LabeledUpdate { + repeated HaskellDiff values = 1; +} + +message Lambda { + HaskellDiff lambdaHead = 1; + HaskellDiff lambdaBody = 2; +} + +message LambdaCase { + repeated HaskellDiff values = 1; +} + +message LeftOperatorSection { + HaskellDiff lhs = 1; + HaskellDiff rhs = 2; +} + +message Let { + repeated HaskellDiff letStatements = 1; + HaskellDiff letInClause = 2; +} + +message ListComprehension { + HaskellDiff comprehensionValue = 1; + repeated HaskellDiff comprehensionSource = 2; +} + +message ListConstructor { } + +message ListPattern { + HaskellDiff value = 1; +} + +message Module { + repeated HaskellDiff moduleContext = 1; + HaskellDiff moduleIdentifier = 2; + repeated HaskellDiff moduleExports = 3; + HaskellDiff moduleStatements = 4; +} + +message ModuleExport { + HaskellDiff moduleExportContent = 1; +} + +message ModuleIdentifier { + bytes name = 1; +} + +message NamedFieldPun { + HaskellDiff value = 1; +} + +message NegativeLiteral { + HaskellDiff value = 1; +} + +message NewType { + repeated HaskellDiff newTypeContext = 1; + HaskellDiff newTypeLeft = 2; + HaskellDiff newTypeRight = 3; + HaskellDiff newTypeDeriving = 4; +} + +message PatternGuard { + HaskellDiff patternGuardPattern = 1; + HaskellDiff patternGuardExpression = 2; +} + +message Pragma { + string value = 1; +} + +message PrefixNegation { + HaskellDiff value = 1; +} + +message PrimitiveConstructorIdentifier { + bytes name = 1; +} + +message PrimitiveVariableIdentifier { + bytes name = 1; +} + +message PromotedTypeOperator { + HaskellDiff value = 1; +} + +message QualifiedConstructorIdentifier { + repeated HaskellDiff values = 1; +} + +message QualifiedInfixVariableIdentifier { + repeated HaskellDiff values = 1; +} + +message QualifiedModuleIdentifier { + repeated HaskellDiff values = 1; +} + +message QualifiedImportDeclaration { + HaskellDiff qualifiedImportPackageQualifiedContent = 1; + HaskellDiff qualifiedImportModule = 2; + repeated HaskellDiff qualifiedImportSpec = 3; +} + +message QualifiedTypeClassIdentifier { + repeated HaskellDiff values = 1; +} + +message QualifiedTypeConstructorIdentifier { + repeated HaskellDiff values = 1; +} + +message QualifiedVariableIdentifier { + repeated HaskellDiff values = 1; +} + +message QuasiQuotation { + HaskellDiff quasiQuotationHead = 1; + HaskellDiff quasiQuotationBody = 2; +} + +message QuasiQuotationDeclaration { } + +message QuasiQuotationExpression { } + +message QuasiQuotationExpressionBody { + bytes name = 1; +} + +message QuasiQuotationPattern { } + +message QuasiQuotationQuoter { + bytes name = 1; +} + +message QuasiQuotationType { } + +message QuotedName { + HaskellDiff quotedNameContent = 1; +} + +message RecordDataConstructor { + repeated HaskellDiff recordDataConstructorContext = 1; + HaskellDiff recordDataConstructorName = 2; + HaskellDiff recordDataConstructorFields = 3; +} + +message RecordWildCards { } + +message RightOperatorSection { + HaskellDiff lhs = 1; + HaskellDiff rhs = 2; +} + +message ScopedTypeVariables { + HaskellDiff scopedTypeVariablesContent = 1; +} + +message Splice { + HaskellDiff value = 1; +} + +message StandaloneDerivingInstance { + repeated HaskellDiff standaloneDerivingInstanceContext = 1; + HaskellDiff standaloneDerivingInstanceClass = 2; + HaskellDiff standaloneDerivingInstanceInstance = 3; +} + +message Star { } + +message StrictPattern { + HaskellDiff value = 1; +} + +message StrictType { + HaskellDiff strictTypeIdentifier = 1; + HaskellDiff strictTypeParameters = 2; +} + +message StrictTypeVariable { + HaskellDiff value = 1; +} + +message TupleConstructor { + int64 tupleConstructorArity = 1; +} + +message TupleExpression { + repeated HaskellDiff values = 1; +} + +message TuplePattern { + repeated HaskellDiff value = 1; +} + +message Type { + HaskellDiff typeIdentifier = 1; + HaskellDiff typeParameters = 2; + HaskellDiff typeKindSignature = 3; +} + +message TypeApp { + HaskellDiff typeAppType = 1; +} + +message TypeClass { + HaskellDiff typeClassContext = 1; + HaskellDiff typeClassIdentifier = 2; + repeated HaskellDiff typeClassParameters = 3; + HaskellDiff typeClassBody = 4; +} + +message TypeClassIdentifier { + bytes name = 1; +} + +message TypeClassInstance { + repeated HaskellDiff typeClassInstanceContext = 1; + HaskellDiff typeClassInstanceIdentifier = 2; + HaskellDiff typeClassInstanceInstance = 3; + HaskellDiff typeClassInstanceBody = 4; +} + +message TypeConstructorExport { + HaskellDiff typeConstructorExportContent = 1; +} + +message TypeConstructorIdentifier { + bytes name = 1; +} + +message TypeFamily { + HaskellDiff typeFamilyIdentifier = 1; + repeated HaskellDiff typeFamilyParameters = 2; + HaskellDiff typeFamilySignature = 3; + HaskellDiff typeFamilyBody = 4; +} + +message TypeInstance { + HaskellDiff typeInstanceType = 1; + HaskellDiff typeInstanceBody = 2; +} + +message TypeOperator { + bytes name = 1; +} + +message TypePattern { + HaskellDiff typePatternContent = 1; +} + +message TypeSignature { + repeated HaskellDiff typeSignatureName = 1; + repeated HaskellDiff typeSignatureContext = 2; + HaskellDiff typeSignatureContent = 3; +} + +message TypeSynonym { + HaskellDiff typeSynonymLeft = 1; + repeated HaskellDiff typeSynonymContext = 2; + HaskellDiff typeSynonymRight = 3; +} + +message TypeVariableIdentifier { + bytes name = 1; +} + +message UnitConstructor { } + +message VariableIdentifier { + bytes name = 1; +} + +message VariableOperator { + HaskellDiff value = 1; +} + +message VariableSymbol { + bytes variableSymbolName = 1; +} + +message ViewPattern { + HaskellDiff viewPatternLeft = 1; + HaskellDiff viewPatternRight = 2; +} + +message Wildcard { } + +message TypeParameters { + repeated HaskellDiff terms = 1; +} + +message List { + repeated HaskellDiff listContent = 1; +} diff --git a/proto/java_diff.proto b/proto/java_diff.proto new file mode 100644 index 000000000..fce159120 --- /dev/null +++ b/proto/java_diff.proto @@ -0,0 +1,660 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.javadiff; + +import "types.proto"; + +option java_package = "com.github.semantic.javadiff"; +option go_package = "github.com/semantic/javadiff;java"; + +message JavaDiff { + oneof diff { + Merge merge = 1; + Delete delete = 2; + Insert insert = 3; + Replace replace = 4; + } + message Merge { + JavaSyntax syntax = 1; + } + message Delete { + JavaSyntax before = 1; + } + message Insert { + JavaSyntax after = 1; + } + message Replace { + JavaSyntax before = 1; + JavaSyntax after = 2; + } +} + +message JavaSyntax { + oneof syntax { + Comment comment = 1; + Class class = 2; + InterfaceDeclaration interfaceDeclaration = 3; + Method method = 4; + VariableDeclaration variableDeclaration = 5; + Plus plus = 6; + Minus minus = 7; + Times times = 8; + DividedBy dividedBy = 9; + Modulo modulo = 10; + Power power = 11; + Negate negate = 12; + FloorDivision floorDivision = 13; + Call call = 14; + LessThan lessThan = 15; + LessThanEqual lessThanEqual = 16; + GreaterThan greaterThan = 17; + GreaterThanEqual greaterThanEqual = 18; + Equal equal = 19; + StrictEqual strictEqual = 20; + Comparison comparison = 21; + BOr bOr = 22; + BXOr bXOr = 23; + BAnd bAnd = 24; + LShift lShift = 25; + RShift rShift = 26; + UnsignedRShift unsignedRShift = 27; + Complement complement = 28; + And and = 29; + Not not = 30; + Or or = 31; + XOr xOr = 32; + InstanceOf instanceOf = 33; + MemberAccess memberAccess = 34; + Subscript subscript = 35; + Member member = 36; + Super super = 37; + This this = 38; + AnnotatedType annotatedType = 39; + JavaAnnotation javaAnnotation = 40; + AnnotationField annotationField = 41; + AnnotationTypeElement annotationTypeElement = 42; + ArrayCreationExpression arrayCreationExpression = 43; + AssertStatement assertStatement = 44; + Asterisk asterisk = 45; + CatchType catchType = 46; + Constructor constructor = 47; + ClassBody classBody = 48; + ClassLiteral classLiteral = 49; + DefaultValue defaultValue = 50; + DimsExpr dimsExpr = 51; + EnumDeclaration enumDeclaration = 52; + GenericType genericType = 53; + Import import = 54; + Lambda lambda = 55; + LambdaBody lambdaBody = 56; + MethodReference methodReference = 57; + Module module = 58; + New new = 59; + NewKeyword newKeyword = 60; + Package package = 61; + SpreadParameter spreadParameter = 62; + StaticInitializer staticInitializer = 63; + Synchronized synchronized = 64; + TryWithResources tryWithResources = 65; + TypeParameter typeParameter = 66; + TypeWithModifiers typeWithModifiers = 67; + Variable variable = 68; + Wildcard wildcard = 69; + WildcardBounds wildcardBounds = 70; + Array array = 71; + Boolean boolean = 72; + Integer integer = 73; + Float float = 74; + Null null = 75; + String string = 76; + TextElement textElement = 77; + Assignment assignment = 78; + Break break = 79; + Catch catch = 80; + Continue continue = 81; + DoWhile doWhile = 82; + Finally finally = 83; + For for = 84; + ForEach forEach = 85; + If if = 86; + Match match = 87; + Pattern pattern = 88; + PostIncrement postIncrement = 89; + PostDecrement postDecrement = 90; + PreIncrement preIncrement = 91; + PreDecrement preDecrement = 92; + While while = 93; + Statements statements = 94; + Throw throw = 95; + Try try = 96; + Context context = 97; + Empty empty = 98; + Error error = 99; + Identifier identifier = 100; + AccessibilityModifier accessibilityModifier = 101; + TypeArray typeArray = 102; + Bool bool = 103; + Int int = 104; + Void void = 105; + TypeFloat typeFloat = 106; + Annotation annotation = 107; + Return return = 108; + List list = 109; + } +} + +message Comment { + string commentContent = 1; +} + +message Class { + repeated JavaDiff classContext = 1; + JavaDiff classIdentifier = 2; + repeated JavaDiff classSuperclasses = 3; + JavaDiff classBody = 4; +} + +message InterfaceDeclaration { + repeated JavaDiff interfaceDeclarationContext = 1; + JavaDiff interfaceDeclarationIdentifier = 2; + repeated JavaDiff interfaceDeclarationSuperInterfaces = 3; + JavaDiff interfaceDeclarationBody = 4; +} + +message Method { + repeated JavaDiff methodContext = 1; + JavaDiff methodReceiver = 2; + JavaDiff methodName = 3; + repeated JavaDiff methodParameters = 4; + JavaDiff methodBody = 5; +} + +message VariableDeclaration { + repeated JavaDiff variableDeclarations = 1; +} + +message Plus { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message Minus { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message Times { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message DividedBy { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message Modulo { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message Power { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message Negate { + JavaDiff value = 1; +} + +message FloorDivision { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message Call { + repeated JavaDiff callContext = 1; + JavaDiff callFunction = 2; + repeated JavaDiff callParams = 3; + JavaDiff callBlock = 4; +} + +message LessThan { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message LessThanEqual { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message GreaterThan { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message GreaterThanEqual { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message Equal { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message StrictEqual { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message Comparison { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message BOr { + JavaDiff left = 1; + JavaDiff right = 2; +} + +message BXOr { + JavaDiff left = 1; + JavaDiff right = 2; +} + +message BAnd { + JavaDiff left = 1; + JavaDiff right = 2; +} + +message LShift { + JavaDiff left = 1; + JavaDiff right = 2; +} + +message RShift { + JavaDiff left = 1; + JavaDiff right = 2; +} + +message UnsignedRShift { + JavaDiff left = 1; + JavaDiff right = 2; +} + +message Complement { + JavaDiff value = 1; +} + +message And { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message Not { + JavaDiff value = 1; +} + +message Or { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message XOr { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message InstanceOf { + JavaDiff instanceOfSubject = 1; + JavaDiff instanceOfObject = 2; +} + +message MemberAccess { + JavaDiff lhs = 1; + bytes rhs = 2; +} + +message Subscript { + JavaDiff lhs = 1; + repeated JavaDiff rhs = 2; +} + +message Member { + JavaDiff lhs = 1; + JavaDiff rhs = 2; +} + +message Super { } + +message This { } + +message AnnotatedType { + repeated JavaDiff annotationes = 1; + JavaDiff annotatedType = 2; +} + +message JavaAnnotation { + JavaDiff annotationName = 1; + repeated JavaDiff annotationField = 2; +} + +message AnnotationField { + JavaDiff annotationFieldName = 1; + JavaDiff annotationFieldValue = 2; +} + +message AnnotationTypeElement { + repeated JavaDiff modifiers = 1; + JavaDiff annotationType = 2; + JavaDiff identifier = 3; + repeated JavaDiff dims = 4; + JavaDiff defaultValue = 5; +} + +message ArrayCreationExpression { + JavaDiff arrayCreationExpressionType = 1; + repeated JavaDiff arrayCreationExpressionDims = 2; +} + +message AssertStatement { + JavaDiff assertLHS = 1; + repeated JavaDiff assertRHS = 2; +} + +message Asterisk { } + +message CatchType { + repeated JavaDiff types = 1; +} + +message Constructor { + repeated JavaDiff constructorModifiers = 1; + repeated JavaDiff constructorTypeParams = 2; + JavaDiff constructorIdentifier = 3; + repeated JavaDiff constructorParams = 4; + repeated JavaDiff constructorThrows = 5; + JavaDiff constructorBody = 6; +} + +message ClassBody { + repeated JavaDiff classBodyExpression = 1; +} + +message ClassLiteral { + JavaDiff classLiteralType = 1; +} + +message DefaultValue { + JavaDiff defaultValueElement = 1; +} + +message DimsExpr { + repeated JavaDiff dimsExprAnnotation = 1; + repeated JavaDiff dimsExprExpression = 2; +} + +message EnumDeclaration { + repeated JavaDiff enumDeclarationModifier = 1; + JavaDiff enumDeclarationIdentifier = 2; + repeated JavaDiff enumDeclarationSuperInterfaces = 3; + repeated JavaDiff enumDeclarationConstant = 4; + repeated JavaDiff enumDeclarationBody = 5; +} + +message GenericType { + JavaDiff genericTypeIdentifier = 1; + repeated JavaDiff genericTypeArguments = 2; +} + +message Import { + repeated JavaDiff imports = 1; +} + +message Lambda { + repeated JavaDiff lambdaParams = 1; + JavaDiff lambdaBody = 2; +} + +message LambdaBody { + repeated JavaDiff lambdaBodyExpression = 1; +} + +message MethodReference { + JavaDiff methodReferenceType = 1; + repeated JavaDiff methodReferenceTypeArgs = 2; + JavaDiff methodReferenceIdentifier = 3; +} + +message Module { + JavaDiff moduleIdentifier = 1; + repeated JavaDiff moduleStatements = 2; +} + +message New { + JavaDiff newType = 1; + repeated JavaDiff newArgs = 2; + repeated JavaDiff newClassBody = 3; +} + +message NewKeyword { } + +message Package { + repeated JavaDiff packages = 1; +} + +message SpreadParameter { + JavaDiff spreadParameterVariableDeclarator = 1; +} + +message StaticInitializer { + JavaDiff staticInitializerBlock = 1; +} + +message Synchronized { + JavaDiff synchronizedSubject = 1; + JavaDiff synchronizedBody = 2; +} + +message TryWithResources { + repeated JavaDiff tryResources = 1; + JavaDiff tryBody = 2; + repeated JavaDiff tryCatch = 3; +} + +message TypeParameter { + repeated JavaDiff typeParamAnnotation = 1; + JavaDiff typeParamIdentifier = 2; + repeated JavaDiff typeParamTypeBound = 3; +} + +message TypeWithModifiers { + repeated JavaDiff types = 1; + JavaDiff modifier = 2; +} + +message Variable { + repeated JavaDiff variableModifiers = 1; + JavaDiff variableType = 2; + JavaDiff variableName = 3; +} + +message Wildcard { + repeated JavaDiff wildcardAnnotation = 1; + repeated JavaDiff wildcardBounds = 2; +} + +message WildcardBounds { + oneof sum { + JavaDiff wildcardBoundExtendsType = 1; + JavaDiff wildcardBoundSuperType = 2; + } +} + +message Array { + repeated JavaDiff arrayElements = 1; +} + +message Boolean { + bool booleanContent = 1; +} + +message Integer { + string integerContent = 1; +} + +message Float { + string floatContent = 1; +} + +message Null { } + +message String { + repeated JavaDiff stringElements = 1; +} + +message TextElement { + string textElementContent = 1; +} + +message Assignment { + repeated JavaDiff assignmentContext = 1; + JavaDiff assignmentTarget = 2; + JavaDiff assignmentValue = 3; +} + +message Break { + JavaDiff value = 1; +} + +message Catch { + JavaDiff catchException = 1; + JavaDiff catchBody = 2; +} + +message Continue { + JavaDiff value = 1; +} + +message DoWhile { + JavaDiff doWhileCondition = 1; + JavaDiff doWhileBody = 2; +} + +message Finally { + JavaDiff value = 1; +} + +message For { + JavaDiff forBefore = 1; + JavaDiff forCondition = 2; + JavaDiff forStep = 3; + JavaDiff forBody = 4; +} + +message ForEach { + JavaDiff forEachBinding = 1; + JavaDiff forEachSubject = 2; + JavaDiff forEachBody = 3; +} + +message If { + JavaDiff ifCondition = 1; + JavaDiff ifThenBody = 2; + JavaDiff ifElseBody = 3; +} + +message Match { + JavaDiff matchSubject = 1; + JavaDiff matchPatterns = 2; +} + +message Pattern { + JavaDiff value = 1; + JavaDiff patternBody = 2; +} + +message PostIncrement { + JavaDiff value = 1; +} + +message PostDecrement { + JavaDiff value = 1; +} + +message PreIncrement { + JavaDiff value = 1; +} + +message PreDecrement { + JavaDiff value = 1; +} + +message While { + JavaDiff whileCondition = 1; + JavaDiff whileBody = 2; +} + +message Statements { + repeated JavaDiff statements = 1; +} + +message Throw { + JavaDiff value = 1; +} + +message Try { + JavaDiff tryBody = 1; + repeated JavaDiff tryCatch = 2; +} + +message Context { + repeated JavaDiff contextTerms = 1; + JavaDiff contextSubject = 2; +} + +message Empty { } + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated JavaDiff errorChildren = 4; +} + +message Identifier { + bytes name = 1; +} + +message AccessibilityModifier { + string contents = 1; +} + +message TypeArray { + repeated JavaDiff arraySize = 1; + JavaDiff arrayElementType = 2; +} + +message Bool { } + +message Int { } + +message Void { } + +message TypeFloat { } + +message Annotation { + JavaDiff annotationSubject = 1; + JavaDiff annotationType = 2; +} + +message Return { + JavaDiff value = 1; +} + +message List { + repeated JavaDiff listContent = 1; +} diff --git a/proto/json_diff.proto b/proto/json_diff.proto new file mode 100644 index 000000000..0af03a339 --- /dev/null +++ b/proto/json_diff.proto @@ -0,0 +1,78 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.jsondiff; + +import "types.proto"; + +option java_package = "com.github.semantic.jsondiff"; +option go_package = "github.com/semantic/jsondiff;json"; + +message JSONDiff { + oneof diff { + Merge merge = 1; + Delete delete = 2; + Insert insert = 3; + Replace replace = 4; + } + message Merge { + JSONSyntax syntax = 1; + } + message Delete { + JSONSyntax before = 1; + } + message Insert { + JSONSyntax after = 1; + } + message Replace { + JSONSyntax before = 1; + JSONSyntax after = 2; + } +} + +message JSONSyntax { + oneof syntax { + Null null = 1; + Array array = 2; + Boolean boolean = 3; + Hash hash = 4; + Float float = 5; + KeyValue keyValue = 6; + TextElement textElement = 7; + Error error = 8; + } +} + +message Null { } + +message Array { + repeated JSONDiff arrayElements = 1; +} + +message Boolean { + bool booleanContent = 1; +} + +message Hash { + repeated JSONDiff hashElements = 1; +} + +message Float { + string floatContent = 1; +} + +message KeyValue { + JSONDiff key = 1; + JSONDiff value = 2; +} + +message TextElement { + string textElementContent = 1; +} + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated JSONDiff errorChildren = 4; +} diff --git a/proto/markdown_diff.proto b/proto/markdown_diff.proto new file mode 100644 index 000000000..e21843f9b --- /dev/null +++ b/proto/markdown_diff.proto @@ -0,0 +1,145 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.markdowndiff; + +import "types.proto"; + +option java_package = "com.github.semantic.markdowndiff"; +option go_package = "github.com/semantic/markdowndiff;markdown"; + +message MarkdownDiff { + oneof diff { + Merge merge = 1; + Delete delete = 2; + Insert insert = 3; + Replace replace = 4; + } + message Merge { + MarkdownSyntax syntax = 1; + } + message Delete { + MarkdownSyntax before = 1; + } + message Insert { + MarkdownSyntax after = 1; + } + message Replace { + MarkdownSyntax before = 1; + MarkdownSyntax after = 2; + } +} + +message MarkdownSyntax { + oneof syntax { + Document document = 1; + BlockQuote blockQuote = 2; + Heading heading = 3; + HTMLBlock hTMLBlock = 4; + OrderedList orderedList = 5; + Paragraph paragraph = 6; + ThematicBreak thematicBreak = 7; + UnorderedList unorderedList = 8; + Table table = 9; + TableRow tableRow = 10; + TableCell tableCell = 11; + Code code = 12; + Emphasis emphasis = 13; + Image image = 14; + LineBreak lineBreak = 15; + Link link = 16; + Strong strong = 17; + Text text = 18; + Strikethrough strikethrough = 19; + Error error = 20; + List list = 21; + } +} + +message Document { + repeated MarkdownDiff values = 1; +} + +message BlockQuote { + repeated MarkdownDiff values = 1; +} + +message Heading { + int64 headingLevel = 1; + repeated MarkdownDiff headingContent = 2; + repeated MarkdownDiff sectionContent = 3; +} + +message HTMLBlock { + string value = 1; +} + +message OrderedList { + repeated MarkdownDiff values = 1; +} + +message Paragraph { + repeated MarkdownDiff values = 1; +} + +message ThematicBreak { } + +message UnorderedList { + repeated MarkdownDiff values = 1; +} + +message Table { + repeated MarkdownDiff values = 1; +} + +message TableRow { + repeated MarkdownDiff values = 1; +} + +message TableCell { + repeated MarkdownDiff values = 1; +} + +message Code { + string codeLanguage = 1; + string codeContent = 2; +} + +message Emphasis { + repeated MarkdownDiff values = 1; +} + +message Image { + string imageURL = 1; + string imageTitle = 2; +} + +message LineBreak { } + +message Link { + string linkUrl = 1; + string linkTitle = 2; +} + +message Strong { + repeated MarkdownDiff values = 1; +} + +message Text { + string value = 1; +} + +message Strikethrough { + repeated MarkdownDiff values = 1; +} + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated MarkdownDiff errorChildren = 4; +} + +message List { + repeated MarkdownDiff listContent = 1; +} diff --git a/proto/php_diff.proto b/proto/php_diff.proto new file mode 100644 index 000000000..2f95183fe --- /dev/null +++ b/proto/php_diff.proto @@ -0,0 +1,723 @@ +// This file was generated by proto-gen. Do not edit by hand. +syntax = "proto3"; + +package github.semantic.phpdiff; + +import "types.proto"; + +option java_package = "com.github.semantic.phpdiff"; +option go_package = "github.com/semantic/phpdiff;php"; + +message PHPDiff { + oneof diff { + Merge merge = 1; + Delete delete = 2; + Insert insert = 3; + Replace replace = 4; + } + message Merge { + PHPSyntax syntax = 1; + } + message Delete { + PHPSyntax before = 1; + } + message Insert { + PHPSyntax after = 1; + } + message Replace { + PHPSyntax before = 1; + PHPSyntax after = 2; + } +} + +message PHPSyntax { + oneof syntax { + Comment comment = 1; + Class class = 2; + Function function = 3; + Method method = 4; + VariableDeclaration variableDeclaration = 5; + Plus plus = 6; + Minus minus = 7; + Times times = 8; + DividedBy dividedBy = 9; + Modulo modulo = 10; + Power power = 11; + Negate negate = 12; + FloorDivision floorDivision = 13; + BAnd bAnd = 14; + BOr bOr = 15; + BXOr bXOr = 16; + LShift lShift = 17; + RShift rShift = 18; + And and = 19; + Not not = 20; + Or or = 21; + XOr xOr = 22; + Call call = 23; + Cast cast = 24; + LessThan lessThan = 25; + LessThanEqual lessThanEqual = 26; + GreaterThan greaterThan = 27; + GreaterThanEqual greaterThanEqual = 28; + Equal equal = 29; + StrictEqual strictEqual = 30; + Comparison comparison = 31; + InstanceOf instanceOf = 32; + MemberAccess memberAccess = 33; + New new = 34; + SequenceExpression sequenceExpression = 35; + Subscript subscript = 36; + Member member = 37; + Array array = 38; + Float float = 39; + Integer integer = 40; + KeyValue keyValue = 41; + TextElement textElement = 42; + Assignment assignment = 43; + Break break = 44; + Catch catch = 45; + Continue continue = 46; + DoWhile doWhile = 47; + Else else = 48; + Finally finally = 49; + For for = 50; + ForEach forEach = 51; + Goto goto = 52; + If if = 53; + Match match = 54; + Pattern pattern = 55; + Return return = 56; + Statements statements = 57; + Throw throw = 58; + Try try = 59; + While while = 60; + Yield yield = 61; + AliasAs aliasAs = 62; + ArrayElement arrayElement = 63; + BaseTypeDeclaration baseTypeDeclaration = 64; + CastType castType = 65; + ClassBaseClause classBaseClause = 66; + ClassConstDeclaration classConstDeclaration = 67; + ClassInterfaceClause classInterfaceClause = 68; + ClassModifier classModifier = 69; + Clone clone = 70; + ConstDeclaration constDeclaration = 71; + ConstructorDeclaration constructorDeclaration = 72; + Context context = 73; + Declare declare = 74; + DeclareDirective declareDirective = 75; + DestructorDeclaration destructorDeclaration = 76; + Echo echo = 77; + Empty empty = 78; + EmptyIntrinsic emptyIntrinsic = 79; + Error error = 80; + ErrorControl errorControl = 81; + EvalIntrinsic evalIntrinsic = 82; + ExitIntrinsic exitIntrinsic = 83; + GlobalDeclaration globalDeclaration = 84; + Identifier identifier = 85; + Include include = 86; + IncludeOnce includeOnce = 87; + InsteadOf insteadOf = 88; + InterfaceBaseClause interfaceBaseClause = 89; + InterfaceDeclaration interfaceDeclaration = 90; + IssetIntrinsic issetIntrinsic = 91; + LabeledStatement labeledStatement = 92; + Namespace namespace = 93; + NamespaceAliasingClause namespaceAliasingClause = 94; + NamespaceName namespaceName = 95; + NamespaceUseClause namespaceUseClause = 96; + NamespaceUseDeclaration namespaceUseDeclaration = 97; + NamespaceUseGroupClause namespaceUseGroupClause = 98; + NewVariable newVariable = 99; + PrintIntrinsic printIntrinsic = 100; + PropertyDeclaration propertyDeclaration = 101; + PropertyModifier propertyModifier = 102; + QualifiedName qualifiedName = 103; + RelativeScope relativeScope = 104; + Require require = 105; + RequireOnce requireOnce = 106; + ReturnType returnType = 107; + ScalarType scalarType = 108; + ShellCommand shellCommand = 109; + SimpleVariable simpleVariable = 110; + Static static = 111; + Text text = 112; + TraitDeclaration traitDeclaration = 113; + TraitUseClause traitUseClause = 114; + TraitUseSpecification traitUseSpecification = 115; + TypeDeclaration typeDeclaration = 116; + Unset unset = 117; + Update update = 118; + UseClause useClause = 119; + VariableName variableName = 120; + Annotation annotation = 121; + List list = 122; + } +} + +message Comment { + string commentContent = 1; +} + +message Class { + repeated PHPDiff classContext = 1; + PHPDiff classIdentifier = 2; + repeated PHPDiff classSuperclasses = 3; + PHPDiff classBody = 4; +} + +message Function { + repeated PHPDiff functionContext = 1; + PHPDiff functionName = 2; + repeated PHPDiff functionParameters = 3; + PHPDiff functionBody = 4; +} + +message Method { + repeated PHPDiff methodContext = 1; + PHPDiff methodReceiver = 2; + PHPDiff methodName = 3; + repeated PHPDiff methodParameters = 4; + PHPDiff methodBody = 5; +} + +message VariableDeclaration { + repeated PHPDiff variableDeclarations = 1; +} + +message Plus { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message Minus { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message Times { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message DividedBy { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message Modulo { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message Power { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message Negate { + PHPDiff value = 1; +} + +message FloorDivision { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message BAnd { + PHPDiff left = 1; + PHPDiff right = 2; +} + +message BOr { + PHPDiff left = 1; + PHPDiff right = 2; +} + +message BXOr { + PHPDiff left = 1; + PHPDiff right = 2; +} + +message LShift { + PHPDiff left = 1; + PHPDiff right = 2; +} + +message RShift { + PHPDiff left = 1; + PHPDiff right = 2; +} + +message And { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message Not { + PHPDiff value = 1; +} + +message Or { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message XOr { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message Call { + repeated PHPDiff callContext = 1; + PHPDiff callFunction = 2; + repeated PHPDiff callParams = 3; + PHPDiff callBlock = 4; +} + +message Cast { + PHPDiff castSubject = 1; + PHPDiff castType = 2; +} + +message LessThan { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message LessThanEqual { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message GreaterThan { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message GreaterThanEqual { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message Equal { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message StrictEqual { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message Comparison { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message InstanceOf { + PHPDiff instanceOfSubject = 1; + PHPDiff instanceOfObject = 2; +} + +message MemberAccess { + PHPDiff lhs = 1; + bytes rhs = 2; +} + +message New { + repeated PHPDiff newSubject = 1; +} + +message SequenceExpression { + PHPDiff firstExpression = 1; + PHPDiff secondExpression = 2; +} + +message Subscript { + PHPDiff lhs = 1; + repeated PHPDiff rhs = 2; +} + +message Member { + PHPDiff lhs = 1; + PHPDiff rhs = 2; +} + +message Array { + repeated PHPDiff arrayElements = 1; +} + +message Float { + string floatContent = 1; +} + +message Integer { + string integerContent = 1; +} + +message KeyValue { + PHPDiff key = 1; + PHPDiff value = 2; +} + +message TextElement { + string textElementContent = 1; +} + +message Assignment { + repeated PHPDiff assignmentContext = 1; + PHPDiff assignmentTarget = 2; + PHPDiff assignmentValue = 3; +} + +message Break { + PHPDiff value = 1; +} + +message Catch { + PHPDiff catchException = 1; + PHPDiff catchBody = 2; +} + +message Continue { + PHPDiff value = 1; +} + +message DoWhile { + PHPDiff doWhileCondition = 1; + PHPDiff doWhileBody = 2; +} + +message Else { + PHPDiff elseCondition = 1; + PHPDiff elseBody = 2; +} + +message Finally { + PHPDiff value = 1; +} + +message For { + PHPDiff forBefore = 1; + PHPDiff forCondition = 2; + PHPDiff forStep = 3; + PHPDiff forBody = 4; +} + +message ForEach { + PHPDiff forEachBinding = 1; + PHPDiff forEachSubject = 2; + PHPDiff forEachBody = 3; +} + +message Goto { + PHPDiff gotoLocation = 1; +} + +message If { + PHPDiff ifCondition = 1; + PHPDiff ifThenBody = 2; + PHPDiff ifElseBody = 3; +} + +message Match { + PHPDiff matchSubject = 1; + PHPDiff matchPatterns = 2; +} + +message Pattern { + PHPDiff value = 1; + PHPDiff patternBody = 2; +} + +message Return { + PHPDiff value = 1; +} + +message Statements { + repeated PHPDiff statements = 1; +} + +message Throw { + PHPDiff value = 1; +} + +message Try { + PHPDiff tryBody = 1; + repeated PHPDiff tryCatch = 2; +} + +message While { + PHPDiff whileCondition = 1; + PHPDiff whileBody = 2; +} + +message Yield { + PHPDiff value = 1; +} + +message AliasAs { + PHPDiff aliasAsName = 1; + PHPDiff aliasAsModifier = 2; + PHPDiff aliasAsClause = 3; +} + +message ArrayElement { + PHPDiff value = 1; +} + +message BaseTypeDeclaration { + PHPDiff value = 1; +} + +message CastType { + string _castType = 1; +} + +message ClassBaseClause { + PHPDiff value = 1; +} + +message ClassConstDeclaration { + PHPDiff visibility = 1; + repeated PHPDiff elements = 2; +} + +message ClassInterfaceClause { + repeated PHPDiff values = 1; +} + +message ClassModifier { + string value = 1; +} + +message Clone { + PHPDiff value = 1; +} + +message ConstDeclaration { + repeated PHPDiff values = 1; +} + +message ConstructorDeclaration { + repeated PHPDiff modifiers = 1; + repeated PHPDiff parameters = 2; + PHPDiff body = 3; +} + +message Context { + repeated PHPDiff contextTerms = 1; + PHPDiff contextSubject = 2; +} + +message Declare { + PHPDiff left = 1; + PHPDiff right = 2; +} + +message DeclareDirective { + PHPDiff value = 1; +} + +message DestructorDeclaration { + repeated PHPDiff body = 1; + PHPDiff name = 2; +} + +message Echo { + PHPDiff value = 1; +} + +message Empty { } + +message EmptyIntrinsic { + PHPDiff value = 1; +} + +message Error { + repeated ErrorSite errorCallStack = 1; + repeated string errorExpected = 2; + string errorActual = 3; + repeated PHPDiff errorChildren = 4; +} + +message ErrorControl { + PHPDiff value = 1; +} + +message EvalIntrinsic { + PHPDiff value = 1; +} + +message ExitIntrinsic { + PHPDiff value = 1; +} + +message GlobalDeclaration { + repeated PHPDiff values = 1; +} + +message Identifier { + bytes name = 1; +} + +message Include { + PHPDiff value = 1; +} + +message IncludeOnce { + PHPDiff value = 1; +} + +message InsteadOf { + PHPDiff left = 1; + PHPDiff right = 2; +} + +message InterfaceBaseClause { + repeated PHPDiff values = 1; +} + +message InterfaceDeclaration { + PHPDiff name = 1; + PHPDiff base = 2; + repeated PHPDiff declarations = 3; +} + +message IssetIntrinsic { + PHPDiff value = 1; +} + +message LabeledStatement { + PHPDiff _labeledStatementIdentifier = 1; +} + +message Namespace { + repeated PHPDiff namespaceName = 1; + PHPDiff namespaceBody = 2; +} + +message NamespaceAliasingClause { + PHPDiff value = 1; +} + +message NamespaceName { + repeated PHPDiff names = 1; +} + +message NamespaceUseClause { + repeated PHPDiff values = 1; +} + +message NamespaceUseDeclaration { + repeated PHPDiff values = 1; +} + +message NamespaceUseGroupClause { + repeated PHPDiff values = 1; +} + +message NewVariable { + repeated PHPDiff values = 1; +} + +message PrintIntrinsic { + PHPDiff value = 1; +} + +message PropertyDeclaration { + PHPDiff modifier = 1; + repeated PHPDiff elements = 2; +} + +message PropertyModifier { + PHPDiff visibility = 1; + PHPDiff static = 2; +} + +message QualifiedName { + PHPDiff name = 1; + PHPDiff identifier = 2; +} + +message RelativeScope { + string value = 1; +} + +message Require { + PHPDiff value = 1; +} + +message RequireOnce { + PHPDiff value = 1; +} + +message ReturnType { + PHPDiff value = 1; +} + +message ScalarType { + string value = 1; +} + +message ShellCommand { + string value = 1; +} + +message SimpleVariable { + PHPDiff value = 1; +} + +message Static { + string value = 1; +} + +message Text { + string value = 1; +} + +message TraitDeclaration { + PHPDiff traitName = 1; + repeated PHPDiff traitStatements = 2; +} + +message TraitUseClause { + repeated PHPDiff namespace = 1; + PHPDiff alias = 2; +} + +message TraitUseSpecification { + repeated PHPDiff values = 1; +} + +message TypeDeclaration { + PHPDiff value = 1; +} + +message Unset { + PHPDiff value = 1; +} + +message Update { + PHPDiff _updateSubject = 1; +} + +message UseClause { + repeated PHPDiff values = 1; +} + +message VariableName { + PHPDiff value = 1; +} + +message Annotation { + PHPDiff annotationSubject = 1; + PHPDiff annotationType = 2; +} + +message List { + repeated PHPDiff listContent = 1; +} diff --git a/proto/terms.proto b/proto/terms.proto index 7612ed33a..5294fda54 100644 --- a/proto/terms.proto +++ b/proto/terms.proto @@ -4,14 +4,23 @@ syntax = "proto3"; package github.semantic; import "go_term.proto"; +import "go_diff.proto"; import "haskell_term.proto"; +import "haskell_diff.proto"; import "java_term.proto"; +import "java_diff.proto"; import "json_term.proto"; +import "json_diff.proto"; import "markdown_term.proto"; +import "markdown_diff.proto"; import "python_term.proto"; +import "python_diff.proto"; import "ruby_term.proto"; +import "ruby_diff.proto"; import "typescript_term.proto"; +import "typescript_diff.proto"; import "php_term.proto"; +import "php_diff.proto"; import "types.proto"; option java_package = "com.github.semantic.terms"; @@ -33,3 +42,22 @@ message ParseTree { phpterm.PHPTerm php_tree = 12; } } + +message DiffTree { + Language language_before = 1; + Language language_after = 2; + string path_before = 3; + string path_after = 4; + oneof response_type { + string error = 5; + godiff.GoDiff go_diff = 6; + haskelldiff.HaskellDiff haskell_diff = 7; + javadiff.JavaDiff java_diff = 8; + jsondiff.JSONDiff json_diff = 9; + markdowndiff.MarkdownDiff markdown_diff = 10; + pythondiff.PythonDiff python_diff = 11; + rubydiff.RubyDiff ruby_diff = 12; + typescriptdiff.TypeScriptDiff typescript_diff = 13; + phpdiff.PHPDiff php_diff = 14; + } +} diff --git a/semantic.cabal b/semantic.cabal index 09969beea..e41d8c92b 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -89,6 +89,7 @@ library , Data.JSON.Fields , Data.Language , Data.Map.Monoidal + , Data.Proto.DiffTree , Data.Proto.ParseTree , Data.Patch , Data.Project diff --git a/src/Data/Graph/DiffVertex.hs b/src/Data/Graph/DiffVertex.hs index 7725ba826..82099cd0b 100644 --- a/src/Data/Graph/DiffVertex.hs +++ b/src/Data/Graph/DiffVertex.hs @@ -89,7 +89,5 @@ instance ToJSON DiffVertex where toJSON (DiffVertex i (Inserted t)) = object [ "id" .= T.pack (show i), "inserted" .= t ] toJSON (DiffVertex i (Replaced t)) = object [ "id" .= T.pack (show i), "replaced" .= t ] toJSON (DiffVertex i (Merged t)) = object [ "id" .= T.pack (show i), "merged" .= t ] - -- TODO - -- toEncoding = undefined instance VertexTag DiffVertex where uniqueTag = diffVertexId diff --git a/src/Data/Proto/DiffTree.hs b/src/Data/Proto/DiffTree.hs new file mode 100644 index 000000000..dc3fe6629 --- /dev/null +++ b/src/Data/Proto/DiffTree.hs @@ -0,0 +1,93 @@ +{-# LANGUAGE DeriveAnyClass #-} +module Data.Proto.DiffTree (DiffTree(..), ResponseType(..)) where + +import Prologue + +import Data.Language +import Data.Term +import Data.Diff +import qualified Language.Go.Assignment as Go +import qualified Language.Haskell.Assignment as Haskell +import qualified Language.Java.Assignment as Java +import qualified Language.JSON.Assignment as JSON +import qualified Language.Markdown.Assignment as Markdown +import qualified Language.PHP.Assignment as PHP +import qualified Language.Python.Assignment as Python +import qualified Language.Ruby.Assignment as Ruby +import qualified Language.TypeScript.Assignment as TypeScript +import Proto3.Suite +import qualified Proto3.Suite as PB +import qualified Proto3.Wire.Encode as Encode + +type GoDiff = Diff (Sum Go.Syntax) () () +type HaskellDiff = Diff (Sum Haskell.Syntax) () () +type JavaDiff = Diff (Sum Java.Syntax) () () +type JSONDiff = Diff (Sum JSON.Syntax) () () +type MarkdownDiff = Diff (Sum Markdown.Syntax) () () +type PythonDiff = Diff (Sum Python.Syntax) () () +type RubyDiff = Diff (Sum Ruby.Syntax) () () +type TypeScriptDiff = Diff (Sum TypeScript.Syntax) () () +type PHPDiff = Diff (Sum PHP.Syntax) () () + +data DiffTree + = DiffTree + { languageBefore :: Language + , languageAfter :: Language + , pathBefore :: FilePath + , pathAfter :: FilePath + , responseType :: Maybe ResponseType + } deriving (Eq, Show, Generic, Named) + +data ResponseType + = ParseDiffError String + | GoDiffResponse GoDiff + | HaskellDiffResponse HaskellDiff + | JavaDiffResponse JavaDiff + | JSONDiffResponse JSONDiff + | MarkdownDiffResponse MarkdownDiff + | PythonDiffResponse PythonDiff + | RubyDiffResponse RubyDiff + | TypeScriptDiffResponse TypeScriptDiff + | PHPDiffResponse PHPDiff + deriving (Eq, Show) + + +-- Instances + +instance Message DiffTree where + encodeMessage _ DiffTree{..} + = encodeMessageField 1 languageBefore + <> encodeMessageField 2 languageAfter + <> encodeMessageField 3 pathBefore + <> encodeMessageField 4 pathAfter + <> case responseType of + Just (ParseDiffError x) -> Encode.embedded 5 (encodeMessageField 1 x) + Just (GoDiffResponse x) -> Encode.embedded 6 (encodeMessage 1 x) + Just (HaskellDiffResponse x) -> Encode.embedded 7 (encodeMessage 1 x) + Just (JavaDiffResponse x) -> Encode.embedded 8 (encodeMessage 1 x) + Just (JSONDiffResponse x) -> Encode.embedded 9 (encodeMessage 1 x) + Just (MarkdownDiffResponse x) -> Encode.embedded 10 (encodeMessage 1 x) + Just (PythonDiffResponse x) -> Encode.embedded 11 (encodeMessage 1 x) + Just (RubyDiffResponse x) -> Encode.embedded 12 (encodeMessage 1 x) + Just (TypeScriptDiffResponse x) -> Encode.embedded 13 (encodeMessage 1 x) + Just (PHPDiffResponse x) -> Encode.embedded 14 (encodeMessage 1 x) + _ -> mempty + decodeMessage = undefined + dotProto _ = + [ DotProtoMessageField $ DotProtoField 1 (Prim . Named $ Single "Language") (Single "language_before") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim . Named $ Single "Language") (Single "language_after") [] Nothing + , DotProtoMessageField $ DotProtoField 3 (Prim PB.String) (Single "path_before") [] Nothing + , DotProtoMessageField $ DotProtoField 4 (Prim PB.String) (Single "path_after") [] Nothing + , DotProtoMessageOneOf (Single "response_type") + [ DotProtoField 5 (Prim PB.String) (Single "error") [] Nothing + , DotProtoField 6 (Prim . Named $ Dots (Path ["godiff", "GoDiff"])) (Single "go_diff") [] Nothing + , DotProtoField 7 (Prim . Named $ Dots (Path ["haskelldiff", "HaskellDiff"])) (Single "haskell_diff") [] Nothing + , DotProtoField 8 (Prim . Named $ Dots (Path ["javadiff", "JavaDiff"])) (Single "java_diff") [] Nothing + , DotProtoField 9 (Prim . Named $ Dots (Path ["jsondiff", "JSONDiff"])) (Single "json_diff") [] Nothing + , DotProtoField 10 (Prim . Named $ Dots (Path ["markdowndiff", "MarkdownDiff"])) (Single "markdown_diff") [] Nothing + , DotProtoField 11 (Prim . Named $ Dots (Path ["pythondiff", "PythonDiff"])) (Single "python_diff") [] Nothing + , DotProtoField 12 (Prim . Named $ Dots (Path ["rubydiff", "RubyDiff"])) (Single "ruby_diff") [] Nothing + , DotProtoField 13 (Prim . Named $ Dots (Path ["typescriptdiff", "TypeScriptDiff"])) (Single "typescript_diff") [] Nothing + , DotProtoField 14 (Prim . Named $ Dots (Path ["phpdiff", "PHPDiff"])) (Single "php_diff") [] Nothing + ] + ] diff --git a/src/Data/Proto/ParseTree.hs b/src/Data/Proto/ParseTree.hs index 04211e0bc..6022fe800 100644 --- a/src/Data/Proto/ParseTree.hs +++ b/src/Data/Proto/ParseTree.hs @@ -35,12 +35,28 @@ data ParseTree , responseType :: Maybe ResponseType } deriving (Eq, Show, Generic, Named) +data ResponseType + = ParseError String + | GoResponse GoTerm + | HaskellResponse HaskellTerm + | JavaResponse JavaTerm + | JSONResponse JSONTerm + | MarkdownResponse MarkdownTerm + | PythonResponse PythonTerm + | RubyResponse RubyTerm + | TypeScriptResponse TypeScriptTerm + | PHPResponse PHPTerm + deriving (Eq, Show) + + +-- Instances + instance Message ParseTree where encodeMessage _ ParseTree{..} = encodeMessageField 1 language <> encodeMessageField 2 path <> case responseType of - Just (ParseError x) -> Encode.embedded 3 (encodeMessageField 1 x) + Just (ParseError x) -> Encode.embedded 3 (encodeMessageField 1 x) Just (GoResponse x) -> Encode.embedded 4 (encodeMessage 1 x) Just (HaskellResponse x) -> Encode.embedded 5 (encodeMessage 1 x) Just (JavaResponse x) -> Encode.embedded 6 (encodeMessage 1 x) @@ -68,16 +84,3 @@ instance Message ParseTree where , DotProtoField 12 (Prim . Named $ Dots (Path ["phpterm", "PHPTerm"])) (Single "php_tree") [] Nothing ] ] - -data ResponseType - = ParseError String - | GoResponse GoTerm - | HaskellResponse HaskellTerm - | JavaResponse JavaTerm - | JSONResponse JSONTerm - | MarkdownResponse MarkdownTerm - | PythonResponse PythonTerm - | RubyResponse RubyTerm - | TypeScriptResponse TypeScriptTerm - | PHPResponse PHPTerm - deriving (Eq, Show) From 3bb5a8ea39e5414debdec39c12a3d818ea3088b0 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 11 Sep 2018 10:40:52 -0700 Subject: [PATCH 33/39] Remove extra import --- src/Data/Proto/DiffTree.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Data/Proto/DiffTree.hs b/src/Data/Proto/DiffTree.hs index dc3fe6629..c25b38f69 100644 --- a/src/Data/Proto/DiffTree.hs +++ b/src/Data/Proto/DiffTree.hs @@ -4,7 +4,6 @@ module Data.Proto.DiffTree (DiffTree(..), ResponseType(..)) where import Prologue import Data.Language -import Data.Term import Data.Diff import qualified Language.Go.Assignment as Go import qualified Language.Haskell.Assignment as Haskell From 0eff6f70addc1da3718ced44e985b50e2d3d44b4 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 11 Sep 2018 10:49:21 -0700 Subject: [PATCH 34/39] Remove these specialized diff functions --- src/Semantic/Diff.hs | 48 -------------------------------------------- 1 file changed, 48 deletions(-) diff --git a/src/Semantic/Diff.hs b/src/Semantic/Diff.hs index 33d58b48d..1a914abf0 100644 --- a/src/Semantic/Diff.hs +++ b/src/Semantic/Diff.hs @@ -1,10 +1,6 @@ {-# LANGUAGE ConstraintKinds, GADTs, RankNTypes, ScopedTypeVariables #-} module Semantic.Diff ( runDiff - , runPythonDiff - , runRubyDiff - , runTypeScriptDiff - , runJSONDiff , diffBlobTOCPairs ) where @@ -43,50 +39,6 @@ runDiff SExpressionDiffRenderer = withParsedBlobPairs (const pure) (const (seria runDiff ShowDiffRenderer = withParsedBlobPairs (const pure) (const (serialize Show)) runDiff DOTDiffRenderer = withParsedBlobPairs (const pure) (const (render renderTreeGraph)) >=> serialize (DOT (diffStyle "diffs")) -runRubyDiff :: (Member Telemetry effs, Member (Lift IO) effs, Member Distribute effs, Member Task effs) => [BlobPair] -> Eff effs [Diff (Sum Ruby.Syntax) () ()] -runRubyDiff = flip distributeFor (\ (blobs :: BlobPair) -> do - terms <- distributeFor blobs (parse rubyParser) - diffs <- diffTerms blobs terms - pure (bimap (const ()) (const ()) diffs)) - where - diffTerms blobs terms = time "diff" languageTag $ do - diff <- diff (runJoin terms) - diff <$ writeStat (Stat.count "diff.nodes" (bilength diff) languageTag) - where languageTag = languageTagForBlobPair blobs - -runTypeScriptDiff :: (Member Telemetry effs, Member (Lift IO) effs, Member Distribute effs, Member Task effs) => [BlobPair] -> Eff effs [Diff (Sum TypeScript.Syntax) () ()] -runTypeScriptDiff = flip distributeFor (\ (blobs :: BlobPair) -> do - terms <- distributeFor blobs (parse typescriptParser) - diffs <- diffTerms blobs terms - pure (bimap (const ()) (const ()) diffs)) - where - diffTerms blobs terms = time "diff" languageTag $ do - diff <- diff (runJoin terms) - diff <$ writeStat (Stat.count "diff.nodes" (bilength diff) languageTag) - where languageTag = languageTagForBlobPair blobs - -runPythonDiff :: (Member Telemetry effs, Member (Lift IO) effs, Member Distribute effs, Member Task effs) => [BlobPair] -> Eff effs [Diff (Sum Python.Syntax) () ()] -runPythonDiff = flip distributeFor (\ (blobs :: BlobPair) -> do - terms <- distributeFor blobs (parse pythonParser) - diffs <- diffTerms blobs terms - pure (bimap (const ()) (const ()) diffs)) - where - diffTerms blobs terms = time "diff" languageTag $ do - diff <- diff (runJoin terms) - diff <$ writeStat (Stat.count "diff.nodes" (bilength diff) languageTag) - where languageTag = languageTagForBlobPair blobs - -runJSONDiff :: (Member Telemetry effs, Member (Lift IO) effs, Member Distribute effs, Member Task effs) => [BlobPair] -> Eff effs [Diff (Sum JSON.Syntax) () ()] -runJSONDiff = flip distributeFor (\ (blobs :: BlobPair) -> do - terms <- distributeFor blobs (parse jsonParser) - diffs <- diffTerms blobs terms - pure (bimap (const ()) (const ()) diffs)) - where - diffTerms blobs terms = time "diff" languageTag $ do - diff <- diff (runJoin terms) - diff <$ writeStat (Stat.count "diff.nodes" (bilength diff) languageTag) - where languageTag = languageTagForBlobPair blobs - data SomeTermPair typeclasses ann where SomeTermPair :: ApplyAll typeclasses syntax => Join These (Term syntax ann) -> SomeTermPair typeclasses ann From b9e2491d74ec6245cc06bf0705975d9cadf88749 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 11 Sep 2018 10:56:04 -0700 Subject: [PATCH 35/39] Extra space --- src/Data/Term.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/Term.hs b/src/Data/Term.hs index 0c45e97ee..22faabefb 100644 --- a/src/Data/Term.hs +++ b/src/Data/Term.hs @@ -103,7 +103,7 @@ instance (Show1 f, Show a) => Show (Term f a) where showsPrec = showsPrec1 instance (Named1 f, Message1 f) => Message (Term f ()) where - encodeMessage num (Term (In _ f)) = Encode.embedded num (liftEncodeMessage encodeMessage 1 f) + encodeMessage num (Term (In _ f)) = Encode.embedded num (liftEncodeMessage encodeMessage 1 f) decodeMessage num = termIn () . fromMaybe undefined <$> Decode.at (Decode.embedded (liftDecodeMessage decodeMessage 1)) num dotProto (_ :: Proxy (Term f ())) = [ DotProtoMessageField (DotProtoField 1 (Prim . Named $ Single (nameOf1 (Proxy @f))) (Single "syntax") [] Nothing) ] From 177ce176e4edd3ec5d714842e80527b0b858adf8 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 11 Sep 2018 11:33:59 -0700 Subject: [PATCH 36/39] More extra imports --- src/Rendering/Graph.hs | 2 -- src/Semantic/Diff.hs | 4 ---- 2 files changed, 6 deletions(-) diff --git a/src/Rendering/Graph.hs b/src/Rendering/Graph.hs index db4526b22..1b835ab60 100644 --- a/src/Rendering/Graph.hs +++ b/src/Rendering/Graph.hs @@ -99,5 +99,3 @@ instance (ConstructorName syntax, Foldable syntax, HasField fields1 Range, HasFi let root = vertex (DiffVertex i a) subGraph <- foldl' (\acc x -> overlay <$> acc <*> local (const root) x) (pure mempty) syntax pure (parent `connect` root `overlay` subGraph) - - -- flatTerm (n, r, s) = FlatTerm n r s diff --git a/src/Semantic/Diff.hs b/src/Semantic/Diff.hs index 1a914abf0..efe756ec7 100644 --- a/src/Semantic/Diff.hs +++ b/src/Semantic/Diff.hs @@ -24,10 +24,6 @@ import Semantic.Task as Task import Serializing.Format import Rendering.JSON (SomeJSON (..)) import qualified Rendering.JSON as JSON -import qualified Language.TypeScript.Assignment as TypeScript -import qualified Language.Ruby.Assignment as Ruby -import qualified Language.JSON.Assignment as JSON -import qualified Language.Python.Assignment as Python runDiff :: (Member Distribute effs, Member (Exc SomeException) effs, Member (Lift IO) effs, Member Task effs, Member Telemetry effs) => DiffRenderer output -> [BlobPair] -> Eff effs Builder runDiff ToCDiffRenderer = withParsedBlobPairs (decorate . declarationAlgebra) (render . renderToCDiff) >=> serialize JSON From 77d296c5f18193ace1a96a9e94377f3b251e643a Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 11 Sep 2018 15:19:02 -0700 Subject: [PATCH 37/39] Call error here instead of undefined --- src/Data/Graph/ControlFlowVertex.hs | 6 +++--- src/Data/Graph/TermVertex.hs | 4 ++-- src/Data/Proto/DiffTree.hs | 2 +- src/Data/Proto/ParseTree.hs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Data/Graph/ControlFlowVertex.hs b/src/Data/Graph/ControlFlowVertex.hs index 0901dd363..09a2927d1 100644 --- a/src/Data/Graph/ControlFlowVertex.hs +++ b/src/Data/Graph/ControlFlowVertex.hs @@ -91,7 +91,7 @@ instance Named (G.Graph ControlFlowVertex) where nameOf _ = "ControlFlowGraph" instance Message (G.Graph ControlFlowVertex) where encodeMessage _ graph = encodeMessageField 1 (NestedVec (fromList (G.vertexList graph))) <> encodeMessageField 2 (NestedVec (fromList (G.edgeList graph))) - decodeMessage = undefined + decodeMessage = error "decodeMessage not implemented for (G.Graph ControlFlowVertex)" dotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Repeated . Named $ Single "ControlFlowVertex") (Single "vertices") [] Nothing , DotProtoMessageField $ DotProtoField 2 (Repeated . Named $ Single "ControlFlowEdge") (Single "edges") [] Nothing @@ -110,7 +110,7 @@ instance Message ControlFlowVertex where encodeMessage _ v@Variable{..} = Encode.embedded 4 (encodePrimitive 1 (uniqueTag v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 (vertexIdentifier v) <> encodePrimitive 4 vertexModuleName <> Encode.embedded 5 (encodeMessage 1 vertexSpan)) encodeMessage _ v@Method{..} = Encode.embedded 5 (encodePrimitive 1 (uniqueTag v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 (vertexIdentifier v) <> encodePrimitive 4 vertexModuleName <> Encode.embedded 5 (encodeMessage 1 vertexSpan)) encodeMessage _ v@Function{..} = Encode.embedded 6 (encodePrimitive 1 (uniqueTag v) <> encodePrimitive 2 vertexName <> encodePrimitive 3 (vertexIdentifier v) <> encodePrimitive 4 vertexModuleName <> Encode.embedded 5 (encodeMessage 1 vertexSpan)) - decodeMessage = undefined + decodeMessage = error "decodeMessage not implemented for ControlFlowVertex" dotProto _ = [ DotProtoMessageOneOf (Single "vertex") [ DotProtoField 1 (Prim . Named $ Single "Package") (Single "package") [] Nothing @@ -143,7 +143,7 @@ instance Named (G.Edge ControlFlowVertex) where nameOf _ = "ControlFlowEdge" instance Message (G.Edge ControlFlowVertex) where encodeMessage _ (G.Edge (from, to)) = encodePrimitive 1 (uniqueTag from) <> encodePrimitive 2 (uniqueTag to) - decodeMessage = undefined + decodeMessage = error "decodeMessage not implemented for (G.Edge ControlFlowVertex)" dotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "from") [] Nothing , DotProtoMessageField $ DotProtoField 2 (Prim PB.Int64) (Single "to") [] Nothing diff --git a/src/Data/Graph/TermVertex.hs b/src/Data/Graph/TermVertex.hs index b33a62100..c8b5ec39f 100644 --- a/src/Data/Graph/TermVertex.hs +++ b/src/Data/Graph/TermVertex.hs @@ -39,7 +39,7 @@ instance Named (Graph TermVertex) where nameOf _ = "TermGraph" instance Message (Graph TermVertex) where encodeMessage _ graph = encodeMessageField 1 (NestedVec (fromList (vertexList graph))) <> encodeMessageField 2 (NestedVec (fromList (edgeList graph))) - decodeMessage = undefined + decodeMessage = error "decodeMessage not implemented for (Graph TermVertex)" dotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Repeated . Named $ Single "TermVertex") (Single "vertices") [] Nothing , DotProtoMessageField $ DotProtoField 2 (Repeated . Named $ Single "TermEdge") (Single "edges") [] Nothing @@ -48,7 +48,7 @@ instance Message (Graph TermVertex) where instance Named (Edge TermVertex) where nameOf _ = "TermEdge" instance Message (Edge TermVertex) where encodeMessage _ (Edge (from, to)) = encodePrimitive 1 (uniqueTag from) <> encodePrimitive 2 (uniqueTag to) - decodeMessage = undefined + decodeMessage = error "decodeMessage not implemented for (Edge TermVertex)" dotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "from") [] Nothing , DotProtoMessageField $ DotProtoField 2 (Prim PB.Int64) (Single "to") [] Nothing diff --git a/src/Data/Proto/DiffTree.hs b/src/Data/Proto/DiffTree.hs index c25b38f69..78859768c 100644 --- a/src/Data/Proto/DiffTree.hs +++ b/src/Data/Proto/DiffTree.hs @@ -71,7 +71,7 @@ instance Message DiffTree where Just (TypeScriptDiffResponse x) -> Encode.embedded 13 (encodeMessage 1 x) Just (PHPDiffResponse x) -> Encode.embedded 14 (encodeMessage 1 x) _ -> mempty - decodeMessage = undefined + decodeMessage = error "decodeMessage not implemented for DiffTree" dotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim . Named $ Single "Language") (Single "language_before") [] Nothing , DotProtoMessageField $ DotProtoField 2 (Prim . Named $ Single "Language") (Single "language_after") [] Nothing diff --git a/src/Data/Proto/ParseTree.hs b/src/Data/Proto/ParseTree.hs index 6022fe800..41708f85e 100644 --- a/src/Data/Proto/ParseTree.hs +++ b/src/Data/Proto/ParseTree.hs @@ -67,7 +67,7 @@ instance Message ParseTree where Just (TypeScriptResponse x) -> Encode.embedded 11 (encodeMessage 1 x) Just (PHPResponse x) -> Encode.embedded 12 (encodeMessage 1 x) _ -> mempty - decodeMessage = undefined + decodeMessage = error "decodeMessage not implemented for ParseTree" dotProto _ = [ DotProtoMessageField $ DotProtoField 1 (Prim . Named $ Single "Language") (Single "language") [] Nothing , DotProtoMessageField $ DotProtoField 2 (Prim PB.String) (Single "path") [] Nothing From 4dedb928b219acd4f7827830b44e5210601a7441 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 11 Sep 2018 15:20:19 -0700 Subject: [PATCH 38/39] New command line flag json-graph --- src/Rendering/Renderer.hs | 4 ++-- src/Semantic/CLI.hs | 4 ++-- src/Semantic/Diff.hs | 2 +- src/Semantic/Parse.hs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Rendering/Renderer.hs b/src/Rendering/Renderer.hs index d675f676e..c564a302a 100644 --- a/src/Rendering/Renderer.hs +++ b/src/Rendering/Renderer.hs @@ -36,7 +36,7 @@ data DiffRenderer output where -- | Render to JSON with the format documented in docs/json-format.md JSONDiffRenderer :: DiffRenderer (JSON "diffs" SomeJSON) -- | Render to JSON as an adjacency list. - JSONAdjDiffRenderer :: DiffRenderer (JSON "diffs" SomeJSON) + JSONGraphDiffRenderer :: DiffRenderer (JSON "diffs" SomeJSON) -- | Render to a 'ByteString' formatted as nested s-expressions with patches indicated. SExpressionDiffRenderer :: DiffRenderer Builder -- | Render to a 'ByteString' formatted as a DOT description of the diff. @@ -52,7 +52,7 @@ data TermRenderer output where -- | Render to JSON with the format documented in docs/json-format.md under “Term.” JSONTermRenderer :: TermRenderer (JSON "trees" SomeJSON) -- | Render to JSON as an adjacency list represenation. - JSONAdjTermRenderer :: TermRenderer (JSON "trees" SomeJSON) + JSONGraphTermRenderer :: TermRenderer (JSON "trees" SomeJSON) -- | Render to a 'ByteString' formatted as nested s-expressions. SExpressionTermRenderer :: TermRenderer Builder -- | Render to a list of symbols. diff --git a/src/Semantic/CLI.hs b/src/Semantic/CLI.hs index 909d7f176..bd7f57107 100644 --- a/src/Semantic/CLI.hs +++ b/src/Semantic/CLI.hs @@ -60,7 +60,7 @@ diffCommand = command "diff" (info diffArgumentsParser (progDesc "Compute change diffArgumentsParser = do renderer <- flag (Diff.runDiff SExpressionDiffRenderer) (Diff.runDiff SExpressionDiffRenderer) (long "sexpression" <> help "Output s-expression diff tree (default)") <|> flag' (Diff.runDiff JSONDiffRenderer) (long "json" <> help "Output JSON diff trees") - <|> flag' (Diff.runDiff JSONAdjDiffRenderer) (long "json-adj" <> help "Output JSON diff trees") + <|> flag' (Diff.runDiff JSONGraphDiffRenderer) (long "json-graph" <> help "Output JSON diff trees") <|> flag' (Diff.runDiff ToCDiffRenderer) (long "toc" <> help "Output JSON table of contents diff summary") <|> flag' (Diff.runDiff DOTDiffRenderer) (long "dot" <> help "Output the diff as a DOT graph") <|> flag' (Diff.runDiff ShowDiffRenderer) (long "show" <> help "Output using the Show instance (debug only, format subject to change without notice)") @@ -73,7 +73,7 @@ parseCommand = command "parse" (info parseArgumentsParser (progDesc "Generate pa parseArgumentsParser = do renderer <- flag (Parse.runParse SExpressionTermRenderer) (Parse.runParse SExpressionTermRenderer) (long "sexpression" <> help "Output s-expression parse trees (default)") <|> flag' (Parse.runParse JSONTermRenderer) (long "json" <> help "Output JSON parse trees") - <|> flag' (Parse.runParse JSONAdjTermRenderer) (long "json-adj" <> help "Output JSON adjacency list") + <|> flag' (Parse.runParse JSONGraphTermRenderer) (long "json-graph" <> help "Output JSON adjacency list") <|> flag' (Parse.runParse . SymbolsTermRenderer) (long "symbols" <> help "Output JSON symbol list") <*> (option symbolFieldsReader ( long "fields" <> help "Comma delimited list of specific fields to return (symbols output only)." diff --git a/src/Semantic/Diff.hs b/src/Semantic/Diff.hs index efe756ec7..77100bc6c 100644 --- a/src/Semantic/Diff.hs +++ b/src/Semantic/Diff.hs @@ -28,7 +28,7 @@ import qualified Rendering.JSON as JSON runDiff :: (Member Distribute effs, Member (Exc SomeException) effs, Member (Lift IO) effs, Member Task effs, Member Telemetry effs) => DiffRenderer output -> [BlobPair] -> Eff effs Builder runDiff ToCDiffRenderer = withParsedBlobPairs (decorate . declarationAlgebra) (render . renderToCDiff) >=> serialize JSON runDiff JSONDiffRenderer = withParsedBlobPairs (const pure) (render . renderJSONDiff) >=> serialize JSON -runDiff JSONAdjDiffRenderer = withParsedBlobPairs (const pure) (render . renderAdjGraph) >=> serialize JSON +runDiff JSONGraphDiffRenderer = withParsedBlobPairs (const pure) (render . renderAdjGraph) >=> serialize JSON where renderAdjGraph :: (Recursive t, ToTreeGraph DiffVertex (Base t)) => BlobPair -> t -> JSON.JSON "diffs" SomeJSON renderAdjGraph blob diff = renderJSONAdjDiff blob (renderTreeGraph diff) runDiff SExpressionDiffRenderer = withParsedBlobPairs (const pure) (const (serialize (SExpression ByConstructorName))) diff --git a/src/Semantic/Parse.hs b/src/Semantic/Parse.hs index 73bceed3a..b009653d0 100644 --- a/src/Semantic/Parse.hs +++ b/src/Semantic/Parse.hs @@ -24,7 +24,7 @@ import Serializing.Format runParse :: (Member Distribute effs, Member (Exc SomeException) effs, Member Task effs) => TermRenderer output -> [Blob] -> Eff effs Builder runParse JSONTermRenderer = withParsedBlobs renderJSONError (render . renderJSONTerm) >=> serialize JSON -runParse JSONAdjTermRenderer = withParsedBlobs renderJSONError (render . renderAdjGraph) >=> serialize JSON +runParse JSONGraphTermRenderer = withParsedBlobs renderJSONError (render . renderAdjGraph) >=> serialize JSON where renderAdjGraph :: (Recursive t, ToTreeGraph TermVertex (Base t)) => Blob -> t -> JSON.JSON "trees" SomeJSON renderAdjGraph blob term = renderJSONAdjTerm blob (renderTreeGraph term) runParse SExpressionTermRenderer = withParsedBlobs (\_ _ -> mempty) (const (serialize (SExpression ByConstructorName))) From 06029f2be62dd91f9019bc3684c95dae82dc9b1e Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Tue, 11 Sep 2018 15:29:24 -0700 Subject: [PATCH 39/39] Rename to source/target for consistently --- proto/types.proto | 8 ++++---- src/Data/Graph/ControlFlowVertex.hs | 4 ++-- src/Data/Graph/TermVertex.hs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/proto/types.proto b/proto/types.proto index a4a97d1ec..99c1810f4 100644 --- a/proto/types.proto +++ b/proto/types.proto @@ -75,8 +75,8 @@ message ControlFlowGraph { } message ControlFlowEdge { - int64 from = 1; - int64 to = 2; + int64 source = 1; + int64 target = 2; } message ControlFlowVertex { @@ -132,8 +132,8 @@ message TermGraph { } message TermEdge { - int64 from = 1; - int64 to = 2; + int64 source = 1; + int64 target = 2; } message TermVertex { diff --git a/src/Data/Graph/ControlFlowVertex.hs b/src/Data/Graph/ControlFlowVertex.hs index 09a2927d1..906f9e214 100644 --- a/src/Data/Graph/ControlFlowVertex.hs +++ b/src/Data/Graph/ControlFlowVertex.hs @@ -145,8 +145,8 @@ instance Message (G.Edge ControlFlowVertex) where encodeMessage _ (G.Edge (from, to)) = encodePrimitive 1 (uniqueTag from) <> encodePrimitive 2 (uniqueTag to) decodeMessage = error "decodeMessage not implemented for (G.Edge ControlFlowVertex)" dotProto _ = - [ DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "from") [] Nothing - , DotProtoMessageField $ DotProtoField 2 (Prim PB.Int64) (Single "to") [] Nothing + [ DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "source") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.Int64) (Single "target") [] Nothing ] diff --git a/src/Data/Graph/TermVertex.hs b/src/Data/Graph/TermVertex.hs index c8b5ec39f..cce6035e5 100644 --- a/src/Data/Graph/TermVertex.hs +++ b/src/Data/Graph/TermVertex.hs @@ -50,8 +50,8 @@ instance Message (Edge TermVertex) where encodeMessage _ (Edge (from, to)) = encodePrimitive 1 (uniqueTag from) <> encodePrimitive 2 (uniqueTag to) decodeMessage = error "decodeMessage not implemented for (Edge TermVertex)" dotProto _ = - [ DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "from") [] Nothing - , DotProtoMessageField $ DotProtoField 2 (Prim PB.Int64) (Single "to") [] Nothing + [ DotProtoMessageField $ DotProtoField 1 (Prim PB.Int64) (Single "source") [] Nothing + , DotProtoMessageField $ DotProtoField 2 (Prim PB.Int64) (Single "target") [] Nothing ] instance Message TermVertex where