static void leading( VBUF *pbuf, char lead, int len ) /***************************************************/ { while( len-- > 0 ) { VbufConcChr( pbuf, lead ); } }
static DUMP_INFO* bufferChr( // CONCATENATE CHAR TO BUFFER DUMP_INFO* di, // - dump information char chr ) // - to be concatenated { VbufConcChr( &di->buffer, chr ); return di; }
void CmdLnCtxInfo( // PRINT CONTEXT INFO void ) { CTX_CL* entry; // - current entry VBUF buf; // - buffer VbufInit( &buf ); for( entry = VstkTop( &cmdLnContexts ) ; entry != NULL ; entry = VstkNext( &cmdLnContexts, entry ) ) { VbufRewind( &buf ); switch( entry->base.ctx_type ) { case CTX_CLTYPE_ENV : VbufConcChr( &buf, '@' ); VbufConcStr( &buf, entry->env.var ); break; case CTX_CLTYPE_FC : VbufConcStr( &buf, "batch file of commands, line " ); VbufConcDecimal( &buf, CompInfo.fc_file_line ); break; case CTX_CLTYPE_PGM : VbufConcStr( &buf, "command line" ); break; case CTX_CLTYPE_FILE : VbufConcStr( &buf, SrcFileFullName( entry->file.source ) ); break; DbgDefault( "bad command-line context" ); } if( entry->base.sw_ptr != NULL ) { size_t size; char const * not_used; char const* old = CmdScanAddr(); CmdScanInit( entry->base.sw_ptr ); CmdScanChar(); size = CmdScanOption( ¬_used ) + 1; CmdScanInit( old ); VbufConcStr( &buf, ", switch: " ); for( old = entry->base.sw_ptr; size > 0; ++old, --size ) { VbufConcChr( &buf, *old ); } } InfMsgPtr( INF_SWITCH, VbufString( &buf ) ); } VbufFree( &buf ); }
// this prints grammatically correct messages. // i.e. no errors, or 1 error, or 5 errors static void intPrint // PRINT INT LINE SEGMENT ( VBUF *buf , char *thing , char *end , unsigned int count ) { if( count == 0 ) { VbufConcStr( buf, "no " ); } else { VbufConcDecimal( buf, count ); VbufConcChr( buf, ' ' ); } VbufConcStr( buf, thing ); if( count != 1 ) { VbufConcChr( buf, 's' ); } VbufConcStr( buf, end ); }
bool CmdLnBatchRead( // READ NEXT LINE IN COMMAND BUFFER VBUF *buf ) // - virtual buffer { VbufInit( buf ); for(;;) { int c = nextChar(); if( CompFlags.batch_file_eof ) break; if( c == '\n' ) break; VbufConcChr( buf, c ); } DbgVerify( VbufLen( buf ) > 0, "CmdLnReadBatch -- nothing" ); ++ CompInfo.fc_file_line; return( VbufLen( buf ) ); }
static void processCmdFile( // PROCESS A COMMAND FILE OPT_STORAGE *data ) // - option data { VBUF rec; // - record for file int c; // - next character VbufInit( &rec ); for(;;) { for(;;) { c = NextChar(); if( c == LCHR_EOF ) break; if( c == '\n' ) break; if( c == '\r' ) break; VbufConcChr( &rec, (char)c ); } procOptions( data, VbufString( &rec ) ); for( ; ( c == '\n' ) || ( c == '\r' ); c = NextChar() ); if( c == LCHR_EOF ) break; VbufRewind( &rec ); VbufConcChr( &rec, (char)c ); } VbufFree( &rec ); }
SYMBOL FormatMsg( VBUF *pbuf, char *fmt, va_list arg ) /****************************************************/ // this function assumes that pbuf is initialized // all information is concatenated to the end of pbuf { VBUF prefix, suffix; char cfmt; char local_buf[ 1 + sizeof( int ) * 2 + 1 ]; unsigned len; SYMBOL retn_symbol; retn_symbol = NULL; cfmt = *fmt; while( cfmt ) { if( cfmt == '%' ) { fmt++; cfmt = *fmt; switch( cfmt ) { case '1': /* %01d */ case '2': /* %02d */ case '3': /* %03d */ case '4': /* %04d */ case '5': /* %05d */ case '6': /* %06d */ case '7': /* %07d */ case '8': /* %08d */ case '9': /* %09d */ len = sticpy( local_buf, va_arg( arg, int ) ) - local_buf; leading( pbuf, '0', ( cfmt - '0' ) - len ); VbufConcStr( pbuf, local_buf ); break; case 'c': /* %c */ VbufConcChr( pbuf, va_arg( arg, int ) ); break; case 's': /* %s */ VbufConcStr( pbuf, va_arg( arg, char * ) ); break; case 'u': /* %u */ VbufConcDecimal( pbuf, va_arg( arg, unsigned int ) ); break; case 'd': /* %d */ VbufConcInteger( pbuf, va_arg( arg, int ) ); break; case 'L': /* token location */ { TOKEN_LOCN *locn; locn = va_arg( arg, TOKEN_LOCN * ); if( locn == NULL ) { VbufConcStr( pbuf, "by compiler" ); } else { char *src_file = SrcFileName( locn->src_file ); if( src_file == NULL ) { VbufConcStr( pbuf, "on the command line" ); } else { if( ( CompFlags.ew_switch_used ) &&( locn->src_file == SrcFileTraceBackFile() ) ) { VbufConcStr( pbuf, "at: " ); } else { VbufConcStr( pbuf, "in: " ); VbufConcStr( pbuf, SrcFileName( locn->src_file ) ); } VbufConcChr( pbuf, '(' ); VbufConcInteger( pbuf, locn->line ); if( locn->column ) { if( CompFlags.ew_switch_used ) { VbufConcChr( pbuf, ',' ); VbufConcInteger( pbuf, locn->column ); } else { VbufConcStr( pbuf, ") (col " ); VbufConcInteger( pbuf, locn->column ); } } VbufConcChr( pbuf, ')' ); } } } break; case 'N': /* name */ FormatName( va_arg( arg, NAME ), &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); break; case 'F': /* symbol name (decorated) */ { SYMBOL sym; sym = va_arg( arg, SYMBOL ); FormatSym( sym, &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); } break; case 'S': /* symbol name (abbreviated) */ { SYMBOL sym; SYMBOL_NAME sn; NAME name; sym = va_arg( arg, SYMBOL ); if( sym == NULL ) { VbufConcStr( pbuf, "module data" ); } else { if( formatClassForSym( sym, pbuf ) ) { VbufConcStr( pbuf, "::" ); } if( SymIsCtor( sym ) ) { formatClassForSym( sym, pbuf ); } else if( SymIsDtor( sym ) ) { VbufConcChr( pbuf, '~' ); formatClassForSym( sym, pbuf ); } else { sn = sym->name; #ifndef NDEBUG if( sn == NULL ) { CFatal( "FormatMsg -- %S symbol has NULL SYMBOL_NAME" ); } #endif name = sn->name; #ifndef NDEBUG if( name == NULL ) { CFatal( "FormatMsg -- %S SYMBOL_NAME has NULL name" ); } #endif if( name == CppConversionName() ) { VbufConcStr( pbuf, "operator " ); FormatType( SymFuncReturnType( sym ) , &prefix , &suffix ); VbufFree( &suffix ); } else { FormatName( name, &prefix ); } VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); } if( sym->flag2 & SF2_TOKEN_LOCN ) { DbgVerify( retn_symbol == NULL, "too many symbols" ); retn_symbol = sym; } } } break; case 'T': /* type name */ { TYPE type = va_arg( arg, TYPE ); TYPE refed = TypeReference( type ); if( NULL != refed ) { type = refed; } FormatType( type, &prefix, &suffix ); VbufConcVbuf( pbuf, &prefix ); VbufConcVbuf( pbuf, &suffix ); VbufFree( &prefix ); VbufFree( &suffix ); VbufTruncWhite( pbuf ); if( NULL != refed ) { VbufConcStr( pbuf, " (lvalue)" ); } } break; case 'P': /* PTREE list */ { const PTREE p = va_arg( arg, PTREE ); FormatPTreeList( p, &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); } break; case 'I': /* PTREE id */ { const PTREE p = va_arg( arg, PTREE ); FormatPTreeId( p, &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); } break; case 'M': /* template info */ { TEMPLATE_INFO * const tinfo = va_arg( arg, TEMPLATE_INFO * ); const SYMBOL sym = tinfo->sym; FormatTemplateInfo( tinfo, &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); if( sym->flag2 & SF2_TOKEN_LOCN ) { DbgVerify( retn_symbol == NULL, "too many symbols" ); retn_symbol = sym; } } break; case 'C': /* template specialisation */ { TEMPLATE_SPECIALIZATION * const tspec = va_arg( arg, TEMPLATE_SPECIALIZATION * ); FormatTemplateSpecialization( tspec, &prefix ); VbufConcVbuf( pbuf, &prefix ); VbufFree( &prefix ); } break; default: VbufConcChr( pbuf, cfmt ); } } else {
void DumpObjectModelEnum( // DUMP OBJECT MODEL: ENUM TYPE type ) // - enum type { SYMBOL sym; // - current symbol TYPE base; // - base type VBUF buffer; // - printing buffer char buf[16]; // - buffer int numb; // - a numeric value const char *name; // - name to be printed bool sign; // - TRUE ==> signed enum unsigned mask; // - used to mask to true size unsigned val; // - value as unsigned CompFlags.log_note_msgs = TRUE; base = TypedefModifierRemoveOnly( type ); sym = base->u.t.sym; VbufInit( &buffer ); VbufConcStr( &buffer, "Object Model for: " ); if( NULL == sym->name->name || NameStr( sym->name->name )[0] == '.' ) { VbufConcStr( &buffer, "anonymous enum type" ); } else { VbufConcStr( &buffer, NameStr( sym->name->name ) ); } switch( TypedefModifierRemove( base->of ) -> id ) { case TYP_CHAR : case TYP_UCHAR : name = "unsigned char"; sign = FALSE; break; case TYP_SCHAR : name = "signed char"; sign = TRUE; break; case TYP_SSHORT : name = "signed short"; sign = TRUE; break; case TYP_USHORT : name = "unsigned short"; sign = FALSE; break; case TYP_SINT : name = "signed int"; sign = TRUE; break; case TYP_UINT : name = "unsigned int"; sign = FALSE; break; case TYP_SLONG : name = "signed long"; sign = TRUE; break; case TYP_ULONG : name = "unsigned long"; sign = FALSE; break; case TYP_SLONG64 : name = "__int64"; sign = TRUE; break; case TYP_ULONG64 : name = "unsigned __int64"; sign = FALSE; break; DbgDefault( "DumpObjectModelEnum -- bad underlying type" ); } VbufConcStr( &buffer, ", base type is " ); VbufConcStr( &buffer, name ); vbufWrite( &buffer ); mask = CgMemorySize( base ); if( mask == sizeof( unsigned ) ) { mask = -1; } else { mask = ( 1 << ( mask * 8 ) ) - 1; } for( ; ; ) { sym = sym->thread; if( ! SymIsEnumeration( sym ) ) break; VbufRewind( &buffer ); VbufConcStr( &buffer, " " ); VbufConcStr( &buffer, NameStr( sym->name->name ) ); VbufConcStr( &buffer, " = " ); numb = sym->u.sval; if( sign && numb < 0 ) { VbufConcChr( &buffer, '-' ); VbufConcDecimal( &buffer, -numb ); } else { VbufConcDecimal( &buffer, numb ); } val = mask & numb; if( val > 10 ) { itoa( val, buf, 16 ); VbufConcStr( &buffer, " /0x" ); VbufConcStr( &buffer, buf ); } vbufWrite( &buffer ); } VbufFree( &buffer ); CompFlags.log_note_msgs = FALSE; }