Esempio n. 1
0
static char *fileName(          // get name of SRCFILE
    SRCFILE src )               // - source file
{
    char *fname;

    if( CompFlags.error_use_full ) {
        fname = SrcFileFullName( src );
    } else {
        fname = SrcFileName( src );
    }
    return( fname );
}
Esempio n. 2
0
void DbgDumpTokenLocn           // DUMP A TOKEN_LOCN
    ( void const* parm )        // - the location
{
    TOKEN_LOCN const * locn;    // - the location

    locn = parm;
    if( NULL == locn
     || NULL == locn->src_file ) {
        printf( " <No SrcFile Location>" );
    } else {
        printf( " SrcFile(%s,%d-%d)"
              , SrcFileName( locn->src_file )
              , locn->line
              , locn->column
              );
    }
}
Esempio n. 3
0
void *CtxWhereAreYou(           // SET DEBUGGING BUFFER
    void )
{
    char *buf;                  // - points into buffer

    buf = stpcpy( CompilerContext, ctx_names[ context ] );
    switch( context ) {
      case CTX_CMDLN_ENV :
      case CTX_CMDLN_PGM :
        buf = stpcpy( buf, ": " );
        buf = stpcpy( buf, CtxGetSwitchAddr() );
        break;
      case CTX_FORCED_INCS :
      case CTX_SOURCE :
        if( location.src_file == NULL ) break;
        buf = stpcpy( buf, ": " );
        buf = stpcpy( buf, SrcFileName( location.src_file ) );
        buf = stpcpy( buf, "(" );
        buf = stdcpy( buf, location.line );
        buf = stpcpy( buf, "," );
        buf = stdcpy( buf, location.column );
        buf = stpcpy( buf, ")" );
        break;
      case CTX_CG_FUNC :
      case CTX_FUNC_GEN :
        buf = stpcpy( buf, ": " );
        if( func == NULL ) {
            buf = stpcpy( buf, "data generation" );
        } else {
            VBUF vbuf;
            buf = stpcpy( buf, DbgSymNameFull( func, &vbuf ) );
            VbufFree( &vbuf );
        }
        if( ( context == CTX_FUNC_GEN )
          &&( line != 0 ) ) {
            buf = stpcpy( buf, "(" );
            buf = stdcpy( buf, location.line );
            buf = stpcpy( buf, ")" );
        }
        break;
    }
    return CompilerContext;
}
Esempio n. 4
0
static void dumpCheckData( char *include_file )
{
    SRCFILE src;
    time_t stamp;
    auto char buff[_MAX_PATH];

    PCHWriteVar( GenSwitches );
    PCHWriteVar( TargetSwitches );
    PCHWriteUInt( ErrPCHVersion() );
    PCHWriteUInt( TYPC_LAST );
    PCHWriteUInt( sizeof( COMP_FLAGS ) );
    PCHWriteVar( CompFlags );
    dumpFileString( WholeFName );
    include_file = IoSuppFullPath( include_file, buff, sizeof( buff ) );
    dumpFileString( include_file );
    getcwd( buff, sizeof( buff ) );
    dumpFileString( buff );
    HFileListStart();
    for( ; ; ) {
        HFileListNext( buff );
        dumpFileString( buff );
        if( buff[0] == '\0' ) break;
    }
    src = SrcFileNotReadOnly( SrcFileWalkInit() );
    for( ; src != NULL; ) {
        if( ! IsSrcFilePrimary( src ) ) {
            dumpFileString( SrcFileName( src ) );
            stamp = SrcFileTimeStamp( src );
            PCHWriteVar( stamp );
        }
        src = SrcFileNotReadOnly( SrcFileWalkNext( src ) );
    }
    buff[0] = '\0';
    dumpFileString( buff );
    PCHDumpMacroCheck();
}
Esempio n. 5
0
static boolean doIoSuppOpenSrc(  // OPEN A SOURCE FILE (PRIMARY,HEADER)
    struct path_descr *fd,      // - descriptor for file name
    enum file_type typ )        // - type of search path to use
{
    char **paths;               // - optional paths to prepend
    char **exts;                // - optional extensions to append
    boolean retn;               // - return: TRUE ==> opened
    char *path;                 // - next path
    char bufpth[ _MAX_PATH ];   // - buffer for next path
    SRCFILE curr;               // - current included file
    SRCFILE stdin_srcfile;      // - srcfile for stdin
    struct path_descr idescr;   // - descriptor for included file
    LINE_NO dummy;              // - dummy line number holder
    char prevpth[ _MAX_PATH ];  // - buffer for previous path

    switch( typ ) {
    case FT_SRC:
        if( fd->fnm[0] == '\0' && fd->ext[0] == '.' && fd->ext[1] == '\0' ) {
            if( ErrCount != 0 ) {
                // command line errors may result in "." as the input name
                // so the user thinks that the compiler is hung!
                return( FALSE );
            }
            WholeFName = FNameAdd( "stdin" );
            stdin_srcfile = SrcFileOpen( stdin, WholeFName );
            SrcFileNotAFile( stdin_srcfile );
            goto file_was_found;
        }
        paths = pathSrc;
        exts = extsSrc;
        break;
    case FT_HEADER:
    case FT_LIBRARY:
        if( !CompFlags.ignore_current_dir ) {
            paths = pathHdr;
        } else {
            paths = NULL;
        }
        exts = extsHdr;
        break;
    case FT_CMD:
        paths = pathCmd;
        exts = extsCmd;
        break;
    }
    switch( typ ) {
    case FT_LIBRARY:
        if( fd->drv[0] != '\0' || IS_DIR_SEP( fd->dir[0] ) ) {
            retn = openSrcPath( "", exts, fd, typ );
            if( retn ) goto file_was_found;
        }
        break;
    case FT_HEADER:
        // even if ignoreing current dir, have to look for absolute paths
        if( !CompFlags.ignore_current_dir || fd->drv[0] != '\0' ) {
             // look in current directory
            retn = openSrcPath( "", exts, fd, typ );
            if( retn ) goto file_was_found;
        }
        /* check directories of currently included files */
        if( !IS_PATH_SEP( fd->dir[0] ) ) {
            prevpth[0] = '\xff'; /* to make it not compare with anything else */
            prevpth[1] = '\0';
            curr = SrcFileCurrent();
            for( ;; ) {
                if( curr == NULL ) break;
                splitFileName( SrcFileName( curr ), &idescr );
                _makepath( bufpth, idescr.drv, idescr.dir, NULL, NULL );
                /*optimization: don't try and open if in previously checked dir*/
                if( strcmp( bufpth, prevpth ) != 0 ) {
                    retn = openSrcPath( bufpth, exts, fd, FT_HEADER );
                    if( retn ) goto file_was_found;
                }
                curr = SrcFileIncluded( curr, &dummy );
                strcpy( prevpth, bufpth );
            }
        }
        break;
    case FT_SRC:
    case FT_CMD:
        retn = openSrcPath( "", exts, fd, typ );
        if( retn ) goto file_was_found;
        break;
    }
    switch( typ ) {
    case FT_HEADER:
    case FT_LIBRARY:
        HFileListStart();
        for( ; ; ) {
            HFileListNext( bufpth );
            if( *bufpth == '\0' ) break;
            retn = openSrcPath( bufpth, exts, fd, typ );
            if( retn ) goto file_was_found;
        }
        break;
    }
    switch( typ ) {
    case FT_HEADER:
    case FT_CMD:
    case FT_SRC:
        if( IS_PATH_SEP( fd->dir[0] ) ) {
            // absolute path
            break;
        }
        if( paths != NULL ) {
            for( ; ; ) {
                path = *paths++;
                if( path == NULL ) break;
                retn = openSrcPath( path, exts, fd, typ );
                if( retn ) goto file_was_found;
            }
        }
        break;
    }
    return FALSE;
file_was_found:
    switch( typ ) {
    case FT_CMD:
        SrcFileCommand();
        break;
    case FT_LIBRARY:
        SrcFileLibrary();
        break;
    }
    return TRUE;
}
Esempio n. 6
0
static void rptRepository       // PRINT REPOSITORY REPORT
    ( INITFINI* defn )          // - definition
{
    REPO_STAT** last;           // - addr[ REPO_STAT ]
    REPO_STAT* repo;            // - REPO_STAT for source file
    long ref_syms;              // - # symbol references
    long ref_types;             // - # type references
    long avg_defs;              // - average definitions
    long avg_syms;              // - average symbol references
    long avg_types;             // - average type references
    unsigned file_count;        // - # files

    defn = defn;
    if( ! CompFlags.extra_stats_wanted ) {
        for(;;) {
            last = VstkPop( &srcFiles );
            if( NULL == last ) break;
            repo = *last;
            VstkClose( &repo->refset );
            VstkClose( &repo->typeset );
        }
        return;
    }
    MsgDisplayLine( "" );
    MsgDisplayLine( "Repository Statistics" );
    MsgDisplayLine( "" );
    MsgDisplayLine( "Defns  Syms Types Total File" );
    MsgDisplayLine( "" );
    avg_defs = 0;
    avg_syms = 0;
    avg_types = 0;
    file_count = 0;
    for(;;) {
        last = VstkPop( &srcFiles );
        if( NULL == last ) break;
        repo = *last;
        ref_syms = VstkDimension( &repo->refset ) + 1;
        ref_types = VstkDimension( &repo->typeset ) + 1;
        ++file_count;
        avg_syms += ref_syms;
        avg_types += ref_types;
        avg_defs += repo->defns;
        sprintf( sbuff
              , fmt_repos
              , repo->defns
              , ref_syms
              , ref_types
              , ref_syms + ref_types
              , SrcFileName( repo->srcfile )
              );
        MsgDisplayLine( sbuff );
        VstkClose( &repo->refset );
        VstkClose( &repo->typeset );
    }
    if( 0 < file_count ) {
        long fuzz = file_count / 2;
        MsgDisplayLine( "" );
        sprintf( sbuff
              , fmt_repos
              , avg_defs
              , avg_syms
              , avg_types
              , avg_syms + avg_types
              , "---- Totals ------"
              );
        MsgDisplayLine( sbuff );
        avg_defs = ( avg_defs + fuzz ) / file_count;
        avg_syms = ( avg_syms + fuzz ) / file_count;
        avg_types = ( avg_types + fuzz ) / file_count;
        sprintf( sbuff
              , fmt_repos
              , avg_defs
              , avg_syms
              , avg_types
              , avg_syms + avg_types
              , "---- Averages ----"
              );
        MsgDisplayLine( sbuff );
        MsgDisplayLine( "" );
        sprintf( sbuff, "%d files processed", file_count );
        MsgDisplayLine( sbuff );
        MsgDisplayLine( "" );
    }
    fflush( stdout );
}
Esempio n. 7
0
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 {