From da89a11fae0ea105ddef31f3b7f321452efb4d6a Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 26 Apr 2018 13:43:49 -0700 Subject: [PATCH] Introduce place to put all these directives --- semantic.cabal | 1 + src/Data/Syntax/Directive.hs | 18 ++++++++++++++++++ src/Language/Ruby/Assignment.hs | 5 +++-- src/Language/Ruby/Syntax.hs | 10 ---------- 4 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 src/Data/Syntax/Directive.hs diff --git a/semantic.cabal b/semantic.cabal index 32eb3e24b..3d6247711 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -94,6 +94,7 @@ library , Data.Syntax , Data.Syntax.Comment , Data.Syntax.Declaration + , Data.Syntax.Directive , Data.Syntax.Expression , Data.Syntax.Literal , Data.Syntax.Statement diff --git a/src/Data/Syntax/Directive.hs b/src/Data/Syntax/Directive.hs new file mode 100644 index 000000000..6ad37c564 --- /dev/null +++ b/src/Data/Syntax/Directive.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE DeriveAnyClass, MultiParamTypeClasses, ScopedTypeVariables, UndecidableInstances #-} +module Data.Syntax.Directive where + +import Data.Abstract.Evaluatable +import Data.Abstract.Module (ModuleInfo(..)) +import qualified Data.ByteString.Char8 as BC +import Diffing.Algorithm +import Prologue + +data FileDirective a = FileDirective + deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1, Declarations1) + +instance Eq1 FileDirective where liftEq = genericLiftEq +instance Ord1 FileDirective where liftCompare = genericLiftCompare +instance Show1 FileDirective where liftShowsPrec = genericLiftShowsPrec + +instance Evaluatable FileDirective where + eval FileDirective{} = currentModule >>= string . BC.pack . modulePath diff --git a/src/Language/Ruby/Assignment.hs b/src/Language/Ruby/Assignment.hs index 83f894610..f9cd2607d 100644 --- a/src/Language/Ruby/Assignment.hs +++ b/src/Language/Ruby/Assignment.hs @@ -17,6 +17,7 @@ import qualified Assigning.Assignment as Assignment import qualified Data.Syntax as Syntax import qualified Data.Syntax.Comment as Comment import qualified Data.Syntax.Declaration as Declaration +import qualified Data.Syntax.Directive as Directive import qualified Data.Syntax.Expression as Expression import qualified Data.Syntax.Literal as Literal import qualified Data.Syntax.Statement as Statement @@ -28,6 +29,7 @@ type Syntax = '[ Comment.Comment , Declaration.Function , Declaration.Method + , Directive.FileDirective , Expression.Arithmetic , Expression.Bitwise , Expression.Boolean @@ -74,7 +76,6 @@ type Syntax = '[ , Syntax.Identifier , Syntax.Program , Ruby.Syntax.Class - , Ruby.Syntax.FileDirective , Ruby.Syntax.Load , Ruby.Syntax.LowPrecedenceBoolean , Ruby.Syntax.Module @@ -179,7 +180,7 @@ identifier = vcallOrLocal = do (loc, ident, locals) <- identWithLocals case ident of - "__FILE__" -> pure $ makeTerm loc (Ruby.Syntax.FileDirective ident) + "__FILE__" -> pure $ makeTerm loc Directive.FileDirective _ -> do let identTerm = makeTerm loc (Syntax.Identifier (name ident)) if ident `elem` locals diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index 955dde38f..4cc3fda37 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -106,16 +106,6 @@ doLoad path shouldWrap = do -- TODO: autoload -newtype FileDirective a = FileDirective ByteString - deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1, Declarations1) - -instance Eq1 FileDirective where liftEq = genericLiftEq -instance Ord1 FileDirective where liftCompare = genericLiftCompare -instance Show1 FileDirective where liftShowsPrec = genericLiftShowsPrec - -instance Evaluatable FileDirective where - eval (FileDirective _) = currentModule >>= string . BC.pack . modulePath - data Class a = Class { classIdentifier :: !a, classSuperClasses :: ![a], classBody :: !a } deriving (Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1, Declarations1)