RPA Toolkit
Added more documentation files. Added rpastatpriv.h, containing the private interface...
authorMartin Stoilov <martin@rpasearch.com>
Thu, 19 May 2011 06:41:19 +0000 (23:41 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Thu, 19 May 2011 06:41:19 +0000 (23:41 -0700)
28 files changed:
doc/doxygen/rpa.cfg
rgrep/rpagrep.c
rgrep/rpagrep.h
rgrep/unix/main.c
rpa/rpadbex.c
rpa/rpadbex.h
rpa/rpaerror.h
rpa/rpaparser.c
rpa/rparecord.h
rpa/rpastat.c
rpa/rpastat.h
rpa/rpastatpriv.h [new file with mode: 0644]
rpa/rpavm.c
tests/testrpa/rpacompiler-altexp.c
tests/testrpa/rpacompiler-class.c
tests/testrpa/rpacompiler-exp.c
tests/testrpa/rpacompiler-minusexp.c
tests/testrpa/rpacompiler-notexp.c
tests/testrpa/rpacompiler-rule.c
tests/testrpa/rpacompiler-rulealtrec.c
tests/testrpa/rpacompiler-ruleloop.c
tests/testrpa/rpacompiler-ruleloopcls.c
tests/testrpa/rpacompiler-rulerec.c
tests/testrpa/rpaparser-test.c
tests/testrpa/rpavm-matchchr.c
tests/testrpa/rpavm-matchrng.c
tests/testrpa/rpavm-mnode.c
tests/testrpa/rpavm-ref.c

index dcbcee4..48645f2 100644 (file)
@@ -612,6 +612,9 @@ WARN_LOGFILE           =
 
 
 INPUT                  = ../../rpa/rpadbex.h \
+                         ../../rpa/rpastat.h \
+                         ../../rpa/rparecord.h \
+                         ../../rpa/rpaerror.h \
                          ../../rpa/doc/main.txt \
                          ../../rpa/doc/introduction.txt \
                          ../../rpa/doc/overview.txt \
index 984cac0..3502454 100644 (file)
@@ -170,7 +170,7 @@ error:
 
 void rpa_grep_list_patterns(rpa_grep_t *pGrep)
 {
-       rpa_dbex_dumprules(pGrep->hDbex);
+       rpa_dbex_dumpproductions(pGrep->hDbex);
 }
 
 
@@ -190,7 +190,7 @@ void rpa_grep_dump_pattern_info(rpa_grep_t *pGrep)
 void rpa_grep_dump_alias_info(rpa_grep_t *pGrep)
 {
        rpa_dbex_compile(pGrep->hDbex);
-       rpa_dbex_dumpalias(pGrep->hDbex);
+       rpa_dbex_dumpuids(pGrep->hDbex);
 }
 
 
@@ -480,7 +480,7 @@ void rpa_grep_setup_matched_callback(rpa_grep_t *pGrep, rpa_buffer_t *pattern)
 
 void rpa_grep_dump_pattern_tree(rpa_grep_t *pGrep, rpa_buffer_t *pattern)
 {
-       rpa_dbex_dumptree_s(pGrep->hDbex, pattern->s, 0);
+       rpa_dbex_dumptree(pGrep->hDbex, rpa_dbex_lookup_s(pGrep->hDbex, pattern->s));
 }
 
 
index 1e16aab..c6e6469 100644 (file)
@@ -25,7 +25,7 @@
 #include <stdio.h>
 #include "rpaerror.h"
 #include "rpadbex.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 
 
 #ifdef __cplusplus
index 356d016..454029b 100644 (file)
@@ -51,7 +51,7 @@ int usage(int argc, const char *argv[])
                fprintf(stderr, "\t-l                       Line mode.\n");
                fprintf(stderr, "\t-16                      Force UTF16 encoding.\n");
                fprintf(stderr, "\t-b                       Force byte encoding.\n");
-               fprintf(stderr, "\t-d                       Dump the pattern tree.\n");
+               fprintf(stderr, "\t-d                       Dump a production in a tree format.\n");
                fprintf(stderr, "\t-t                       Display time elapsed.\n");
                fprintf(stderr, "\t-L, --list-rules         List all patterns.\n");
                fprintf(stderr, "\t-v                       Display version information.\n");
@@ -141,10 +141,9 @@ int main(int argc, const char *argv[])
                if (strcmp(argv[i], "--dump-code") == 0) {
                        if (rpa_dbex_compile(pGrep->hDbex) == 0) {
                                if (++i < argc) {
-                                       rpa_dbex_dumpcode(pGrep->hDbex, argv[i]);
+                                       rpa_dbex_dumpcode(pGrep->hDbex, rpa_dbex_lookup_s(pGrep->hDbex, argv[i]));
                                }
                        }
-
                        goto end;
                }
        }
index 6bc53e8..8912d48 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "rpacompiler.h"
 #include "rpadbex.h"
+#include "rpastatpriv.h"
 #include "rpaparser.h"
 #include "rpaoptimization.h"
 #include "rmem.h"
@@ -1115,34 +1116,32 @@ static void rpa_dbex_dumptree_do(rpadbex_t *dbex, rlong rec, rint level)
 }
 
 
-rint rpa_dbex_dumptree(rpadbex_t *dbex, const rchar *rulename, rsize_t namesize, rint level)
+rint rpa_dbex_dumptree(rpadbex_t *dbex, rparule_t rid)
 {
        rpa_ruleinfo_t *info;
 
        if (!dbex)
                return -1;
+       if (rid < 0) {
+               RPA_DBEX_SETERRINFO_CODE(dbex, RPA_E_PARAM);
+               return -1;
+       }
        if (!dbex->rules) {
                RPA_DBEX_SETERRINFO_CODE(dbex, RPA_E_NOTCLOSED);
                return -1;
        }
-       if (!(info = (rpa_ruleinfo_t *)r_harray_get(dbex->rules, rpa_dbex_lookup(dbex, rulename, namesize)))) {
+       if (!(info = (rpa_ruleinfo_t *)r_harray_get(dbex->rules, rid))) {
                RPA_DBEX_SETERRINFO_CODE(dbex, RPA_E_NOTFOUND);
                return -1;
        }
        r_array_add(dbex->inlinestack, &info->startrec);
-       rpa_dbex_dumptree_do(dbex, info->startrec, level);
+       rpa_dbex_dumptree_do(dbex, info->startrec, 0);
        r_array_removelast(dbex->inlinestack);
        return 0;
 }
 
 
-rint rpa_dbex_dumptree_s(rpadbex_t *dbex, const rchar *rulename, rint level)
-{
-       return rpa_dbex_dumptree(dbex, rulename, r_strlen(rulename), level);
-}
-
-
-rint rpa_dbex_dumprules(rpadbex_t *dbex)
+rint rpa_dbex_dumpproductions(rpadbex_t *dbex)
 {
        rint ret = 0;
        rparule_t rid;
@@ -1219,7 +1218,7 @@ rint rpa_dbex_dumpinfo(rpadbex_t *dbex)
 }
 
 
-rint rpa_dbex_dumpalias(rpadbex_t *dbex)
+rint rpa_dbex_dumpuids(rpadbex_t *dbex)
 {
        rlong i;
        rlong rec;
@@ -1260,16 +1259,20 @@ rint rpa_dbex_dumpalias(rpadbex_t *dbex)
 }
 
 
-rint rpa_dbex_dumpcode(rpadbex_t* dbex, const rchar *rulename)
+rint rpa_dbex_dumpcode(rpadbex_t* dbex, rparule_t rid)
 {
        rpa_ruleinfo_t *info;
        if (!dbex)
                return -1;
+       if (rid < 0) {
+               RPA_DBEX_SETERRINFO_CODE(dbex, RPA_E_PARAM);
+               return -1;
+       }
        if (!dbex->rules) {
                RPA_DBEX_SETERRINFO_CODE(dbex, RPA_E_NOTCLOSED);
                return -1;
        }
-       info = (rpa_ruleinfo_t *)r_harray_get(dbex->rules, rpa_dbex_lookup_s(dbex, rulename));
+       info = (rpa_ruleinfo_t *)r_harray_get(dbex->rules, rid);
        if (!info)
                return -1;
        rvm_asm_dump(rvm_codegen_getcode(dbex->co->cg, info->codeoff), info->codesiz);
index 3d7efe8..09431db 100644 (file)
 
 /**
  * \file rpadbex.h
- * \brief The public interface to BNF expression database API
+ * \brief The public interface to BNF productions database API
  *
  *
  * <h2>Synopsis</h2>
- * The following APIs are used to Create, Compile, Enumerate, etc. BNF expressions schema.
+ * The following APIs are used to Create, Compile, Enumerate, etc. BNF productions.
  */
 
 #ifndef _RPADBEX_H_
@@ -42,7 +42,7 @@ extern "C" {
 
 /**
  * \typedef rpadbex_t
- * \brief Database of BNF expressions (The BNF schema)
+ * \brief Database of BNF productions (The BNF schema)
  */
 typedef struct rpadbex_s rpadbex_t;
 
@@ -63,10 +63,10 @@ const rchar *rpa_dbex_version();
 
 
 /**
- * \brief Creates and returns a pointer to an object of type rpadbex_t.
+ * \brief Create an object of type \ref rpadbex_t.
  *
  * The created object must be destroyed with rpa_dbex_destroy.
- * \return pointer to newly create BNF expressions database object.
+ * \return pointer to newly create BNF productions database object.
  */
 rpadbex_t *rpa_dbex_create(void);
 
@@ -103,9 +103,9 @@ rlong rpa_dbex_lasterrorinfo(rpadbex_t *dbex, rpa_errinfo_t *errinfo);
 
 
 /**
- * \brief Open the BNF expressions database.
+ * \brief Open the BNF productions database.
  *
- * This function must be called before inserting any BNF expression with
+ * This function must be called before inserting any BNF production with
  * \ref  rpa_dbex_load or \ref rpa_dbex_load_s. To close the database you
  * must use \ref rpa_dbex_close. The database can opened and closed multiple
  * times as long it is not destroyed with \ref rpa_dbex_destroy.
@@ -119,7 +119,7 @@ rint rpa_dbex_open(rpadbex_t *dbex);
 
 
 /**
- * \brief Close the BNF expressions database.
+ * \brief Close the BNF productions database.
  *
  * This function must be called when the BNF schema is complete and ready
  * to be compiled.
@@ -130,9 +130,9 @@ void rpa_dbex_close(rpadbex_t *dbex);
 
 
 /**
- * \brief Compile the BNF expressions database to byte code.
+ * \brief Compile the BNF productions database to byte code.
  *
- * Compile the BNF expressions database to byte code. This function generates
+ * Compile the BNF productions database to byte code. This function generates
  * the byte code (executable code) used to parse or search input stream.
  * Parsing, Matching, Searching (Running the code) is controlled by \ref rpastat_t.
  *
@@ -145,13 +145,13 @@ rint rpa_dbex_compile(rpadbex_t *dbex);
 
 
 /**
- * \brief Load BNF expression(s) into the database.
+ * \brief Load BNF production(s) into the database.
  *
- * Loads the BNF expression(s) from the buffer into the dbex database.
+ * Loads the BNF production(s) from the buffer into the dbex database.
  * \param dbex Pointer to \ref rpadbex_t object.
- * \param buffer UTF8 string containing BNF expression(s).
+ * \param buffer UTF8 string containing BNF production(s).
  * \param size Buffer size.
- * \return Upon successful completion, the function returns the size of the loaded BNF expression(s), otherwise returns negative.
+ * \return Upon successful completion, the function returns the size of the loaded BNF production(s), otherwise returns negative.
  *         Use \ref rpa_dbex_lasterror or \ref rpa_dbex_lasterrorinfo to retrieve the error
  *         information.
  */
@@ -159,12 +159,12 @@ rlong rpa_dbex_load(rpadbex_t *dbex, const rchar *buffer, rsize_t size);
 
 
 /**
- * \brief Load BNF expression(s) into the database. Same as \ref rpa_dbex_load,
+ * \brief Load BNF production(s) into the database. Same as \ref rpa_dbex_load,
  *                     but the buffer is NULL terminated string.
  *
  * \param dbex Pointer to \ref rpadbex_t object.
- * \param buffer UTF8 string containing BNF expression(s).
- * \return Upon successful completion, the function returns the size of the loaded expressions,
+ * \param buffer UTF8 string containing BNF production(s).
+ * \return Upon successful completion, the function returns the size of the copied productions,
  *         otherwise returns negative.
  *         Use \ref rpa_dbex_lasterror or \ref rpa_dbex_lasterrorinfo to retrieve the error
  *         information.
@@ -189,11 +189,11 @@ rvm_asmins_t *rpa_dbex_executable(rpadbex_t *dbex);
  *
  * Return the offset of the executable byte code segment returned by \ref rpa_dbex_executable for the specified rule.
  * The two functions \ref rpa_dbex_executable and \ref rpa_dbex_executableoffset work together to locate the
- * beginning of the executable byte code for the specified rule id.
+ * beginning of the executable byte code for the specified ID.
  * This function will succeed only if it is called after a call to \ref rpa_dbex_compile.
  *
  * \param dbex Pointer to \ref rpadbex_t object.
- * \param rid Rule Id of the requested BNF rule(expression).
+ * \param rid Unique ID of the requested BNF production.
  * \return Pointer the offset of the executable byte code. In case of an error it returns negative.
  *         Use \ref rpa_dbex_lasterror or \ref rpa_dbex_lasterrorinfo to retrieve the error
  *         information.
@@ -202,23 +202,23 @@ rlong rpa_dbex_executableoffset(rpadbex_t *dbex, rparule_t rid);
 
 
 /**
- * \brief Lookup Rule ID in the expression database.
+ * \brief Lookup BNF production ID in the database.
  *
- * Lookup the unique Rule ID for BNF expression in the dbex database. For example if you
- * have loaded and compiled a BNF expression like: "alpha ::= [a-zA-Z]" with a previous call to
- * \ref rpa_dbex_load. You can lookup the unique rule id for this expression by using this
+ * Lookup the unique ID for BNF production in the dbex database. For example if you
+ * have loaded and compiled a BNF production like: "alpha ::= [a-zA-Z]" with a previous call to
+ * \ref rpa_dbex_load. You can lookup the unique ID for this production by using this
  * function.
  *
  * \param dbex Pointer to \ref rpadbex_t object.
- * \param name The rule name (the identifier located before the operator '::= ')
+ * \param name The production name (the identifier located before the operator '::= ')
  * \param namesize The size of the buffer to be used.
- * \return Unique id of the specified rule(expression).
+ * \return Unique ID for the specified production name.
  */
 rparule_t rpa_dbex_lookup(rpadbex_t *dbex, const rchar *name, rsize_t namesize);
 
 
 /**
- * \brief Lookup Rule ID in the expression database.
+ * \brief Lookup BNF production ID in the database.
  *
  * Same as \ref rpa_dbex_lookup, but the name parameter is NULL terminated string.
  */
@@ -226,64 +226,64 @@ rparule_t rpa_dbex_lookup_s(rpadbex_t *dbex, const rchar *name);
 
 
 /**
- * \brief Return the first expression id in the database.
+ * \brief Return the first production ID in the database.
  *
- * Depending on how the BNF schema is structured, if the first expression is also the
- * root expression you should use this function to get the root id.
+ * Depending on how the BNF schema is structured, if the first production is also the
+ * root production you should use this function to get the root ID.
  *
  * \param dbex Pointer to \ref rpadbex_t object.
- * \return Returns the id of the first expression.
+ * \return Returns the ID of the first production.
  */
 rparule_t rpa_dbex_first(rpadbex_t *dbex);
 
 
 /**
- * \brief Return the last expression id
+ * \brief Return the last production ID
  *
- * Depending on how the BNF schema is structured, if the last expression is also the
- * root expression you should use this function to get the root id.
+ * Depending on how the BNF schema is structured, if the last production is also the
+ * root production you should use this function to get the root ID.
  *
  * \param dbex Pointer to \ref rpadbex_t object.
- * \return Returns the id of the last expression.
+ * \return Returns the ID of the last production.
  */
 rparule_t rpa_dbex_last(rpadbex_t *dbex);
 
 
 /**
- * \brief Return the next expression id
+ * \brief Return the next production ID
  *
  * \param dbex Pointer to \ref rpadbex_t object.
- * \param rid current expression id.
- * \return Returns the id of the next expression.
+ * \param rid current production ID.
+ * \return Returns the ID of the next production.
  */
 rparule_t rpa_dbex_next(rpadbex_t *dbex, rparule_t rid);
 
 
 /**
- * \brief Return the previous expression id
+ * \brief Return the previous production ID
  *
  * \param dbex Pointer to \ref rpadbex_t object.
- * \param rid current expression id.
- * \return Returns the id of the previous expression.
+ * \param rid current production ID.
+ * \return Returns the ID of the previous production.
  */
 rparule_t rpa_dbex_prev(rpadbex_t *dbex, rparule_t rid);
 
 
 /**
- * \brief Returns the string length of the specified BNF expression
+ * \brief Returns the string length of the specified BNF production
  *
  * \param dbex Pointer to \ref rpadbex_t object.
- * \param rid expression id.
- * \return the string length of the specified expression
+ * \param rid production ID.
+ * \return the string length of the specified production
  */
 rsize_t rpa_dbex_strlen(rpadbex_t *dbex, rparule_t rid);
 
 
 /**
- * \brief Copy the string of the specified BNF expression to the destination buffer
+ * \brief Copy the string of the specified BNF production to the destination buffer
  *
  * \param dbex Pointer to \ref rpadbex_t object.
- * \param rid expression id.
+ * \param rid production ID.
  * \param dest destination buffer
  * \param size to be copied
  * \return Return the number of bytes written in the buffer.
@@ -295,7 +295,7 @@ rsize_t rpa_dbex_strncpy(rpadbex_t *dbex, rchar *dest, rparule_t rid, rsize_t si
  * \brief Set a configuration value for the dbex object.
  *
  * \param dbex Pointer to \ref rpadbex_t object.
- * \param cfg Configuration id
+ * \param cfg Configuration ID
  * \param val Configuration value
  *
  * Supported configuration IDs / Values:
@@ -320,32 +320,63 @@ rlong rpa_dbex_cfgget(rpadbex_t *dbex, rulong cfg);
 
 
 /**
- * \brief Print a BFN expression in a tree format
- *
+ * \brief Print a BNF production in a tree format
  *
+ * Use \ref rpa_dbex_lookup to find the ID of a BNF production
+ * \param dbex Pointer to \ref rpadbex_t object.
+ * \param rid production ID.
+ * \return Return 0 on success or negative if error occurred.
  */
-rint rpa_dbex_dumptree(rpadbex_t *dbex, const rchar *rulename, rsize_t namesize, rint level);
-
+rint rpa_dbex_dumptree(rpadbex_t *dbex, rparule_t rid);
 
 /**
- * \brief Print a BNF expression in a tree format
- *
+ * \brief Dump the compiled byte code for the specified production ID
  *
+ * This function is a debug helper, you shouldn't need it.
+ * \param dbex Pointer to \ref rpadbex_t object.
+ * \param rid production ID.
+ * \return Return 0 on success or negative if error occurred.
  */
-rint rpa_dbex_dumptree_s(rpadbex_t *dbex, const rchar *name, rint level);
+rint rpa_dbex_dumpcode(rpadbex_t* dbex, rparule_t rid);
 
 
 /*
- * \brief Print the AST of the parsed BNF expressions.
+ * \brief Print the AST of the parsed BNF productions.
  *
- * This function is a debugging helper, you shouldn't need it
+ * This function is a debug helper, you shouldn't need it.
  * unless you are debugging this library.
+ *
+ * \param dbex Pointer to \ref rpadbex_t object.
+ * \return Return 0 on success or negative if error occurred.
  */
 rint rpa_dbex_dumprecords(rpadbex_t *dbex);
-rint rpa_dbex_dumprules(rpadbex_t *dbex);
+
+/*
+ * \brief Print the content of BNF productions database.
+ *
+ * Enumerate all BNF productions and print them in a text format.
+ * \param dbex Pointer to \ref rpadbex_t object.
+ * \return Return 0 on success or negative if error occurred.
+ */
+rint rpa_dbex_dumpproductions(rpadbex_t *dbex);
+
+/*
+ * \brief Print debug information about the state of the BNF productions database.
+ *
+ * This is a debug helper, you shouldn't need it.
+ * \param dbex Pointer to \ref rpadbex_t object.
+ * \return Return 0 on success or negative if error occurred.
+ */
 rint rpa_dbex_dumpinfo(rpadbex_t *dbex);
-rint rpa_dbex_dumpcode(rpadbex_t* dbex, const rchar *rule);
-rint rpa_dbex_dumpalias(rpadbex_t *dbex);
+
+/*
+ * \brief Print the production user IDs in a format suitable to be
+ * included in source code.
+ *
+ * If you define user IDs for your productions you can dump all user IDs
+ * in a format suitable to be included in a C/C++ source code.
+ */
+rint rpa_dbex_dumpuids(rpadbex_t *dbex);
 
 
 
index f96f4e3..98155ce 100644 (file)
  *  Martin Stoilov <martin@rpasearch.com>
  */
 
+/**
+ * \file rpaerror.h
+ * \brief The public interface for examining errors.
+ *
+ *
+ * <h2>Synopsis</h2>
+ * The RPA error(s) interface.
+ */
+
 #ifndef _RPAERROR_H_
 #define _RPAERROR_H_
 
 #define RPA_E_NOTFOUND 1005
 #define RPA_E_SYNTAX_ERROR 1006
 #define RPA_E_UNRESOLVED_SYMBOL 1007
+#define RPA_E_PARAM 1008
 
 #define RPA_E_USERABORT 2001
 
-
+/**
+ * \typedef rpaerror_t
+ * \brief RPA error description.
+ */
 typedef struct rpa_errinfo_s rpa_errinfo_t;
 struct rpa_errinfo_s {
        rulong mask;
index 885fe04..81e5b91 100644 (file)
@@ -2,6 +2,7 @@
 #include "rvmcodegen.h"
 #include "rstring.h"
 #include "rpaparser.h"
+#include "rpastatpriv.h"
 
 static rint rpa_parser_init(rpa_parser_t *pa);
 
index b7c22bb..26f4bd1 100644 (file)
@@ -1,3 +1,38 @@
+/*
+ *  Regular Pattern Analyzer (RPA)
+ *  Copyright (c) 2009-2010 Martin Stoilov
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  Martin Stoilov <martin@rpasearch.com>
+ */
+
+/**
+ * \file rparecord.h
+ * \brief The public interface for working with the produced Abstract Syntax Tree (AST).
+ *
+ *
+ * <h2>Synopsis</h2>
+ * Upon a successful call to \ref rpa_stat_parse, the parser produces a stack of \ref rparecord_t records.
+ * There are two kinds of records: \ref RPA_RECORD_START and \ref RPA_RECORD_END. \ref RPA_RECORD_START marks
+ * the beginning of a branch and \ref RPA_RECORD_END marks the end of that branch. Empty branches are specified by
+ * a record \ref RPA_RECORD_START followed immediately by \ref RPA_RECORD_END (no child records in between).
+ * Empty branches are considered leaves.
+ *
+ */
+
+
 #ifndef _RPARECORD_H_
 #define _RPARECORD_H_
 
@@ -20,6 +55,10 @@ extern "C" {
 
 #define RPA_RECORD_INVALID_UID ((ruint32)-1)
 
+/**
+ * \typedef rparecord_t
+ * \brief Abstract Syntax Tree (AST) construction element.
+ */
 typedef struct rparecord_s {
        rlong next;
        const rchar *rule;
index 5eaf981..52cc1bc 100644 (file)
@@ -1,6 +1,6 @@
 #include "rmem.h"
 #include "rarray.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "rvmcodegen.h"
 #include "rvmcpu.h"
 #include "rutf.h"
index 5ff542b..3001211 100644 (file)
@@ -4,9 +4,7 @@
 #include "rtypes.h"
 #include "rarray.h"
 #include "rvmreg.h"
-#include "rpavm.h"
 #include "rpadbex.h"
-#include "rpacache.h"
 
 #define RPA_ENCODING_UTF8 0
 #define RPA_ENCODING_BYTE 1
 extern "C" {
 #endif
 
+/**
+ * \file rpastat.h
+ * \brief The public interface to the execution context.
+ *
+ *
+ * <h2>Synopsis</h2>
+ * The following APIs are used to parse, match, scan an input stream, using an existing
+ * BNF productions database \ref rpadbex_t
+ */
 
 
+/**
+ * \typedef rpastat_t
+ * \brief Execution context. If you need mutli-threading, multiple objects of this
+ * type must be created for every concurrent thread. All objects can be created/destroyed from the
+ * main thread. Only the execution functions: \ref rpa_stat_parse, \ref rpa_stat_match and
+ * \ref rpa_stat_scan have to be called from separate threads.
+ */
 typedef struct rpastat_s rpastat_t;
-struct rpastat_s {
-       rpadbex_t *dbex;
-       const rchar *input;
-       const rchar *start;
-       const rchar *end;
-       ruint error;
-       ruint encoding;
-       ruint debug;
-       rarray_t *records;
-       rarray_t *emitstack;
-       rarray_t *orphans;
-       rpainput_t *instackbuffer;
-       rpainput_t *instack;                    /* instack = &instackbuffer[1]; This allows R_TOP = -1, without any additional checks */
-       rulong instacksize;
-       rpacache_t *cache;
-       rpainmap_t ip;
-       rvmcpu_t *cpu;
-};
-
 
+/**
+ * \brief Create an object of type \ref rpastat_t.
+ *
+ * Multi-threading is supported by creating multiple \ref rpastat_t objects,
+ * referencing the same \ref rpadbex_t BNF productions database. Every thread
+ * must have its own \ref rpastat_t object, created with this function. This
+ * function can be called from the main thread multiple times to allocate the objects and
+ * then the returned pointer(s) passed to the child threads.
+ *
+ * If you don't need multi-threading, call this function and any one of the execution
+ * functions \ref rpa_stat_parse, \ref rpa_stat_match and \ref rpa_stat_scan from the
+ * main thread.
+ *
+ * The allocated \ref rpastat_t object must be destroyed with \ref rpa_stat_destroy.
+ *
+ * \param dbex BNF productions database created with \ref rpa_dbex_create.
+ * \param stacksize Execution stack size. The size is specified in byts.
+ * \return Returns a pointer to newly created \ref rpastat_t object or NULL if error occured.
+ */
 rpastat_t *rpa_stat_create(rpadbex_t *dbex, rulong stacksize);
+
+
+/**
+ * \brief Destroy an object of type \ref rpastat_t
+ *
+ * Destroy the object created with \ref rpa_stat_create. After calling this function
+ * the pointer is invalid and must never be used again.
+ *
+ * \param stat Pointer to object.
+ */
 void rpa_stat_destroy(rpastat_t *stat);
-rint rpa_stat_init(rpastat_t *stat, const rchar *input, const rchar *start, const rchar *end);
-void rpa_stat_cachedisable(rpastat_t *stat, ruint disable);
-void rpa_stat_cacheinvalidate(rpastat_t *stat);
-rint rpa_stat_encodingset(rpastat_t *stat, ruint encoding);
 
-rlong rpa_stat_exec(rpastat_t *stat, rvm_asmins_t *prog, rword off);
+
+rint rpa_stat_encodingset(rpastat_t *stat, ruint encoding);
 rlong rpa_stat_scan(rpastat_t *stat, rparule_t rid, const rchar *input, const rchar *start, const rchar *end, const rchar **where);
 rlong rpa_stat_match(rpastat_t *stat, rparule_t rid, const rchar *input, const rchar *start, const rchar *end);
 rlong rpa_stat_parse(rpastat_t *stat, rparule_t rid, const rchar *input, const rchar *start, const rchar *end, rarray_t **records);
 rint rpa_stat_abort(rpastat_t *stat);
-
-rint rpa_stat_matchchr(rpastat_t *stat, rssize_t top, rulong wc);
-rint rpa_stat_matchspchr(rpastat_t *stat, rssize_t top, rulong wc);
-rint rpa_stat_matchrng(rpastat_t *stat, rssize_t top, rulong wc1, rulong wc2);
-rlong rpa_stat_shift(rpastat_t *stat, rssize_t top);
+rlong rpa_stat_exec(rpastat_t *stat, rvm_asmins_t *prog, rword off);
 
 
 #ifdef __cplusplus
diff --git a/rpa/rpastatpriv.h b/rpa/rpastatpriv.h
new file mode 100644 (file)
index 0000000..477a08c
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef _RPASTATPRIV_H_
+#define _RPASTATPRIV_H_
+
+#include "rtypes.h"
+#include "rarray.h"
+#include "rvmreg.h"
+#include "rpavm.h"
+#include "rpadbex.h"
+#include "rpacache.h"
+#include "rpastat.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+struct rpastat_s {
+       rpadbex_t *dbex;
+       const rchar *input;
+       const rchar *start;
+       const rchar *end;
+       ruint error;
+       ruint encoding;
+       ruint debug;
+       rarray_t *records;
+       rarray_t *emitstack;
+       rarray_t *orphans;
+       rpainput_t *instackbuffer;
+       rpainput_t *instack;                    /* instack = &instackbuffer[1]; This allows R_TOP = -1, without any additional checks */
+       rulong instacksize;
+       rpacache_t *cache;
+       rpainmap_t ip;
+       rvmcpu_t *cpu;
+};
+
+rint rpa_stat_init(rpastat_t *stat, const rchar *input, const rchar *start, const rchar *end);
+void rpa_stat_cachedisable(rpastat_t *stat, ruint disable);
+void rpa_stat_cacheinvalidate(rpastat_t *stat);
+rint rpa_stat_matchchr(rpastat_t *stat, rssize_t top, rulong wc);
+rint rpa_stat_matchspchr(rpastat_t *stat, rssize_t top, rulong wc);
+rint rpa_stat_matchrng(rpastat_t *stat, rssize_t top, rulong wc1, rulong wc2);
+rlong rpa_stat_shift(rpastat_t *stat, rssize_t top);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
index ab67d65..bf852c5 100644 (file)
@@ -1,5 +1,5 @@
 #include "rpavm.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "rutf.h"
 #include "rmem.h"
 
index 9905eaf..9398693 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index d6d595b..f45bc44 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index 26e373b..f3563ca 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index f017b9e..12c41c7 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index f89f7c7..0aa83e0 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index 481c578..8ce1f8b 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index 9eb297a..1b41293 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index 56438a7..d45c022 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index 7327a89..0be313c 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 /*
index 9559a5c..18db205 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index 1b3ffff..2e1e91c 100644 (file)
@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
 
        for (i = 1; i < argc; i++) {
                if (r_strcmp(argv[i], "-i") == 0) {
-                       rpa_dbex_dumprules(dbex);
+                       rpa_dbex_dumpproductions(dbex);
                }
        }
 
@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
        for (i = 1; i < argc; i++) {
                if (r_strcmp(argv[i], "-d") == 0) {
                        if (++i < argc) {
-                               rpa_dbex_dumptree_s(dbex, argv[i], 0);
+                               rpa_dbex_dumptree(dbex, rpa_dbex_lookup_s(dbex, argv[i]));
                        }
                }
        }
index 72cf1a9..31b1cab 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index a36f37f..7dbedb9 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index 64a9fdd..8e82159 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"
 
 
index 036775f..3ec2356 100644 (file)
@@ -8,7 +8,7 @@
 #include <sys/mman.h>
 #include "rmem.h"
 #include "rpacompiler.h"
-#include "rpastat.h"
+#include "rpastatpriv.h"
 #include "common.h"