[<<][meta][>>][..]
Mon Nov 7 14:44:43 EST 2011

Language.C Functor

The light went on..

Each node in the AST has a hole in it.  For parsing/printing this
seems to be filled with a NodeInfo type.  However, there is a Functor
instance for each type in the tree, which is for mapping over an
entire tree, changing those holes.

So to remove all the NodeInfo nodes for the purpose of prettyprinting
the syntax tree only, use this:

  pc = Prelude.putStrLn . Pretty.ppShow . (fmap $ \_ -> ())
     
This then doesn't need any code patching as described in a previous
post.  Starting from 

  int fun(void *state, void **ins, void **outs, int n) { }

We get the following tree which is a lot easier to dissect:

CTranslUnit
  [ CFDefExt (
      CFunDef
        [ CTypeSpec ( CIntType () )
        ] (
        CDeclr (
          Just "fun" )
          [ CFunDeclr (
              Right
                ( [ CDecl
                      [ CTypeSpec ( CVoidType () )
                      ]
                      [ ( Just (
                            CDeclr (
                              Just "state" )
                              [ CPtrDeclr
                                  []
                                  ()
                              ]
                              Nothing
                              []
                              () )
                        , Nothing
                        , Nothing
                        )
                      ]
                      ()
                  , CDecl
                      [ CTypeSpec ( CVoidType () )
                      ]
                      [ ( Just (
                            CDeclr (
                              Just "ins" )
                              [ CPtrDeclr
                                  []
                                  ()
                              , CPtrDeclr
                                  []
                                  ()
                              ]
                              Nothing
                              []
                              () )
                        , Nothing
                        , Nothing
                        )
                      ]
                      ()
                  , CDecl
                      [ CTypeSpec ( CVoidType () )
                      ]
                      [ ( Just (
                            CDeclr (
                              Just "outs" )
                              [ CPtrDeclr
                                  []
                                  ()
                              , CPtrDeclr
                                  []
                                  ()
                              ]
                              Nothing
                              []
                              () )
                        , Nothing
                        , Nothing
                        )
                      ]
                      ()
                  , CDecl
                      [ CTypeSpec ( CIntType () )
                      ]
                      [ ( Just (
                            CDeclr (
                              Just "n" )
                              []
                              Nothing
                              []
                              () )
                        , Nothing
                        , Nothing
                        )
                      ]
                      ()
                  ]
                , False
                ) )
              []
              ()
          ]
          Nothing
          []
          () )
        [] (
        CCompound
          []
          []
          () )
        () )
  ]
  ()



[Reply][About]
[<<][meta][>>][..]