From: Baptiste L. <gai...@fr...> - 2002-12-23 20:21:55
|
----- Original Message ----- From: "Andre Baresel" <and...@gm...> To: "Baptiste Lepilleur" <gai...@fr...> Sent: Sunday, December 22, 2002 3:35 PM Subject: Re: [Cpptool-develop] Next things .. > Baptiste Lepilleur wrote: > [...] > >I was blocked on this topic for a long time, but I had an idea yesterday > >(still ill defined) which I'm trying to implement. Basically, when you will > >do: > > > >CompoundStatementPtr compound= ...; > >compound->appendStatement( new WhileStatement( ... ) > > > >CompoundStatement will memorize that a new statement was added and rewrite > >the code as required. > > > So you think about implementing the code writer within extra classes for > the statement types ? > I was thinking about using some visitation of the parsed AST and to do > the rewriting on basis of the > parsed AST. This kind of rewriter would use the original source code > parts that cannot be parsed yet > (maybe remove new lines or extra whitespaces) and introduces the > formatting for all known code parts. > Also the idea of configurable formatting has to be included. I was > thinking about having some formatter > context that knows about the settings how to format and for instance > the level for indention etc. > The visitor can than collect the formatted code. You need more than just the new AST to rewrite the code. You also need to know which node were deleted, and which were replaced to know which part of the original source need to be modified. The CodeModel provided a somewhat higher level of abstraction of the code. For instance, in the AST, the type of an declaration node is the same weither it is a statement or an expression. The CodeModel clearly distinguish both case. If things work out correctly, the current refactoring will be modified to use the code model instead of doing direct text manipulation. The new classes living in CodeModel will not rewrite the code directly. They will remember the change made and their original SourceRange is they where generated from parsing. When the rewriting occurs, those change are collected during visitation and the rewriting will be done based on those change. This rewritting will also need to be combined with a formatter. Making formatting configurable will be trivial once we manage to do it. My current confusion is more around of what we should reformat and when: - For an ExpressionStatement, should it be completly reformatted if a part of the expression changed ? (a variable was renamed for instance) - For conditional statements, should the condition be reformatted if the condition expression changed ? At the current, I'm going for 'no' as an answer to both questions since we don't know how to reformat expression at the current time. Reformatting will only occur for modification of a CompoundStatement (call to add/remove/set). Also, notes that it is better to just replace what need to be as it is easier on the undo buffer of the IDE (this is just the matter of doing a 'skip over' instead of copying). Baptiste. |