説明なし

cedlemo fd16fdce24 Update the README.md 8 年 前
data cf78f1ff7a add ability to parse only main file 10 年 前
m4 dac9c2440a add support for CppUnit v 1.12 9 年 前
src ac571dcde9 Fix style issue 8 年 前
tests dac9c2440a add support for CppUnit v 1.12 9 年 前
.travis.yml 885d09470e Use simple Travis config 9 年 前
Makefile.am 78480aa610 add support for Clang/LLVM 3.4 9 年 前
README.md fd16fdce24 Update the README.md 8 年 前
TODO fbc76a9a9b remove methods getFields 9 年 前
Vagrantfile cb6baaa78a Add a Vagrantfile 8 年 前
autogen.sh ccf45f3502 Finished truckboris library for distribution 10 年 前
configure.ac 19f5298ef7 Decrease needed version of Automake for Travis 9 年 前
parserClasses.class.violet.html db2d0da5c9 Initial commit 10 年 前
truckboris.pc.in ccf45f3502 Finished truckboris library for distribution 10 年 前

README.md

Truckboris

Build Status

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.

Installation

Dependencies

TruckBoris depends on LLVM and Clang >= 3.4. You need CPPUNIT (>= 1.12) for the tests.

Systems tested :

  • Archlinux (clang 3.4 to 3.7, CppUnit 1.13)
  • Fedora (clang 3.5, CppUnit 1.12)
  • Centos (clang 3.4, CppUnit 1.12)

Get the repository:

git clone https://github.com/cedlemo/truckboris

Generate the make file and install

./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:

  • /usr/lib/libtruckboris.{so,la,so.1,so.x.x.x}
  • /usr/include/truckboris with the needed headers.
  • /usr/include/pkgconfig/truckboris.pc

Test easily with Vagrant:

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

Use truckboris:

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.

Examples:

#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);
}