[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [cdt-dev] Using the CDT parser for debug expressions?
|
Title: Using the CDT parser for debug expressions?
Hi Ken,
I'm of course not an expert but I've been down this
path before. There's some more API for this since the last time I looked,
but in 5.0.x I thought this would be a way to do this:
IStorage storage = /* some custom in-memory
implementation */;
IASTTranslationUnit tu
= CDOM.getTranslationUnit(storage, project);
But I see that 'storage' is only used to fetch a path,
and then the core assumes everything's in a file. I assume the debugger
won't want to write a lot of files to populate the Variables
view...
Another approach requires touching non-API code
but you should at least be able to control where the parsed content comes
from:
ILanguage language =
GCCLanguage.DEFAULT_INSTANCE;
IIndex index =
CCorePlugin.getIndexManager.getIndex(project, 0 /* ??
*/);
IScanner scanner = new CPreprocessor/**non API**/(..
lots of stuff you have to implement or instantiate...);
ISourceCodeParser
parser = language.createParser(scanner, ParserMode.QUICK_PARSE /* ?? */, new
DefaultLogService(), index);
IASTTranslationUnit tu =
parser.parse();
... then see what 'tu' has to offer. N.B. you'll probably need to wrap the _expression_ in a
dummy function body, like "void debugger_func() { /* _expression_ */ }
".
You would need to manually visit this tree to evaluate
the _expression_ or find something that does it for you.
An important question, though, is how the TU will respond to all the
identifiers, struct/class dereferences, etc. it will encounter
along the way in a complex _expression_... I think IASTProblem[Holder] nodes will
appear in the tree, which you may or may not be able to work around.
This is
where the experts can help more :)
--
Ed
I have a question for the folks who have more experience
with CDT language parsing than I:
The EDC debugger needs to parse and
then evaluate C/C++ expressions. The JDT debugger does this for java expressions
using an ASTEvaluationEngine. It looks like it can take a snippet of Java code
and create a CompilationUnit, which extends ASTNode. The CompilationUnit accepts
a visitor (ASTInstructionCompiler) which produces a compiled version of the
_expression_ that the debugger can evaluate. This is all done in
org.eclipse.jdt.internal.debug.eval.ast.engine and
org.eclipse.jdt.internal.debug.eval.ast.instructions
So I'm wondering if
I can take the same approach in CDT. It would need to parse a snippet of code
but would usually have a translation unit and project context to consider
too.
Thanks for your thoughts,
- Ken