diff --git a/src/Data/Syntax/Expression.hs b/src/Data/Syntax/Expression.hs index 887c9eedb..65aad0f62 100644 --- a/src/Data/Syntax/Expression.hs +++ b/src/Data/Syntax/Expression.hs @@ -1,12 +1,12 @@ {-# LANGUAGE DeriveAnyClass, MultiParamTypeClasses, ScopedTypeVariables, UndecidableInstances, DuplicateRecordFields #-} module Data.Syntax.Expression where -import Data.Abstract.Evaluatable +import Data.Abstract.Evaluatable hiding (Member) import Data.Abstract.Number (liftIntegralFrac, liftReal, liftedExponent, liftedFloorDiv) import Data.Fixed import Data.JSON.Fields import Diffing.Algorithm -import Prologue hiding (index) +import Prologue hiding (index, Member) import Proto3.Suite.Class -- | Typical prefix function application, like `f(x)` in many languages, or `f x` in Haskell. @@ -322,9 +322,7 @@ instance Evaluatable MemberAccess where pure $! LvalMember ptr propName -- | Subscript (e.g a[1]) -data Subscript a - = Subscript !a ![a] - | Member !a !a +data Subscript a = Subscript { lhs :: a, rhs :: [a] } deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) instance Eq1 Subscript where liftEq = genericLiftEq @@ -336,8 +334,15 @@ instance Show1 Subscript where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Subscript where eval (Subscript l [r]) = Rval <$> join (index <$> subtermValue l <*> subtermValue r) eval (Subscript _ _) = rvalBox =<< throwResumable (Unspecialized "Eval unspecialized for subscript with slices") - eval (Member _ _) = rvalBox =<< throwResumable (Unspecialized "Eval unspecialized for member access") +data Member a = Member { lhs :: a, rhs :: a } + deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) + +instance Eq1 Member where liftEq = genericLiftEq +instance Ord1 Member where liftCompare = genericLiftCompare +instance Show1 Member where liftShowsPrec = genericLiftShowsPrec + +instance Evaluatable Member where -- | Enumeration (e.g. a[1:10:1] in Python (start at index 1, stop at index 10, step 1 element from start to stop)) data Enumeration a = Enumeration { enumerationStart :: !a, enumerationEnd :: !a, enumerationStep :: !a } diff --git a/src/Language/Go/Assignment.hs b/src/Language/Go/Assignment.hs index 8e092e3fb..f7f18d489 100644 --- a/src/Language/Go/Assignment.hs +++ b/src/Language/Go/Assignment.hs @@ -50,6 +50,7 @@ type Syntax = , Expression.StrictEqual , Expression.Comparison , Expression.Subscript + , Expression.Member , Statement.PostDecrement , Statement.PostIncrement , Expression.MemberAccess diff --git a/src/Language/Java/Assignment.hs b/src/Language/Java/Assignment.hs index 7e3448f05..9a65afb8c 100644 --- a/src/Language/Java/Assignment.hs +++ b/src/Language/Java/Assignment.hs @@ -57,6 +57,7 @@ type Syntax = , Expression.InstanceOf , Expression.MemberAccess , Expression.Subscript + , Expression.Member , Expression.Super , Expression.This , Java.Syntax.Annotation diff --git a/src/Language/PHP/Assignment.hs b/src/Language/PHP/Assignment.hs index ecdc4ef18..91d4d48b3 100644 --- a/src/Language/PHP/Assignment.hs +++ b/src/Language/PHP/Assignment.hs @@ -65,6 +65,7 @@ type Syntax = '[ , Expression.New , Expression.SequenceExpression , Expression.Subscript + , Expression.Member , Literal.Array , Literal.Float , Literal.Integer diff --git a/src/Language/Python/Assignment.hs b/src/Language/Python/Assignment.hs index 4f6489642..1ec06f624 100644 --- a/src/Language/Python/Assignment.hs +++ b/src/Language/Python/Assignment.hs @@ -71,6 +71,7 @@ type Syntax = , Expression.ScopeResolution , Expression.MemberAccess , Expression.Subscript + , Expression.Member , Literal.Array , Literal.Boolean , Literal.Float diff --git a/src/Language/Ruby/Assignment.hs b/src/Language/Ruby/Assignment.hs index 9dd98b417..2516a86e6 100644 --- a/src/Language/Ruby/Assignment.hs +++ b/src/Language/Ruby/Assignment.hs @@ -69,6 +69,7 @@ type Syntax = '[ , Expression.MemberAccess , Expression.ScopeResolution , Expression.Subscript + , Expression.Member , Literal.Array , Literal.Complex , Literal.Float diff --git a/src/Language/TypeScript/Assignment.hs b/src/Language/TypeScript/Assignment.hs index a7e09eb4d..7bd6ead80 100644 --- a/src/Language/TypeScript/Assignment.hs +++ b/src/Language/TypeScript/Assignment.hs @@ -74,6 +74,7 @@ type Syntax = '[ , Expression.ScopeResolution , Expression.SequenceExpression , Expression.Subscript + , Expression.Member , Expression.Delete , Expression.Void , Expression.Typeof