mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Merge branch 'module-resolution' into default-extensions
This commit is contained in:
commit
9b2524cc81
@ -13,7 +13,7 @@ import Prologue
|
||||
-- | The effects necessary for caching analyses.
|
||||
type CachingEffects term value effects
|
||||
= Fresh -- For 'MonadFresh'.
|
||||
': NonDet -- For 'Alternative' and 'MonadNonDet'.
|
||||
': NonDet -- For 'Alternative' and 'MonadNonDet'.
|
||||
': Reader (CacheFor term value) -- The in-cache used as an oracle while converging on a result.
|
||||
': State (CacheFor term value) -- The out-cache used to record results in each iteration of convergence.
|
||||
': effects
|
||||
|
@ -116,13 +116,12 @@ newtype Evaluating term value effects a = Evaluating (Eff effects a)
|
||||
|
||||
deriving instance Member Fail effects => MonadFail (Evaluating term value effects)
|
||||
deriving instance Member Fresh effects => MonadFresh (Evaluating term value effects)
|
||||
deriving instance Member NonDet effects => Alternative (Evaluating term value effects)
|
||||
deriving instance Member NonDet effects => MonadNonDet (Evaluating term value effects)
|
||||
deriving instance Member NonDet effects => Alternative (Evaluating term value effects)
|
||||
deriving instance Member NonDet effects => MonadNonDet (Evaluating term value effects)
|
||||
|
||||
-- | Effects necessary for evaluating (whether concrete or abstract).
|
||||
type EvaluatingEffects term value
|
||||
= '[
|
||||
Resumable Prelude.String value
|
||||
= '[ Resumable Prelude.String value
|
||||
, Fail -- Failure with an error message
|
||||
, State (EnvironmentFor value) -- Environments (both local and global)
|
||||
, State (HeapFor value) -- The heap
|
||||
|
@ -88,7 +88,7 @@ class (Monad m, Show value) => MonadValue value m where
|
||||
|
||||
-- | Build a class value from a name and environment.
|
||||
klass :: Name -- ^ The new class's identifier
|
||||
-> Maybe value -- ^ An optional superclass.
|
||||
-> [value] -- ^ A list of superclasses
|
||||
-> EnvironmentFor value -- ^ The environment to capture
|
||||
-> m value
|
||||
|
||||
@ -155,10 +155,10 @@ instance ( Monad m
|
||||
multiple = pure . injValue . Value.Tuple
|
||||
array = pure . injValue . Value.Array
|
||||
|
||||
klass n Nothing env = pure . injValue $ Class n env
|
||||
klass n (Just super) env
|
||||
| Just (Class _ superEnv) <- prjValue super = pure . injValue $ Class n (Env.push superEnv <> env)
|
||||
| otherwise = fail ("Attempted to inherit from a non-class object: " <> show super)
|
||||
klass n [] env = pure . injValue $ Class n env
|
||||
klass n supers env = do
|
||||
product <- mconcat <$> traverse objectEnvironment supers
|
||||
pure . injValue $ Class n (Env.push product <> env)
|
||||
|
||||
|
||||
objectEnvironment o
|
||||
|
@ -151,7 +151,7 @@ instance Evaluatable Class where
|
||||
(v, addr) <- letrec name $ do
|
||||
void $ subtermValue classBody
|
||||
classEnv <- Env.head <$> getEnv
|
||||
klass name (listToMaybe supers) classEnv
|
||||
klass name supers classEnv
|
||||
v <$ modifyEnv (Env.insert name addr)
|
||||
|
||||
data Module a = Module { moduleIdentifier :: !a, moduleScope :: ![a] }
|
||||
|
@ -340,12 +340,9 @@ yield = makeTerm <$> symbol Yield <*> (Statement.Yield <$> children (term ( expr
|
||||
-- Identifiers and qualified identifiers (e.g. `a.b.c`) from things like DottedName and Attribute
|
||||
identifier :: Assignment
|
||||
identifier = makeTerm <$> (symbol Identifier <|> symbol Identifier') <*> (Syntax.Identifier <$> (name <$> source))
|
||||
<|> makeQualifiedIdentifier <$> symbol Attribute <*> children (attribute <|> identifierPair)
|
||||
<|> makeQualifiedIdentifier <$> symbol DottedName <*> children (some identifier')
|
||||
<|> symbol DottedName *> children identifier
|
||||
where
|
||||
attribute = (\a b -> a <> [b]) <$> (symbol Attribute *> children (attribute <|> identifierPair)) <*> identifier'
|
||||
identifierPair = (\a b -> [a, b]) <$> identifier' <*> identifier'
|
||||
identifier' = (symbol Identifier <|> symbol Identifier') *> source
|
||||
makeQualifiedIdentifier loc xs = makeTerm loc (Syntax.Identifier (qualifiedName xs))
|
||||
|
||||
|
@ -34,10 +34,19 @@ spec = parallel $ do
|
||||
]
|
||||
env `shouldBe` expectedEnv
|
||||
|
||||
it "subclasses" $ do
|
||||
res <- evaluate' "subclass.py"
|
||||
join (fst res) `shouldBe` Right (injValue (String "\"bar\""))
|
||||
|
||||
it "handles multiple inheritance left-to-right" $ do
|
||||
res <- evaluate' "multiple_inheritance.py"
|
||||
join (fst res) `shouldBe` Right (injValue (String "\"foo!\""))
|
||||
|
||||
where
|
||||
addr = Address . Precise
|
||||
fixtures = "test/fixtures/python/analysis/"
|
||||
evaluate entry = snd . fst . fst . fst . fst <$>
|
||||
evaluate entry = snd <$> evaluate' entry
|
||||
evaluate' entry = fst . fst . fst . fst <$>
|
||||
evaluateFiles pythonParser
|
||||
[ fixtures <> entry
|
||||
, fixtures <> "a.py"
|
||||
|
@ -28,7 +28,7 @@ spec = parallel $ do
|
||||
|
||||
it "subclass" $ do
|
||||
res <- evaluate' "subclass.rb"
|
||||
fst res `shouldBe` Right (injValue (String "\"<bar>\""))
|
||||
join (fst res) `shouldBe` Right (injValue (String "\"<bar>\""))
|
||||
|
||||
where
|
||||
addr = Address . Precise
|
||||
|
@ -34,6 +34,7 @@ import Data.Functor.Both as X (Both, runBothWith, both)
|
||||
import Data.Maybe as X
|
||||
import Data.Monoid as X (Monoid(..), First(..), Last(..))
|
||||
import Data.Semigroup as X (Semigroup(..))
|
||||
import Control.Monad as X
|
||||
|
||||
import Test.Hspec as X (Spec, SpecWith, context, describe, it, xit, parallel, pendingWith, around, runIO)
|
||||
import Test.Hspec.Expectations.Pretty as X
|
||||
|
12
test/fixtures/python/analysis/multiple_inheritance.py
vendored
Normal file
12
test/fixtures/python/analysis/multiple_inheritance.py
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
class Foo:
|
||||
def dang(self):
|
||||
return "foo!"
|
||||
|
||||
class Bar:
|
||||
def dang(self):
|
||||
return "bar!"
|
||||
|
||||
|
||||
class Baz(Foo, Bar): pass
|
||||
|
||||
Baz.dang()
|
9
test/fixtures/python/analysis/subclass.py
vendored
Normal file
9
test/fixtures/python/analysis/subclass.py
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
class Foo():
|
||||
def dang():
|
||||
return "foo"
|
||||
|
||||
class Bar():
|
||||
def dang():
|
||||
return "bar"
|
||||
|
||||
Bar.dang()
|
4
test/fixtures/python/call.diffA-B.txt
vendored
4
test/fixtures/python/call.diffA-B.txt
vendored
@ -14,6 +14,8 @@
|
||||
{+(Identifier)+}
|
||||
(Empty))
|
||||
{+(Call
|
||||
{+(Identifier)+}
|
||||
{+(MemberAccess
|
||||
{+(Identifier)+}
|
||||
{+(Identifier)+})+}
|
||||
{+(Integer)+}
|
||||
{+(Empty)+})+})
|
||||
|
4
test/fixtures/python/call.diffB-A.txt
vendored
4
test/fixtures/python/call.diffB-A.txt
vendored
@ -14,6 +14,8 @@
|
||||
{+(Identifier)+}
|
||||
(Empty))
|
||||
{-(Call
|
||||
{-(Identifier)-}
|
||||
{-(MemberAccess
|
||||
{-(Identifier)-}
|
||||
{-(Identifier)-})-}
|
||||
{-(Integer)-}
|
||||
{-(Empty)-})-})
|
||||
|
4
test/fixtures/python/call.parseB.txt
vendored
4
test/fixtures/python/call.parseB.txt
vendored
@ -12,6 +12,8 @@
|
||||
(Identifier)
|
||||
(Empty))
|
||||
(Call
|
||||
(Identifier)
|
||||
(MemberAccess
|
||||
(Identifier)
|
||||
(Identifier))
|
||||
(Integer)
|
||||
(Empty)))
|
||||
|
24
test/fixtures/python/import-graph/main.json
vendored
24
test/fixtures/python/import-graph/main.json
vendored
@ -269,8 +269,10 @@
|
||||
22
|
||||
]
|
||||
},
|
||||
"symbol": "os.getcwd",
|
||||
"targets": []
|
||||
"symbol": "getcwd",
|
||||
"targets": [
|
||||
"os"
|
||||
]
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -283,8 +285,10 @@
|
||||
31
|
||||
]
|
||||
},
|
||||
"symbol": "np.array",
|
||||
"targets": []
|
||||
"symbol": "array",
|
||||
"targets": [
|
||||
"np"
|
||||
]
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -297,8 +301,10 @@
|
||||
20
|
||||
]
|
||||
},
|
||||
"symbol": "x.sum",
|
||||
"targets": []
|
||||
"symbol": "sum",
|
||||
"targets": [
|
||||
"x"
|
||||
]
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -311,8 +317,10 @@
|
||||
19
|
||||
]
|
||||
},
|
||||
"symbol": "x.sum",
|
||||
"targets": []
|
||||
"symbol": "sum",
|
||||
"targets": [
|
||||
"x"
|
||||
]
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
|
8
test/fixtures/python/with.diffA-B.txt
vendored
8
test/fixtures/python/with.diffA-B.txt
vendored
@ -25,7 +25,9 @@
|
||||
{+(Let
|
||||
{+(Empty)+}
|
||||
{+(Call
|
||||
{+(Identifier)+}
|
||||
{+(MemberAccess
|
||||
{+(Identifier)+}
|
||||
{+(Identifier)+})+}
|
||||
{+(Identifier)+}
|
||||
{+(TextElement)+}
|
||||
{+(Identifier)+}
|
||||
@ -34,7 +36,9 @@
|
||||
{+(Let
|
||||
{+(Empty)+}
|
||||
{+(Call
|
||||
{+(Identifier)+}
|
||||
{+(MemberAccess
|
||||
{+(Identifier)+}
|
||||
{+(Identifier)+})+}
|
||||
{+(Identifier)+}
|
||||
{+(TextElement)+}
|
||||
{+(Identifier)+}
|
||||
|
8
test/fixtures/python/with.diffB-A.txt
vendored
8
test/fixtures/python/with.diffB-A.txt
vendored
@ -25,7 +25,9 @@
|
||||
{-(Let
|
||||
{-(Empty)-}
|
||||
{-(Call
|
||||
{-(Identifier)-}
|
||||
{-(MemberAccess
|
||||
{-(Identifier)-}
|
||||
{-(Identifier)-})-}
|
||||
{-(Identifier)-}
|
||||
{-(TextElement)-}
|
||||
{-(Identifier)-}
|
||||
@ -34,7 +36,9 @@
|
||||
{-(Let
|
||||
{-(Empty)-}
|
||||
{-(Call
|
||||
{-(Identifier)-}
|
||||
{-(MemberAccess
|
||||
{-(Identifier)-}
|
||||
{-(Identifier)-})-}
|
||||
{-(Identifier)-}
|
||||
{-(TextElement)-}
|
||||
{-(Identifier)-}
|
||||
|
8
test/fixtures/python/with.parseB.txt
vendored
8
test/fixtures/python/with.parseB.txt
vendored
@ -12,7 +12,9 @@
|
||||
(Let
|
||||
(Empty)
|
||||
(Call
|
||||
(Identifier)
|
||||
(MemberAccess
|
||||
(Identifier)
|
||||
(Identifier))
|
||||
(Identifier)
|
||||
(TextElement)
|
||||
(Identifier)
|
||||
@ -21,7 +23,9 @@
|
||||
(Let
|
||||
(Empty)
|
||||
(Call
|
||||
(Identifier)
|
||||
(MemberAccess
|
||||
(Identifier)
|
||||
(Identifier))
|
||||
(Identifier)
|
||||
(TextElement)
|
||||
(Identifier)
|
||||
|
Loading…
Reference in New Issue
Block a user