diff --git a/RainPassTest.hs b/RainPassTest.hs index a059964..6564991 100644 --- a/RainPassTest.hs +++ b/RainPassTest.hs @@ -169,12 +169,48 @@ assertVarDef prefix state varName varDef Just actVarDef -> assertPatternMatch (prefix ++ " variable definition not as expected for " ++ varName) varDef actVarDef -testRecordNames0 :: Test -testRecordNames0 = testPassWithStateCheck "testRecordNames0" exp (recordNameTypes orig) (return ()) check +testRecordDeclNames0 :: Test +testRecordDeclNames0 = testPassWithStateCheck "testRecordDeclNames0" exp (recordDeclNameTypes orig) (return ()) check where orig = (A.Specification m (simpleName "c") $ A.Declaration m A.Byte) exp = orig - check state = assertVarDef "testRecordNames0" state "c" (tag7 A.NameDef DontCare "c" "c" A.VariableName (A.Declaration m A.Byte) A.Original A.Unplaced) + check state = assertVarDef "testRecordDeclNames0" state "c" + (tag7 A.NameDef DontCare "c" "c" A.VariableName (A.Declaration m A.Byte) A.Original A.Unplaced) + +-- | checks that c's type is recorded in: ***each (c : "hello") {} +testRecordInfNames0 :: Test +testRecordInfNames0 = testPassWithStateCheck "testRecordInfNames0" exp (recordInfNameTypes orig) (return ()) check + where + orig = (A.Rep m (A.ForEach m (simpleName "c") (makeLiteralString "hello")) skipP) + exp = orig + check state = assertVarDef "testRecordInfNames0" state "c" + (tag7 A.NameDef DontCare "c" "c" A.VariableName (A.Declaration m A.Byte) A.Original A.Unplaced) + +-- | checks that c's type is recorded in: ***each (c : str) {}, where str is known to be of type string +testRecordInfNames1 :: Test +testRecordInfNames1 = testPassWithStateCheck "testRecordInfNames1" exp (recordInfNameTypes orig) (startState') check + where + startState' :: State CompState () + startState' = do defineName (simpleName "str") $ simpleDef "str" (A.Declaration m (A.Array [A.Dimension 10] A.Byte)) + orig = (A.Rep m (A.ForEach m (simpleName "c") (exprVariable "str")) skipP) + exp = orig + check state = assertVarDef "testRecordInfNames1" state "c" + (tag7 A.NameDef DontCare "c" "c" A.VariableName (A.Declaration m A.Byte) A.Original A.Unplaced) + +-- | checks that c's and d's type are recorded in: ***each (c : multi) { seqeach (d : c) {} } where multi is known to be of type [string] +testRecordInfNames2 :: Test +testRecordInfNames2 = testPassWithStateCheck "testRecordInfNames2" exp (recordInfNameTypes orig) (startState') check + where + startState' :: State CompState () + startState' = do defineName (simpleName "multi") $ simpleDef "multi" (A.Declaration m (A.Array [A.Dimension 10, A.Dimension 20] A.Byte)) + orig = A.Rep m (A.ForEach m (simpleName "c") (exprVariable "multi")) $ + A.OnlyP m $ A.Seq m $ A.Rep m (A.ForEach m (simpleName "d") (exprVariable "c")) skipP + exp = orig + check state = do assertVarDef "testRecordInfNames2" state "c" + (tag7 A.NameDef DontCare "c" "c" A.VariableName (A.Declaration m (A.Array [A.Dimension 20] A.Byte)) A.Original A.Unplaced) + assertVarDef "testRecordInfNames2" state "d" + (tag7 A.NameDef DontCare "d" "d" A.VariableName (A.Declaration m A.Byte) A.Original A.Unplaced) + --Returns the list of tests: tests :: Test @@ -185,7 +221,10 @@ tests = TestList ,testUnique0 ,testUnique1 ,testUnique2 - ,testRecordNames0 + ,testRecordDeclNames0 + ,testRecordInfNames0 + ,testRecordInfNames1 + ,testRecordInfNames2 ] diff --git a/RainPasses.hs b/RainPasses.hs index ffbe106..fffa3d4 100644 --- a/RainPasses.hs +++ b/RainPasses.hs @@ -16,7 +16,8 @@ rainPasses = runPasses passes where passes = [ ("Uniquify variable declarations and resolve variable names",uniquifyAndResolveVars) - ,("Record name types in dictionary",recordNameTypes) + ,("Record declared name types in dictionary",recordDeclNameTypes) + ,("Record inferred name types in dictionary",recordInfNameTypes) ,("Convert seqeach/pareach loops into classic replicated SEQ/PAR",transformEach) ] @@ -33,16 +34,19 @@ uniquifyAndResolveVars = everywhereM (mkM uniquifyAndResolveVars') replaceNameName :: String -> String -> A.Name -> A.Name replaceNameName find replace n = if (A.nameName n) == find then n {A.nameName = replace} else n -recordNameTypes :: Data t => t -> PassM t -recordNameTypes = everywhereM (mkM recordNameTypes') +recordDeclNameTypes :: Data t => t -> PassM t +recordDeclNameTypes = everywhereM (mkM recordDeclNameTypes') where - recordNameTypes' :: A.Specification -> PassM A.Specification - recordNameTypes' input@(A.Specification m n decl@(A.Declaration _ declType)) + recordDeclNameTypes' :: A.Specification -> PassM A.Specification + recordDeclNameTypes' input@(A.Specification m n decl@(A.Declaration _ declType)) = defineName n A.NameDef {A.ndMeta = m, A.ndName = A.nameName n, A.ndOrigName = A.nameName n, A.ndNameType = A.VariableName, A.ndType = decl, A.ndAbbrevMode = A.Original, A.ndPlacement = A.Unplaced} >> return input - recordNameTypes' s = return s + recordDeclNameTypes' s = return s + +recordInfNameTypes :: Data t => t -> PassM t +recordInfNameTypes = return transformEach :: Data t => t -> PassM t