[cfe-dev] Returning original parsing state after parsing arbitrary tokens

ja_comp ja_comp at yahoo.com
Tue Oct 30 01:35:14 PDT 2012


Eli Friedman wrote
> Hmm... the problem is, semantic analysis is really not designed to
> deal with something like this.  Even if you ignore template
> instantiation, an arbitrary declaration still inserts things into the
> AST which can't be easily removed.  If you can reject input code which
> contains any  declarations before it hits semantic analysis, and don't
> need to deal with input code that uses templates, that should suppress
> most of the ripple effects I can think of, though.

Your help is greatly appreciated! I have a fair working knowledge of the AST
once it's produced, but I admit my ignorance when it comes to what's
involved with the parsing and production of the AST.

So, it appears that some ways to attack this problem are:

*1) PushState() and PopState():* /[Grade: ---]/ Although technically
possible, based on our discussion this appears unlikely without a major
overhaul.

*2) fork():* /[Grade: +]/ I modified my code to use fork(), and it works as
you would expect it: arbitrary tokens can be parsed with no alteration of
the parent AST. However, the resultant StmtResult is isolated in the child
process.

	a) Could the StmtResult be "deep copied" to the parent process somehow?
(I'm not even sure what would be involved in creating a "inter-process
compatible" StmtResult.)
	
	b) It might be possible to do the necessary source-to-source transformation
in the child process and pass that back to the parent process, but this
would not be ideal.

*3) Identify and reject tokens that lead to declarations or use templates:*
/[Grade: ---]/ I'm not sure I know how to do this without actually parsing
the tokens. (I'm not even sure I know how to do this even *after* parsing
the tokens).

*4) fork() for verification:*  /[Grade: ++]/ It should be possible to use a
forked child process to identify valid StmtResults that don't modify the
AST, and then tell the Parent process to "go ahead" and parse the valid
token streams when appropriate. This seems to be a promising avenue. So,
given a valid StmtResult in the child process, it would be necessary to
determine if parsing in the parent process would alter the parent AST in an
adverse way.

Any recommendations on a good methodology for a new function "bool
StmtResultCausesAdverseRipples(StmtResult &SR);"?

Thanks again for your help!



--
View this message in context: http://clang-developers.42468.n3.nabble.com/Returning-original-parsing-state-after-parsing-arbitrary-tokens-tp4027659p4027829.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list