• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. printself and indention

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 143
  • Views 13984
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

printself and indention

theopaone
theopaone over 10 years ago

I am using printself to pretty print an object with a slot that is a list of other objects with their own printself method. When these print out, all the data starts from the left margin, the nested object descriptions are not indented like pretty printing. I am looking for a way to print the nested sub elements indented (and their nested elements indented from them, etc.)

Thanks

Ted

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 10 years ago

    Hi Ted,

    I had a bit of a play with this and it can be done without using the dreaded global variables by using lexical scoping instead. The example below is not perfect (not 100% happy about how I handle carriage returns to make it prettier), but the idea is OK, I think:

    /* hierObj.ils
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Jan 02, 2015 
    Modified   
    By         
    
    Example of printself methods on a hierarchical object
    which use a lexically scoped variable to keep track
    of the indent level
    
    ***************************************************
    
    */
    
    (defclass topThing ()
      (
       (subThings @reader CCFgetThings @writer CCFsetThings @initarg subThings @initform nil)
       )
    )
    
    (defclass subThing ()
      (
       (color @reader CCFgetColor @writer CCFsetColor @initarg color)
       (subThings @reader CCFgetThings @writer CCFsetThings @initarg subThings @initform nil)
       )
    )
    
    (setq top 
          (makeInstance 'topThing 
                        ?subThings (list
                                     (makeInstance 'subThing
                                                   ?color "red"
                                                   ?subThings
                                                   (list
                                                     (makeInstance 'subThing
                                                                   ?color "green")
                                                     (makeInstance 'subThing
                                                                   ?color "blue")
                                                     ))
                                     (makeInstance 'subThing
                                                   ?color "yellow"
                                                   ?subThings
                                                   (list
                                                     (makeInstance 'subThing
                                                                   ?color "cyan")
                                                     (makeInstance 'subThing
                                                                   ?color "magenta")
                                                     ))
                                     )
                        )
          )
    
    (let ((indent 0))
      (defmethod printself ((obj topThing))
        (letseq ((subThings (CCFgetThings obj)))
                (prog2
                  (setq indent (plus indent 2))
                  (if subThings
                    ; then
                    (sprintf nil "#{instance of topThing:%L}:\n%s" 
                             (callNextMethod obj)
                             (buildString (mapcar 'printself subThings) "\n")
                             )
                    ; else
                    (sprintf nil "#{instance of topThing:%L}" 
                             (callNextMethod obj)
                             )
                    )
                  (setq indent (difference indent 2))
                  )
                )
        )
      (defmethod printself ((obj subThing))
        (letseq ((format (sprintf nil "%%%ds" indent))
                 (indentStr (sprintf nil format ""))
                 (subThings (CCFgetThings obj)))
                (prog2
                  (setq indent (plus indent 2))
                  (if subThings
                    ; then
                    (sprintf nil "%s#{instance of subThing:%L (%Y)}:\n%s" 
                             indentStr 
                             (callNextMethod obj) 
                             (CCFgetColor obj)
                             (buildString (mapcar 'printself subThings) "\n")
                           )
                    ; else
                    (sprintf nil "%s#{instance of subThing:%L (%Y)}" 
                             indentStr 
                             (callNextMethod obj) 
                             (CCFgetColor obj)
                             )
                    )
                  (setq indent (difference indent 2))
                  )
                )
        )
      )

    If you load this file and then look at the variable top you get:

    ILS-<2> top
    #{instance of topThing:"stdobj@0x8942060"}:
      #{instance of subThing:"stdobj@0x8942030" (red)}:
        #{instance of subThing:"stdobj@0x8942018" (green)}
        #{instance of subThing:"stdobj@0x8942024" (blue)}
      #{instance of subThing:"stdobj@0x8942054" (yellow)}:
        #{instance of subThing:"stdobj@0x894203c" (cyan)}
        #{instance of subThing:"stdobj@0x8942048" (magenta)}

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 10 years ago

    Hi Ted,

    I had a bit of a play with this and it can be done without using the dreaded global variables by using lexical scoping instead. The example below is not perfect (not 100% happy about how I handle carriage returns to make it prettier), but the idea is OK, I think:

    /* hierObj.ils
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Jan 02, 2015 
    Modified   
    By         
    
    Example of printself methods on a hierarchical object
    which use a lexically scoped variable to keep track
    of the indent level
    
    ***************************************************
    
    */
    
    (defclass topThing ()
      (
       (subThings @reader CCFgetThings @writer CCFsetThings @initarg subThings @initform nil)
       )
    )
    
    (defclass subThing ()
      (
       (color @reader CCFgetColor @writer CCFsetColor @initarg color)
       (subThings @reader CCFgetThings @writer CCFsetThings @initarg subThings @initform nil)
       )
    )
    
    (setq top 
          (makeInstance 'topThing 
                        ?subThings (list
                                     (makeInstance 'subThing
                                                   ?color "red"
                                                   ?subThings
                                                   (list
                                                     (makeInstance 'subThing
                                                                   ?color "green")
                                                     (makeInstance 'subThing
                                                                   ?color "blue")
                                                     ))
                                     (makeInstance 'subThing
                                                   ?color "yellow"
                                                   ?subThings
                                                   (list
                                                     (makeInstance 'subThing
                                                                   ?color "cyan")
                                                     (makeInstance 'subThing
                                                                   ?color "magenta")
                                                     ))
                                     )
                        )
          )
    
    (let ((indent 0))
      (defmethod printself ((obj topThing))
        (letseq ((subThings (CCFgetThings obj)))
                (prog2
                  (setq indent (plus indent 2))
                  (if subThings
                    ; then
                    (sprintf nil "#{instance of topThing:%L}:\n%s" 
                             (callNextMethod obj)
                             (buildString (mapcar 'printself subThings) "\n")
                             )
                    ; else
                    (sprintf nil "#{instance of topThing:%L}" 
                             (callNextMethod obj)
                             )
                    )
                  (setq indent (difference indent 2))
                  )
                )
        )
      (defmethod printself ((obj subThing))
        (letseq ((format (sprintf nil "%%%ds" indent))
                 (indentStr (sprintf nil format ""))
                 (subThings (CCFgetThings obj)))
                (prog2
                  (setq indent (plus indent 2))
                  (if subThings
                    ; then
                    (sprintf nil "%s#{instance of subThing:%L (%Y)}:\n%s" 
                             indentStr 
                             (callNextMethod obj) 
                             (CCFgetColor obj)
                             (buildString (mapcar 'printself subThings) "\n")
                           )
                    ; else
                    (sprintf nil "%s#{instance of subThing:%L (%Y)}" 
                             indentStr 
                             (callNextMethod obj) 
                             (CCFgetColor obj)
                             )
                    )
                  (setq indent (difference indent 2))
                  )
                )
        )
      )

    If you load this file and then look at the variable top you get:

    ILS-<2> top
    #{instance of topThing:"stdobj@0x8942060"}:
      #{instance of subThing:"stdobj@0x8942030" (red)}:
        #{instance of subThing:"stdobj@0x8942018" (green)}
        #{instance of subThing:"stdobj@0x8942024" (blue)}
      #{instance of subThing:"stdobj@0x8942054" (yellow)}:
        #{instance of subThing:"stdobj@0x894203c" (cyan)}
        #{instance of subThing:"stdobj@0x8942048" (magenta)}

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information