Verified Commit 926a918c authored by Camil Staps's avatar Camil Staps 🚀

Find used record fields separately from local/global expressions

parent 2b6da6e6
......@@ -9,8 +9,9 @@ from Data.Set import :: Set
from syntax import :: ParsedDefinition
:: Idents =
{ locals :: Set String
, globals :: Set String
{ locals :: !Set String
, globals :: !Set String
, record_fields :: !Set String
}
:: IdentContext
......
......@@ -15,22 +15,25 @@ noLocals ids = {ids & locals=newSet}
instance zero Idents
where
zero =
{ locals = newSet
, globals = newSet
{ locals = newSet
, globals = newSet
, record_fields = newSet
}
instance + Idents
where
+ a b = removeLocalGlobals
{ locals = union a.locals b.locals
, globals = union a.globals b.globals
{ locals = union a.locals b.locals
, globals = union a.globals b.globals
, record_fields = union a.record_fields b.record_fields
}
instance idents [t] | idents t
where
idents c xs = removeLocalGlobals
{ locals = unions [x.locals \\ x <- xids]
, globals = unions [x.globals \\ x <- xids]
{ locals = unions [x.locals \\ x <- xids]
, globals = unions [x.globals \\ x <- xids]
, record_fields = unions [x.record_fields \\ x <- xids]
}
where xids = map (idents c) xs
......@@ -79,7 +82,7 @@ where
PE_Bound _ -> zero
PE_Lambda _ args rhs _ -> noLocals (idents ICPattern args + idents ICExpression rhs)
PE_Tuple es -> idents c es
PE_Record init _ fields -> idents c init + idents c [f.bind_src \\ f <- fields]
PE_Record init _ fields -> idents c init + idents c [f.bind_dst \\ f <- fields] + idents c [f.bind_src \\ f <- fields]
PE_ArrayPattern _ -> abort "idents PE_ArrayPattern\n"
//(PE_ArrayPattern ![ElemAssignment]
PE_UpdateComprehension base (PE_Update _ sels new) _ qs -> noLocals (idents ICExpression [base,new] + idents ICExpression sels + idents ICPattern qs)
......@@ -155,6 +158,11 @@ where
idents ICPattern q.qual_let_defs +
idents ICExpression q.qual_filter
instance idents FieldNameOrQualifiedFieldName
where
idents _ (FieldName id) = {zero & record_fields=fromList [id.id_name]}
idents _ (QualifiedFieldName _ f) = {zero & record_fields=fromList [f]}
instance idents Generator
where
idents ICPattern g = idents ICPattern g.gen_pattern + idents ICExpression g.gen_expr
......@@ -170,7 +178,7 @@ where
instance idents ParsedSelection
where
idents c ps = case ps of
PS_Record id _ -> idents c id
PS_QualifiedRecord _ s _ -> idents c s
PS_Record id _ -> {zero & record_fields=fromList [id.id_name]}
PS_QualifiedRecord _ s _ -> {zero & record_fields=fromList [s]}
PS_Array e -> idents c e
PS_Erroneous -> zero
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment