[cfe-dev] extending Sema and integrating it...

Douglas Gregor dgregor at apple.com
Mon Jan 24 07:35:45 PST 2011

On Jan 21, 2011, at 12:54 PM, christopher taylor wrote:

> To the list:
> I was interested in extending ForStmt to support some pragma work I've
> been doing in a Preprocessor Handler.
> I'd like to be able to add my ForStmt extension into Sema (with an
> ActOn function) but, I'm not 100% where and how to modify Sema to
> support this additional AST node.

The typical approach is to find something similar to what you want to do (in this case, ForStmt), and model your new AST node like that AST node. Once you've added the definition of the node to the appropriate header and to StmtNodes.td, you'll end up getting a bunch of warnings from switch statements that are now missing a case for your new statement and then a bunch of link errors for visitors that need to be extended to support your case statement. Eliminating those link errors and warnings will get you close to updating everything you need.

> If there isn't a very straightforward mechanism for this, would
> modeling how PragmaHandlers operate in the Preprocessor be a good
> addition to Sema?

If there were a general framework that made it easier to associate pragmas with the statements/declarations/etc. that they apply to, that would be a good addition to Clang.

	- Doug

More information about the cfe-dev mailing list