From: Grzegorz J. <ja...@ac...> - 2004-09-01 14:11:12
|
Gilles J. Seguin wrote: [...] > > Templates make a C++ parser at least 'x' times harder. > Can you explain how we can handle template specialization with current > parser. Almost none in HEAD (there is some code in 'exp_templates' branch, but dated and perhaps it is not worth dragging in). > What I understand, > - specializing templates requires that the tokens for a template > declaration be saved so that the template can be reprocessed when the > actual template arguments are specified. More than that. Types in template definition that do not depend on template arguments must be bound in the point of definition; remaining types are bound in the point of instantiation. This means, that either you have to bind the types after you read the definition or you need to store the environment "snapshot" from the point of definition, to be able to bind appropriately at the point of instantiation. > - it requires the syntax phase to perform near-complete type, scope, and > expression analysis, including function overloading. Not really. First of all, if you just want to *parse*, then parser does have to perform all this analysis; for parser it is enough to know if a given identifier denotes template or not. Second, even if you want to perform all this analysis during parsing, you don't have to (and IMO you should not) put the implementation into parser. The design I am suggesting is that Parser stores a pointer to AbstractStaticAnalyzer. AbstractStaticAnalyzer is an interface that Parser uses to inform the rest of the system, that it parsed certain constructs. The implementation of AbstractStaticAnalyzer may, based on the information from Parser, maintain the data structures such as representations of scopes, classes or templates. However, another implementation of AbstractStaticAnalyzer may just do nothing, and it can be used for testing or in applications that are not concerned with full templates processing (e.g. pretty-printer). > Present design predate such change to the language. > In my vocabulary, present design is "C-Front style". That's right. > So my believed is that we need to rejuvenate the design. > But my question is how. Let me know if the description above makes sense for you. BR Grzegorz |