Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Initial work to format integer based on type. Control chars and Unico…
Browse files Browse the repository at this point in the history
…de yet to do.
  • Loading branch information
complexmath committed Sep 2, 2011
1 parent 89a65b5 commit 42b53f5
Showing 1 changed file with 91 additions and 3 deletions.
94 changes: 91 additions & 3 deletions src/core/demangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,15 @@ private struct Demangle
debug(trace) printf( "decodeNumber+\n" );
debug(trace) scope(success) printf( "decodeNumber-\n" );

auto num = sliceNumber();
return decodeNumber( sliceNumber() );
}


size_t decodeNumber( const(char)[] num )
{
debug(trace) printf( "decodeNumber+\n" );
debug(trace) scope(success) printf( "decodeNumber-\n" );

size_t val = 0;

foreach( i, e; num )
Expand Down Expand Up @@ -1099,6 +1107,7 @@ private struct Demangle
debug(trace) printf( "parseValue+\n" );
debug(trace) scope(success) printf( "parseValue-\n" );

printf( "*** %c\n", tok() );

This comment has been minimized.

Copy link
@WalterBright

WalterBright Sep 3, 2011

Member

printf is not defined. Fails to compile under Windows.

switch( tok() )
{
case 'n':
Expand All @@ -1111,12 +1120,12 @@ private struct Demangle
error( "Number expected" );
// fall-through intentional
case '0': .. case '9':
put( sliceNumber() );
putIntegerValue( name, type );
return;
case 'N':
next();
put( "-" );
put( sliceNumber() );
putIntegerValue( name, type );
return;
case 'e':
next();
Expand Down Expand Up @@ -1209,6 +1218,85 @@ private struct Demangle
}


void putIntegerValue( char[] name = null, char type = '\0' )
{
debug(trace) printf( "putIntegerValue+\n" );
debug(trace) scope(success) printf( "putIntegerValue-\n" );

switch( type )
{
case 'a': // char
case 'u': // wchar
case 'w': // dchar
{
auto val = sliceNumber();
auto num = decodeNumber( val );

switch( num )
{
case '\'':
put( "'\\''" );
return;
// \", \?
case '\\':
put( "'\\\\'" );
case '\a':
put( "'\\a'" );
return;
case '\b':
put( "'\\b'" );
return;
case '\f':
put( "'\\f'" );
case '\n':
put( "'\\n'" );
return;
case '\r':
put( "'\\r'" );
return;
case '\t':
put( "'\\t'" );
return;
case '\v':
put( "'\\v'" );
return;
default:
if( num < 0x20 || num == 0x7F )
{
// TODO: Put as hex.
put( val );
return;
}
else
{
// TODO: Handle wchar & dchar.
put( val );
return;
}
}
}
case 'b': // bool
put( decodeNumber() ? "true" : "false" );
return;
case 'h', 't', 'k': // ubyte, ushort, uint
put( sliceNumber() );
put( "u" );
return;
case 'l': // long
put( sliceNumber() );
put( "L" );
return;
case 'm': // ulong
put( sliceNumber() );
put( "uL" );
return;
default:
put( sliceNumber() );
return;
}
}


/*
TemplateArgs:
TemplateArg
Expand Down

1 comment on commit 42b53f5

@WalterBright
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now fails to compile with:

src\core\demangle.d(1067): Warning: statement is not reachable
src\core\demangle.d(1067): Warning: statement is not reachable
src\core\demangle.d(1243): Error: switch case fallthrough - use 'goto case;' if intended
src\core\demangle.d(1251): Error: switch case fallthrough - use 'goto case;' if intended

Please sign in to comment.