Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Would like library to export symbols of HashDefines #5

Open
ddssff opened this issue Jun 10, 2016 · 2 comments
Open

Would like library to export symbols of HashDefines #5

ddssff opened this issue Jun 10, 2016 · 2 comments

Comments

@ddssff
Copy link

ddssff commented Jun 10, 2016

I want to use the data structure and a couple of the functions in a project.

@malcolmwallace
Copy link
Owner

Can you be more specific about which types and functions you would like to be exported?

@ddssff
Copy link
Author

ddssff commented Jun 11, 2016

I am using the HashDefine type, and I've written functions to convert a HashDefine to a CPP argument and to a CPP predicate:

asArgument :: HashDefine -> String
asArgument (AntiDefined{..}) = "-U" <> name
asArgument (SymbolReplacement{..}) =
    "-D" <> name <> if replacement == "" then "" else ("=" <> replacement)
asArgument _ = error $ "Unexpected HashDefine value"

asPredicate :: HashDefine -> String
asPredicate (AntiDefined{..}) = "!defined(" <> name <> ")"
asPredicate (SymbolReplacement{..}) | replacement == "" = "defined(" <> name <> ")"
asPredicate (SymbolReplacement{..}) | all (== '0') replacement = "!" <> name
asPredicate (SymbolReplacement{..}) | all isDigit replacement = name
asPredicate (SymbolReplacement{..}) = name <> " == " <> replacement
asPredicate _ = ""

I might need the parseHashDefine function in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants