1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

De-Prologue various assignment and syntax modules.

This commit is contained in:
Patrick Thomson 2020-01-27 13:10:00 -05:00
parent 458903ef6d
commit 26723f9e1e
15 changed files with 200 additions and 81 deletions

View File

@ -36,6 +36,7 @@ import Data.Abstract.Module (Module (moduleInfo), ModuleInfo (..))
import Data.ByteString.Builder
import Data.Graph
import Data.Graph.ControlFlowVertex
import Data.Map (Map)
import qualified Data.Map as Map
import qualified Data.Text.Encoding as T
import Source.Loc
@ -131,7 +132,7 @@ graphingModules recur m = do
where
-- NB: path is null for Languages like Ruby that have module imports that require concrete value semantics.
includeModule path
= let path' = if Prologue.null path then "unknown, concrete semantics required" else path
= let path' = if Prelude.null path then "unknown, concrete semantics required" else path
info = moduleInfo m
in moduleInclusion (moduleVertex (ModuleInfo path' (moduleLanguage info) (moduleOid info)))

View File

@ -1,4 +1,7 @@
{-# LANGUAGE DeriveGeneric, DeriveTraversable, DerivingVia, RecordWildCards #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE RecordWildCards #-}
module Assigning.Assignment.Table
( Table(tableAddresses)
, singleton
@ -7,10 +10,15 @@ module Assigning.Assignment.Table
, lookup
) where
import Prologue
import Prelude hiding (lookup)
import Data.Bifunctor
import Data.Functor.Classes
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import qualified Data.IntSet as IntSet
import Data.Monoid.Generic
import Data.Traversable
import GHC.Generics (Generic)
import Prelude hiding (lookup)
data Table i a = Table { tableAddresses :: [i], tableBranches :: IntMap a }
deriving (Eq, Foldable, Functor, Show, Traversable, Generic)

View File

@ -1,4 +1,10 @@
{-# LANGUAGE DataKinds, DeriveAnyClass, DeriveGeneric, GADTs, RankNTypes, RecordWildCards, TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} -- FIXME
module Diffing.Algorithm.RWS
( rws
@ -14,16 +20,27 @@ module Diffing.Algorithm.RWS
, equalTerms
) where
import Control.Applicative
import Control.Arrow ((&&&))
import Control.Monad.State.Strict
import Data.Diff (DiffF(..), comparing, deleting, inserting, merge)
import Data.Diff (DiffF (..), comparing, deleting, inserting, merge)
import Data.Edit
import Data.Foldable
import Data.Function
import Data.Functor.Classes
import Data.Functor.Foldable (cata)
import Data.Hashable
import Data.Hashable.Lifted
import Data.Ix (inRange)
import qualified Data.KdMap.Static as KdMap
import Data.List (sortOn)
import Data.Maybe
import Data.Term as Term
import Diffing.Algorithm (Diffable(..))
import Data.Traversable
import Diffing.Algorithm (Diffable (..))
import Diffing.Algorithm.RWS.FeatureVector
import Diffing.Algorithm.SES
import Prologue
import GHC.Generics (Generic)
-- | A relation on 'Term's, guaranteed constant-time in the size of the 'Term' by parametricity.
--

View File

@ -1,4 +1,8 @@
{-# LANGUAGE DataKinds, FlexibleContexts, RankNTypes, TypeFamilies, TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Language.Go.Assignment
( assignment
, Go.Syntax
@ -6,12 +10,14 @@ module Language.Go.Assignment
, Go.Term(..)
) where
import Prologue
import Assigning.Assignment hiding (Assignment, Error)
import qualified Assigning.Assignment as Assignment
import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl(..))
import Control.Monad
import Data.Abstract.Name (name)
import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl (..))
import Data.ImportPath (defaultAlias, importPath)
import Data.List.NonEmpty (NonEmpty (..), some1)
import Data.Sum
import Data.Syntax
(contextualize, emptyTerm, handleError, infixContext, makeTerm, makeTerm', makeTerm'', makeTerm1, parseError)
import qualified Data.Syntax as Syntax
@ -22,10 +28,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.Go.Syntax as Go.Syntax hiding (runeLiteral, labelName)
import Language.Go.Syntax as Go.Syntax hiding (labelName, runeLiteral)
import Language.Go.Term as Go
import Language.Go.Type as Go.Type
import Data.ImportPath (importPath, defaultAlias)
import TreeSitter.Go as Grammar
type Assignment = Assignment.Assignment [] Grammar

View File

@ -1,11 +1,15 @@
{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DeriveTraversable, DuplicateRecordFields #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DuplicateRecordFields #-}
module Language.Go.Type (module Language.Go.Type) where
import Prologue
import Data.Abstract.Evaluatable
import Data.Functor.Classes.Generic
import Data.Hashable.Lifted
import Data.JSON.Fields
import Diffing.Algorithm
import GHC.Generics (Generic1)
-- | A Bidirectional channel in Go (e.g. `chan`).
newtype BidirectionalChannel a = BidirectionalChannel { value :: a }

View File

@ -1,4 +1,9 @@
{-# LANGUAGE DataKinds, FlexibleContexts, RankNTypes, RecordWildCards, TypeFamilies, TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Language.Markdown.Assignment
( assignment
, Markdown.Syntax
@ -6,11 +11,11 @@ module Language.Markdown.Assignment
, Markdown.Term(..)
) where
import Prologue
import Assigning.Assignment hiding (Assignment, Error)
import qualified Assigning.Assignment as Assignment
import qualified CMarkGFM
import Control.Monad
import Data.Sum
import Data.Syntax (makeTerm)
import qualified Data.Syntax as Syntax
import qualified Data.Term as Term

View File

@ -1,11 +1,17 @@
{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DeriveTraversable, DuplicateRecordFields #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DuplicateRecordFields #-}
module Language.Markdown.Syntax (module Language.Markdown.Syntax) where
import Data.Abstract.Declarations
import Data.Functor.Classes
import Data.Functor.Classes.Generic
import Data.Hashable.Lifted
import Data.JSON.Fields
import qualified Data.Text as T
import Diffing.Algorithm
import Prologue hiding (Text)
import GHC.Generics (Generic1)
newtype Document a = Document { values :: [a] }
deriving (Declarations1, Foldable, Traversable, Functor, Generic1, Hashable1, Diffable, ToJSONFields1)

View File

@ -1,4 +1,8 @@
{-# LANGUAGE DataKinds, FlexibleContexts, RankNTypes, TypeFamilies, TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Language.PHP.Assignment
( assignment
, PHP.Syntax
@ -6,13 +10,14 @@ module Language.PHP.Assignment
, PHP.Term(..)
) where
import Prologue
import Assigning.Assignment hiding (Assignment, Error)
import qualified Assigning.Assignment as Assignment
import qualified Data.Abstract.Name as Name
import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl(..))
import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl (..))
import Data.Foldable
import Data.List.NonEmpty (NonEmpty (..), some1)
import qualified Data.List.NonEmpty as NonEmpty
import Data.Sum
import Data.Syntax
( contextualize
, emptyTerm

View File

@ -1,11 +1,19 @@
{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DeriveTraversable, DuplicateRecordFields, FlexibleContexts #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
module Language.PHP.Syntax (module Language.PHP.Syntax) where
import Prologue hiding (Text)
import Control.Lens.Getter
import Data.Functor.Classes
import Data.Functor.Classes.Generic
import Data.Hashable.Lifted
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.Map.Strict as Map
import Data.Maybe.Exts
import qualified Data.Text as T
import GHC.Generics (Generic1)
import Control.Abstract as Abstract
import Data.Abstract.BaseError

View File

@ -1,4 +1,8 @@
{-# LANGUAGE DataKinds, FlexibleContexts, RankNTypes, TypeFamilies, TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Language.Python.Assignment
( assignment
, Python.Syntax
@ -8,8 +12,12 @@ module Language.Python.Assignment
import Assigning.Assignment hiding (Assignment, Error)
import qualified Assigning.Assignment as Assignment
import Control.Monad
import Data.Abstract.Name (name)
import Data.Functor
import Data.List.NonEmpty (some1)
import qualified Data.List.NonEmpty as NonEmpty
import Data.Maybe
import Data.Sum
import Data.Syntax
( contextualize
@ -32,7 +40,6 @@ import qualified Data.Syntax.Statement as Statement
import qualified Data.Syntax.Type as Type
import Language.Python.Syntax as Python.Syntax
import Language.Python.Term as Python
import Prologue
import TreeSitter.Python as Grammar
type Assignment = Assignment.Assignment [] Grammar

View File

@ -1,14 +1,27 @@
{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DeriveTraversable, FlexibleContexts, RecordWildCards, TypeApplications #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
module Language.Python.Syntax (module Language.Python.Syntax) where
import Prologue
import Control.Lens.Getter
import Data.Aeson hiding (object)
import Data.Foldable
import Data.Functor.Classes
import Data.Functor.Classes.Generic
import Data.Hashable
import Data.Hashable.Lifted
import qualified Data.List as List
import Data.List.NonEmpty (NonEmpty (..))
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Map.Strict as Map
import Data.Maybe.Exts
import Data.Text (Text)
import qualified Data.Text as T
import Data.Traversable
import GHC.Generics (Generic, Generic1)
import System.FilePath.Posix
import Control.Abstract.Heap
@ -160,7 +173,7 @@ instance Evaluatable Import where
-- Last module path is the one we want to import
let path = NonEmpty.last modulePaths
((moduleScope, moduleFrame), _) <- require path
if Prologue.null xs then do
if Prelude.null xs then do
insertImportEdge moduleScope
insertFrameLink ScopeGraph.Import (Map.singleton moduleScope moduleFrame)
else do

View File

@ -1,4 +1,9 @@
{-# LANGUAGE DataKinds, FlexibleContexts, OverloadedStrings, RankNTypes, TypeFamilies, TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Language.Ruby.Assignment
( assignment
, Ruby.Syntax
@ -6,13 +11,15 @@ module Language.Ruby.Assignment
, Ruby.Term(..)
) where
import Prologue hiding (for, unless)
import Assigning.Assignment hiding (Assignment, Error)
import qualified Assigning.Assignment as Assignment
import Control.Monad hiding (unless)
import Data.Abstract.Name (name)
import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl(..))
import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl (..))
import Data.List.NonEmpty (some1)
import qualified Data.List.NonEmpty as NonEmpty
import Data.Maybe
import Data.Sum
import Data.Syntax
( contextualize
, emptyTerm

View File

@ -1,22 +1,37 @@
{-# LANGUAGE DeriveAnyClass, DeriveGeneric, DeriveTraversable, DuplicateRecordFields, FlexibleContexts, OverloadedStrings, RecordWildCards, TupleSections, TypeApplications #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
module Language.Ruby.Syntax (module Language.Ruby.Syntax) where
import Prologue
import Control.Abstract as Abstract hiding (Load, String)
import Control.Monad
import Data.Abstract.BaseError
import Data.Abstract.Evaluatable
import qualified Data.Abstract.Module as M
import Data.Abstract.Name as Name
import Data.Abstract.Path
import qualified Data.Abstract.ScopeGraph as ScopeGraph
import Data.Functor.Classes
import Data.Functor.Classes.Generic
import Data.Hashable.Lifted
import Data.JSON.Fields
import qualified Data.Language as Language
import Data.List.NonEmpty (nonEmpty)
import qualified Data.Map.Strict as Map
import Data.Maybe.Exts
import Data.Semigroup.App
import Data.Semigroup.Foldable
import Data.Text (Text)
import qualified Data.Text as T
import Data.Traversable (for)
import Diffing.Algorithm
import GHC.Generics (Generic1)
import System.FilePath.Posix
-- TODO: Fully sort out ruby require/load mechanics

View File

@ -1,4 +1,9 @@
{-# LANGUAGE DataKinds, FlexibleContexts, OverloadedStrings, RankNTypes, TypeFamilies, TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Language.TSX.Assignment
( assignment
, TSX.Syntax
@ -7,9 +12,14 @@ module Language.TSX.Assignment
) where
import Assigning.Assignment hiding (Assignment, Error)
import Data.Abstract.Name (name)
import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl(..))
import qualified Assigning.Assignment as Assignment
import Control.Monad
import Data.Abstract.Name (name)
import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl (..))
import Data.Foldable
import Data.Function
import Data.List.NonEmpty (nonEmpty, some1)
import Data.Maybe
import Data.Sum
import Data.Syntax
( contextualize
@ -31,9 +41,8 @@ import qualified Data.Syntax.Literal as Literal
import qualified Data.Syntax.Statement as Statement
import qualified Data.Syntax.Type as Type
import qualified Language.TSX.Syntax as TSX.Syntax
import qualified Language.TypeScript.Resolution as TypeScript.Resolution
import Language.TSX.Term as TSX
import Prologue
import qualified Language.TypeScript.Resolution as TypeScript.Resolution
import TreeSitter.TSX as Grammar
type Assignment = Assignment.Assignment [] Grammar

View File

@ -1,4 +1,9 @@
{-# LANGUAGE DataKinds, FlexibleContexts, OverloadedStrings, RankNTypes, TypeFamilies, TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Language.TypeScript.Assignment
( assignment
, TypeScript.Syntax
@ -7,9 +12,14 @@ module Language.TypeScript.Assignment
) where
import Assigning.Assignment hiding (Assignment, Error)
import Data.Abstract.Name (name)
import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl(..))
import qualified Assigning.Assignment as Assignment
import Control.Monad
import Data.Abstract.Name (name)
import qualified Data.Abstract.ScopeGraph as ScopeGraph (AccessControl (..))
import Data.Foldable
import Data.Function
import Data.List.NonEmpty (nonEmpty, some1)
import Data.Maybe
import Data.Sum
import Data.Syntax
( contextualize
@ -30,10 +40,9 @@ 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 qualified Language.TypeScript.Syntax as TypeScript.Syntax
import qualified Language.TypeScript.Resolution as TypeScript.Resolution
import qualified Language.TypeScript.Syntax as TypeScript.Syntax
import Language.TypeScript.Term as TypeScript
import Prologue
import TreeSitter.TypeScript as Grammar
type Assignment = Assignment.Assignment [] Grammar