Fixed channel arrays that are abbreviations to have the proper indirection, because they can be constructed in a special way (using IsChannelArray)

This commit is contained in:
Neil Brown 2007-10-06 00:57:03 +00:00
parent 9d5164d9c1
commit 24b3975cf8
2 changed files with 16 additions and 8 deletions

View File

@ -689,9 +689,9 @@ MYREC r: MYREC r; MYREC *r; MYREC *r;
CHAN OF INT c: Channel c; Channel *c;
c &c c
[10]CHAN OF INT cs: Channel *cs; Channel *cs;
[10]CHAN OF INT cs: Channel cs[10]; Channel *cs[10];
cs cs cs
cs[i] &cs[i] &cs[i]
cs[i] &cs[i] cs[i]
I suspect there's probably a nicer way of doing this, but as a translation of
the above table this isn't too horrible...
@ -729,15 +729,18 @@ cgenVariable' ops checkValid v
-- | Find the effective abbreviation mode for the variable we're looking at.
-- This differs from abbrevModeOfVariable in that it will return Original
-- for array and record elements (because when we're generating C, we can
-- treat c->x as if it's just x).
-- treat c->x as if it's just x). Abbreviated channel arrays are a special
-- case, however.
accessAbbrevMode :: A.Variable -> CGen A.AbbrevMode
accessAbbrevMode (A.Variable _ n) = abbrevModeOfName n
accessAbbrevMode (A.DirectedVariable _ _ v) = accessAbbrevMode v
accessAbbrevMode (A.SubscriptedVariable _ sub v)
= do am <- accessAbbrevMode v
return $ case (am, sub) of
(_, A.Subscript _ _) -> A.Original
(_, A.SubscriptField _ _) -> A.Original
t <- typeOfVariable v
return $ case (sub, t) of
(A.Subscript _ _, A.Array _ (A.Chan A.DirUnknown _ _)) -> am
(A.Subscript _ _, _) -> A.Original
(A.SubscriptField _ _, _) -> A.Original
_ -> am
inner :: A.Variable -> CGen ()

View File

@ -522,7 +522,8 @@ testGenVariable = TestList
,testAC 300 ("foo@C4","foo@U4") (sub 4) (A.Array [A.Dimension 8] A.Int)
,testAC 305 ("foo@C4,5,6","foo@U4,5,6") ((sub 6) . (sub 5) . (sub 4)) (A.Array [A.Dimension 8,A.Dimension 9,A.Dimension 10] A.Int)
,testAC 310 ("(&foo@C4)","(&foo@U4)") (sub 4) (A.Array [A.Dimension 8] $ A.Record bar)
,testAC 320 ("(&foo@C4)","(&foo@U4)") (sub 4) (A.Array [A.Dimension 8] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int)
-- Original channel arrays are Channel[], but abbreviated channel arrays are Channel*[]:
,testAC2 320 ("(&foo@C4)","(&foo@U4)") ("foo@C4","foo@U4") (sub 4) (A.Array [A.Dimension 8] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int)
,testAC 330 ("foo@C4","foo@U4") (sub 4) (A.Array [A.Dimension 8] $ A.Chan A.DirInput (A.ChanAttributes False False) A.Int)
-- Fully subscripted array, and record field reference:
@ -550,9 +551,13 @@ testGenVariable = TestList
testA :: Int -> (String,String) -> (String,String) -> (A.Variable -> A.Variable) -> A.Type -> Test
testA n eC eCPP sub t = TestList [test n eC eCPP sub A.Original t, test (n+1) eC eCPP sub A.Abbrev t, test (n+2) eC eCPP sub A.ValAbbrev t]
-- | Tests that the given (checked,unchecked) expected values occur in both C and C++
testAC :: Int -> (String,String) -> (A.Variable -> A.Variable) -> A.Type -> Test
testAC n e sub t = testA n e e sub t
-- | Tests that the given (checked,unchecked) expected values (for Original and Abbrev modes) occur in both C and C++
testAC2 :: Int -> (String,String) -> (String,String) -> (A.Variable -> A.Variable) -> A.Type -> Test
testAC2 n e e' sub t = TestList [test n e e sub A.Original t, test (n+1) e' e' sub A.Abbrev t]
testSame :: Int -> String -> (A.Variable -> A.Variable) -> A.AbbrevMode -> A.Type -> Test
testSame n e sub am t = test n (e,e) (e,e) sub am t