Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #50 from juanjux/feature/iterator
Browse files Browse the repository at this point in the history
UAST Iterators for PreOrder/LevelOrder/PostOrder traversal
  • Loading branch information
abeaumont authored Dec 5, 2017
2 parents c5b553d + 88c24a1 commit c70f19e
Show file tree
Hide file tree
Showing 11 changed files with 478 additions and 174 deletions.
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
cmake_minimum_required (VERSION 2.6)
cmake_policy(SET CMP0048 NEW)
project (LIBUAST
VERSION 0.0.0
LANGUAGES C)
project (LIBUAST VERSION 0.0.0 LANGUAGES CXX C)

set (CMAKE_CXX_STANDARD 11)

set(CMAKE_C_STANDARD 99)
set(CMAKE_MACOSX_RPATH ON) # fixes CMP0042

set(OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib")

# Required dependencies
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
find_package (CUnit REQUIRED)
find_package(CUnit REQUIRED)
find_package(LibXml2 REQUIRED)

# Library name
set(libname uast)

# Source files
set(libsrc
${CMAKE_SOURCE_DIR}/src/uast.c
${CMAKE_SOURCE_DIR}/src/uast.cc
${CMAKE_SOURCE_DIR}/src/roles.c)

# Header files
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ More features may be implemented in the future, like UAST iterators.
#### Ubuntu instructions

```
sudo apt install cmake libxml2 libxml2-dev libcunit1 libcunit1-dev
sudo apt install build-essential cmake libxml2 libxml2-dev libcunit1 libcunit1-dev
```


Expand Down Expand Up @@ -164,6 +164,24 @@ if (nodes) {
NodesFree(nodes);
```
#### UAST Iterators
The API provides a UASTIterator type that can iterate over the UAST in
pre-order, post-order or level-order.
Example:
```c
UastIterator *iter = UastIteratorNew(ctx, node, PRE_ORDER);
void *curNode = NULL;
while((curNode = UastIteratorNext(iter)) != NULL) {
// ... do something with the node
}
UastIteratorFree(iter);
```

## Contribute

Please follow [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html).
20 changes: 0 additions & 20 deletions src/testing_tools.c → src/testing_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,12 @@

#ifdef TESTING

bool fail_calloc = false;
bool fail_realloc = false;
bool fail_xmlNewNode = false;
bool fail_xmlNewDoc = false;
bool fail_xmlNewProc = false;
bool fail_xmlAddChild = false;
bool fail_xmlXPathNewContext = false;

#undef calloc
void *MockCalloc(int count, size_t size) {
if (fail_calloc) {
return NULL;
} else {
return calloc(count, size);
}
}

#undef realloc
void *MockRealloc(void *ptr, size_t size) {
if (fail_realloc) {
return NULL;
} else {
return realloc(ptr, size);
}
}

#undef xmlNewNode
void *MockXmlNewNode(xmlNsPtr ns, const xmlChar *name) {
if (fail_xmlNewNode) {
Expand Down
8 changes: 0 additions & 8 deletions src/testing_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,12 @@
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>

extern bool fail_calloc;
extern bool fail_realloc;
extern bool fail_xmlNewNode;
extern bool fail_xmlNewDoc;
extern bool fail_xmlNewProc;
extern bool fail_xmlAddChild;
extern bool fail_xmlXPathNewContext;

void *MockCalloc(int count, size_t size);
#define calloc MockCalloc

void *MockRealloc(void *ptr, size_t size);
#define realloc MockRealloc

void *MockXmlNewNode(xmlNsPtr ns, const xmlChar *name);
#define xmlNewNode MockXmlNewNode

Expand Down
Loading

0 comments on commit c70f19e

Please sign in to comment.