X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FLangDumpDecl.c;fp=bundles%2Forg.simantics.databoard%2Fcpp%2FDataBoardTest%2FDataBoard%2FLangDumpDecl.c;h=d72cfbf05e82b1b72aca4ccbbb93a20d060141f2;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/LangDumpDecl.c b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/LangDumpDecl.c new file mode 100644 index 000000000..d72cfbf05 --- /dev/null +++ b/bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/LangDumpDecl.c @@ -0,0 +1,644 @@ +/** \file + * This C source file was generated by $ANTLR version 3.2 Sep 23, 2009 12:02:23 + * + * - From the grammar source file : LangDumpDecl.g + * - On : 2010-02-24 13:30:09 + * - for the tree parser : LangDumpDeclTreeParser * + * Editing it, at least manually, is not wise. + * + * C language generator and runtime by Jim Idle, jimi|hereisanat|idle|dotgoeshere|ws. + * + * +*/ +// [The "BSD licence"] +// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC +// http://www.temporal-wave.com +// http://www.linkedin.com/in/jimidle +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/* ----------------------------------------- + * Include the ANTLR3 generated header file. + */ +#include "LangDumpDecl.h" +/* ----------------------------------------- */ + + + + + +/* MACROS that hide the C interface implementations from the + * generated code, which makes it a little more understandable to the human eye. + * I am very much against using C pre-processor macros for function calls and bits + * of code as you cannot see what is happening when single stepping in debuggers + * and so on. The exception (in my book at least) is for generated code, where you are + * not maintaining it, but may wish to read and understand it. If you single step it, you know that input() + * hides some indirect calls, but is always referring to the input stream. This is + * probably more readable than ctx->input->istream->input(snarfle0->blarg) and allows me to rejig + * the runtime interfaces without changing the generated code too often, without + * confusing the reader of the generated output, who may not wish to know the gory + * details of the interface inheritance. + */ + +#define CTX ctx + +/* Aids in accessing scopes for grammar programmers + */ +#undef SCOPE_TYPE +#undef SCOPE_STACK +#undef SCOPE_TOP +#define SCOPE_TYPE(scope) pLangDumpDecl_##scope##_SCOPE +#define SCOPE_STACK(scope) pLangDumpDecl_##scope##Stack +#define SCOPE_TOP(scope) ctx->pLangDumpDecl_##scope##Top +#define SCOPE_SIZE(scope) ctx->pLangDumpDecl_##scope##Stack_limit +#define SCOPE_INSTANCE(scope, i) (ctx->SCOPE_STACK(scope)->get(ctx->SCOPE_STACK(scope),i)) + +/* Macros for accessing things in the parser + */ + +#undef PARSER +#undef RECOGNIZER +#undef HAVEPARSEDRULE +#undef INPUT +#undef STRSTREAM +#undef HASEXCEPTION +#undef EXCEPTION +#undef MATCHT +#undef MATCHANYT +#undef FOLLOWSTACK +#undef FOLLOWPUSH +#undef FOLLOWPOP +#undef PRECOVER +#undef PREPORTERROR +#undef LA +#undef LT +#undef CONSTRUCTEX +#undef CONSUME +#undef MARK +#undef REWIND +#undef REWINDLAST +#undef PERRORRECOVERY +#undef HASFAILED +#undef FAILEDFLAG +#undef RECOVERFROMMISMATCHEDSET +#undef RECOVERFROMMISMATCHEDELEMENT +#undef BACKTRACKING +#undef ADAPTOR +#undef RULEMEMO +#undef SEEK +#undef INDEX +#undef DBG + +#define PARSER ctx->pTreeParser +#define RECOGNIZER PARSER->rec +#define PSRSTATE RECOGNIZER->state +#define HAVEPARSEDRULE(r) RECOGNIZER->alreadyParsedRule(RECOGNIZER, r) +#define INPUT PARSER->ctnstream +#define ISTREAM INPUT->tnstream->istream +#define STRSTREAM INPUT->tnstream +#define HASEXCEPTION() (PSRSTATE->error == ANTLR3_TRUE) +#define EXCEPTION PSRSTATE->exception +#define MATCHT(t, fs) RECOGNIZER->match(RECOGNIZER, t, fs) +#define MATCHANYT() RECOGNIZER->matchAny(RECOGNIZER) +#define FOLLOWSTACK PSRSTATE->following +#define FOLLOWPUSH(x) FOLLOWSTACK->push(FOLLOWSTACK, ((void *)(&(x))), NULL) +#define FOLLOWPOP() FOLLOWSTACK->pop(FOLLOWSTACK) +#define PRECOVER() RECOGNIZER->recover(RECOGNIZER) +#define PREPORTERROR() RECOGNIZER->reportError(RECOGNIZER) +#define LA(n) ISTREAM->_LA(ISTREAM, n) +#define LT(n) INPUT->tnstream->_LT(INPUT->tnstream, n) +#define CONSTRUCTEX() RECOGNIZER->exConstruct(RECOGNIZER) +#define CONSUME() ISTREAM->consume(ISTREAM) +#define MARK() ISTREAM->mark(ISTREAM) +#define REWIND(m) ISTREAM->rewind(ISTREAM, m) +#define REWINDLAST() ISTREAM->rewindLast(ISTREAM) +#define PERRORRECOVERY PSRSTATE->errorRecovery +#define FAILEDFLAG PSRSTATE->failed +#define HASFAILED() (FAILEDFLAG == ANTLR3_TRUE) +#define BACKTRACKING PSRSTATE->backtracking +#define RECOVERFROMMISMATCHEDSET(s) RECOGNIZER->recoverFromMismatchedSet(RECOGNIZER, s) +#define RECOVERFROMMISMATCHEDELEMENT(e) RECOGNIZER->recoverFromMismatchedElement(RECOGNIZER, s) +#define ADAPTOR INPUT->adaptor +#define RULEMEMO PSRSTATE->ruleMemo +#define SEEK(n) ISTREAM->seek(ISTREAM, n) +#define INDEX() ISTREAM->index(ISTREAM) +#define DBG RECOGNIZER->debugger + + +#define TOKTEXT(tok, txt) tok, (pANTLR3_UINT8)txt + +/* The 4 tokens defined below may well clash with your own #defines or token types. If so + * then for the present you must use different names for your defines as these are hard coded + * in the code generator. It would be better not to use such names internally, and maybe + * we can change this in a forthcoming release. I deliberately do not #undef these + * here as this will at least give you a redefined error somewhere if they clash. + */ +#define UP ANTLR3_TOKEN_UP +#define DOWN ANTLR3_TOKEN_DOWN +#define EOR ANTLR3_TOKEN_EOR +#define INVALID ANTLR3_TOKEN_INVALID + + +/* ============================================================================= + * Functions to create and destroy scopes. First come the rule scopes, followed + * by the global declared scopes. + */ + + + +/* ============================================================================= */ + +/* ============================================================================= + * Start of recognizer + */ + + + +/** \brief Table of all token names in symbolic order, mainly used for + * error reporting. + */ +pANTLR3_UINT8 LangDumpDeclTokenNames[7+4] + = { + (pANTLR3_UINT8) "", /* String to print to indicate an invalid token */ + (pANTLR3_UINT8) "", + (pANTLR3_UINT8) "", + (pANTLR3_UINT8) "", + (pANTLR3_UINT8) "DECL", + (pANTLR3_UINT8) "ID", + (pANTLR3_UINT8) "INTTYPE", + (pANTLR3_UINT8) "FLOATTYPE", + (pANTLR3_UINT8) "INT", + (pANTLR3_UINT8) "WS", + (pANTLR3_UINT8) "';'" + }; + + + +// Forward declare the locally static matching functions we have generated. +// +static void decl (pLangDumpDecl ctx); +static void decls (pLangDumpDecl ctx); +static void type (pLangDumpDecl ctx); +static LangDumpDecl_declarator_return declarator (pLangDumpDecl ctx); +static void LangDumpDeclFree(pLangDumpDecl ctx); +/* For use in tree output where we are accumulating rule labels via label += ruleRef + * we need a function that knows how to free a return scope when the list is destroyed. + * We cannot just use ANTLR3_FREE because in debug tracking mode, this is a macro. + */ +static void ANTLR3_CDECL freeScope(void * scope) +{ + ANTLR3_FREE(scope); +} + +/** \brief Name of the grammar file that generated this code + */ +static const char fileName[] = "LangDumpDecl.g"; + +/** \brief Return the name of the grammar file that generated this code. + */ +static const char * getGrammarFileName() +{ + return fileName; +} +/** \brief Create a new LangDumpDecl parser and return a context for it. + * + * \param[in] instream Pointer to an input stream interface. + * + * \return Pointer to new parser context upon success. + */ +ANTLR3_API pLangDumpDecl +LangDumpDeclNew (pANTLR3_COMMON_TREE_NODE_STREAM instream) +{ + // See if we can create a new parser with the standard constructor + // + return LangDumpDeclNewSSD(instream, NULL); +} + +/** \brief Create a new LangDumpDecl parser and return a context for it. + * + * \param[in] instream Pointer to an input stream interface. + * + * \return Pointer to new parser context upon success. + */ +ANTLR3_API pLangDumpDecl +LangDumpDeclNewSSD (pANTLR3_COMMON_TREE_NODE_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state) +{ + pLangDumpDecl ctx; /* Context structure we will build and return */ + + ctx = (pLangDumpDecl) ANTLR3_CALLOC(1, sizeof(LangDumpDecl)); + + if (ctx == NULL) + { + // Failed to allocate memory for parser context + // + return NULL; + } + + /* ------------------------------------------------------------------- + * Memory for basic structure is allocated, now to fill in + * the base ANTLR3 structures. We initialize the function pointers + * for the standard ANTLR3 parser function set, but upon return + * from here, the programmer may set the pointers to provide custom + * implementations of each function. + * + * We don't use the macros defined in LangDumpDecl.h here, in order that you can get a sense + * of what goes where. + */ + + /* Create a base Tree parser/recognizer, using the supplied tree node stream + */ + ctx->pTreeParser = antlr3TreeParserNewStream(ANTLR3_SIZE_HINT, instream, state); + /* Install the implementation of our LangDumpDecl interface + */ + ctx->decl = decl; + ctx->decls = decls; + ctx->type = type; + ctx->declarator = declarator; + ctx->free = LangDumpDeclFree; + ctx->getGrammarFileName = getGrammarFileName; + + /* Install the scope pushing methods. + */ + + + + + + /* Install the token table + */ + PSRSTATE->tokenNames = LangDumpDeclTokenNames; + + + /* Return the newly built parser to the caller + */ + return ctx; +} + +/** Free the parser resources + */ + static void + LangDumpDeclFree(pLangDumpDecl ctx) + { + /* Free any scope memory + */ + + + // Free this parser + // + ctx->pTreeParser->free(ctx->pTreeParser); + ANTLR3_FREE(ctx); + + /* Everything is released, so we can return + */ + return; + } + +/** Return token names used by this tree parser + * + * The returned pointer is used as an index into the token names table (using the token + * number as the index). + * + * \return Pointer to first char * in the table. + */ +static pANTLR3_UINT8 *getTokenNames() +{ + return LangDumpDeclTokenNames; +} + + +/* Declare the bitsets + */ + +/** Bitset defining follow set for error recovery in rule state: FOLLOW_decls_in_decl58 */ +static ANTLR3_BITWORD FOLLOW_decls_in_decl58_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000012) }; +static ANTLR3_BITSET_LIST FOLLOW_decls_in_decl58 = { FOLLOW_decls_in_decl58_bits, 1 }; +/** Bitset defining follow set for error recovery in rule state: FOLLOW_DECL_in_decls71 */ +static ANTLR3_BITWORD FOLLOW_DECL_in_decls71_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000004) }; +static ANTLR3_BITSET_LIST FOLLOW_DECL_in_decls71 = { FOLLOW_DECL_in_decls71_bits, 1 }; +/** Bitset defining follow set for error recovery in rule state: FOLLOW_type_in_decls73 */ +static ANTLR3_BITWORD FOLLOW_type_in_decls73_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000020) }; +static ANTLR3_BITSET_LIST FOLLOW_type_in_decls73 = { FOLLOW_type_in_decls73_bits, 1 }; +/** Bitset defining follow set for error recovery in rule state: FOLLOW_declarator_in_decls77 */ +static ANTLR3_BITWORD FOLLOW_declarator_in_decls77_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000008) }; +static ANTLR3_BITSET_LIST FOLLOW_declarator_in_decls77 = { FOLLOW_declarator_in_decls77_bits, 1 }; +/** Bitset defining follow set for error recovery in rule state: FOLLOW_INTTYPE_in_type110 */ +static ANTLR3_BITWORD FOLLOW_INTTYPE_in_type110_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; +static ANTLR3_BITSET_LIST FOLLOW_INTTYPE_in_type110 = { FOLLOW_INTTYPE_in_type110_bits, 1 }; +/** Bitset defining follow set for error recovery in rule state: FOLLOW_ID_in_declarator126 */ +static ANTLR3_BITWORD FOLLOW_ID_in_declarator126_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) }; +static ANTLR3_BITSET_LIST FOLLOW_ID_in_declarator126 = { FOLLOW_ID_in_declarator126_bits, 1 }; + + + + +/* ============================================== + * Parsing rules + */ +/** + * $ANTLR start decl + * LangDumpDecl.g:10:1: decl : ( decls )+ ; + */ +static void +decl(pLangDumpDecl ctx) +{ + /* Initialize rule variables + */ + + + { + // LangDumpDecl.g:10:6: ( ( decls )+ ) + // LangDumpDecl.g:10:8: ( decls )+ + { + // LangDumpDecl.g:10:8: ( decls )+ + { + int cnt1=0; + + for (;;) + { + int alt1=2; + switch ( LA(1) ) + { + case DECL: + { + alt1=1; + } + break; + + } + + switch (alt1) + { + case 1: + // LangDumpDecl.g:10:8: decls + { + FOLLOWPUSH(FOLLOW_decls_in_decl58); + decls(ctx); + + FOLLOWPOP(); + if (HASEXCEPTION()) + { + goto ruledeclEx; + } + + + } + break; + + default: + + if ( cnt1 >= 1 ) + { + goto loop1; + } + /* mismatchedSetEx() + */ + CONSTRUCTEX(); + EXCEPTION->type = ANTLR3_EARLY_EXIT_EXCEPTION; + EXCEPTION->name = (void *)ANTLR3_EARLY_EXIT_NAME; + + + goto ruledeclEx; + } + cnt1++; + } + loop1: ; /* Jump to here if this rule does not match */ + } + + } + + } + + + // This is where rules clean up and exit + // + goto ruledeclEx; /* Prevent compiler warnings */ + ruledeclEx: ; + + if (HASEXCEPTION()) + { + PREPORTERROR(); + PRECOVER(); + } + + + return ; +} +/* $ANTLR end decl */ + +/** + * $ANTLR start decls + * LangDumpDecl.g:13:1: decls : ^( DECL type d= declarator ) ; + */ +static void +decls(pLangDumpDecl ctx) +{ + LangDumpDecl_declarator_return d; + #undef RETURN_TYPE_d + #define RETURN_TYPE_d LangDumpDecl_declarator_return + + /* Initialize rule variables + */ + + + { + // LangDumpDecl.g:13:7: ( ^( DECL type d= declarator ) ) + // LangDumpDecl.g:13:9: ^( DECL type d= declarator ) + { + MATCHT(DECL, &FOLLOW_DECL_in_decls71); + if (HASEXCEPTION()) + { + goto ruledeclsEx; + } + + + MATCHT(ANTLR3_TOKEN_DOWN, NULL); + if (HASEXCEPTION()) + { + goto ruledeclsEx; + } + + FOLLOWPUSH(FOLLOW_type_in_decls73); + type(ctx); + + FOLLOWPOP(); + if (HASEXCEPTION()) + { + goto ruledeclsEx; + } + + FOLLOWPUSH(FOLLOW_declarator_in_decls77); + d=declarator(ctx); + + FOLLOWPOP(); + if (HASEXCEPTION()) + { + goto ruledeclsEx; + } + + + MATCHT(ANTLR3_TOKEN_UP, NULL); + if (HASEXCEPTION()) + { + goto ruledeclsEx; + } + + { + + printf("int %s\n", (STRSTREAM->toStringSS(STRSTREAM, d.start, d.start))->chars); + + } + + } + + } + + + // This is where rules clean up and exit + // + goto ruledeclsEx; /* Prevent compiler warnings */ + ruledeclsEx: ; + + if (HASEXCEPTION()) + { + PREPORTERROR(); + PRECOVER(); + } + + + return ; +} +/* $ANTLR end decls */ + +/** + * $ANTLR start type + * LangDumpDecl.g:21:1: type : INTTYPE ; + */ +static void +type(pLangDumpDecl ctx) +{ + /* Initialize rule variables + */ + + + { + // LangDumpDecl.g:21:6: ( INTTYPE ) + // LangDumpDecl.g:21:8: INTTYPE + { + MATCHT(INTTYPE, &FOLLOW_INTTYPE_in_type110); + if (HASEXCEPTION()) + { + goto ruletypeEx; + } + + + } + + } + + + // This is where rules clean up and exit + // + goto ruletypeEx; /* Prevent compiler warnings */ + ruletypeEx: ; + + if (HASEXCEPTION()) + { + PREPORTERROR(); + PRECOVER(); + } + + + return ; +} +/* $ANTLR end type */ + +/** + * $ANTLR start declarator + * LangDumpDecl.g:23:1: declarator : i= ID ; + */ +static LangDumpDecl_declarator_return +declarator(pLangDumpDecl ctx) +{ + LangDumpDecl_declarator_return retval; + + pANTLR3_BASE_TREE i; + + /* Initialize rule variables + */ + + + i = NULL; + retval.start = LT(1); retval.stop = retval.start; + + { + // LangDumpDecl.g:24:6: (i= ID ) + // LangDumpDecl.g:24:8: i= ID + { + i = (pANTLR3_BASE_TREE) MATCHT(ID, &FOLLOW_ID_in_declarator126); + if (HASEXCEPTION()) + { + goto ruledeclaratorEx; + } + + + } + + } + + + // This is where rules clean up and exit + // + goto ruledeclaratorEx; /* Prevent compiler warnings */ + ruledeclaratorEx: ; + + if (HASEXCEPTION()) + { + PREPORTERROR(); + PRECOVER(); + } + + + return retval; +} +/* $ANTLR end declarator */ +/* End of parsing rules + * ============================================== + */ + +/* ============================================== + * Syntactic predicates + */ +/* End of syntactic predicates + * ============================================== + */ + + + + + + +/* End of code + * ============================================================================= + */