|
From: Baptiste L. <gai...@fr...> - 2003-04-23 08:25:02
|
I'll give this a more thorough look later on. A few primilary remarks
though:
Our 'C++' is wider than the standard (we have single pass parsing). For
example, we should support class declaration such as:
class RFTA_API TextDocument { };
Were RFTA_API is stored as the optional 'export macro name'. This is a
widely used idiom on Win32.
The AST should capture all data required for the source code manipulation
(capture the range of all element that might be removed, inserted,
modified).
A primary goal would probably be able to identify the function/method bodies
(this would solve the issue you raised concerning the starting compound
statement for variable declaration search).
Next, I would probably go for class parsing (rough, just extract the name,
methods, and method/function implementation parsing. Having those two open
doors for ExtractInterface refactoring (just needs the class methods), and
ExtractMethod refactoring (need to add a method in the class declaration,
adding a new method body, and know what are the method parameters).
Baptiste.
----- Original Message -----
From: "Andre Baresel" <and...@gm...>
To: "CppTool Mailing List" <Cpp...@li...>
Sent: Thursday, April 17, 2003 9:26 PM
Subject: [Cpptool-develop] Declaration parsing started...
> hello together,
>
> I'm currently working on the "declaration" parsing.
>
> That's stuff like:
>
> typedef class x { ... } x_type;
> const int * (*f)(...);
>
> I've analyzed the C++ Spec. and identified the following elements.
> However I'm not yet sure if the parsing has to go that deep at the moment.
> Maybe at implementation phase I decide to reduce the level for the first.
>
> Here comes a proposal for a possible AST structure:
> ===============================================================
> * Declaration-Level-Elements
>
> // each declaration consists of a list of specifier and a list of
> declarators (with optional init part)
> [simple-declaration]
> declaration-specifier-property => [declaration-specifier-list] //
> specifiers for all declarators...
> n [init-declarator] // each declaration can declare 'n' identifier
>
> [declaration-specifier-list] // type declaration is organized as list
> n [declaration-specifier]
>
> [init-declarator] // each declarator consist of a
> declarator identifier, initialize-part and the declarator-description
> (pointer, const, ref etc.)
> ?identifier-property => [#declarator-identifier]
> ?initializer => [expression]
> declarator-property => [unparsed-declarator] , [declarator]
>
> [unparsed-declarator]
> #mutate: declarator
>
> [declarator] // declarators are organized
> hierarchical, the property 'sub-declarator-property' links to the sub
> element.
> ?sub-declarator-property => [declarator]
> ?[function-declarator] // int ... (...)
> ?[array-declarator] // int ... [...]
> ?[#braces] // int (...)
> ?[ptr-declarator] // int (* ...)
> ?[#ref-declarator] // int (& ...)
> ?[named-ptr-declarator] // int (::c::d * ...)
>
> [declaration-specifier]
> ?[#type-specifier] // "simple-type-specifier" (char, wchar_t, bool,
> etc.) also "cv-qualifier" ---> see C++ Spec.
> ?[class-specifier] // full class spec: "class x { ... }"
> ?[enum-specifier] // full enum spec
> ?[elaborated-type-specifier] // something like "class xxx" or "struct y"
> ===============================================================
>
> I will put this on a wiki page for discussion
> and add examples which use this ast.
>
> Just feel free to send your opinion !
>
> greetings,
> André
|