Fix blocks getting invalid ranges
This commit is contained in:
parent
20014a7926
commit
508b111374
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
function main() : int is
|
function main() : int is
|
||||||
block
|
block {
|
||||||
var j := 1;
|
var j : int := 1;
|
||||||
j := j + 1;
|
j := j + 1;
|
||||||
j := j - 1;
|
j := j - 1
|
||||||
with j
|
} with j
|
@ -12,13 +12,19 @@ import Range
|
|||||||
import Pretty
|
import Pretty
|
||||||
import Product
|
import Product
|
||||||
|
|
||||||
|
import Data.Text (Text)
|
||||||
-- import Debug.Trace
|
-- import Debug.Trace
|
||||||
|
|
||||||
findScopedDecl
|
type CanSearch xs =
|
||||||
:: ( Contains [ScopedDecl] xs
|
( Contains [ScopedDecl] xs
|
||||||
, Contains Range xs
|
, Contains Range xs
|
||||||
, Contains (Maybe Category) xs
|
, Contains (Maybe Category) xs
|
||||||
|
, Contains [Text] xs
|
||||||
|
, Pretty (Product xs)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
findScopedDecl
|
||||||
|
:: CanSearch xs
|
||||||
=> Range
|
=> Range
|
||||||
-> Pascal (Product xs)
|
-> Pascal (Product xs)
|
||||||
-> Maybe ScopedDecl
|
-> Maybe ScopedDecl
|
||||||
@ -32,10 +38,7 @@ findScopedDecl pos tree = do
|
|||||||
lookupEnv (ppToText $ void pt) filtered
|
lookupEnv (ppToText $ void pt) filtered
|
||||||
|
|
||||||
definitionOf
|
definitionOf
|
||||||
:: ( Contains [ScopedDecl] xs
|
:: CanSearch xs
|
||||||
, Contains Range xs
|
|
||||||
, Contains (Maybe Category) xs
|
|
||||||
)
|
|
||||||
=> Range
|
=> Range
|
||||||
-> Pascal (Product xs)
|
-> Pascal (Product xs)
|
||||||
-> Maybe Range
|
-> Maybe Range
|
||||||
@ -43,10 +46,7 @@ definitionOf pos tree =
|
|||||||
_sdOrigin <$> findScopedDecl pos tree
|
_sdOrigin <$> findScopedDecl pos tree
|
||||||
|
|
||||||
typeOf
|
typeOf
|
||||||
:: ( Contains [ScopedDecl] xs
|
:: CanSearch xs
|
||||||
, Contains Range xs
|
|
||||||
, Contains (Maybe Category) xs
|
|
||||||
)
|
|
||||||
=> Range
|
=> Range
|
||||||
-> Pascal (Product xs)
|
-> Pascal (Product xs)
|
||||||
-> Maybe (Either (Pascal ()) Kind)
|
-> Maybe (Either (Pascal ()) Kind)
|
||||||
@ -54,10 +54,7 @@ typeOf pos tree =
|
|||||||
_sdType =<< findScopedDecl pos tree
|
_sdType =<< findScopedDecl pos tree
|
||||||
|
|
||||||
implementationOf
|
implementationOf
|
||||||
:: ( Contains [ScopedDecl] xs
|
:: CanSearch xs
|
||||||
, Contains Range xs
|
|
||||||
, Contains (Maybe Category) xs
|
|
||||||
)
|
|
||||||
=> Range
|
=> Range
|
||||||
-> Pascal (Product xs)
|
-> Pascal (Product xs)
|
||||||
-> Maybe Range
|
-> Maybe Range
|
||||||
@ -65,10 +62,7 @@ implementationOf pos tree =
|
|||||||
_sdBody =<< findScopedDecl pos tree
|
_sdBody =<< findScopedDecl pos tree
|
||||||
|
|
||||||
referencesOf
|
referencesOf
|
||||||
:: ( Contains [ScopedDecl] xs
|
:: CanSearch xs
|
||||||
, Contains Range xs
|
|
||||||
, Contains (Maybe Category) xs
|
|
||||||
)
|
|
||||||
=> Range
|
=> Range
|
||||||
-> Pascal (Product xs)
|
-> Pascal (Product xs)
|
||||||
-> Maybe [Range]
|
-> Maybe [Range]
|
||||||
|
@ -15,7 +15,8 @@ import Range
|
|||||||
import Product
|
import Product
|
||||||
import Tree hiding (skip)
|
import Tree hiding (skip)
|
||||||
|
|
||||||
-- import Debug.Trace
|
import Pretty
|
||||||
|
import Debug.Trace
|
||||||
|
|
||||||
ranged
|
ranged
|
||||||
:: ( Functor f
|
:: ( Functor f
|
||||||
@ -779,11 +780,12 @@ letExpr = do
|
|||||||
-> Pascal ASTInfo
|
-> Pascal ASTInfo
|
||||||
-> Pascal ASTInfo
|
-> Pascal ASTInfo
|
||||||
-> Pascal ASTInfo
|
-> Pascal ASTInfo
|
||||||
let'' r decl b = mk (Cons r' rest) $ Let decl b
|
let'' r decl b =
|
||||||
|
mk (Cons r' rest) $ Let decl b
|
||||||
where
|
where
|
||||||
r' = Range start end f
|
r' = Range start end f
|
||||||
Range _ end f = r
|
Range _ end f = r
|
||||||
Cons (Range start _ _) rest = infoOf b
|
Cons (Range start _ _) rest = infoOf decl
|
||||||
|
|
||||||
statement :: Parser (Pascal ASTInfo)
|
statement :: Parser (Pascal ASTInfo)
|
||||||
statement = ranged do pure Action <*> expr
|
statement = ranged do pure Action <*> expr
|
||||||
@ -913,12 +915,12 @@ example :: FilePath
|
|||||||
-- example = "../../../src/test/contracts/bytes_arithmetic.ligo"
|
-- example = "../../../src/test/contracts/bytes_arithmetic.ligo"
|
||||||
-- example = "../../../src/test/contracts/bytes_unpack.ligo"
|
-- example = "../../../src/test/contracts/bytes_unpack.ligo"
|
||||||
-- example = "../../../src/test/contracts/chain_id.ligo"
|
-- example = "../../../src/test/contracts/chain_id.ligo"
|
||||||
-- example = "../../../src/test/contracts/coase.ligo"
|
example = "../../../src/test/contracts/coase.ligo"
|
||||||
-- example = "../../../src/test/contracts/failwith.ligo"
|
-- example = "../../../src/test/contracts/failwith.ligo"
|
||||||
-- example = "../../../src/test/contracts/loop.ligo"
|
-- example = "../../../src/test/contracts/loop.ligo"
|
||||||
-- example = "../../../src/test/contracts/redeclaration.ligo"
|
-- example = "../../../src/test/contracts/redeclaration.ligo"
|
||||||
-- example = "../../../src/test/contracts/includer.ligo"
|
-- example = "../../../src/test/contracts/includer.ligo"
|
||||||
-- example = "../../../src/test/contracts/namespaces.ligo"
|
-- example = "../../../src/test/contracts/namespaces.ligo"
|
||||||
example = "../../../src/test/contracts/application.ligo"
|
-- example = "../../../src/test/contracts/blocks.ligo"
|
||||||
-- example = "../../../src/test/contracts/application.ligo"
|
-- example = "../../../src/test/contracts/application.ligo"
|
||||||
-- example = "../../../src/test/contracts/application.ligo"
|
-- example = "../../../src/test/contracts/application.ligo"
|
||||||
|
@ -220,6 +220,10 @@ instance Pretty ScopedDecl where
|
|||||||
instance Pretty Kind where
|
instance Pretty Kind where
|
||||||
pp _ = "TYPE"
|
pp _ = "TYPE"
|
||||||
|
|
||||||
|
instance Pretty Category where
|
||||||
|
pp Variable = "Variable"
|
||||||
|
pp Type = "Type"
|
||||||
|
|
||||||
-- | Search for a name inside a local scope.
|
-- | Search for a name inside a local scope.
|
||||||
lookupEnv :: Text -> [ScopedDecl] -> Maybe ScopedDecl
|
lookupEnv :: Text -> [ScopedDecl] -> Maybe ScopedDecl
|
||||||
lookupEnv name = listToMaybe . filter ((name ==) . ppToText . _sdName)
|
lookupEnv name = listToMaybe . filter ((name ==) . ppToText . _sdName)
|
||||||
|
@ -34,7 +34,7 @@ import Pretty
|
|||||||
import Error
|
import Error
|
||||||
import Range
|
import Range
|
||||||
|
|
||||||
-- import Debug.Trace
|
import Debug.Trace
|
||||||
|
|
||||||
-- | A tree, where each layer is one of @layers@ `Functor`s.
|
-- | A tree, where each layer is one of @layers@ `Functor`s.
|
||||||
--
|
--
|
||||||
@ -115,6 +115,9 @@ lookupTree
|
|||||||
. ( Apply Foldable fs
|
. ( Apply Foldable fs
|
||||||
, Apply Functor fs
|
, Apply Functor fs
|
||||||
, HasRange info
|
, HasRange info
|
||||||
|
-- , HasComments info
|
||||||
|
-- , Pretty1 (Sum fs)
|
||||||
|
-- , Pretty info
|
||||||
)
|
)
|
||||||
=> Range
|
=> Range
|
||||||
-> Tree fs info
|
-> Tree fs info
|
||||||
|
Loading…
Reference in New Issue
Block a user