@@ -380,15 +380,15 @@ convertLHS l = do
380380-- try expression conversion by looking at the *innermost* type first
381381convertSubExpr :: Scopes Type -> Expr -> (Type , Expr )
382382convertSubExpr scopes (Dot e x) =
383- if isntStruct subExprType then
383+ if isntStruct subExprType || isHier then
384384 fallbackType scopes $ Dot e' x
385385 else if structIsntReady subExprType then
386386 (fieldType, Dot e' x)
387387 else
388388 (fieldType, undottedWithSign)
389389 where
390390 (subExprType, e') = convertSubExpr scopes e
391- (fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
391+ (isHier, fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
392392 base = fst bounds
393393 len = rangeSize bounds
394394 undotted = if null dims || rangeSize (head dims) == RawNum 1
@@ -403,7 +403,7 @@ convertSubExpr scopes (Dot e x) =
403403 else undotted
404404
405405convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) =
406- if isntStruct subExprType then
406+ if isntStruct subExprType || isHier then
407407 (UnknownType , orig')
408408 else if structIsntReady subExprType then
409409 (replaceInnerTypeRange NonIndexed rOuter' fieldType, orig')
@@ -420,7 +420,7 @@ convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) =
420420 (_, roRight') = convertSubExpr scopes roRight
421421 rOuter' = (roLeft', roRight')
422422 orig' = Range (Dot e' x) NonIndexed rOuter'
423- (fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
423+ (isHier, fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
424424 [dim] = dims
425425 rangeLeft = ( BinOp Sub (fst bounds) $ BinOp Sub (fst dim) roLeft'
426426 , BinOp Sub (fst bounds) $ BinOp Sub (fst dim) roRight' )
@@ -429,7 +429,7 @@ convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) =
429429 undotted = Range e' NonIndexed $
430430 endianCondRange dim rangeLeft rangeRight
431431convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) =
432- if isntStruct subExprType then
432+ if isntStruct subExprType || isHier then
433433 (UnknownType , orig')
434434 else if structIsntReady subExprType then
435435 (replaceInnerTypeRange mode (baseO', lenO') fieldType, orig')
@@ -444,7 +444,7 @@ convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) =
444444 (_, baseO') = convertSubExpr scopes baseO
445445 (_, lenO') = convertSubExpr scopes lenO
446446 orig' = Range (Dot e' x) mode (baseO', lenO')
447- (fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
447+ (isHier, fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
448448 [dim] = dims
449449 baseLeft = BinOp Sub (fst bounds) $ BinOp Sub (fst dim) baseO'
450450 baseRight = BinOp Add (snd bounds) $ BinOp Sub (snd dim) baseO'
@@ -463,7 +463,7 @@ convertSubExpr scopes (Range e mode (left, right)) =
463463 (_, right') = convertSubExpr scopes right
464464 r' = (left', right')
465465convertSubExpr scopes (Bit (Dot e x) i) =
466- if isntStruct subExprType then
466+ if isntStruct subExprType || isHier then
467467 (dropInnerTypeRange backupType, orig')
468468 else if structIsntReady subExprType then
469469 (dropInnerTypeRange fieldType, orig')
@@ -477,7 +477,7 @@ convertSubExpr scopes (Bit (Dot e x) i) =
477477 (_, i') = convertSubExpr scopes i
478478 (backupType, _) = fallbackType scopes $ Dot e' x
479479 orig' = Bit (Dot e' x) i'
480- (fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
480+ (isHier, fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
481481 [dim] = dims
482482 left = BinOp Sub (fst bounds) $ BinOp Sub (fst dim) i'
483483 right = BinOp Add (snd bounds) $ BinOp Sub (snd dim) i'
@@ -536,20 +536,22 @@ isntStruct = (== Nothing) . getFields
536536
537537-- get the field type, flattened bounds, and original type dimensions
538538lookupFieldInfo :: Scopes Type -> Type -> Expr -> Identifier
539- -> (Type , Range , [Range ])
539+ -> (Bool , Type , Range , [Range ])
540540lookupFieldInfo scopes struct base fieldName =
541541 if maybeFieldType == Nothing
542- then scopedError scopes $ " field '" ++ fieldName ++ " ' not found in "
543- ++ show struct ++ " , in expression "
544- ++ show (Dot base fieldName)
545- else (fieldType, bounds, dims)
542+ then (isHier, err, err, err)
543+ else (False , fieldType, bounds, dims)
546544 where
547545 Just fields = getFields struct
548546 maybeFieldType = lookup fieldName $ map swap fields
549547 Just fieldType = maybeFieldType
550548 dims = snd $ typeRanges fieldType
551549 Just (_, unstructRanges) = convertStruct struct
552550 Just bounds = lookup fieldName unstructRanges
551+ err = scopedError scopes $ " field '" ++ fieldName ++ " ' not found in "
552+ ++ show struct ++ " , in expression "
553+ ++ show (Dot base fieldName)
554+ isHier = lookupElem scopes (Dot base fieldName) /= Nothing
553555
554556-- attempts to convert based on the assignment-like contexts of TF arguments
555557convertCall :: Scopes Type -> Expr -> Args -> Args
0 commit comments