From 6e3af69137f6fbe000ce2d8dca33cef764722a40 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Sun, 7 Nov 2021 15:24:41 -0800 Subject: moved the findAlphType code from colm over here --- src/common.cc | 37 ------------------------------------- src/ncommon.cc | 39 +++++++++++++++++++++++++++++++++++++++ src/nragel.h | 11 +++++++++++ src/parsedata.cc | 3 ++- 4 files changed, 52 insertions(+), 38 deletions(-) create mode 100644 src/nragel.h diff --git a/src/common.cc b/src/common.cc index b36dcace..ff8934e6 100644 --- a/src/common.cc +++ b/src/common.cc @@ -28,43 +28,6 @@ #include "ragel.h" -HostType *findAlphType( const HostLang *hostLang, const char *s1 ) -{ - for ( int i = 0; i < hostLang->numHostTypes; i++ ) { - if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && - hostLang->hostTypes[i].data2 == 0 ) - { - return hostLang->hostTypes + i; - } - } - - return 0; -} - -HostType *findAlphType( const HostLang *hostLang, const char *s1, const char *s2 ) -{ - for ( int i = 0; i < hostLang->numHostTypes; i++ ) { - if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && - hostLang->hostTypes[i].data2 != 0 && - strcmp( s2, hostLang->hostTypes[i].data2 ) == 0 ) - { - return hostLang->hostTypes + i; - } - } - - return 0; -} - -HostType *findAlphTypeInternal( const HostLang *hostLang, const char *s1 ) -{ - for ( int i = 0; i < hostLang->numHostTypes; i++ ) { - if ( strcmp( s1, hostLang->hostTypes[i].internalName ) == 0 ) - return hostLang->hostTypes + i; - } - - return 0; -} - std::streamsize output_filter::countAndWrite( const char *s, std::streamsize n ) { for ( int i = 0; i < n; i++ ) { diff --git a/src/ncommon.cc b/src/ncommon.cc index ae959efd..4e7f270d 100644 --- a/src/ncommon.cc +++ b/src/ncommon.cc @@ -26,6 +26,8 @@ #include #include +#include "nragel.h" + /* * C */ @@ -68,3 +70,40 @@ extern "C" const HostLang hostLangC = { &genLineDirectiveC }; +HostType *findAlphType( const HostLang *hostLang, const char *s1 ) +{ + for ( int i = 0; i < hostLang->numHostTypes; i++ ) { + if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && + hostLang->hostTypes[i].data2 == 0 ) + { + return hostLang->hostTypes + i; + } + } + + return 0; +} + +HostType *findAlphType( const HostLang *hostLang, const char *s1, const char *s2 ) +{ + for ( int i = 0; i < hostLang->numHostTypes; i++ ) { + if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && + hostLang->hostTypes[i].data2 != 0 && + strcmp( s2, hostLang->hostTypes[i].data2 ) == 0 ) + { + return hostLang->hostTypes + i; + } + } + + return 0; +} + +HostType *findAlphTypeInternal( const HostLang *hostLang, const char *s1 ) +{ + for ( int i = 0; i < hostLang->numHostTypes; i++ ) { + if ( strcmp( s1, hostLang->hostTypes[i].internalName ) == 0 ) + return hostLang->hostTypes + i; + } + + return 0; +} + diff --git a/src/nragel.h b/src/nragel.h new file mode 100644 index 00000000..f8c7f4ad --- /dev/null +++ b/src/nragel.h @@ -0,0 +1,11 @@ +#ifndef _NRAGEL_H +#define _NRAGEL_H + +#include +#include + +HostType *findAlphType( const HostLang *hostLang, const char *s1 ); +HostType *findAlphType( const HostLang *hostLang, const char *s1, const char *s2 ); +HostType *findAlphTypeInternal( const HostLang *hostLang, const char *s1 ); + +#endif diff --git a/src/parsedata.cc b/src/parsedata.cc index 9eb0b262..07474582 100644 --- a/src/parsedata.cc +++ b/src/parsedata.cc @@ -26,13 +26,14 @@ #include #include +#include #include #include "parsedata.h" #include "parsetree.h" #include "mergesort.h" #include "version.h" #include "inputdata.h" -#include +#include "nragel.h" using namespace std; -- cgit v1.2.1