[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] Using the CDT Parser as a stand-alone module
|
Hi Rick,
The CDT parser is part of the org.eclipse.cdt.core plugin. The easiest way
to get at it would be to add these JARs to your classpath:
- org.eclipse.cdt.core_4.0.0.___.jar
- org.eclipse.equinox.common_3.3.0.___.jar
The parser is decoupled enough that you can use it without Eclipse running.
There isn't much documentation on it so I've included an example of how to
use the GNU C++ parser at the bottom of this message. To use the GNU C
parser, substitute GCCLanguage for GPPLanguage.
The only thing in the above example that isn't API is
FileCodeReaderFactory. You'd probably want to make your own
ICodeReaderFactory implementation to replace it.
Hope this helps. Let me know if you have any further questions.
Jason Montojo
IBM CDT Team
IBM Toronto Lab
905-413-5228
jmontojo@xxxxxxxxxx
-----8<----------------------------------------
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.gnu.cpp.GPPLanguage;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.DefaultLogService;
import org.eclipse.cdt.core.parser.IParserLogService;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.internal.core.parser.scanner2.FileCodeReaderFactory;
public class ParserExample {
public static void main(String[] args) throws Exception {
IParserLogService log = new DefaultLogService();
String code = "class Class { public: int x,y; Class();
~Class(); private: Class f(); }; int function(double parameter) { return
parameter; };";
CodeReader reader = new CodeReader(code.toCharArray());
Map definedSymbols = new HashMap();
String[] includePaths = new String[0];
IScannerInfo info = new ScannerInfo(definedSymbols,
includePaths);
ICodeReaderFactory readerFactory =
FileCodeReaderFactory.getInstance();
IASTTranslationUnit translationUnit =
GPPLanguage.getDefault().getASTTranslationUnit(reader, info, readerFactory,
null, log);
ASTVisitor visitor = new ASTVisitor() {
public int visit(IASTName name) {
System.out.println(name.getRawSignature());
return ASTVisitor.PROCESS_CONTINUE;
}
};
visitor.shouldVisitNames = true;
translationUnit.accept(visitor);
}
}
cdt-dev-bounces@xxxxxxxxxxx wrote on 17/07/2007 11:31:30 AM:
> Hi all,
>
> I am on the development team of the open source project
> Frysk(http://sourceware.org/frysk) which is well into the process of
> designing/writing a new monitor/debugger to take advantage of the latest
> hardware/software technologies. At the current time I am working on the
> UI part of Frysk(there is also a command-line side), specifically the
> source window view.
>
> At the beginning of the Frysk project a couple of years ago we imported
> an older version, 2.0, of the CDT parser which we use to
> markup/highlight the keywords/macros/variables/etc. in our source window
> view. While this parser has been fairly reliable, we have found a few
> problems and we would like to upgrade it to a newer model. I understand
> that the latest CDT Parser is available to be used as a stand alone
> module and am very interested in importing it and having Frysk use it as
> its parsing engine.
>
> I have read the documentation Mike Kucera posted to this list at the end
> of June and it has a lot of good information. I was wondering if there
> was some information somewhere or if someone could give me some guidance
> about pulling the CDT Parser out of the CDT source proper and creating a
> stand alone module. If there is other info around like how to use it,
> that would be helpful too. As I said previously, at the current time we
> only use it for highlighting keywords/macros/variables/etc.
>
> BTW, future plans for Frysk are to integrate it into the Eclipse CDT
> framework so it can be used as gdb is right now. The main focus of
> Frysk for its initial release is for debugging C++ code and handling
> multi-threaded apps more gracefully.
>
> Thanks in advance for any help you can render here.
>
> Rick Moseley
> rmoseley@xxxxxxxxxx
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev