|
definition: |
attrDefaultValues :: CExpr -> [Attribute] -> [CExpr]
attrDefaultValues defaultctime attrs = map defaultValue attrs
where
defaultValue (Attribute _ domain _ null) = case domain of
IntDom Nothing -> nothingOrDefault
IntDom (Just n) -> addJust (CLit (CIntc n))
FloatDom Nothing -> nothingOrDefault
FloatDom (Just x) -> addJust (CLit (CFloatc x))
CharDom Nothing -> nothingOrDefault
CharDom (Just c) -> addJust (CLit (CCharc c))
StringDom Nothing -> string2ac "" -- null string values are empty strings
StringDom (Just s) -> string2ac s
BoolDom Nothing -> nothingOrDefault
BoolDom (Just b) -> addJust (constF (pre (if b then "True" else "False")))
DateDom Nothing -> nothingOrDefault
DateDom (Just (CalendarTime y mo d h m s tz))
-> addJust (applyF (timeModule, "toClockTime")
[applyF (timeModule, "CalendarTime")
(map (CLit . CIntc) [y,mo,d,h,m,s,tz])])
UserDefined _ _ -> nothingOrDefault
KeyDom _ -> nothingOrDefault
_ -> error "GenerationHelper.attrDefaultValues: unknown domain for attribute"
where
nothingOrDefault = if null
then constF (pre "Nothing")
else domainDefaultValue defaultctime domain
-- add "Just" constructor if the attribute can be null-valued:
addJust e = if null then applyF (pre "Just") [e] else e
|
|
demand: |
argument 2 |
|
deterministic: |
deterministic operation |
|
documentation: |
Generates Curry expressions representing default values. The first argument contains an expression that is used for ClockTime attributes (it is set to the current time as a default value). |
|
failfree: |
(_, _) |
|
indeterministic: |
referentially transparent operation |
|
infix: |
no fixity defined |
|
iotype: |
{(_,_) |-> {:,[]}}
|
|
name: |
attrDefaultValues |
|
precedence: |
no precedence defined |
|
result-values: |
{:,[]}
|
|
signature: |
AbstractCurry.Types.CExpr -> [Database.ERD.Attribute] -> [AbstractCurry.Types.CExpr] |
|
solution-complete: |
operation might suspend on free variables |
|
terminating: |
yes |
|
totally-defined: |
reducible on all ground data terms |