GithubHelp home page GithubHelp logo

cedlemo / truckboris Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 7.21 MB

A C++ tiny library based on Clang that implements a simple C source files parser.

Shell 0.09% C++ 11.25% C 0.78% HTML 87.88%

truckboris's Introduction

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

truckboris's People

Contributors

cedlemo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.