Added the generation of IsDefined checks, and stopped them being applied to derefenced arrays

This commit is contained in:
Neil Brown 2009-03-23 15:48:24 +00:00
parent fae0d6d6a2
commit 228523e7e7
2 changed files with 6 additions and 0 deletions

View File

@ -904,6 +904,10 @@ cgenExpression (A.BytesInType m t) = call genBytesIn m t (Left False)
--cgenExpression (A.ExprConstr {})
cgenExpression (A.AllocMobile m t me) = call genAllocMobile m t me
cgenExpression (A.CloneMobile m e) = call genCloneMobile m e
cgenExpression (A.IsDefined m (A.ExprVariable _ (A.DerefVariable _ v)))
= tell ["("] >> call genVariable v A.Original >> tell ["!=NULL)"]
cgenExpression (A.IsDefined m e)
= tell ["("] >> call genExpression e >> tell ["!=NULL)"]
cgenExpression (A.SubscriptedExpr m sub (A.ExprVariable _ v))
= call genVariable (A.SubscriptedVariable m sub v) A.Original
cgenExpression (A.SubscriptedExpr m (A.SubscriptFromFor _ _ start _) e@(A.AllSizesVariable {}))

View File

@ -399,6 +399,8 @@ pullUp pullUpArraysInsideRecords = pass "Pull up definitions"
-- | Pull array expressions that aren't already non-subscripted variables.
-- Also pull lists that are literals or constructed
doExpression :: A.Expression -> PassM A.Expression
-- For is-defined, we don't want to pull up:
doExpression e@(A.IsDefined {}) = return e
doExpression e
-- This part handles recursing into the expression first:
= do e' <- doExpression' e