cedlemo fd16fdce24 Update the README.md | 8 年 前 | |
---|---|---|
data | 10 年 前 | |
m4 | 9 年 前 | |
src | 8 年 前 | |
tests | 9 年 前 | |
.travis.yml | 9 年 前 | |
Makefile.am | 9 年 前 | |
README.md | 8 年 前 | |
TODO | 9 年 前 | |
Vagrantfile | 8 年 前 | |
autogen.sh | 10 年 前 | |
configure.ac | 9 年 前 | |
parserClasses.class.violet.html | 10 年 前 | |
truckboris.pc.in | 10 年 前 |
Truckboris is a little library based on Clang (3.4 to 3.8). Truckboris allows you to easily create a simple C source file parser.
TruckBoris depends on LLVM and Clang >= 3.4. You need CPPUNIT (>= 1.12) for the tests.
git clone https://github.com/cedlemo/truckboris
./autogen.sh --prefix=/usr #use the prefix you want
make
sudo make install
You can generate the tests in order to see if everything is ok:
make check
./test/truckBorisTests
With this configuration, the installation create those files/directory:
You can find a Vagrantfile in the root directory of this project. This vagrant file is intended to be used with an archlinux vagrant box.
vagrant box add archlinux-x86_64 http://cloud.terry.im/vagrant/archlinux-x86_64.box
mkdir truckboris_test
cd truckboris_test
cp /path/to/Vagranfile ./
vagrant up
For example, with the file tests/libtest_headerParser_obj.cpp:
clang++ -o libtest_headerParser_obj $(pkg-config --libs --cflags truckboris) libtest_headerParser_obj.cpp
You don't have to bother with the clang LLVM flags.
#include <string>
#include <iostream>
#include <vector>
#include <HeaderParser.h>
#define TEST_SOURCE_FILE "../data/test.cpp"
/*Compile with:
clang++ -o libtest_headerParser_obj $(pkg-config --libs --cflags truckboris) libtest_headerParser_obj.cpp
*/
int main(int argc, char **argv)
{
std::vector<std::string> hp;
hp.push_back(std::string("/usr/include"));
TruckBoris::HeaderParser headerParser;
headerParser.addSourceFile(std::string(TEST_SOURCE_FILE));
headerParser.addSearchPaths(hp);
if(headerParser.isInitialized())
std::cout << "Header Parser is initialized " << std::endl;
else
return 1;
std::cout << "File to parse : " << headerParser.getSourceFile() << std::endl;
if(headerParser.parse())
std::cout << "Parsing succeeded " << std::endl;
else
std::cout << "Parsing failed " << std::endl;
std::vector<TruckBoris::Function> fns;
fns = headerParser.getFunctions();
std::cout << fns.size() << std::endl;
return 0;
}
The TruckBoris::HeaderParser
object, lists all top level functions , typedefs,
structures, unions enumerations. When the parsing is done you can get, from
each functions for example, its name, its return type or an array of arguments.
You can see in the file tests/TruckBorisTests.h how to use all the TruckBoris objects and methodsi with the source files in data/.
void setUp()
{
m_headerParser = NULL;
std::vector<std::string> hp;
hp.push_back(std::string("/usr/include"));
m_headerParser = new TruckBoris::HeaderParser(std::string(TEST_SOURCE_FILE),hp);
}
/*-------------------------------*/
void headerParser_testFunctions()
{
CPPUNIT_ASSERT(m_headerParser->isInitialized() == true);
STR_MESSASSERT(m_headerParser->getSourceFile(), std::string(TEST_SOURCE_FILE) );
CPPUNIT_ASSERT(m_headerParser->parse() == true);
std::vector<TruckBoris::Function> f;
f = m_headerParser->getFunctions();
STR_MESSASSERT(f[0].getName(), std::string("une_fonction"));
CPPUNIT_ASSERT(f[0].getParameters().size() == 2);
CPPUNIT_ASSERT(f[0].isMain() == false);
STR_MESSASSERT(f[1].getName(), std::string("pupute"));
CPPUNIT_ASSERT(f[1].getParameters().size() == 2);
CPPUNIT_ASSERT(f[1].isMain() == false);
STR_MESSASSERT(f[2].getName(), std::string("fonction_vide"));
CPPUNIT_ASSERT(f[2].getParameters().size() == 0);
CPPUNIT_ASSERT(f[2].isMain() == false);
STR_MESSASSERT(f[3].getName(), std::string("main"));
CPPUNIT_ASSERT(f[3].getParameters().size() == 2);
CPPUNIT_ASSERT(f[3].isMain() == true);
}