Created
December 27, 2011 13:37
-
-
Save alistra/1523682 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | Merges the simple 'DSInfo's based on function calls from the functions | |
analyzeFunctions :: [DSFun t] -> [DSInfo] | |
analyzeFunctions dsfs = let startingDSF = lookupDSF dsfs startingFunction in | |
let functions = map getDSFFun dsfs in | |
let startingVars = map snd $ concatMap getDSINames $ getDSFDSI startingDSF in | |
let runMain = mapMaybe (\var -> analyzeFunction functions startingDSF var []) startingVars in --update the accumulator | |
concatMap (uncurry (:)) runMain where | |
analyzeFunction :: [FunctionDeclaration t] -> DSFun t1 -> VariableName -> [FunctionName] -> Maybe (DSInfo, [DSInfo]) | |
analyzeFunctiog functions dsf variable accumulator = let functionName = getFunName.getDSFFun $ dsf in | |
toMaybe (functionName `notElem` accumulator) (let functionCalls = getDSFCalls dsf in | |
let relevantFunctionCalls = filter (\(_, funArgs) -> Just variable `elem` funArgs) functionCalls in | |
let irrelevantFunctionCalls = functionCalls \\ relevantFunctionCalls in --TODO remodel so we also analyze those | |
let dsis = getDSFDSI dsf in | |
let thisVariableDSI = lookupDSI dsis variable functionName in | |
let otherVariablesDSIs = dsis \\ [thisVariableDSI] in | |
let variableBindings = map (\call@(funName, _) -> second (bindFuncall functions funName) call) relevantFunctionCalls in | |
let recursiveCalls = mapMaybe (\(funName, varPairs) -> (analyzeFunction functions (lookupDSF dsfs funName) (lookupJust variable varPairs) (funName:accumulator))) variableBindings in | |
let relevantRecursiveDSI = mconcat $ map fst recursiveCalls in | |
let irrelevantRecursiveDSI = concatMap snd recursiveCalls in | |
(thisVariableDSI `mappend` relevantRecursiveDSI, otherVariablesDSIs `union` irrelevantRecursiveDSI)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment