no accum
This commit is contained in:
parent
8db24a3336
commit
f372e1f144
1 changed files with 13 additions and 22 deletions
|
@ -180,14 +180,14 @@ invalidReads s = [] -- do magic here
|
|||
invalidWrites s = [] -- do magic here
|
||||
|
||||
-- facade to init invAcc
|
||||
invalidAccesses = invAcc [] "" 0
|
||||
invalidAccesses = invAcc [] 0
|
||||
|
||||
-- (alternative if easier than invalid read/invalid write separated)
|
||||
-- :: CurrentAssignments -> AccumulatorString -> GlobalIndex
|
||||
invAcc :: [(String,Slice,Bool)] -> String -> Int -> CheckString -> Slices
|
||||
invAcc a accumStr i ('{':t) = invAcc (enterBlock a) "" (i+1+(length accumStr)) t
|
||||
invAcc a accumStr i ('}':t) = getUnread a ++ invAcc (leaveBlock a) "" (i+1+(length accumStr)) t
|
||||
invAcc a accumStr i ('[':t) = invAcc a accumStr (i+1 + g) (drop g t) -- TODO check reads in first part
|
||||
invAcc :: [(String,Slice,Bool)] -> Int -> CheckString -> Slices
|
||||
invAcc a i ('{':t) = invAcc (enterBlock a) (i+1) t
|
||||
invAcc a i ('}':t) = getUnread a ++ invAcc (leaveBlock a) (i+1) t
|
||||
invAcc a i ('[':t) = invAcc a (i+1 + g) (drop g t) -- TODO check reads in first part
|
||||
where g = fromJust (elemIndex ':' t)
|
||||
-- when reading an assignment :word: =
|
||||
-- put :word:, slice, false in the list
|
||||
|
@ -195,29 +195,20 @@ invAcc a accumStr i ('[':t) = invAcc a accumStr (i+1 + g) (drop g t) -- TOD
|
|||
-- if it is found set its boolean value to true
|
||||
-- if it is not found add its slice to the result
|
||||
-- all variables with false at the end of a block are unused
|
||||
invAcc a accumStr i (c:t) = let writeAcc = getWrite i accumStr
|
||||
invAcc a i s@(c:t) = let writeAcc = getWrite i s
|
||||
in if isNothing writeAcc
|
||||
then invAcc a (accumStr ++ [c]) i t -- no assignment in accumStr, don't advance offset
|
||||
else invAcc (a ++ [fromJust writeAcc]) [c] (i+(length accumStr)) t -- assignment in accumStr, advance offset to end
|
||||
invAcc a _ _ _ = map (\(_,s,_) -> s) a
|
||||
{-where aToSlices (a:as) slices = let a2 = (\(v,s,b) -> (s,b)) a
|
||||
in if snd a2
|
||||
then aToSlices as slices
|
||||
else aToSlices as ((fst a2):slices)
|
||||
aToSlices _ slices = slices-}
|
||||
then invAcc a (i+1) t -- no assignment in rest str
|
||||
else invAcc (a ++ [fromJust writeAcc]) (i+1+(length $ (\(v,_,_) -> v) (fromJust writeAcc))) t -- assignment in accumStr, advance offset to end
|
||||
invAcc a _ _ = map (\(_,s,_) -> s) a
|
||||
|
||||
getWrite :: Int -> String -> Maybe (String, Slice, Bool)
|
||||
getWrite offset accumStr = ((Tdfa.matchOnceText §~ "(\\**[[:word:]]+)[[:blank:]]*=") accumStr) >>= matchToA
|
||||
getWrite offset s = ((Tdfa.matchOnceText §~ "^(\\**[[:word:]]+)[[:blank:]]*=") s) >>= matchToA
|
||||
where matchToA (before, match, after) =
|
||||
let m = match ! 1 -- extract the match group (0 = the whole match)
|
||||
in Just (fst m, (offset+(fst (snd m)), offset+(fst (snd m))+(snd (snd m))), False)
|
||||
|
||||
getWrites :: CheckString -> [(String, Slice, Bool)]
|
||||
getWrites s = matchToAs $ (Tdfa.matchAllText §~ "(\\**[[:word:]]+)[[:blank:]]*=") s
|
||||
where matchToAs (match: mts) =
|
||||
let m = match ! 1 -- extract the match group (0 = the whole match)
|
||||
in (fst m, (fst (snd m), (fst (snd m))+(snd (snd m))), False): matchToAs mts
|
||||
matchToAs _ = []
|
||||
fst3 :: (a,b,c) -> a
|
||||
fst3 (a,b,c) = a
|
||||
|
||||
enterBlock :: [(String,Slice,Bool)] -> [(String,Slice,Bool)]
|
||||
enterBlock = map (\(v,s,b) -> ('*':v,s,b))
|
||||
|
|
Loading…
Reference in a new issue