Ejemplo n.º 1
0
static void setMsgLocation      // SET LOCATION FOR MESSAGE
    ( CTX context )             // - current context
{
    switch( context ) {
      case CTX_FINI :
      case CTX_FUNC_GEN :
      case CTX_CG_FUNC :
      case CTX_CG_OPT :
      case CTX_ENDFILE :
        if( CompFlags.ew_switch_used ) {
      // drops thru
      case CTX_INIT :
      case CTX_CMDLN_ENV :
      case CTX_CMDLN_PGM :
      case CTX_CMDLN_VALID :
            err_locn.src_file = NULL;
            break;
        }
        // drops thru
      case CTX_FORCED_INCS :
      case CTX_SOURCE :
        if( err_locn.src_file == NULL ) {
            if( SrcFilesOpen() ) {
                SrcFileGetTokenLocn( &err_locn );
            } else {
                err_locn.line = SrcLineCount;
                err_locn.column = 0;
                err_locn.src_file = SrcFileCurrent();
            }
        }
        break;
    }
}
Ejemplo n.º 2
0
static void extraRptTypeUsage   // TYPE USAGE
    ( TYPE type )               // - the type
{
    SRCFILE current = SrcFileCurrent();
    for( ; type != NULL; type = type->of ) {
        switch( type->id ) {
          case TYP_ENUM :
          case TYP_TYPEDEF :
          { SYMBOL sym = type->u.t.sym;
            reportOnType( current, type, sym );
          } break;
          case TYP_CLASS :
            if( type->u.c.scope->id == SCOPE_FUNCTION ) {
                SYMBOL sym = type->u.c.scope->owner.sym;
                reportOnType( current, type, sym );
            }
            break;
          case TYP_MEMBER_POINTER :
            extraRptTypeUsage( type->u.mp.host );
            continue;
          case TYP_FUNCTION :
          { arg_list* args = type->u.f.args;
            int count = args->num_args;
            for( ; count > 0; ) {
                -- count;
                extraRptTypeUsage( args->type_list[count] );
            }
          }
          // drops thru
          default :
            continue;
        }
        break;
    }
}
Ejemplo n.º 3
0
void CtxScanToken(              // SET TOKEN LOCATION FOR SCANNED TOKEN
    void )
{
    location.src_file = SrcFileCurrent();
    location.line = TokenLine;
    location.column = TokenColumn;
}
Ejemplo n.º 4
0
void ExtraRptSymDefn(           // REPORT SYMBOL DEFINITION IN PRIMARY SOURCE
    SYMBOL sym )
{
    extraRptTypeUsage( sym->sym_type );
    if( isReposSym( sym ) ) {
        SRCFILE current = SrcFileCurrent();
        REPO_STAT* repo = reposStat( current );
        ++ repo->defns;
    }
}
Ejemplo n.º 5
0
static bool openSrc(            // ATTEMPT TO OPEN FILE
    char *name,                 // - file name
    enum file_type typ )        // - type of file being opened
{
    pch_absorb pch_OK;          // - pre-compiled header load status
    FILE *fp;                   // - file pointer
#ifdef OPT_BR
    bool might_browse;          // - true ==> might browse, if right file type
#endif

    if( SrcFileProcessOnce( name ) ) {
        SrcFileOpen( NULL, name );
        return( TRUE );
    }
    fp = SrcFileFOpen( name, SFO_SOURCE_FILE );
    if( fp == NULL ) {
        return( FALSE );
    }
#ifdef OPT_BR
    might_browse = FALSE;
#endif
    if( CompFlags.watch_for_pcheader ) {
        CompFlags.watch_for_pcheader = FALSE;
        pch_OK = PCHeaderAbsorb( name );
        if( pch_OK != PCHA_OK ) {
            SrcFileSetCreatePCHeader();
            SrcFileOpen( fp, name );
#ifdef OPT_BR
            might_browse = TRUE;
#endif
        } else {
            SrcFileOpen( NULL, name );
            fclose( fp );
        }
    } else {
        SrcFileOpen( fp, name );
        if( typ == FT_SRC ) {
            SetSrcFilePrimary();
        }
#ifdef OPT_BR
        might_browse = TRUE;
#endif
    }
#ifdef OPT_BR
    if( might_browse ) switch( typ ) {
      case FT_SRC :
      case FT_LIBRARY :
      case FT_HEADER :
        BrinfOpenSource( SrcFileCurrent() );
        break;
    }
#endif
    return( TRUE );
}
Ejemplo n.º 6
0
static void procOptions(        // PROCESS AN OPTIONS LINE
    OPT_STORAGE *data,          // - options data
    const char *str )           // - scan position in command line
{
    int c;                      // - next character
    char const *fnm;            // - scanned @ name
    char *env;                  // - environment name
    size_t len;                 // - length of file name

    if( indirectionLevel >= MAX_INDIRECTION ) {
        BadCmdLine( ERR_MAX_CMD_INDIRECTION );
    } else if( str != NULL ) {
        ++indirectionLevel;
        CtxSetSwitchAddr( str );
        CmdScanInit( str );
        for(;;) {
            c = CmdScanWhiteSpace();
            if( c == '\0' ) break;
            CmdScanSwitchBegin();
            CmdLnCtxSwitch( CmdScanAddr() - 1 );
            if( c == '-'  ||  c == SwitchChar ) {
                if( OPT_PROCESS( data ) ) {
                    BadCmdLine( ERR_INVALID_OPTION );
                }
            } else if( c == '@' ) {
                CmdScanWhiteSpace();
                CmdScanUngetChar();
                len = CmdScanFilename( &fnm );
                env = get_env( fnm, len );
                if( NULL == env ) {
                    if( openCmdFile( fnm, len ) ) {
                        CmdLnCtxPushCmdFile( SrcFileCurrent() );
                        processCmdFile( data );
                        CmdLnCtxPop();
                    } else {
                        CmdLnCtxPushEnv( fnm );
                        BadCmdLine( ERR_BAD_CMD_INDIRECTION );
                        CmdLnCtxPop();
                    }
                } else {
                    CmdLnCtxPushEnv( fnm );
                    procOptions( data, env );
                    CmdLnCtxPop();
                }
            } else {
                CmdScanUngetChar();
                scanInputFile();
            }
        }
        --indirectionLevel;
    }
}
Ejemplo n.º 7
0
static REWRITE *newREWRITE( TOKEN end_token, TOKEN_LOCN *locn )
{
    REWRITE *r;
    REWRITE_TOKENS *rt;

    r = CarveAlloc( carveREWRITE );
    rt = tokenAlloc();
    r->list = rt;
    r->curr = rt;
    r->srcfiles_refd = NULL;
    r->stream = rt->stream;
    r->last_token = end_token;
    r->busy = FALSE;
    r->free = FALSE;
    r->alternate = FALSE;
    locn->src_file = SrcFileCurrent();
    putSrcFile( r, locn );
    return( r );
}
Ejemplo n.º 8
0
void ExtraRptSymUsage(          // REPORT SYMBOL USAGE FROM PRIMARY SOURCE
    SYMBOL sym )
{
    extraRptTypeUsage( sym->sym_type );
    if( isReposSym( sym ) ) {
        SRCFILE current = SrcFileCurrent();
        SRCFILE refed = sym->locn->tl.src_file;
        if( current != refed ) {
            REPO_STAT* repo = reposStat( current );
            SYMBOL* last;
            for( last = VstkTop( &repo->refset )
               ;
               ; last = VstkNext( &repo->refset, last ) ) {
                if( NULL == last ) {
                    *(SYMBOL*)VstkPush( &repo->refset ) = sym;
                    break;
                }
                if( sym == *last ) break;
            }
        }
    }
}
Ejemplo n.º 9
0
static void putSrcLocn( REWRITE *r, TOKEN_LOCN *locn )
{
    SRCFILE currfile;
    uint_32 absolute;
    uint_8 code_byte;

    currfile = SrcFileCurrent();
    if( currfile != locn->src_file ) {
        locn->src_file = currfile;
        putSrcFile( r, locn );
    }
    putToken( r, T_REWRITE_MODS );
    if( ( TokenLine - locn->line ) > 127 ) {
        putByte( r, CODE_ABS );
        absolute = TokenLine | MASK_ABS_LINE;
        putBinary( r, (uint_8*)&absolute, sizeof( absolute ) );
        locn->line = TokenLine;
    } else if( ( TokenLine - locn->line ) > 0 ) {
        code_byte = ( TokenLine - locn->line ) | MASK_DELTA_LINE;
        putByte( r, code_byte );
        locn->line = TokenLine;
    }
    if( ( TokenColumn - locn->column ) > 127 ) {
        putByte( r, CODE_ABS );
        absolute = TokenColumn;
        putBinary( r, (uint_8*)&absolute, sizeof( absolute ) );
        locn->column = TokenColumn;
    } else if( ( TokenColumn - locn->column ) > 0 ) {
        code_byte = TokenColumn - locn->column;
        putByte( r, code_byte );
        locn->column = TokenColumn;
    } else {                        // this guards against token at same col.
        putByte( r, CODE_ABS );
        absolute = TokenColumn;
        putBinary( r, (uint_8*)&absolute, sizeof( absolute ) );
        locn->column = TokenColumn;
    }
}
Ejemplo n.º 10
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;
}