"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/common.cc" between
ragel-7.0.0.11.tar.gz and ragel-7.0.0.12.tar.gz

About: Ragel compiles executable finite state machines from regular languages (C, C++, Obj-C, C#, D, Java, Go and Ruby). Development version.

common.cc  (ragel-7.0.0.11):common.cc  (ragel-7.0.0.12)
skipping to change at line 34 skipping to change at line 34
#include "common.h" #include "common.h"
#include "stdlib.h" #include "stdlib.h"
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include "ragel.h" #include "ragel.h"
/* /*
* C * C
*/ */
const char *c_defaultOutFn( const char *inputFileName ) const char *defaultOutFnC( const char *inputFileName )
{ {
const char *ext = findFileExtension( inputFileName ); const char *ext = findFileExtension( inputFileName );
if ( ext != 0 && strcmp( ext, ".rh" ) == 0 ) if ( ext != 0 && strcmp( ext, ".rh" ) == 0 )
return fileNameFromStem( inputFileName, ".h" ); return fileNameFromStem( inputFileName, ".h" );
else else
return fileNameFromStem( inputFileName, ".c" ); return fileNameFromStem( inputFileName, ".c" );
} }
HostType hostTypesC[] = HostType hostTypesC[] =
{ {
{ "char", 0, "char", true, true, false, CHAR_MIN, CHAR_ { "char", 0, "char", true, true, false, CHAR_MIN, CHAR_
MAX, 0, 0, sizeof(char) }, MAX, 0, 0, sizeof(char) },
{ "signed", "char", "char", true, true, false, CHAR_MIN, CHAR_
MAX, 0, 0, sizeof(char) },
{ "unsigned", "char", "uchar", false, true, false, 0, 0, 0, UCHAR_MAX, sizeof(unsigned char) }, { "unsigned", "char", "uchar", false, true, false, 0, 0, 0, UCHAR_MAX, sizeof(unsigned char) },
{ "short", 0, "short", true, true, false, SHRT_MIN, SHRT_ { "short", 0, "short", true, true, false, SHRT_MIN, SHRT_
MAX, 0, 0, sizeof(short) }, MAX, 0, 0, sizeof(short) },
{ "signed", "short", "short", true, true, false, SHRT_MIN, SHRT_
MAX, 0, 0, sizeof(short) },
{ "unsigned", "short", "ushort", false, true, false, 0, 0, 0, USHRT_MAX, sizeof(unsigned short) }, { "unsigned", "short", "ushort", false, true, false, 0, 0, 0, USHRT_MAX, sizeof(unsigned short) },
{ "int", 0, "int", true, true, false, INT_MIN, INT_M { "int", 0, "int", true, true, false, INT_MIN, INT_M
AX, 0, 0, sizeof(int) }, AX, 0, 0, sizeof(int) },
{ "signed", "int", "int", true, true, false, INT_MIN, INT_M
AX, 0, 0, sizeof(int) },
{ "unsigned", "int", "uint", false, true, false, 0, 0, 0, UINT_MAX, sizeof(unsigned int) }, { "unsigned", "int", "uint", false, true, false, 0, 0, 0, UINT_MAX, sizeof(unsigned int) },
{ "long", 0, "long", true, true, false, LONG_MIN, LONG_ { "long", 0, "long", true, true, false, LONG_MIN, LONG_
MAX, 0, 0, sizeof(long) }, MAX, 0, 0, sizeof(long) },
{ "signed", "long", "long", true, true, false, LONG_MIN, LONG_
MAX, 0, 0, sizeof(long) },
{ "unsigned", "long", "ulong", false, true, false, 0, 0, 0, ULONG_MAX, sizeof(unsigned long) }, { "unsigned", "long", "ulong", false, true, false, 0, 0, 0, ULONG_MAX, sizeof(unsigned long) },
}; };
const HostLang hostLangC = { const HostLang hostLangC = {
"C", hostTypesC,
"-C", 12,
(HostLang::Lang)-1, 0,
hostTypesC, 8,
hostTypesC+0,
true, true,
false, false, /* loopLabels */
"c",
&c_defaultOutFn,
&makeCodeGen,
Direct, Direct,
GotoFeature GotoFeature,
&makeCodeGen,
&defaultOutFnC,
&genLineDirectiveC
}; };
/* /*
* ASM * ASM
*/ */
const char *asm_defaultOutFn( const char *inputFileName ) const char *defaultOutFnAsm( const char *inputFileName )
{ {
return fileNameFromStem( inputFileName, ".s" ); return fileNameFromStem( inputFileName, ".s" );
} }
HostType hostTypesAsm[] = HostType hostTypesAsm[] =
{ {
{ "char", 0, "char", true, true, false, CHAR_MIN, CHAR_ MAX, 0, 0, sizeof(char) }, { "char", 0, "char", true, true, false, CHAR_MIN, CHAR_ MAX, 0, 0, sizeof(char) },
{ "unsigned", "char", "uchar", false, true, false, 0, 0, 0, UCHAR_MAX, sizeof(unsigned char) }, { "unsigned", "char", "uchar", false, true, false, 0, 0, 0, UCHAR_MAX, sizeof(unsigned char) },
{ "short", 0, "short", true, true, false, SHRT_MIN, SHRT_ MAX, 0, 0, sizeof(short) }, { "short", 0, "short", true, true, false, SHRT_MIN, SHRT_ MAX, 0, 0, sizeof(short) },
{ "unsigned", "short", "ushort", false, true, false, 0, 0, 0, USHRT_MAX, sizeof(unsigned short) }, { "unsigned", "short", "ushort", false, true, false, 0, 0, 0, USHRT_MAX, sizeof(unsigned short) },
{ "int", 0, "int", true, true, false, INT_MIN, INT_M AX, 0, 0, sizeof(int) }, { "int", 0, "int", true, true, false, INT_MIN, INT_M AX, 0, 0, sizeof(int) },
{ "unsigned", "int", "uint", false, true, false, 0, 0, 0, UINT_MAX, sizeof(unsigned int) }, { "unsigned", "int", "uint", false, true, false, 0, 0, 0, UINT_MAX, sizeof(unsigned int) },
{ "long", 0, "long", true, true, false, LONG_MIN, LONG_ MAX, 0, 0, sizeof(long) }, { "long", 0, "long", true, true, false, LONG_MIN, LONG_ MAX, 0, 0, sizeof(long) },
{ "unsigned", "long", "ulong", false, true, false, 0, 0, 0, ULONG_MAX, sizeof(unsigned long) }, { "unsigned", "long", "ulong", false, true, false, 0, 0, 0, ULONG_MAX, sizeof(unsigned long) },
}; };
const HostLang hostLangAsm = { const HostLang hostLangAsm = {
"ASM", hostTypesAsm,
"--asm", 8,
(HostLang::Lang)-1, 0,
hostTypesAsm, 8,
hostTypesAsm+0,
true, true,
false, false, /* loopLabels */
"no-lang",
&asm_defaultOutFn,
&asm_makeCodeGen,
Direct, Direct,
GotoFeature GotoFeature,
&makeCodeGenAsm,
&defaultOutFnC,
&genLineDirectiveAsm
}; };
const HostLang *hostLangs[] = {
&hostLangC,
};
const int numHostLangs = sizeof(hostLangs)/sizeof(hostLangs[0]);
HostType *findAlphType( const HostLang *hostLang, const char *s1 ) HostType *findAlphType( const HostLang *hostLang, const char *s1 )
{ {
for ( int i = 0; i < hostLang->numHostTypes; i++ ) { for ( int i = 0; i < hostLang->numHostTypes; i++ ) {
if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 &&
hostLang->hostTypes[i].data2 == 0 ) hostLang->hostTypes[i].data2 == 0 )
{ {
return hostLang->hostTypes + i; return hostLang->hostTypes + i;
} }
} }
skipping to change at line 277 skipping to change at line 271
} }
/* We did not find a match. Bad Argument. */ /* We did not find a match. Bad Argument. */
parameter = argChar; parameter = argChar;
paramArg = 0; paramArg = 0;
argOffset += 1; argOffset += 1;
state = invalid; state = invalid;
return true; return true;
} }
/* Counts newlines before sending sync. */
int output_filter::sync( )
{
line += 1;
return std::filebuf::sync();
}
std::streamsize output_filter::countAndWrite( const char *s, std::streamsize n ) std::streamsize output_filter::countAndWrite( const char *s, std::streamsize n )
{ {
for ( int i = 0; i < n; i++ ) { for ( int i = 0; i < n; i++ ) {
switch ( s[i] ) { switch ( s[i] ) {
case '\n': case '\n':
line += 1; line += 1;
break; break;
case '{': case '{':
/* If we detec an open block then eliminate the single-in
dent
* addition, which is to account for single statements. *
/
singleIndent = false;
level += 1; level += 1;
break; break;
case '}': case '}':
level -= 1; level -= 1;
break; break;
} }
} }
return std::filebuf::xsputn( s, n ); return std::filebuf::xsputn( s, n );
} }
bool openSingleIndent( const char *s, int n )
{
if ( n >= 3 && memcmp( s, "if ", 3 ) == 0 )
return true;
if ( n >= 8 && memcmp( s, "else if ", 8 ) == 0 )
return true;
if ( n >= 5 && memcmp( s, "else\n", 4 ) == 0 )
return true;
return false;
}
/* Counts newlines before sending sync. */
int output_filter::sync( )
{
line += 1;
return std::filebuf::sync();
}
/* Counts newlines before sending data out to file. */ /* Counts newlines before sending data out to file. */
std::streamsize output_filter::xsputn( const char *s, std::streamsize n ) std::streamsize output_filter::xsputn( const char *s, std::streamsize n )
{ {
std::streamsize ret = n; std::streamsize ret = n;
int l; int l;
restart: restart:
if ( indent ) { if ( indent ) {
/* Consume mode Looking for the first non-whitespace. */ /* Consume mode Looking for the first non-whitespace. */
while ( n > 0 && ( *s == ' ' || *s == '\t' ) ) { while ( n > 0 && ( *s == ' ' || *s == '\t' ) ) {
s += 1; s += 1;
n -= 1; n -= 1;
} }
if ( n > 0 ) { if ( n > 0 ) {
int tabs = level; int tabs = level + ( singleIndent ? 1 : 0 );
if ( *s == '}' ) { if ( *s == '}' ) {
/* If the next char is de-dent, then reduce the t abs. This is /* If the next char is de-dent, then reduce the t abs. This is
* not a stream state change. The level reduction will be * not a stream state change. The level reduction will be
* computed in write. */ * computed in write. */
tabs -= 1; tabs -= 1;
} }
/* Found some data, print the indentation and turn off in /* Note that the count and write will eliminate this if i
dentation t detects
* mode. */ * an open block. */
for ( l = 0; l < tabs; l++ ) if ( openSingleIndent( s, n ) )
countAndWrite( "\t", 1 ); singleIndent = true;
else
singleIndent = false;
if ( *s != '#' ) {
/* Found some data, print the indentation and tur
n off indentation
* mode. */
for ( l = 0; l < tabs; l++ )
countAndWrite( "\t", 1 );
}
indent = 0; indent = 0;
goto restart; goto restart;
} }
} }
else { else {
char *nl; char *nl;
if ( (nl = (char*)memchr( s, '\n', n )) ) { if ( (nl = (char*)memchr( s, '\n', n )) ) {
/* Print up to and including the newline. */ /* Print up to and including the newline. */
skipping to change at line 421 skipping to change at line 441
return retVal; return retVal;
} }
exit_object endp; exit_object endp;
void operator<<( std::ostream &out, exit_object & ) void operator<<( std::ostream &out, exit_object & )
{ {
out << std::endl; out << std::endl;
throw AbortCompile( 1 ); throw AbortCompile( 1 );
} }
void genLineDirectiveC( std::ostream &out, bool lineDirectives, int line, const
char *fileName )
{
if ( !lineDirectives )
out << "/* ";
out << "#line " << line << " \"";
for ( const char *pc = fileName; *pc != 0; pc++ ) {
if ( *pc == '\\' )
out << "\\\\";
else if ( *pc == '"' )
out << "\\\"";
else
out << *pc;
}
out << '"';
if ( !lineDirectives )
out << " */";
out << '\n';
}
void genLineDirectiveAsm( std::ostream &out, bool lineDirectives, int line, cons
t char *fileName )
{
out << "/* #line " << line << " \"";
for ( const char *pc = fileName; *pc != 0; pc++ ) {
if ( *pc == '\\' )
out << "\\\\";
else if ( *pc == '"' )
out << "\\\"";
else
out << *pc;
}
out << '"';
out << " */\n";
}
void genLineDirectiveTrans( std::ostream &out, bool lineDirectives, int line, co
nst char *fileName )
{
}
 End of changes. 19 change blocks. 
49 lines changed or deleted 76 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)