bug in the new pretty-printer, with strings

; confusingly, there's another pretty-printer at pprint.arc
; this one is loaded by default, but not the original Arc 3.1 pretty-printer

(= pprsyms* (fill-table (table)
                        '(quote "'"
                          quasiquote "`"
                          unquote ","
                          unquote-splicing ",@")))

(def sp ((o n 1))
  " Print a number of spaces. "
  (repeat n (pr " ")))

(def print-spaced (xs)
  " Print the expressions in the list separated by spaces. "
  (when xs
    (print car.xs)
    (each x cdr.xs (sp) print.x)))

(def print (x)
  " Print an expression on one line, replacing quote, unquote,
    quasiquote, unquote-splicing, and make-br-fn with their respective symbols. "
  (do (aif (or atom.x dotted.x (isa x 'string))
             write.x
           (pprsyms* car.x)
             (do pr.it
               (print cadr.x))
           (is car.x 'make-br-fn)
             (do (pr "[") (print-spaced cadr.x) (pr "]"))
           (do (pr "(") print-spaced.x (pr ")")))
      x))

(= oneline* 45)

(mac ppr-sub body
  `(do (unless noindent sp.col)
       (let whole (tostring print.x)
         (if (< len.whole oneline*)
             (do pr.whole nil)
             (do ,@body t)))))

; temporarily change line length
(mac w/line-length (n . body)
  `(let old-oneline@ oneline*
     (= oneline* ,n)
     (after (do ,@body)
        (= oneline* old-oneline@))))

(def indent-pairs (xs (o col 0))
  (let l (apply max 0 (map len:tostring:print:car (keep cdr pair.xs)))
    (on x pair.xs
        (if (~is index 0)
            (do (prn)
                (sp col)))
        (let str (tostring:print car.x)
          (if cdr.x
              (do pr.str
                  (sp:- l len.str -1)
                  (ppr-main cadr.x (+ col 1 l) t))
              ; lone tail expression
              (do (sp (+ l 1))
                  (ppr-main car.x (+ col (+ l 1)) t)))))))

(def indent-block (xs (o col 0))
  (each x xs (prn) (ppr-main x col)))

(def indent-mac (xs (o args 0) (o col 0))
  (print-spaced (firstn args xs))
  (indent-block (nthcdr args xs) (+ col 2)))

(def indent-basic (xs l (o col 0))
  (if (all [or atom._ (and (is car._ 'quote) (atom cadr._))]
           xs)
      print-spaced.xs
      (do (ppr-main car.xs (+ col 2 l) t)
          (indent-block cdr.xs (+ col 2 l)))))

(def indent-wave (xs (o col 0))
  (do (ppr-main car.xs col t)
      (on x cdr.xs
          (prn)
          (ppr-main x (+ col (* 2 (mod (+ index 1) 2)))))))

(= ifline* 20)

(def indent-if (l)
  (fn (xs (o col 0))
      (if (< len.xs 4)
            (on x xs
                (if (~is index 0) (prn))
                (ppr-main x (+ col 2 l) (is index 0)))
          (all [< (len:tostring print._) ifline*]
               pair.xs)
            (indent-pairs xs (+ col 2 l))
          (indent-wave xs (+ col 2 l)))))

(def indent-with (l)
  (fn (xs (o col 0))
      (pr "(")
      (indent-pairs car.xs (+ col 3 l))
      (pr ")")
      (indent-block cdr.xs (+ col 3))))

(def indent-def (xs (o col 0))
  (print-spaced (firstn 2 xs))
  (if (isa xs.2 'string)
      (do (prn)
          (sp (+ col 2))
          (pr #\" xs.2 #\")
          (indent-block (nthcdr 3 xs) (+ col 2)))
      (indent-block (nthcdr 2 xs) (+ col 2))))

(def indent-case (n)
  (fn (xs (o col 0))
      (print-spaced:firstn n xs)
      (prn)
      (sp (+ col 2))
      (indent-pairs (nthcdr n xs) (+ col 2))))

(= indent-rules*
   (fill-table (table)
     `(if      ,(indent-if 2)
       aif     ,(indent-if 3)
       with    ,(indent-with 4)
       withs   ,(indent-with 5)
       def     ,indent-def
       mac     ,indent-def
       do      ,[indent-basic _ 2 _2]
       and     ,[indent-basic _ 3 _2]
       or      ,[indent-basic _ 2 _2]
       nor     ,[indent-basic _ 3 _2]
       case    ,(indent-case 1)
       caselet ,(indent-case 2)
       fn      ,[indent-mac _ 1 _2])))

(def ppr-main (x (o col 0) (o noindent nil))
  " Recursive main body of the ppr function. "
  (aif (or atom.x dotted.x)             ;just print the expression if it's an atom or dotted list
         (do (unless noindent sp.col)
             print.x
             nil)
       (is car.x 'make-br-fn)           ;if the expression is a br-fn, print the brackets and then the contents
         (ppr-sub
           (pr "[")
           (ppr-main cadr.x (+ col 1) t)
           (pr "]"))
       (pprsyms* car.x)
         (ppr-sub
           pr.it
           (ppr-main cadr.x (+ col len.it) t))
       (ppr-sub
         (pr "(")
         (withs (proc car.x
                 args sig*.proc
                 n    len.args
                 str  (tostring:print proc)
                 l    len.str
                 xs   cdr.x)
           (if (isa proc 'cons)
               (do (ppr-main proc (+ col 1) t)
                   (indent-block xs (+ col 1)))
               (do pr.str
                   (when xs
                     (sp)
                     (aif indent-rules*.proc
                            (it xs col)
                          (and (isa proc 'sym) (bound proc) (isa (eval proc) 'mac))
                            (if (or dotted.args (and args (~acons args)))
                                (indent-mac xs (- len.args 1) col)
                                (indent-mac xs 0 col))
                          (indent-basic xs l col)))))
           (pr ")")))))

(def ppr l
  " Pretty print. This function displays arc code with proper
    indenting and representation of syntax. "
  (each x l (ppr-main x) (prn)))

; confusingly, there's another pretty-printer at pprint.arc
; this one is loaded by default, but not the original Arc 3.1 pretty-printer

(= pprsyms* (fill-table (table)
                        '(quote "'"
                          quasiquote "`"
                          unquote ","
                          unquote-splicing ",@")))

(def sp ((o n 1))
  " Print a number of spaces. "
  (repeat n (pr " ")))

(def print-spaced (xs)
  " Print the expressions in the list separated by spaces. "
  (when xs
    (print car.xs)
    (each x cdr.xs (sp) print.x)))

(def print (x)
  " Print an expression on one line, replacing quote, unquote,
    quasiquote, unquote-splicing, and make-br-fn with their respective symbols. "
  (do (aif (or atom.x dotted.x)
             write.x
           (pprsyms* car.x)
             (do pr.it
               (print cadr.x))
           (is car.x 'make-br-fn)
             (do (pr "[") (print-spaced cadr.x) (pr "]"))
           (do (pr "(") print-spaced.x (pr ")")))
      x))

(= oneline* 45)

(mac ppr-sub body
  `(do (unless noindent sp.col)
       (let whole (tostring print.x)
         (if (< len.whole oneline*)
             (do pr.whole nil)
             (do ,@body t)))))

; temporarily change line length
(mac w/line-length (n . body)
  `(let old-oneline@ oneline*
     (= oneline* ,n)
     (after (do ,@body)
        (= oneline* old-oneline@))))

(def indent-pairs (xs (o col 0))
  (let l (apply max 0 (map len:tostring:print:car (keep cdr pair.xs)))
    (on x pair.xs
        (if (~is index 0)
            (do (prn)
                (sp col)))
        (let str (tostring:print car.x)
          (if cdr.x
              (do pr.str
                  (sp:- l len.str -1)
                  (ppr-main cadr.x (+ col 1 l) t))
              ; lone tail expression
              (do (sp (+ l 1))
                  (ppr-main car.x (+ col (+ l 1)) t)))))))

(def indent-block (xs (o col 0))
  (each x xs (prn) (ppr-main x col)))

(def indent-mac (xs (o args 0) (o col 0))
  (print-spaced (firstn args xs))
  (indent-block (nthcdr args xs) (+ col 2)))

(def indent-basic (xs l (o col 0))
  (if (all [or atom._ (and (is car._ 'quote) (atom cadr._))]
           xs)
      print-spaced.xs
      (do (ppr-main car.xs (+ col 2 l) t)
          (indent-block cdr.xs (+ col 2 l)))))

(def indent-wave (xs (o col 0))
  (do (ppr-main car.xs col t)
      (on x cdr.xs
          (prn)
          (ppr-main x (+ col (* 2 (mod (+ index 1) 2)))))))

(= ifline* 20)

(def indent-if (l)
  (fn (xs (o col 0))
      (if (< len.xs 4)
            (on x xs
                (if (~is index 0) (prn))
                (ppr-main x (+ col 2 l) (is index 0)))
          (all [< (len:tostring print._) ifline*]
               pair.xs)
            (indent-pairs xs (+ col 2 l))
          (indent-wave xs (+ col 2 l)))))

(def indent-with (l)
  (fn (xs (o col 0))
      (pr "(")
      (indent-pairs car.xs (+ col 3 l))
      (pr ")")
      (indent-block cdr.xs (+ col 3))))

(def indent-def (xs (o col 0))
  (print-spaced (firstn 2 xs))
  (if (isa xs.2 'string)
      (do (prn)
          (sp (+ col 2))
          (pr #\" xs.2 #\")
          (indent-block (nthcdr 3 xs) (+ col 2)))
      (indent-block (nthcdr 2 xs) (+ col 2))))

(def indent-case (n)
  (fn (xs (o col 0))
      (print-spaced:firstn n xs)
      (prn)
      (sp (+ col 2))
      (indent-pairs (nthcdr n xs) (+ col 2))))

(= indent-rules*
   (fill-table (table)
     `(if      ,(indent-if 2)
       aif     ,(indent-if 3)
       with    ,(indent-with 4)
       withs   ,(indent-with 5)
       def     ,indent-def
       mac     ,indent-def
       do      ,[indent-basic _ 2 _2]
       and     ,[indent-basic _ 3 _2]
       or      ,[indent-basic _ 2 _2]
       nor     ,[indent-basic _ 3 _2]
       case    ,(indent-case 1)
       caselet ,(indent-case 2)
       fn      ,[indent-mac _ 1 _2])))

(def ppr-main (x (o col 0) (o noindent nil))
  " Recursive main body of the ppr function. "
  (aif (or atom.x dotted.x)             ;just print the expression if it's an atom or dotted list
         (do (unless noindent sp.col)
             print.x
             nil)
       (is car.x 'make-br-fn)           ;if the expression is a br-fn, print the brackets and then the contents
         (ppr-sub
           (pr "[")
           (ppr-main cadr.x (+ col 1) t)
           (pr "]"))
       (pprsyms* car.x)
         (ppr-sub
           pr.it
           (ppr-main cadr.x (+ col len.it) t))
       (ppr-sub
         (pr "(")
         (withs (proc car.x
                 args sig*.proc
                 n    len.args
                 str  (tostring:print proc)
                 l    len.str
                 xs   cdr.x)
           (if (isa proc 'cons)
               (do (ppr-main proc (+ col 1) t)
                   (indent-block xs (+ col 1)))
               (do pr.str
                   (when xs
                     (sp)
                     (aif indent-rules*.proc
                            (it xs col)
                          (and (isa proc 'sym) (bound proc) (isa (eval proc) 'mac))
                            (if (or dotted.args (and args (~acons args)))
                                (indent-mac xs (- len.args 1) col)
                                (indent-mac xs 0 col))
                          (indent-basic xs l col)))))
           (pr ")")))))

(def ppr l
  " Pretty print. This function displays arc code with proper
    indenting and representation of syntax. "
  (each x l (ppr-main x) (prn)))


job:  #39  Add missing argument (salt).

job:  #39  Add missing argument (salt).

.//====================================================================
.//
.// $RCSfile: q.val.translate.arc,v $
.//
.// (c) Copyright 1998-2013 Mentor Graphics Corporation  All rights reserved.
.//
.//====================================================================
.//
.// These functions set up the implementation of the values (V_VAL on
.// model of OAL).
.//
.//====================================================================
.//
.//
.function val_translate
  .// Translate "leaf" values first.
  .invoke val_literal_boolean_values()
  .invoke val_literal_integer_values()
  .invoke val_literal_real_values()
  .invoke val_literal_string_values()
  .invoke val_literal_enumerations()
  .invoke val_constant_values()
  .invoke val_transient_values()
  .invoke val_instance_reference_values()
  .invoke val_inst_ref_set_values()
  .invoke val_selection_test_values()
  .invoke val_event_values()
  .invoke val_parameter_values()
  .// The following may be recursed.
  .invoke val_attribute_values()
  .invoke val_member_values()
  .invoke val_array_element_references()
  .invoke val_array_length_values()
  .invoke val_unary_op_values()
  .invoke val_binary_op_values()
  .// V_PARs depend upon values being populated.
  .invoke val_actual_parameters()
  .// These use V_PARs.
  .invoke val_message_values()
  .invoke val_bridge_values()
  .invoke val_transform_values()
  .invoke val_synch_service_values()
.end function
.//
.//--------------------------------------------------------------------
.// Percolate the values from the "leaves" up into the combined
.// expressions by recursively drilling down.
.//--------------------------------------------------------------------
.function gen_value
  .param inst_ref v_val
  .select one v_mvl related by v_val->V_MVL[R801]
  .if ( not_empty v_mvl )
    .invoke val_member_value( v_mvl )
  .else
  .select one v_avl related by v_val->V_AVL[R801]
  .if ( not_empty v_avl )
    .invoke val_attribute_value( v_avl )
  .else
  .select one v_aer related by v_val->V_AER[R801]
  .if ( not_empty v_aer )
    .invoke val_array_element_reference( v_aer )
  .else
  .select one v_alv related by v_val->V_ALV[R801]
  .if ( not_empty v_alv )
    .invoke val_array_length_value( v_alv )
  .else
  .select one v_uny related by v_val->V_UNY[R801]
  .if ( not_empty v_uny )
    .invoke val_unary_op_value( v_uny )
  .else
  .select one v_bin related by v_val->V_BIN[R801]
  .if ( not_empty v_bin )
    .invoke val_binary_op_value( v_bin )
  .else
  .select one v_trv related by v_val->V_TRV[R801]
  .if ( not_empty v_trv )
    .invoke val_transform_value( v_trv )
  .else
  .select one v_msv related by v_val->V_MSV[R801]
  .if ( not_empty v_msv )
    .invoke val_message_value( v_msv )
  .else
  .select one v_brv related by v_val->V_BRV[R801]
  .if ( not_empty v_brv )
    .invoke val_bridge_value( v_brv )
  .else
  .select one v_fnv related by v_val->V_FNV[R801]
  .if ( not_empty v_fnv )
    .invoke val_synch_service_value( v_fnv )
  .else
    .print "ERROR:  Recursive V_VAL resolution issue."
  .end if
  .end if
  .end if
  .end if
  .end if
  .end if
  .end if
  .end if
  .end if
  .end if
.end function
.//
.function val_literal_boolean_values
  .select many v_lbos from instances of V_LBO
  .for each v_lbo in v_lbos
    .select one te_val related by v_lbo->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.OAL = v_lbo.Value
    .assign te_val.buffer = v_lbo.Value
  .end for
.end function
.//
.function val_literal_string_values
  .select any te_string from instances of TE_STRING
  .select many v_lsts from instances of V_LST
  .for each v_lst in v_lsts
    .select one te_val related by v_lst->V_VAL[R801]->TE_VAL[R2040]
    .// s = T::t( s:v_lst.Value );
    .assign s = v_lst.Value
    .// if ( strstr( s, "({" ) )
    .if ( "({" == s )
      .assign te_val.buffer = s
    .else
      .assign te_val.buffer = ( """" + v_lst.Value ) + """"
    .end if
    .assign te_val.OAL = ( "" + v_lst.Value ) + ""
    .assign te_val.dimensions = 1
    .assign te_val.array_spec = ( "[" + te_string.max_string_length ) + "]"
    .//TODO assign dimension
  .end for
.end function
.//
.function val_literal_integer_values
  .select many v_lins from instances of V_LIN
  .for each v_lin in v_lins
    .select one te_val related by v_lin->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.OAL = v_lin.Value
    .assign te_val.buffer = v_lin.Value
  .end for
.end function
.//
.function val_literal_real_values
  .select many v_lrls from instances of V_LRL
  .for each v_lrl in v_lrls
    .select one te_val related by v_lrl->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.OAL = v_lrl.Value
    .assign te_val.buffer = v_lrl.Value
  .end for
.end function
.//
.function val_literal_enumerations
  .select many v_lens from instances of V_LEN
  .for each v_len in v_lens
    .select one te_val related by v_len->V_VAL[R801]->TE_VAL[R2040]
    .select one te_enum related by v_len->S_ENUM[R824]->TE_ENUM[R2027]
    .assign te_val.OAL = te_enum.Name
    .assign te_val.buffer = te_enum.GeneratedName
  .end for
.end function
.//
.function val_constant_values
  .select many v_scvs from instances of V_SCV
  .for each v_scv in v_scvs
    .select one te_val related by v_scv->V_VAL[R801]->TE_VAL[R2040]
    .select one cnst_syc related by v_scv->CNST_SYC[R850]
    .select one cnst_lsc related by cnst_syc->CNST_LFSC[R1502]->CNST_LSC[R1503]
    .select one te_dt related by cnst_syc->S_DT[R1500]->TE_DT[R2021]
    .assign te_val.OAL = cnst_syc.Name
    .assign te_val.buffer = cnst_lsc.Value
    .if ( 4 == te_dt.Core_Typ )
      .select any te_string from instances of TE_STRING
      .assign te_val.buffer = ( """" + cnst_lsc.Value ) + """"
      .assign te_val.dimensions = 1
      .assign te_val.array_spec = ( "[" + te_string.max_string_length ) + "]"
      .//TODO assign dimension
    .end if
  .end for
.end function
.//
.function val_transient_values
  .select many v_tvls from instances of V_TVL
  .for each v_tvl in v_tvls
    .select one v_var related by v_tvl->V_VAR[R805]
    .select one te_var related by v_var->TE_VAR[R2039]
    .select one te_val related by v_tvl->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.OAL = te_var.OAL
    .assign te_val.buffer = te_var.buffer
    .assign te_val.dimensions = te_var.dimensions
    .assign te_val.array_spec = te_var.array_spec
    .select one te_dim related by te_var->TE_DIM[R2057]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end for
.end function
.//
.function val_actual_parameters
  .select many v_pars from instances of V_PAR
  .for each v_par in v_pars
    .select one te_par related by v_par->TE_PAR[R2063]
    .select one v_val related by v_par->V_VAL[R800]
    .select one te_val related by v_val->TE_VAL[R2040]
    .select one te_dt related by v_val->S_DT[R820]->TE_DT[R2021]
    .assign te_val.OAL = ( te_par.Name + ":" ) + te_val.OAL
    .if ( 10 == te_dt.Core_Typ )
      .// Cast event types to the base event type for passing (to timers).
      .assign te_val.buffer = ( "(" + te_dt.ExtName ) + ( ")" + te_val.buffer )
    .end if
  .end for
.end function
.//
.function val_attribute_values
  .select many v_avls from instances of V_AVL
  .for each v_avl in v_avls
    .invoke val_attribute_value( v_avl )
  .end for
.end function
.//
.function val_attribute_value
  .param inst_ref v_avl
  .select one v_val related by v_avl->V_VAL[R801]
  .select one te_val related by v_val->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one root_v_val related by v_avl->V_VAL[R807]
    .select one root_te_val related by root_v_val->TE_VAL[R2040]
    .if ( "" == root_te_val.buffer )
      .invoke gen_value( root_v_val )
    .end if
    .select one te_var related by v_avl->V_VAL[R807]->V_IRF[R801]->V_VAR[R808]->TE_VAR[R2039]
    .select one o_attr related by v_avl->O_ATTR[R806]
    .select one te_attr related by o_attr->TE_ATTR[R2033]
    .if ( not_empty te_attr )
    .assign root = ""
    .if ( empty te_var )
      .assign te_val.OAL = ( root_te_val.OAL + "." ) + te_attr.Name
      .assign te_val.buffer = ( root_te_val.buffer + "->" ) + te_attr.GeneratedName
      .assign root = root_te_val.buffer
    .else
      .assign te_val.OAL = ( te_var.OAL + "." ) + te_attr.Name
      .assign te_val.buffer = ( te_var.buffer + "->" ) + te_attr.GeneratedName
      .assign root = te_var.buffer
    .end if
    .assign te_val.dimensions = te_attr.dimensions
    .assign te_val.array_spec = te_attr.array_spec
    .select one te_dim related by te_attr->TE_DIM[R2055]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
    .// Maybe attribute value is actually derived.
    .select one o_dbattr related by o_attr->O_BATTR[R106]->O_DBATTR[R107]
    .if ( not_empty o_dbattr )
      .select one act_ai related by v_val->ACT_AI[R689]
      .if ( empty act_ai )
        .// Only do this if we are not assigning inside the DAB OAL body.
        .select one te_aba related by o_dbattr->TE_DBATTR[R2026]->TE_ABA[R2010]
        .assign te_val.buffer = ( te_aba.GeneratedName + "( " ) + ( root + " )" )
        .assign te_val.dimensions = te_aba.dimensions
        .assign te_val.array_spec = te_aba.array_spec
        .select one te_dim related by te_aba->TE_DIM[R2058]
        .if ( not_empty te_dim )
          .// relate te_val to te_dim across R2079;
          .assign te_val.te_dimID = te_dim.te_dimID
          .// end relate
        .else
          .assign te_val.te_dimID = 00
        .end if
      .end if
    .end if
    .end if
  .end if
.end function
.//
.function val_member_values
  .select many v_mvls from instances of V_MVL
  .for each v_mvl in v_mvls
    .invoke val_member_value( v_mvl )
  .end for
.end function
.//
.function val_member_value
  .param inst_ref v_mvl
  .select one te_val related by v_mvl->V_VAL[R801]->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one root_v_val related by v_mvl->V_VAL[R837]
    .select one root_te_val related by root_v_val->TE_VAL[R2040]
    .if ( "" == root_te_val.buffer )
      .invoke gen_value( root_v_val )
    .end if
    .select one te_mbr related by v_mvl->S_MBR[R836]->TE_MBR[R2047]
    .assign te_val.dimensions = te_mbr.dimensions
    .assign te_val.array_spec = te_mbr.array_spec
    .select one te_dim related by te_mbr->TE_DIM[R2059]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
    .assign te_val.OAL = ( root_te_val.OAL + "." ) + te_mbr.Name
    .assign te_val.buffer = ( root_te_val.buffer + "." ) + te_mbr.GeneratedName
  .end if
.end function
.//
.function val_instance_reference_values
  .assign unique_num = 0
  .select many v_irfs from instances of V_IRF
  .for each v_irf in v_irfs
    .select one te_val related by v_irf->V_VAL[R801]->TE_VAL[R2040]
    .select one te_var related by v_irf->V_VAR[R808]->TE_VAR[R2039]
    .if ( not_empty te_var )
      .assign te_val.OAL = te_var.OAL
      .assign te_val.buffer = te_var.buffer
    .else
      .print "CDS:  Understand why we do not have V_VAR here."
      .assign te_val.buffer = "v_irf_" + "$t{unique_num}"
      .assign unique_num = unique_num + 1
    .end if
  .end for
.end function
.//
.function val_selection_test_values
  .select many v_slrs from instances of V_SLR
  .for each v_slr in v_slrs
    .select one te_val related by v_slr->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.buffer = "selected"
    .assign te_val.OAL = "SELECTED"
  .end for
.end function
.//
.function val_inst_ref_set_values
  .select many v_isrs from instances of V_ISR
  .for each v_isr in v_isrs
    .select one te_var related by v_isr->V_VAR[R809]->TE_VAR[R2039]
    .select one te_val related by v_isr->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.OAL = te_var.OAL
    .assign te_val.buffer = te_var.buffer
  .end for
.end function
.//
.function val_event_values
  .select many v_edvs from instances of V_EDV
  .for each v_edv in v_edvs
    .select one te_val related by v_edv->V_VAL[R801]->TE_VAL[R2040]
    .// If there are more than one transition into the state, there
    .// may be more than one event parameter reference.  Select
    .// any of them; they have the same names.
    .select any te_parm related by v_edv->V_EPR[R834]->SM_EVTDI[R846]->TE_PARM[R2031]
    .if ( empty te_parm )
      .select any te_parm related by v_edv->V_EPR[R834]->C_PP[R847]->TE_PARM[R2048]
    .else
      .// Mark the event as used.
      .select one te_evt related by te_parm->SM_EVTDI[R2031]->SM_EVT[R532]->TE_EVT[R2036]
      .if ( not_empty te_evt )
        .assign te_evt.UsedCount = te_evt.UsedCount + 1
        .assign te_evt.Used = true
      .end if
    .end if
    .assign te_val.OAL = "PARAM." + te_parm.Name
    .assign te_val.buffer = "rcvd_evt->" + te_parm.GeneratedName
    .assign te_val.dimensions = te_parm.dimensions
    .assign te_val.array_spec = te_parm.array_spec
    .select one te_dim related by te_parm->TE_DIM[R2056]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end for
.end function
.//
.function val_parameter_values
  .select many v_pvls from instances of V_PVL
  .for each v_pvl in v_pvls
    .select one te_val related by v_pvl->V_VAL[R801]->TE_VAL[R2040]
    .select one te_parm related by v_pvl->O_TPARM[R833]->TE_PARM[R2029]
    .if ( empty te_parm )
    .select one te_parm related by v_pvl->C_PP[R843]->TE_PARM[R2048]
    .if ( empty te_parm )
    .select one te_parm related by v_pvl->S_SPARM[R832]->TE_PARM[R2030]
    .if ( empty te_parm )
    .select one te_parm related by v_pvl->S_BPARM[R831]->TE_PARM[R2028]
    .if ( empty te_parm )
      .print "CDS:  Understand why we do not have V_PVL related parameter here."
    .end if
    .end if
    .end if
    .end if
    .assign te_val.OAL = "PARAM." + te_parm.Name
    .assign te_val.buffer = te_parm.GeneratedName
    .assign te_val.dimensions = te_parm.dimensions
    .assign te_val.array_spec = te_parm.array_spec
    .select one te_dim related by te_parm->TE_DIM[R2056]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
    .if ( 1 == te_parm.By_Ref )
      .assign te_val.buffer = ( "(*" + te_parm.GeneratedName ) + ")"
    .end if
  .end for
.end function
.//
.function val_unary_op_values
  .select many v_unys from instances of V_UNY
  .for each v_uny in v_unys
    .invoke val_unary_op_value( v_uny )
  .end for
.end function
.//
.function val_unary_op_value
  .param inst_ref v_uny
  .select one te_val related by v_uny->V_VAL[R801]->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one root_v_val related by v_uny->V_VAL[R804]
    .select one root_te_val related by root_v_val->TE_VAL[R2040]
    .if ( "" == root_te_val.buffer )
      .invoke gen_value( root_v_val )
    .end if
    .// Remove blanks and make lower case.
    .assign op = "$r{v_uny.Operator}"
    .assign op = "$l{op}"
    .select any te_set from instances of TE_SET
    .select one v_irf related by root_v_val->V_IRF[R801]
    .select one v_isr related by root_v_val->V_ISR[R801]
    .if ( not_empty v_irf )
      .if ( op == "not_empty" )
        .assign te_val.buffer = ( "( 0 != " + root_te_val.buffer ) + " )"
      .elif ( op == "empty" )
        .assign te_val.buffer = ( "( 0 == " + root_te_val.buffer ) + " )"
      .elif ( op == "cardinality" )
        .assign te_val.buffer = ( "( 0 != " + root_te_val.buffer ) + " )"
      .else
        .print "ERROR:  Unary set operator ${v_uny.Operator} is not supported."
      .end if
    .elif ( not_empty v_isr )
      .if ( op == "not_empty" )
        .assign te_val.buffer = ( ( "( ! " + te_set.emptiness ) + ( "( " + root_te_val.buffer ) ) + " ) )"
      .elif ( op == "empty" )
        .assign te_val.buffer = ( ( te_set.emptiness + "( " ) + ( root_te_val.buffer + " )" ) )
      .elif ( op == "cardinality" )
        .assign te_val.buffer = ( ( te_set.module + te_set.element_count ) + ( "( " + root_te_val.buffer ) ) + " )"
      .else
        .print "ERROR:  Unary set operator ${v_uny.Operator} is not supported."
      .end if
    .else
      .if ( op == "not" )
        .assign te_val.buffer = "!" + root_te_val.buffer
      .else
        .assign te_val.buffer = op + root_te_val.buffer
      .end if
    .end if
    .assign te_val.OAL = ( op + " " ) + root_te_val.OAL
    .// future support for vector arithmetic goes here
    .assign te_val.dimensions = root_te_val.dimensions
    .assign te_val.array_spec = root_te_val.array_spec
    .select one te_dim related by root_te_val->TE_DIM[R2079]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end if
.end function
.//
.function val_binary_op_values
  .select many v_bins from instances of V_BIN
  .for each v_bin in v_bins
    .invoke val_binary_op_value( v_bin )
  .end for
.end function
.//
.function val_binary_op_value
  .param inst_ref v_bin
  .select one te_val related by v_bin->V_VAL[R801]->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one l_v_val related by v_bin->V_VAL[R802]
    .select one l_te_val related by l_v_val->TE_VAL[R2040]
    .if ( "" == l_te_val.buffer )
      .invoke gen_value( l_v_val )
    .end if
    .select one r_v_val related by v_bin->V_VAL[R803]
    .select one r_te_val related by r_v_val->TE_VAL[R2040]
    .if ( "" == r_te_val.buffer )
      .invoke gen_value( r_v_val )
    .end if
    .select one l_te_dt related by l_v_val->S_DT[R820]->TE_DT[R2021]
    .select one r_te_dt related by r_v_val->S_DT[R820]->TE_DT[R2021]
    .if ( ( 4 == l_te_dt.Core_Typ ) or ( 4 == r_te_dt.Core_Typ ) )
      .// string
      .select any te_string from instances of TE_STRING
      .select any te_instance from instances of TE_INSTANCE
      .if ( "+" == "$r{v_bin.Operator}" )
        .assign te_val.buffer = ( ( ( te_instance.module + te_string.stradd ) + ( "( " + l_te_val.buffer ) ) + ( ", " + r_te_val.buffer ) ) + " )"
      .else
        .assign te_val.buffer = ( ( ( "( " + te_instance.module ) + ( te_string.strcmp + "( " ) ) + ( ( l_te_val.buffer + ", " ) + ( r_te_val.buffer + " ) " ) ) ) + ( v_bin.Operator + " 0 )" )
      .end if
    .else
      .select any te_target from instances of TE_TARGET
      .if ( "and" == "$r{v_bin.Operator}" )
        .assign te_val.buffer = ( ( "( " + l_te_val.buffer ) + ( " && " + r_te_val.buffer ) ) + " )"
      .elif ( "or" == "$r{v_bin.Operator}" )
        .assign te_val.buffer = ( ( "( " + l_te_val.buffer ) + ( " || " + r_te_val.buffer ) ) + " )"
      .elif ( ( ( ( "==" == "$r{v_bin.Operator}" ) or ( "!=" == "$r{v_bin.Operator}" ) ) and ( "C" == te_target.language ) ) and ( l_te_val.dimensions != 0 ) )
        .assign element_count = 0
        .select one r_te_dim related by r_te_val->TE_DIM[R2079]
        .if ( not_empty r_te_dim )
          .assign element_count = r_te_dim.elementCount
        .end if
        .assign te_val.buffer = ( ( ( "( memcmp( " + l_te_val.buffer ) + ( ", " + r_te_val.buffer ) ) + ( ( ", sizeof(" + l_te_val.buffer ) + ( "[0]) * " + "$t{element_count}" ) ) ) + ( ( ") " + v_bin.Operator ) + " 0 )" )
      .else
        .assign te_val.buffer = ( ( "( " + l_te_val.buffer ) + ( " " + v_bin.Operator ) ) + ( ( " " + r_te_val.buffer ) + " )" )
      .end if
    .end if
    .// future support for vector arithmetic goes here
    .assign te_val.dimensions = r_te_val.dimensions
    .assign te_val.array_spec = r_te_val.array_spec
    .select one te_dim related by r_te_val->TE_DIM[R2079]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
    .assign te_val.OAL = ( ( "( " + l_te_val.OAL ) + ( " " + v_bin.Operator ) ) + ( ( " " + r_te_val.OAL ) + " )" )
  .end if
.end function
.//
.function val_message_values
  .assign n = 0
  .select many v_msvs from instances of V_MSV
  .for each v_msv in v_msvs
    .assign salt = "$t{n}" + "msv"
    .assign n = n + 1
    .invoke val_message_value( v_msv, salt )
  .end for
.end function
.//
.function val_message_value
  .param inst_ref v_msv
  .param string salt
  .select one v_val related by v_msv->V_VAL[R801]
  .select one te_val related by v_val->TE_VAL[R2040]
  .select one te_mact related by v_msv->SPR_PEP[R841]->SPR_PO[R4503]->TE_MACT[R2050]
  .if ( empty te_mact )
    .select one te_mact related by v_msv->SPR_REP[R845]->SPR_RO[R4502]->TE_MACT[R2052]
  .end if
  .select many v_pars related by v_msv->V_PAR[R842]
  .select one te_aba related by te_mact->TE_ABA[R2010]
  .invoke r = q_render_msg( te_mact, v_pars, "", false, salt )
  .assign te_val.buffer = r.body
  .assign te_val.OAL = ( ( te_mact.PortName + "::" ) + ( te_mact.MessageName + "(" ) ) + ( te_mact.OALParamBuffer + ")" )
  .assign te_val.dimensions = te_aba.dimensions
  .assign te_val.array_spec = te_aba.array_spec
  .select one te_dim related by te_aba->TE_DIM[R2058]
  .if ( not_empty te_dim )
    .// relate te_val to te_dim across R2079;
    .assign te_val.te_dimID = te_dim.te_dimID
    .// end relate
  .else
    .assign te_val.te_dimID = 00
  .end if
.end function
.//
.function val_bridge_values
  .assign n = 0
  .select many v_brvs from instances of V_BRV
  .for each v_brv in v_brvs
    .assign salt = "$t{n}" + "brv"
    .assign n = n + 1
    .invoke val_bridge_value( v_brv, salt )
  .end for
.end function
.//
.function val_bridge_value
  .param inst_ref v_brv
  .param string salt
  .select one te_brg related by v_brv->S_BRG[R828]->TE_BRG[R2025]
  .if ( not_empty te_brg )
    .select any te_target from instances of TE_TARGET
    .select one v_val related by v_brv->V_VAL[R801]
    .select one te_val related by v_val->TE_VAL[R2040]
    .select many v_pars related by v_brv->V_PAR[R810]
    .select one te_aba related by te_brg->TE_ABA[R2010]
    .select one te_ee related by v_brv->S_BRG[R828]->S_EE[R19]->TE_EE[R2020]
    .assign te_ee.Included = true
    .invoke r = gen_parameter_list( v_pars, false, salt )
    .assign te_parm = r.result
    .assign parameters = te_parm.ParamBuffer
    .assign params_OAL = te_parm.OALParamBuffer
    .assign te_val.OAL = ( ( te_brg.EEkeyletters + "::" ) + ( te_brg.Name + "(" ) ) + ( params_OAL + ")" )
    .if ( "C++" == te_target.language )
      .if ( "TIM" == te_brg.EEkeyletters )
        .assign te_val.buffer = ( "thismodule->tim->" + te_brg.GeneratedName ) + "("
      .else
        .select one te_c related by te_ee->TE_C[R2085]
        .if ( not_empty te_c )
          .if ( "" == parameters )
            .assign parameters = "thismodule"
          .else
            .assign parameters = "thismodule, " + parameters
          .end if
        .end if
      .end if
    .else
      .assign te_val.buffer = ( te_aba.scope + te_brg.GeneratedName ) + "("
    .end if
    .if ( "" != parameters )
      .assign te_val.buffer = ( te_val.buffer + " " ) + ( parameters + " " )
    .end if
    .assign te_val.buffer = te_val.buffer + ")"
    .assign te_val.dimensions = te_aba.dimensions
    .assign te_val.array_spec = te_aba.array_spec
    .select one te_dim related by te_aba->TE_DIM[R2058]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end if
.end function
.//
.function val_transform_values
  .assign n = 0
  .select many v_trvs from instances of V_TRV
  .for each v_trv in v_trvs
    .assign salt = "$t{n}" + "trv"
    .assign n = n + 1
    .invoke val_transform_value( v_trv, salt )
  .end for
.end function
.//
.function val_transform_value
  .param inst_ref v_trv
  .param string salt
  .select one te_tfr related by v_trv->O_TFR[R829]->TE_TFR[R2024]
  .if ( not_empty te_tfr )
  .select any te_target from instances of TE_TARGET
  .select one v_val related by v_trv->V_VAL[R801]
  .select one te_val related by v_val->TE_VAL[R2040]
  .select many v_pars related by v_trv->V_PAR[R811]
  .select one te_aba related by te_tfr->TE_ABA[R2010]
  .assign te_val.buffer = te_tfr.GeneratedName + "("
  .if ( te_tfr.Instance_Based == 1 )
    .select one te_var related by v_trv->V_VAR[R830]->TE_VAR[R2039]
    .if ( not_empty te_var )
      .if ( "C++" == te_target.language )
        .assign te_val.buffer = ( te_var.buffer + "->" ) + te_val.buffer
      .end if
      .assign te_val.buffer = te_val.buffer + te_var.buffer
      .assign te_val.OAL = te_var.OAL + "."
    .else
      .// no variable, must be selection (selected reference)
      .if ( "C++" == te_target.language )
        .assign te_val.buffer = "selected->" + te_val.buffer
      .end if
      .assign te_val.buffer = te_val.buffer + "selected"
      .assign te_val.OAL = "SELECTED."
    .end if
  .else
    .if ( "C++" == te_target.language )
      .select one te_class related by v_trv->O_TFR[R829]->O_OBJ[R115]->TE_CLASS[R2019]
      .assign te_val.buffer = ( te_class.GeneratedName + "::" ) + te_val.buffer
    .end if
    .assign te_val.OAL = te_tfr.Key_Lett + "::"
  .end if
  .invoke r = gen_parameter_list( v_pars, false, salt )
  .assign te_parm = r.result
  .assign parameters = te_parm.ParamBuffer
  .assign params_OAL = te_parm.OALParamBuffer
  .assign te_val.OAL = ( ( te_val.OAL + te_tfr.Name ) + ( "(" + params_OAL ) ) + ")"
  .if ( te_tfr.Instance_Based == 1 )
    .if ( ( "C++" == te_target.language ) or ( "" != parameters ) )
      .assign te_val.buffer = te_val.buffer + ", "
    .end if
  .end if
  .if ( "C++" == te_target.language )
    .assign te_val.buffer = te_val.buffer + "thismodule"
    .if ( "" != parameters )
      .assign te_val.buffer = te_val.buffer + ", "
    .end if
  .end if
  .assign te_val.buffer = ( te_val.buffer + parameters ) + ")"
  .assign te_val.dimensions = te_aba.dimensions
  .assign te_val.array_spec = te_aba.array_spec
  .select one te_dim related by te_aba->TE_DIM[R2058]
  .if ( not_empty te_dim )
    .// relate te_val to te_dim across R2079;
    .assign te_val.te_dimID = te_dim.te_dimID
    .// end relate
  .else
    .assign te_val.te_dimID = 00
  .end if
  .end if
.end function
.//
.function val_synch_service_values
  .assign n = 0
  .select many v_fnvs from instances of V_FNV
  .for each v_fnv in v_fnvs
    .assign salt = "$t{n}" + "fnv"
    .assign n = n + 1
    .invoke val_synch_service_value( v_fnv, salt )
  .end for
.end function
.//
.function val_synch_service_value
  .param inst_ref v_fnv
  .param string salt
  .select one te_sync related by v_fnv->S_SYNC[R827]->TE_SYNC[R2023]
  .if ( not_empty te_sync )
    .select any te_target from instances of TE_TARGET
    .select one v_val related by v_fnv->V_VAL[R801]
    .select one te_val related by v_val->TE_VAL[R2040]
    .select many v_pars related by v_fnv->V_PAR[R817]
    .select one te_aba related by te_sync->TE_ABA[R2010]
    .invoke r = gen_parameter_list( v_pars, false, salt )
    .assign te_parm = r.result
    .assign parameters = te_parm.ParamBuffer
    .assign params_OAL = te_parm.OALParamBuffer
    .assign te_val.OAL = ( ( "::" + te_sync.Name ) + ( "(" + params_OAL ) ) + ")"
    .assign name = te_sync.intraface_method
    .if ( "C++" == te_target.language )
      .assign name = "thismodule->" + name
    .end if
    .assign te_val.buffer = name + "("
    .if ( "" != parameters )
      .assign te_val.buffer = ( te_val.buffer + " " ) + ( parameters + " " )
    .end if
    .assign te_val.buffer = te_val.buffer + ")"
    .assign te_val.dimensions = te_aba.dimensions
    .assign te_val.array_spec = te_aba.array_spec
    .select one te_dim related by te_aba->TE_DIM[R2058]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end if
.end function
.//
.function val_array_element_references
  .select many v_aers from instances of V_AER
  .for each v_aer in v_aers
    .invoke val_array_element_reference( v_aer )
  .end for
.end function
.//
.function val_array_element_reference
  .param inst_ref v_aer
  .select one te_val related by v_aer->V_VAL[R801]->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one root_v_val related by v_aer->V_VAL[R838]
    .select one root_te_val related by root_v_val->TE_VAL[R2040]
    .if ( "" == root_te_val.buffer )
      .invoke gen_value( root_v_val )
    .end if
    .select one index_v_val related by v_aer->V_VAL[R839]
    .select one index_te_val related by index_v_val->TE_VAL[R2040]
    .if ( "" == index_te_val.buffer )
      .invoke gen_value( index_v_val )
    .end if
    .assign te_val.OAL = ( root_te_val.OAL + "[" ) + ( index_te_val.buffer + "]" )
    .assign te_val.buffer = ( root_te_val.buffer + "[" ) + ( index_te_val.buffer + "]" )
    .// Peel off outer layer of dimensions.
    .// CDS:  do not know how to do this with array_spec
    .assign te_val.array_spec = root_te_val.array_spec
    .assign te_val.dimensions = root_te_val.dimensions - 1
    .select one next_te_dim related by root_te_val->TE_DIM[R2079]->TE_DIM[R2060.'succeeds']
    .if ( not_empty next_te_dim )
      .// relate te_val to next_te_dim across R2079;
      .assign te_val.te_dimID = next_te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end if
.end function
.//
.function val_array_length_values
  .select many v_alvs from instances of V_ALV
  .for each v_alv in v_alvs
    .invoke val_array_length_value( v_alv )
  .end for
.end function
.//
.function val_array_length_value
  .param inst_ref v_alv
  .select one te_val related by v_alv->V_VAL[R801]->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one root_v_val related by v_alv->V_VAL[R840]
    .select one root_te_val related by root_v_val->TE_VAL[R2040]
    .if ( "" == root_te_val.buffer )
      .invoke gen_value( root_v_val )
    .end if
    .assign te_val.OAL = root_te_val.OAL + ".length"
    .select any te_target from instances of TE_TARGET
    .if ( "C" == te_target.language )
      .select one te_dim related by root_te_val->TE_DIM[R2079]
      .if ( not_empty te_dim )
        .assign te_val.buffer = ( ( ( "$t{te_dim.elementCount}" + " /" ) + ( "* " + te_val.OAL ) ) + ( " *" + "/" ) )
      .else
        .assign te_val.buffer = root_te_val.buffer + ".ARRAY_LENGTH_NOT_FOUND()"
        .print "ERROR:  C model compiler does not support length operator for OAL value:  ${te_val.OAL}"
        .exit 101
      .end if
    .else
      .assign te_val.buffer = root_te_val.buffer + ".length"
    .end if
  .end if
.end function
.//

.//====================================================================
.//
.// $RCSfile: q.val.translate.arc,v $
.//
.// (c) Copyright 1998-2013 Mentor Graphics Corporation  All rights reserved.
.//
.//====================================================================
.//
.// These functions set up the implementation of the values (V_VAL on
.// model of OAL).
.//
.//====================================================================
.//
.//
.function val_translate
  .// Translate "leaf" values first.
  .invoke val_literal_boolean_values()
  .invoke val_literal_integer_values()
  .invoke val_literal_real_values()
  .invoke val_literal_string_values()
  .invoke val_literal_enumerations()
  .invoke val_constant_values()
  .invoke val_transient_values()
  .invoke val_instance_reference_values()
  .invoke val_inst_ref_set_values()
  .invoke val_selection_test_values()
  .invoke val_event_values()
  .invoke val_parameter_values()
  .// The following may be recursed.
  .invoke val_attribute_values()
  .invoke val_member_values()
  .invoke val_array_element_references()
  .invoke val_array_length_values()
  .invoke val_unary_op_values()
  .invoke val_binary_op_values()
  .// V_PARs depend upon values being populated.
  .invoke val_actual_parameters()
  .// These use V_PARs.
  .invoke val_message_values()
  .invoke val_bridge_values()
  .invoke val_transform_values()
  .invoke val_synch_service_values()
.end function
.//
.//--------------------------------------------------------------------
.// Percolate the values from the "leaves" up into the combined
.// expressions by recursively drilling down.
.//--------------------------------------------------------------------
.function gen_value
  .param inst_ref v_val
  .select one v_mvl related by v_val->V_MVL[R801]
  .if ( not_empty v_mvl )
    .invoke val_member_value( v_mvl )
  .else
  .select one v_avl related by v_val->V_AVL[R801]
  .if ( not_empty v_avl )
    .invoke val_attribute_value( v_avl )
  .else
  .select one v_aer related by v_val->V_AER[R801]
  .if ( not_empty v_aer )
    .invoke val_array_element_reference( v_aer )
  .else
  .select one v_alv related by v_val->V_ALV[R801]
  .if ( not_empty v_alv )
    .invoke val_array_length_value( v_alv )
  .else
  .select one v_uny related by v_val->V_UNY[R801]
  .if ( not_empty v_uny )
    .invoke val_unary_op_value( v_uny )
  .else
  .select one v_bin related by v_val->V_BIN[R801]
  .if ( not_empty v_bin )
    .invoke val_binary_op_value( v_bin )
  .else
  .select one v_trv related by v_val->V_TRV[R801]
  .if ( not_empty v_trv )
    .invoke val_transform_value( v_trv )
  .else
  .select one v_msv related by v_val->V_MSV[R801]
  .if ( not_empty v_msv )
    .invoke val_message_value( v_msv )
  .else
  .select one v_brv related by v_val->V_BRV[R801]
  .if ( not_empty v_brv )
    .invoke val_bridge_value( v_brv )
  .else
  .select one v_fnv related by v_val->V_FNV[R801]
  .if ( not_empty v_fnv )
    .invoke val_synch_service_value( v_fnv )
  .else
    .print "ERROR:  Recursive V_VAL resolution issue."
  .end if
  .end if
  .end if
  .end if
  .end if
  .end if
  .end if
  .end if
  .end if
  .end if
.end function
.//
.function val_literal_boolean_values
  .select many v_lbos from instances of V_LBO
  .for each v_lbo in v_lbos
    .select one te_val related by v_lbo->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.OAL = v_lbo.Value
    .assign te_val.buffer = v_lbo.Value
  .end for
.end function
.//
.function val_literal_string_values
  .select any te_string from instances of TE_STRING
  .select many v_lsts from instances of V_LST
  .for each v_lst in v_lsts
    .select one te_val related by v_lst->V_VAL[R801]->TE_VAL[R2040]
    .// s = T::t( s:v_lst.Value );
    .assign s = v_lst.Value
    .// if ( strstr( s, "({" ) )
    .if ( "({" == s )
      .assign te_val.buffer = s
    .else
      .assign te_val.buffer = ( """" + v_lst.Value ) + """"
    .end if
    .assign te_val.OAL = ( "" + v_lst.Value ) + ""
    .assign te_val.dimensions = 1
    .assign te_val.array_spec = ( "[" + te_string.max_string_length ) + "]"
    .//TODO assign dimension
  .end for
.end function
.//
.function val_literal_integer_values
  .select many v_lins from instances of V_LIN
  .for each v_lin in v_lins
    .select one te_val related by v_lin->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.OAL = v_lin.Value
    .assign te_val.buffer = v_lin.Value
  .end for
.end function
.//
.function val_literal_real_values
  .select many v_lrls from instances of V_LRL
  .for each v_lrl in v_lrls
    .select one te_val related by v_lrl->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.OAL = v_lrl.Value
    .assign te_val.buffer = v_lrl.Value
  .end for
.end function
.//
.function val_literal_enumerations
  .select many v_lens from instances of V_LEN
  .for each v_len in v_lens
    .select one te_val related by v_len->V_VAL[R801]->TE_VAL[R2040]
    .select one te_enum related by v_len->S_ENUM[R824]->TE_ENUM[R2027]
    .assign te_val.OAL = te_enum.Name
    .assign te_val.buffer = te_enum.GeneratedName
  .end for
.end function
.//
.function val_constant_values
  .select many v_scvs from instances of V_SCV
  .for each v_scv in v_scvs
    .select one te_val related by v_scv->V_VAL[R801]->TE_VAL[R2040]
    .select one cnst_syc related by v_scv->CNST_SYC[R850]
    .select one cnst_lsc related by cnst_syc->CNST_LFSC[R1502]->CNST_LSC[R1503]
    .select one te_dt related by cnst_syc->S_DT[R1500]->TE_DT[R2021]
    .assign te_val.OAL = cnst_syc.Name
    .assign te_val.buffer = cnst_lsc.Value
    .if ( 4 == te_dt.Core_Typ )
      .select any te_string from instances of TE_STRING
      .assign te_val.buffer = ( """" + cnst_lsc.Value ) + """"
      .assign te_val.dimensions = 1
      .assign te_val.array_spec = ( "[" + te_string.max_string_length ) + "]"
      .//TODO assign dimension
    .end if
  .end for
.end function
.//
.function val_transient_values
  .select many v_tvls from instances of V_TVL
  .for each v_tvl in v_tvls
    .select one v_var related by v_tvl->V_VAR[R805]
    .select one te_var related by v_var->TE_VAR[R2039]
    .select one te_val related by v_tvl->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.OAL = te_var.OAL
    .assign te_val.buffer = te_var.buffer
    .assign te_val.dimensions = te_var.dimensions
    .assign te_val.array_spec = te_var.array_spec
    .select one te_dim related by te_var->TE_DIM[R2057]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end for
.end function
.//
.function val_actual_parameters
  .select many v_pars from instances of V_PAR
  .for each v_par in v_pars
    .select one te_par related by v_par->TE_PAR[R2063]
    .select one v_val related by v_par->V_VAL[R800]
    .select one te_val related by v_val->TE_VAL[R2040]
    .select one te_dt related by v_val->S_DT[R820]->TE_DT[R2021]
    .assign te_val.OAL = ( te_par.Name + ":" ) + te_val.OAL
    .if ( 10 == te_dt.Core_Typ )
      .// Cast event types to the base event type for passing (to timers).
      .assign te_val.buffer = ( "(" + te_dt.ExtName ) + ( ")" + te_val.buffer )
    .end if
  .end for
.end function
.//
.function val_attribute_values
  .select many v_avls from instances of V_AVL
  .for each v_avl in v_avls
    .invoke val_attribute_value( v_avl )
  .end for
.end function
.//
.function val_attribute_value
  .param inst_ref v_avl
  .select one v_val related by v_avl->V_VAL[R801]
  .select one te_val related by v_val->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one root_v_val related by v_avl->V_VAL[R807]
    .select one root_te_val related by root_v_val->TE_VAL[R2040]
    .if ( "" == root_te_val.buffer )
      .invoke gen_value( root_v_val )
    .end if
    .select one te_var related by v_avl->V_VAL[R807]->V_IRF[R801]->V_VAR[R808]->TE_VAR[R2039]
    .select one o_attr related by v_avl->O_ATTR[R806]
    .select one te_attr related by o_attr->TE_ATTR[R2033]
    .if ( not_empty te_attr )
    .assign root = ""
    .if ( empty te_var )
      .assign te_val.OAL = ( root_te_val.OAL + "." ) + te_attr.Name
      .assign te_val.buffer = ( root_te_val.buffer + "->" ) + te_attr.GeneratedName
      .assign root = root_te_val.buffer
    .else
      .assign te_val.OAL = ( te_var.OAL + "." ) + te_attr.Name
      .assign te_val.buffer = ( te_var.buffer + "->" ) + te_attr.GeneratedName
      .assign root = te_var.buffer
    .end if
    .assign te_val.dimensions = te_attr.dimensions
    .assign te_val.array_spec = te_attr.array_spec
    .select one te_dim related by te_attr->TE_DIM[R2055]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
    .// Maybe attribute value is actually derived.
    .select one o_dbattr related by o_attr->O_BATTR[R106]->O_DBATTR[R107]
    .if ( not_empty o_dbattr )
      .select one act_ai related by v_val->ACT_AI[R689]
      .if ( empty act_ai )
        .// Only do this if we are not assigning inside the DAB OAL body.
        .select one te_aba related by o_dbattr->TE_DBATTR[R2026]->TE_ABA[R2010]
        .assign te_val.buffer = ( te_aba.GeneratedName + "( " ) + ( root + " )" )
        .assign te_val.dimensions = te_aba.dimensions
        .assign te_val.array_spec = te_aba.array_spec
        .select one te_dim related by te_aba->TE_DIM[R2058]
        .if ( not_empty te_dim )
          .// relate te_val to te_dim across R2079;
          .assign te_val.te_dimID = te_dim.te_dimID
          .// end relate
        .else
          .assign te_val.te_dimID = 00
        .end if
      .end if
    .end if
    .end if
  .end if
.end function
.//
.function val_member_values
  .select many v_mvls from instances of V_MVL
  .for each v_mvl in v_mvls
    .invoke val_member_value( v_mvl )
  .end for
.end function
.//
.function val_member_value
  .param inst_ref v_mvl
  .select one te_val related by v_mvl->V_VAL[R801]->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one root_v_val related by v_mvl->V_VAL[R837]
    .select one root_te_val related by root_v_val->TE_VAL[R2040]
    .if ( "" == root_te_val.buffer )
      .invoke gen_value( root_v_val )
    .end if
    .select one te_mbr related by v_mvl->S_MBR[R836]->TE_MBR[R2047]
    .assign te_val.dimensions = te_mbr.dimensions
    .assign te_val.array_spec = te_mbr.array_spec
    .select one te_dim related by te_mbr->TE_DIM[R2059]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
    .assign te_val.OAL = ( root_te_val.OAL + "." ) + te_mbr.Name
    .assign te_val.buffer = ( root_te_val.buffer + "." ) + te_mbr.GeneratedName
  .end if
.end function
.//
.function val_instance_reference_values
  .assign unique_num = 0
  .select many v_irfs from instances of V_IRF
  .for each v_irf in v_irfs
    .select one te_val related by v_irf->V_VAL[R801]->TE_VAL[R2040]
    .select one te_var related by v_irf->V_VAR[R808]->TE_VAR[R2039]
    .if ( not_empty te_var )
      .assign te_val.OAL = te_var.OAL
      .assign te_val.buffer = te_var.buffer
    .else
      .print "CDS:  Understand why we do not have V_VAR here."
      .assign te_val.buffer = "v_irf_" + "$t{unique_num}"
      .assign unique_num = unique_num + 1
    .end if
  .end for
.end function
.//
.function val_selection_test_values
  .select many v_slrs from instances of V_SLR
  .for each v_slr in v_slrs
    .select one te_val related by v_slr->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.buffer = "selected"
    .assign te_val.OAL = "SELECTED"
  .end for
.end function
.//
.function val_inst_ref_set_values
  .select many v_isrs from instances of V_ISR
  .for each v_isr in v_isrs
    .select one te_var related by v_isr->V_VAR[R809]->TE_VAR[R2039]
    .select one te_val related by v_isr->V_VAL[R801]->TE_VAL[R2040]
    .assign te_val.OAL = te_var.OAL
    .assign te_val.buffer = te_var.buffer
  .end for
.end function
.//
.function val_event_values
  .select many v_edvs from instances of V_EDV
  .for each v_edv in v_edvs
    .select one te_val related by v_edv->V_VAL[R801]->TE_VAL[R2040]
    .// If there are more than one transition into the state, there
    .// may be more than one event parameter reference.  Select
    .// any of them; they have the same names.
    .select any te_parm related by v_edv->V_EPR[R834]->SM_EVTDI[R846]->TE_PARM[R2031]
    .if ( empty te_parm )
      .select any te_parm related by v_edv->V_EPR[R834]->C_PP[R847]->TE_PARM[R2048]
    .else
      .// Mark the event as used.
      .select one te_evt related by te_parm->SM_EVTDI[R2031]->SM_EVT[R532]->TE_EVT[R2036]
      .if ( not_empty te_evt )
        .assign te_evt.UsedCount = te_evt.UsedCount + 1
        .assign te_evt.Used = true
      .end if
    .end if
    .assign te_val.OAL = "PARAM." + te_parm.Name
    .assign te_val.buffer = "rcvd_evt->" + te_parm.GeneratedName
    .assign te_val.dimensions = te_parm.dimensions
    .assign te_val.array_spec = te_parm.array_spec
    .select one te_dim related by te_parm->TE_DIM[R2056]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end for
.end function
.//
.function val_parameter_values
  .select many v_pvls from instances of V_PVL
  .for each v_pvl in v_pvls
    .select one te_val related by v_pvl->V_VAL[R801]->TE_VAL[R2040]
    .select one te_parm related by v_pvl->O_TPARM[R833]->TE_PARM[R2029]
    .if ( empty te_parm )
    .select one te_parm related by v_pvl->C_PP[R843]->TE_PARM[R2048]
    .if ( empty te_parm )
    .select one te_parm related by v_pvl->S_SPARM[R832]->TE_PARM[R2030]
    .if ( empty te_parm )
    .select one te_parm related by v_pvl->S_BPARM[R831]->TE_PARM[R2028]
    .if ( empty te_parm )
      .print "CDS:  Understand why we do not have V_PVL related parameter here."
    .end if
    .end if
    .end if
    .end if
    .assign te_val.OAL = "PARAM." + te_parm.Name
    .assign te_val.buffer = te_parm.GeneratedName
    .assign te_val.dimensions = te_parm.dimensions
    .assign te_val.array_spec = te_parm.array_spec
    .select one te_dim related by te_parm->TE_DIM[R2056]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
    .if ( 1 == te_parm.By_Ref )
      .assign te_val.buffer = ( "(*" + te_parm.GeneratedName ) + ")"
    .end if
  .end for
.end function
.//
.function val_unary_op_values
  .select many v_unys from instances of V_UNY
  .for each v_uny in v_unys
    .invoke val_unary_op_value( v_uny )
  .end for
.end function
.//
.function val_unary_op_value
  .param inst_ref v_uny
  .select one te_val related by v_uny->V_VAL[R801]->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one root_v_val related by v_uny->V_VAL[R804]
    .select one root_te_val related by root_v_val->TE_VAL[R2040]
    .if ( "" == root_te_val.buffer )
      .invoke gen_value( root_v_val )
    .end if
    .// Remove blanks and make lower case.
    .assign op = "$r{v_uny.Operator}"
    .assign op = "$l{op}"
    .select any te_set from instances of TE_SET
    .select one v_irf related by root_v_val->V_IRF[R801]
    .select one v_isr related by root_v_val->V_ISR[R801]
    .if ( not_empty v_irf )
      .if ( op == "not_empty" )
        .assign te_val.buffer = ( "( 0 != " + root_te_val.buffer ) + " )"
      .elif ( op == "empty" )
        .assign te_val.buffer = ( "( 0 == " + root_te_val.buffer ) + " )"
      .elif ( op == "cardinality" )
        .assign te_val.buffer = ( "( 0 != " + root_te_val.buffer ) + " )"
      .else
        .print "ERROR:  Unary set operator ${v_uny.Operator} is not supported."
      .end if
    .elif ( not_empty v_isr )
      .if ( op == "not_empty" )
        .assign te_val.buffer = ( ( "( ! " + te_set.emptiness ) + ( "( " + root_te_val.buffer ) ) + " ) )"
      .elif ( op == "empty" )
        .assign te_val.buffer = ( ( te_set.emptiness + "( " ) + ( root_te_val.buffer + " )" ) )
      .elif ( op == "cardinality" )
        .assign te_val.buffer = ( ( te_set.module + te_set.element_count ) + ( "( " + root_te_val.buffer ) ) + " )"
      .else
        .print "ERROR:  Unary set operator ${v_uny.Operator} is not supported."
      .end if
    .else
      .if ( op == "not" )
        .assign te_val.buffer = "!" + root_te_val.buffer
      .else
        .assign te_val.buffer = op + root_te_val.buffer
      .end if
    .end if
    .assign te_val.OAL = ( op + " " ) + root_te_val.OAL
    .// future support for vector arithmetic goes here
    .assign te_val.dimensions = root_te_val.dimensions
    .assign te_val.array_spec = root_te_val.array_spec
    .select one te_dim related by root_te_val->TE_DIM[R2079]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end if
.end function
.//
.function val_binary_op_values
  .select many v_bins from instances of V_BIN
  .for each v_bin in v_bins
    .invoke val_binary_op_value( v_bin )
  .end for
.end function
.//
.function val_binary_op_value
  .param inst_ref v_bin
  .select one te_val related by v_bin->V_VAL[R801]->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one l_v_val related by v_bin->V_VAL[R802]
    .select one l_te_val related by l_v_val->TE_VAL[R2040]
    .if ( "" == l_te_val.buffer )
      .invoke gen_value( l_v_val )
    .end if
    .select one r_v_val related by v_bin->V_VAL[R803]
    .select one r_te_val related by r_v_val->TE_VAL[R2040]
    .if ( "" == r_te_val.buffer )
      .invoke gen_value( r_v_val )
    .end if
    .select one l_te_dt related by l_v_val->S_DT[R820]->TE_DT[R2021]
    .select one r_te_dt related by r_v_val->S_DT[R820]->TE_DT[R2021]
    .if ( ( 4 == l_te_dt.Core_Typ ) or ( 4 == r_te_dt.Core_Typ ) )
      .// string
      .select any te_string from instances of TE_STRING
      .select any te_instance from instances of TE_INSTANCE
      .if ( "+" == "$r{v_bin.Operator}" )
        .assign te_val.buffer = ( ( ( te_instance.module + te_string.stradd ) + ( "( " + l_te_val.buffer ) ) + ( ", " + r_te_val.buffer ) ) + " )"
      .else
        .assign te_val.buffer = ( ( ( "( " + te_instance.module ) + ( te_string.strcmp + "( " ) ) + ( ( l_te_val.buffer + ", " ) + ( r_te_val.buffer + " ) " ) ) ) + ( v_bin.Operator + " 0 )" )
      .end if
    .else
      .select any te_target from instances of TE_TARGET
      .if ( "and" == "$r{v_bin.Operator}" )
        .assign te_val.buffer = ( ( "( " + l_te_val.buffer ) + ( " && " + r_te_val.buffer ) ) + " )"
      .elif ( "or" == "$r{v_bin.Operator}" )
        .assign te_val.buffer = ( ( "( " + l_te_val.buffer ) + ( " || " + r_te_val.buffer ) ) + " )"
      .elif ( ( ( ( "==" == "$r{v_bin.Operator}" ) or ( "!=" == "$r{v_bin.Operator}" ) ) and ( "C" == te_target.language ) ) and ( l_te_val.dimensions != 0 ) )
        .assign element_count = 0
        .select one r_te_dim related by r_te_val->TE_DIM[R2079]
        .if ( not_empty r_te_dim )
          .assign element_count = r_te_dim.elementCount
        .end if
        .assign te_val.buffer = ( ( ( "( memcmp( " + l_te_val.buffer ) + ( ", " + r_te_val.buffer ) ) + ( ( ", sizeof(" + l_te_val.buffer ) + ( "[0]) * " + "$t{element_count}" ) ) ) + ( ( ") " + v_bin.Operator ) + " 0 )" )
      .else
        .assign te_val.buffer = ( ( "( " + l_te_val.buffer ) + ( " " + v_bin.Operator ) ) + ( ( " " + r_te_val.buffer ) + " )" )
      .end if
    .end if
    .// future support for vector arithmetic goes here
    .assign te_val.dimensions = r_te_val.dimensions
    .assign te_val.array_spec = r_te_val.array_spec
    .select one te_dim related by r_te_val->TE_DIM[R2079]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
    .assign te_val.OAL = ( ( "( " + l_te_val.OAL ) + ( " " + v_bin.Operator ) ) + ( ( " " + r_te_val.OAL ) + " )" )
  .end if
.end function
.//
.function val_message_values
  .assign n = 0
  .select many v_msvs from instances of V_MSV
  .for each v_msv in v_msvs
    .assign salt = "$t{n}" + "msv"
    .assign n = n + 1
    .invoke val_message_value( v_msv, salt )
  .end for
.end function
.//
.function val_message_value
  .param inst_ref v_msv
  .param string salt
  .select one v_val related by v_msv->V_VAL[R801]
  .select one te_val related by v_val->TE_VAL[R2040]
  .select one te_mact related by v_msv->SPR_PEP[R841]->SPR_PO[R4503]->TE_MACT[R2050]
  .if ( empty te_mact )
    .select one te_mact related by v_msv->SPR_REP[R845]->SPR_RO[R4502]->TE_MACT[R2052]
  .end if
  .select many v_pars related by v_msv->V_PAR[R842]
  .select one te_aba related by te_mact->TE_ABA[R2010]
  .invoke r = q_render_msg( te_mact, v_pars, "", false, salt )
  .assign te_val.buffer = r.body
  .assign te_val.OAL = ( ( te_mact.PortName + "::" ) + ( te_mact.MessageName + "(" ) ) + ( te_mact.OALParamBuffer + ")" )
  .assign te_val.dimensions = te_aba.dimensions
  .assign te_val.array_spec = te_aba.array_spec
  .select one te_dim related by te_aba->TE_DIM[R2058]
  .if ( not_empty te_dim )
    .// relate te_val to te_dim across R2079;
    .assign te_val.te_dimID = te_dim.te_dimID
    .// end relate
  .else
    .assign te_val.te_dimID = 00
  .end if
.end function
.//
.function val_bridge_values
  .assign n = 0
  .select many v_brvs from instances of V_BRV
  .for each v_brv in v_brvs
    .assign salt = "$t{n}" + "brv"
    .assign n = n + 1
    .invoke val_bridge_value( v_brv, salt )
  .end for
.end function
.//
.function val_bridge_value
  .param inst_ref v_brv
  .param string salt
  .select one te_brg related by v_brv->S_BRG[R828]->TE_BRG[R2025]
  .if ( not_empty te_brg )
    .select any te_target from instances of TE_TARGET
    .select one v_val related by v_brv->V_VAL[R801]
    .select one te_val related by v_val->TE_VAL[R2040]
    .select many v_pars related by v_brv->V_PAR[R810]
    .select one te_aba related by te_brg->TE_ABA[R2010]
    .select one te_ee related by v_brv->S_BRG[R828]->S_EE[R19]->TE_EE[R2020]
    .assign te_ee.Included = true
    .invoke r = gen_parameter_list( v_pars, false, salt )
    .assign te_parm = r.result
    .assign parameters = te_parm.ParamBuffer
    .assign params_OAL = te_parm.OALParamBuffer
    .assign te_val.OAL = ( ( te_brg.EEkeyletters + "::" ) + ( te_brg.Name + "(" ) ) + ( params_OAL + ")" )
    .if ( "C++" == te_target.language )
      .if ( "TIM" == te_brg.EEkeyletters )
        .assign te_val.buffer = ( "thismodule->tim->" + te_brg.GeneratedName ) + "("
      .else
        .select one te_c related by te_ee->TE_C[R2085]
        .if ( not_empty te_c )
          .if ( "" == parameters )
            .assign parameters = "thismodule"
          .else
            .assign parameters = "thismodule, " + parameters
          .end if
        .end if
      .end if
    .else
      .assign te_val.buffer = ( te_aba.scope + te_brg.GeneratedName ) + "("
    .end if
    .if ( "" != parameters )
      .assign te_val.buffer = ( te_val.buffer + " " ) + ( parameters + " " )
    .end if
    .assign te_val.buffer = te_val.buffer + ")"
    .assign te_val.dimensions = te_aba.dimensions
    .assign te_val.array_spec = te_aba.array_spec
    .select one te_dim related by te_aba->TE_DIM[R2058]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end if
.end function
.//
.function val_transform_values
  .assign n = 0
  .select many v_trvs from instances of V_TRV
  .for each v_trv in v_trvs
    .assign salt = "$t{n}" + "trv"
    .assign n = n + 1
    .invoke val_transform_value( v_trv )
  .end for
.end function
.//
.function val_transform_value
  .param inst_ref v_trv
  .param string salt
  .select one te_tfr related by v_trv->O_TFR[R829]->TE_TFR[R2024]
  .if ( not_empty te_tfr )
  .select any te_target from instances of TE_TARGET
  .select one v_val related by v_trv->V_VAL[R801]
  .select one te_val related by v_val->TE_VAL[R2040]
  .select many v_pars related by v_trv->V_PAR[R811]
  .select one te_aba related by te_tfr->TE_ABA[R2010]
  .assign te_val.buffer = te_tfr.GeneratedName + "("
  .if ( te_tfr.Instance_Based == 1 )
    .select one te_var related by v_trv->V_VAR[R830]->TE_VAR[R2039]
    .if ( not_empty te_var )
      .if ( "C++" == te_target.language )
        .assign te_val.buffer = ( te_var.buffer + "->" ) + te_val.buffer
      .end if
      .assign te_val.buffer = te_val.buffer + te_var.buffer
      .assign te_val.OAL = te_var.OAL + "."
    .else
      .// no variable, must be selection (selected reference)
      .if ( "C++" == te_target.language )
        .assign te_val.buffer = "selected->" + te_val.buffer
      .end if
      .assign te_val.buffer = te_val.buffer + "selected"
      .assign te_val.OAL = "SELECTED."
    .end if
  .else
    .if ( "C++" == te_target.language )
      .select one te_class related by v_trv->O_TFR[R829]->O_OBJ[R115]->TE_CLASS[R2019]
      .assign te_val.buffer = ( te_class.GeneratedName + "::" ) + te_val.buffer
    .end if
    .assign te_val.OAL = te_tfr.Key_Lett + "::"
  .end if
  .invoke r = gen_parameter_list( v_pars, false, salt )
  .assign te_parm = r.result
  .assign parameters = te_parm.ParamBuffer
  .assign params_OAL = te_parm.OALParamBuffer
  .assign te_val.OAL = ( ( te_val.OAL + te_tfr.Name ) + ( "(" + params_OAL ) ) + ")"
  .if ( te_tfr.Instance_Based == 1 )
    .if ( ( "C++" == te_target.language ) or ( "" != parameters ) )
      .assign te_val.buffer = te_val.buffer + ", "
    .end if
  .end if
  .if ( "C++" == te_target.language )
    .assign te_val.buffer = te_val.buffer + "thismodule"
    .if ( "" != parameters )
      .assign te_val.buffer = te_val.buffer + ", "
    .end if
  .end if
  .assign te_val.buffer = ( te_val.buffer + parameters ) + ")"
  .assign te_val.dimensions = te_aba.dimensions
  .assign te_val.array_spec = te_aba.array_spec
  .select one te_dim related by te_aba->TE_DIM[R2058]
  .if ( not_empty te_dim )
    .// relate te_val to te_dim across R2079;
    .assign te_val.te_dimID = te_dim.te_dimID
    .// end relate
  .else
    .assign te_val.te_dimID = 00
  .end if
  .end if
.end function
.//
.function val_synch_service_values
  .assign n = 0
  .select many v_fnvs from instances of V_FNV
  .for each v_fnv in v_fnvs
    .assign salt = "$t{n}" + "fnv"
    .assign n = n + 1
    .invoke val_synch_service_value( v_fnv, salt )
  .end for
.end function
.//
.function val_synch_service_value
  .param inst_ref v_fnv
  .param string salt
  .select one te_sync related by v_fnv->S_SYNC[R827]->TE_SYNC[R2023]
  .if ( not_empty te_sync )
    .select any te_target from instances of TE_TARGET
    .select one v_val related by v_fnv->V_VAL[R801]
    .select one te_val related by v_val->TE_VAL[R2040]
    .select many v_pars related by v_fnv->V_PAR[R817]
    .select one te_aba related by te_sync->TE_ABA[R2010]
    .invoke r = gen_parameter_list( v_pars, false, salt )
    .assign te_parm = r.result
    .assign parameters = te_parm.ParamBuffer
    .assign params_OAL = te_parm.OALParamBuffer
    .assign te_val.OAL = ( ( "::" + te_sync.Name ) + ( "(" + params_OAL ) ) + ")"
    .assign name = te_sync.intraface_method
    .if ( "C++" == te_target.language )
      .assign name = "thismodule->" + name
    .end if
    .assign te_val.buffer = name + "("
    .if ( "" != parameters )
      .assign te_val.buffer = ( te_val.buffer + " " ) + ( parameters + " " )
    .end if
    .assign te_val.buffer = te_val.buffer + ")"
    .assign te_val.dimensions = te_aba.dimensions
    .assign te_val.array_spec = te_aba.array_spec
    .select one te_dim related by te_aba->TE_DIM[R2058]
    .if ( not_empty te_dim )
      .// relate te_val to te_dim across R2079;
      .assign te_val.te_dimID = te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end if
.end function
.//
.function val_array_element_references
  .select many v_aers from instances of V_AER
  .for each v_aer in v_aers
    .invoke val_array_element_reference( v_aer )
  .end for
.end function
.//
.function val_array_element_reference
  .param inst_ref v_aer
  .select one te_val related by v_aer->V_VAL[R801]->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one root_v_val related by v_aer->V_VAL[R838]
    .select one root_te_val related by root_v_val->TE_VAL[R2040]
    .if ( "" == root_te_val.buffer )
      .invoke gen_value( root_v_val )
    .end if
    .select one index_v_val related by v_aer->V_VAL[R839]
    .select one index_te_val related by index_v_val->TE_VAL[R2040]
    .if ( "" == index_te_val.buffer )
      .invoke gen_value( index_v_val )
    .end if
    .assign te_val.OAL = ( root_te_val.OAL + "[" ) + ( index_te_val.buffer + "]" )
    .assign te_val.buffer = ( root_te_val.buffer + "[" ) + ( index_te_val.buffer + "]" )
    .// Peel off outer layer of dimensions.
    .// CDS:  do not know how to do this with array_spec
    .assign te_val.array_spec = root_te_val.array_spec
    .assign te_val.dimensions = root_te_val.dimensions - 1
    .select one next_te_dim related by root_te_val->TE_DIM[R2079]->TE_DIM[R2060.'succeeds']
    .if ( not_empty next_te_dim )
      .// relate te_val to next_te_dim across R2079;
      .assign te_val.te_dimID = next_te_dim.te_dimID
      .// end relate
    .else
      .assign te_val.te_dimID = 00
    .end if
  .end if
.end function
.//
.function val_array_length_values
  .select many v_alvs from instances of V_ALV
  .for each v_alv in v_alvs
    .invoke val_array_length_value( v_alv )
  .end for
.end function
.//
.function val_array_length_value
  .param inst_ref v_alv
  .select one te_val related by v_alv->V_VAL[R801]->TE_VAL[R2040]
  .if ( "" == te_val.buffer )
    .select one root_v_val related by v_alv->V_VAL[R840]
    .select one root_te_val related by root_v_val->TE_VAL[R2040]
    .if ( "" == root_te_val.buffer )
      .invoke gen_value( root_v_val )
    .end if
    .assign te_val.OAL = root_te_val.OAL + ".length"
    .select any te_target from instances of TE_TARGET
    .if ( "C" == te_target.language )
      .select one te_dim related by root_te_val->TE_DIM[R2079]
      .if ( not_empty te_dim )
        .assign te_val.buffer = ( ( ( "$t{te_dim.elementCount}" + " /" ) + ( "* " + te_val.OAL ) ) + ( " *" + "/" ) )
      .else
        .assign te_val.buffer = root_te_val.buffer + ".ARRAY_LENGTH_NOT_FOUND()"
        .print "ERROR:  C model compiler does not support length operator for OAL value:  ${te_val.OAL}"
        .exit 101
      .end if
    .else
      .assign te_val.buffer = root_te_val.buffer + ".length"
    .end if
  .end if
.end function
.//