Re: Re: The Array type

Luke Petre <[email protected]>
Newsgroups gmane.comp.documentation.synopsis
Message-ID <[email protected]>
>Date: Mon, 02 Aug 2004 20:44:10 -0400
>From: Stefan Seefeld <[email protected]>
>To:  [email protected]
>Subject: Re: [Synopsis-devel] Re: The Array type
>Reply-To: [email protected]
>
>Luke Petre wrote:
>  
>
>>It seems like it would be best to do in the Decoder, but I don't think 
>>you have enough information at that point.  Thoughts?
>>    
>>
>
>you are right, the Decoder is a good place to look into. And you are right
>that the other half of the information, i.e. the actual sizes, isn't
>available there :-) The real problem is that the AST as generated by occ
>is much more expressive than the one maintained by synopsis.
>That's one aspect of the work I'm trying to do now on the C++ backend:
>making that rich AST accessible to synopsis, and provide a 'more correct'
>translation into what is currently called 'AST' (but what's really just
>a tree of declarations).
>
>Have a look into Synopsis/Parsers/Cxx/occ/Parser.cc:1790
>
>There a 'PtreeDeclarator' is instantiated with all the information
>about the array sizes (i.e. the sizes are real expressions !).
>A quick fix would be to see in swalker.cc whether you can get back
>that information (via a downcast) and at least extract these expressions
>as strings, so the documentation synopsis generates will at least be
>a bit more useful.
>
>A real fix is obviously quite a bit more involved. (You are more than
>welcome to contribute !)
>
>Regards,
>		Stefan
>
>  
>

I was able to implement a fix without getting into the decoder, although 
I'm still a bit unsure if this is the correct approach.  Basically I 
started by finding all the places in the code where we could encode type 
Array.  I found two places, both in Parser.cc, lines 1784 and 3648.  
Directly below the calls to encode the array type the parser makes new 
Ptree nodes, inserting them into the current parse tree.  What I did was 
to change the types of nodes it was creating so that it would create 
PtreeArrayExpr nodes instead.  changing lines like this:

  decl = Ptree::Nconc(decl, Ptree::List(new Leaf(ob), exp, new Leaf(cb)));

to this:

  decl = Ptree::Nconc(decl, new PtreeArrayExpr(Ptree::List(new Leaf(ob), 
exp, new Leaf(cb)), 0));


and then in swalker.cc, around line 1135 I was able to search for the 
PtreeArrayExpr types in the parse tree.

  // sizes support
  Types::Array::Mods sizes;
  std::deque<Ptree*> aStack;
  aStack.push_back( decl );
  while ( !aStack.empty() )
  {
    Ptree* pHead = aStack.front();
    aStack.pop_front();
    if ( !pHead->IsLeaf() )
    {
      if ( pHead->Car() )
      {
        aStack.push_back( pHead->Car() );
      }

      if ( pHead->Cdr() )
      {
        aStack.push_back( pHead->Cdr() );
      }
    }

    if ( PtreeArrayExpr* pArray = dynamic_cast<PtreeArrayExpr*>(pHead) )
    {
      Ptree* pSize = pArray->First()->Second();
      sizes.push_back( pSize->string() );
    }
  }

  if ( !sizes.empty() )
  {
    type = new Types::Array( type, sizes );
  }



That would have been easier to do with recursive function calls, but 
this seemed less intrusive.

Anyways, it seems to work for all the cases I've been writing.  let me 
know what you think.

Luke
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.