Пример #1
0
Файл: gen.cpp Проект: hyln9/nV
void parser::gen(size_t m)
{
	node_t& n = m_node[m];
	parser::iter_t iter = lower(m);

	switch(n.tag)
	{
	case tag_inequality:
		{
			head(count(m) + 1);
			emit(TAG(Inequality));
			parser::iter_t end = upper(m);
			while(iter != end)
			{
				gen(iter->second);
				++iter;
			}
		}
		break;
	case tag_sequence:
		{
			parser::iter_t end = upper(m);
			while(iter != end)
			{
				gen(iter->second);
				++iter;
			}
		}
		break;
	case tag_expression:
		if (n.value == -1) {
			head(count(m) + 1);
			emit(TAG(CompoundExpression));
			parser::iter_t end = upper(m);
			while(iter != end)
			{
				gen(iter->second);
				++iter;
			}
			break;
		}
		else if(s_oper[n.value].postfix || s_oper[n.value].prefix) {
			head(2);
			emit(s_oper[n.value].symbol);
			gen(iter->second);
			break;
		}
		head(3);
		emit(s_oper[n.value].symbol);
		gen(iter->second);
		gen((++iter)->second);
		break;
	case tag_suffix:
		switch(n.value)
		{
		case -1:
			{
				parser::iter_t begin = lower(m), end = upper(m);
				iter = --end;
				while(iter != begin)
				{
					--iter;
					gen(iter->second);
				}
				gen(end->second);
				while(iter != end)
				{
					gen(iter->second);
					++iter;
				}
			}
			break;
		case -2:
			head(2);
			emit(TAG(Part));
			n.value = -6;
			break;
		case -3:
			head(count(iter->second) + 2);
			emit(TAG(Part));
			n.value = -7;
			break;
		case -4:
			head(1);
			n.value = -8;
			break;
		case -5:
			head(count(iter->second) + 1);
			n.value = -9;
			break;
		case -6: break;
		case -7: gen(iter->second); break;
		case -8: break;
		case -9: gen(iter->second);	break;
		}
		break;
	case tag_primary:
		switch(n.value)
		{
		case instr_symbol:
			sym(m_note.find(m)->second);
			break;
		case instr_integer:
			{
				const wchar *s = m_note.find(m)->second;
				emit(Int(string(s,s + wcslen(s)).c_str(),10));
			}
			break;
		case instr_float:
			{
				const wchar *s = m_note.find(m)->second;
				emit(Flt(string(s,s + wcslen(s)).c_str(),10));
			}
			break;
		case instr_string:
			emit(Str(m_note.find(m)->second));
			break;
		case -1:
			emit(Vec());
			break;
		case -2:
			{
				var r = Vec(count(iter->second));
				emit(r);
				code_stack.push(std::make_pair(r,0));
				gen(iter->second);
			}
			break;
		case -3:
			gen(iter->second);
			break;
		case -4:
			head(2);
			emit(TAG(Blank));
			gen(iter->second);
			break;
		case -5:
			head(2);
			emit(TAG(Optional));
			head(1);
			emit(TAG(Blank));
			break;
		case -6:
			head(1);
			emit(TAG(Blank));
			break;
		case -7:
			head(2);
			emit(TAG(BlankSequence));
			gen(iter->second);
			break;
		case -8:
			head(2);
			emit(TAG(Optional));
			head(1);
			emit(TAG(BlankSequence));
			break;
		case -9:
			head(1);
			emit(TAG(BlankSequence));
			break;
		case -10:
			head(2);
			emit(TAG(Slot));
			gen(iter->second);
			break;
		case -11:
			head(2);
			emit(TAG(Slot));
			emit(Int(1L));
			break;
		case -12:
			head(2);
			emit(TAG(SlotSequence));
			gen(iter->second);
			break;
		case -13:
			head(2);
			emit(TAG(SlotSequence));
			emit(Int(1L));
			break;
		case -14:
			head(3);
			emit(TAG(Pattern));
			gen(iter->second);
			head(2);
			emit(TAG(Blank));
			gen((++iter)->second);
			break;
		case -15:
			head(2);
			emit(TAG(Optional));
			head(3);
			emit(TAG(Pattern));
			gen(iter->second);
			head(1);
			emit(TAG(Blank));
			break;
		case -16:
			head(3);
			emit(TAG(Pattern));
			gen(iter->second);
			head(1);
			emit(TAG(Blank));
			break;
		case -17:
			head(3);
			emit(TAG(Pattern));
			gen(iter->second);
			head(2);
			emit(TAG(BlankSequence));
			gen((++iter)->second);
			break;
		case -18:
			head(2);
			emit(TAG(Optional));
			head(3);
			emit(TAG(Pattern));
			gen(iter->second);
			head(1);
			emit(TAG(BlankSequence));
			break;
		case -19:
			head(3);
			emit(TAG(Pattern));
			gen(iter->second);
			head(1);
			emit(TAG(BlankSequence));
			break;
		case -20:
			head(3);
			emit(TAG(Pattern));
			gen(iter->second);
			gen((++iter)->second);
			break;
		case -21:
			head(3);
			emit(TAG(Property));
			gen(iter->second);
			gen((++iter)->second);
			break;
		}
		break;
	}
}
Пример #2
0
/*****************************************************************************
* First character of command id should be second char of line
* Lexer returns a full line of data, needs to be parsed if .ce
* In version 1.0, valid commands are:
* .* (comment) followed by text to '\n'
* .br (new line), nothing else allowed on line
* .im (include file) 'filename'
* .nameit (define text macro) symbol=[a-zA-Z0-9]+ (10 max) text='text string'
*     text may contain entity references, nameit references and tags
* .ce (center) no tags, but text and both entity types
* Version 2.0 only supports .*, .br, .im
*/
Lexer::Token Document::processCommand( Lexer* lexer, Tag* parent )
{
    if( lexer->cmdId() == Lexer::COMMENT )
        ;//do nothing
    else if( lexer->cmdId() == Lexer::BREAK )
        parent->appendChild( new BrCmd( this, parent, dataName(), dataLine(), dataCol() ) );
    else if( lexer->cmdId() == Lexer::CENTER ) {
        CeCmd* cecmd( new CeCmd( this, parent, dataName(), dataLine(), dataCol() ) );
        parent->appendChild( cecmd );
        return cecmd->parse( lexer );
    }
    else if( lexer->cmdId() == Lexer::IMBED ) {
        std::string env( Environment.value( "IPFCIMBED" ) );
        std::vector< std::wstring > paths;
        std::wstring cwd;   //empty string for current directory
        paths.push_back( cwd );
#ifdef __UNIX__
        std::string separators( ":;" );
        char slash( '/' );
#else
        std::string separators( ";" );
        char slash( '\\' );
#endif
        std::string::size_type idx1( 0 );
        std::string::size_type idx2( env.find_first_of( separators, idx1 ) );
        std::wstring fbuffer;
        mbtowstring( env.substr( idx1, idx2 - idx1 ), fbuffer );
        paths.push_back( fbuffer );
        while( idx2 != std::string::npos ) {
            idx1 = idx2 + 1;
            idx2 = env.find_first_of( separators, idx1 );
            fbuffer.clear();
            mbtowstring( env.substr( idx1, idx2 - idx1 ), fbuffer );
            paths.push_back( fbuffer );
        }
        for( size_t count = 0; count < paths.size(); ++count ) {
            std::wstring* fname( new std::wstring( paths[ count ] ) );
            if( !fname->empty() )
                *fname += slash;
            *fname += lexer->text();
#ifndef __UNIX__
            if( fname->size() > PATH_MAX ) {
                throw FatalError( ERR_PATH_MAX );
            }
#endif
            try {
                IpfFile* ipff( new IpfFile( fname ) );
                fname = addFileName( fname );
                pushInput( ipff );
                break;
            }
            catch( FatalError& e ) {
                delete fname;
                if( count == paths.size() - 1 )
                    throw e;
            }
            catch( FatalIOError& e ) {
                delete fname;
                if( count == paths.size() - 1 )
                    throw e;
            }
        }
    }
    else if( lexer->cmdId() == Lexer::NAMEIT ) {
        std::wstring::size_type idx1( lexer->text().find( L"symbol=" ) );
        std::wstring::size_type idx2( lexer->text().find( L' ', idx1 ) );
        std::wstring sym( lexer->text().substr( idx1 + 7, idx2 - idx1 - 7 ) );
        killQuotes( sym );
        sym.insert( sym.begin(), L'&' );
        sym += L'.';
        std::wstring::size_type idx3( lexer->text().find( L"text=" ) );
        //check for single quotes
        std::wstring::size_type idx4( lexer->text()[ idx3 + 5 ] == L'\'' ? \
            lexer->text().find( L'\'', idx3  + 6 ) : \
            lexer->text().find( L' ', idx3 + 5 ) );
        std::wstring txt( lexer->text().substr( idx3 + 5, idx4 - idx3 - 5 ) );
        killQuotes( txt );
        if( !nls->isEntity( sym ) && nameIts.find( sym ) == nameIts.end() ) //add it to the list
            nameIts.insert( std::map< std::wstring, std::wstring >::value_type( sym, txt ) );
        else
            printError( ERR3_DUPSYMBOL );
    }
    else
        printError( ERR1_CMDNOTDEF );
    return getNextToken();
}
Пример #3
0
ctagread::enResult ctagread::process_ctags(void)
{
    tempbuf sym(400), fil(500), classname(400), numtxt(50), linetxt(4001), fil2(500);
    long int num;
    int numOfLines=0;
    char* retval;
    int scanretval = 0;
    int rc;
    char c;
    char smallstr[2];
    char *cp;
    strctagIDList classIDs, symIDs, parentClassIDs, parentClassIDs_temp;
    enResult res;
    std::vector<stClsID> listClsHist;

    *(fil.get()) = '%'; // for SQL LIKE pattern recognition
    smallstr[1] = 0;
    rc = prepare_stmt(&m_insertstmt, "INSERT INTO membertbl VALUES (?,?,?);");
    if (rc!=0) return resSQLError;
    rc = prepare_stmt(&m_insertinheritstmt, "INSERT INTO inherittbl VALUES (?,?);");
    if (rc!=0) return resSQLError;
    rc = prepare_stmt(&m_readclassstmt, "SELECT symID FROM symtbl WHERE symName=? AND symType=\"c\";");
    if (rc!=0) return resSQLError;
    //rc = prepare_stmt(&m_readsymstmt, "SELECT symID FROM symtbl WHERE symName=? AND lineid IN (SELECT lineID FROM linestbl WHERE linenum=? AND fileid IN (SELECT fileID FROM filestbl WHERE filePath LIKE ?));");
    rc = prepare_stmt(&m_readsymstmt, "SELECT symtbl.symID FROM symtbl INNER JOIN linestbl ON (symtbl.symName=? AND symtbl.lineID = linestbl.lineID AND linestbl.linenum=?) INNER JOIN filestbl ON (linestbl.fileID = filestbl.fileID AND filePath LIKE ?);");
    if (rc!=0) return resSQLError;
    rc = prepare_stmt(&m_writedeststmt, "UPDATE symtbl SET symName=? WHERE symID=?;");
    if (rc!=0) return resSQLError;
    //rc = prepare_stmt(&m_readsymfstmt, "SELECT symID FROM symtbl WHERE symName=? AND symType=\"$\" AND lineid IN (SELECT lineID FROM linestbl WHERE linenum=? AND fileid IN (SELECT fileID FROM filestbl WHERE filePath LIKE ?));");
    rc = prepare_stmt(&m_readsymfstmt, "SELECT symtbl.symID FROM symtbl INNER JOIN linestbl ON (symtbl.symName=? AND symtbl.symType=\"$\" AND symtbl.lineID = linestbl.lineID AND linestbl.linenum=?) INNER JOIN filestbl ON (linestbl.fileID = filestbl.fileID AND filePath LIKE ?);");
    if (rc!=0) return resSQLError;
    rc=sqlite3_exec(m_db,  "BEGIN EXCLUSIVE;\
				DROP INDEX IF EXISTS memberIDIdx;\
				DROP INDEX IF EXISTS groupIDIdx;\
				DROP INDEX IF EXISTS parentIDIdx;\
				DROP INDEX IF EXISTS childIDIdx;\
				DELETE FROM membertbl;\
				DELETE FROM inherittbl;\
				COMMIT;", NULL, 0, NULL);
    if (rc != SQLITE_OK)
    {
        if (m_debug) printf("SQLErr13: %d, %s\n", rc, sqlite3_errmsg(m_db));
        return resSQLError;
    }

    do {
        retval = fgets(linetxt.get(), linetxt.size() - 1, f_tags);
        if (retval != NULL)
        {
            chomp(linetxt.get());
            scanretval = sscanf(linetxt.get(), "%s\t%s\t%ld;\"\t%c\tclass:%s", sym.get(), fil2.get(), &num, &c, classname.get());
        }
        if ((retval != NULL)&&(scanretval == 5))
        {
            strcpy(fil.get(), "%");
            strcat(fil.get(), extract_filename(fil2.get()));
            res = getHListOfClassIDs(&classIDs, classname.get(), &listClsHist);
            if (res != resOK) return res;
            if (classIDs.empty()) continue;
            cp = sym.get();
            if (*(sym.get()) == '~')
            {
                cp = (sym.get()) + 1; //include destructors
                // which cscope missed out
            }
            sprintf(numtxt.get(), "%ld", num);
            if (c == 'f')
                res = getListOfSymIDs(m_readsymfstmt, &symIDs, cp, numtxt.get(), fil.get());
            else
                res = getListOfSymIDs(m_readsymstmt, &symIDs, cp, numtxt.get(), fil.get());
            if (res != resOK) {
                return res;
            }
            if (symIDs.empty() == false)
            {
                for (unsigned int i=0; i < symIDs.size(); i++)
                {
                    smallstr[0] = c;
                    rc=execstmt(m_insertstmt, classIDs[0].c_str(), symIDs[i].c_str(), smallstr);
                    if (rc!=0) return resSQLError;
                    if (*(sym.get()) == '~')
                    {
                        rc=execstmt(m_writedeststmt, sym.get(), symIDs[i].c_str());
                        if (rc!=0) return resSQLError;
                    }
                    numOfLines++;
                }
            }
            //else {if (m_debug) {printf("no match found for symbol: %s\n",sym.get());}}
        }
        else if (retval != NULL)
        {
            scanretval = sscanf(linetxt.get(),
                                "%s\t%s\t%ld;\"\t%c\tinherits:%s", sym.get(), fil2.get(), &num, &c, classname.get());
            if ((scanretval == 5)&&(c == 'c'))
            {
                res = getHListOfClassIDs(&classIDs, sym.get(), &listClsHist);
                if (res != resOK) return res;
                if (classIDs.empty()) continue;
                parentClassIDs.clear();
                parentClassIDs_temp.clear();
                std::vector<std::string> vecstr = splitstr(classname.get(), ',');
                for (unsigned int i=0; i<vecstr.size(); i++)
                {
                    res = getHListOfClassIDs(&parentClassIDs_temp, vecstr[i].c_str(), &listClsHist);
                    if (res != resOK) return res;
                    while (parentClassIDs_temp.empty() == false)
                    {
                        parentClassIDs.push_back(parentClassIDs_temp.back());
                        parentClassIDs_temp.pop_back();
                    }
                }
                for (unsigned int i=0; i<parentClassIDs.size(); i++)
                {
                    rc=execstmt(m_insertinheritstmt, parentClassIDs[i].c_str(), classIDs[0].c_str());
                    if (rc!=0) return resSQLError;
                }
            }
        }
    } while (retval != NULL);
    if (m_debug) printf ("Total membertbl records possible = %d\n", numOfLines);
    return resOK;
}
Пример #4
0
void addString(char *s) {
    pr(sym(s));
}
Пример #5
0
/* If reason is init_reason, creates the connection resources (e.g.
      the FIFOs) to allow a gdb connection to be detected by polling
      using remote_desc_activity.
   Otherwise (other reasons):
       If connection with gdb not yet opened, opens the connection with gdb.
       reads gdb remote protocol packets and executes the requested commands.
*/
static void call_gdbserver ( ThreadId tid , CallReason reason)
{
   ThreadState*     tst = VG_(get_ThreadState)(tid);
   int stepping;
   Addr saved_pc;

   dlog(1, 
        "entering call_gdbserver %s ... pid %d tid %d status %s "
        "sched_jmpbuf_valid %d\n",
        ppCallReason (reason),
        VG_(getpid) (), tid, VG_(name_of_ThreadStatus)(tst->status),
        tst->sched_jmpbuf_valid);

   /* If we are about to die, then just run server_main() once to get
      the resume reply out and return immediately because most of the state
      of this tid and process is about to be torn down. */
   if (reason == exit_reason) {
      server_main();
      return;
   }

   vg_assert(VG_(is_valid_tid)(tid));
   saved_pc = VG_(get_IP) (tid);

   if (gdbserver_exited) {
      dlog(0, "call_gdbserver called when gdbserver_exited %d\n",
           gdbserver_exited);
      return;
   }

   if (gdbserver_called == 0) {
      vg_assert (gs_addresses == NULL);
      vg_assert (gs_watches == NULL);
      gs_addresses = VG_(HT_construct)( "gdbserved_addresses" );
      gs_watches = VG_(newXA)(gs_alloc,
                              "gdbserved_watches",
                              gs_free,
                              sizeof(GS_Watch*));
      VG_(atfork)(NULL, NULL, gdbserver_cleanup_in_child_after_fork);
   }
   vg_assert (gs_addresses != NULL);
   vg_assert (gs_watches != NULL);
   
   gdbserver_called++;

   /* call gdbserver_init if this is the first call to gdbserver. */
   if (gdbserver_called == 1)
      gdbserver_init();

   if (reason == init_reason || gdbserver_called == 1)
      remote_open(VG_(clo_vgdb_prefix));

   /* if the call reason is to initialize, then return control to
      valgrind. After this initialization, gdbserver will be called
      again either if there is an error detected by valgrind or
      if vgdb sends data to the valgrind process. */
   if (reason == init_reason) {
      return;
   }

   stepping = valgrind_single_stepping();

   server_main();

   ignore_this_break_once = valgrind_get_ignore_break_once();
   if (ignore_this_break_once)
      dlog(1, "!!! will ignore_this_break_once %s\n", 
           sym(ignore_this_break_once, /* is_code */ True));
      

   if (valgrind_single_stepping()) {
      /* we are single stepping. If we were not stepping on entry,
         then invalidate the current program counter so as to properly
         do single step. In case the program counter was changed by
         gdb, this will also invalidate the target address we will
         jump to. */
      if (!stepping && tid != 0) {
         invalidate_current_ip (tid, "m_gdbserver single step");
      }
   } else {
      /* We are not single stepping.  If we were stepping on entry,
         then clear the gdbserved addresses.  This will cause all
         these gdbserved blocks to be invalidated so that they can be
         re-translated without being gdbserved. */
      if (stepping)
         clear_gdbserved_addresses(/* clear only jumps */ True);
   }
   
   /* can't do sanity check at beginning. At least the stack
      check is not yet possible. */
   if (gdbserver_called > 1)
      VG_(sanity_check_general) (/* force_expensive */ False);

   /* If the PC has been changed by gdb, then we VG_MINIMAL_LONGJMP to
      the scheduler to execute the block of the new PC.
      Otherwise we just return to continue executing the
      current block. */
   if (VG_(get_IP) (tid) != saved_pc) {
      dlog(1, "tid %d %s PC changed from %s to %s\n",
           tid, VG_(name_of_ThreadStatus) (tst->status),
           sym(saved_pc, /* is_code */ True),
           sym(VG_(get_IP) (tid), /* is_code */ True));
      if (tst->status == VgTs_Yielding) {
         SysRes sres;
         VG_(memset)(&sres, 0, sizeof(SysRes));
         VG_(acquire_BigLock)(tid, VgTs_WriteLock, "gdbsrv VG_MINIMAL_LONGJMP");
      }
      if (tst->sched_jmpbuf_valid) {
         /* resume scheduler */
         VG_MINIMAL_LONGJMP(tst->sched_jmpbuf);
      }
      /* else continue to run */
   }
   /* continue to run */
}
Пример #6
0
vertex Edge_Record::dst() const {
    return sym().get_qr().v;
}
Пример #7
0
void Edge_Record::set_dst(vertex p) {
    sym().get_qr().v = p;
}
Symbol get_first(const SymbolList& str, char start) {
	Symbol sym(start);
	sym.identifier.push_back('0');
	return sym;
}
Пример #9
0
Edge_Record Edge_Record::rnext() const {
    return sym().onext();
}
Пример #10
0
		void
		bindMessage(const char* className, const char* name, void (Component::*method)())
		{
			_bindings[sym(className)].messages[sym(name)] = method;
		}
Пример #11
0
		void
		(Component::*getSetter(size_t id, const char* name))(const BValue&)
		{
			return _bindings[id].setters[sym(name)];
		}
Пример #12
0
		void
		bindSetter(const char* className, const char* name, void (Component::*method)(const BValue&))
		{
			_bindings[sym(className)].setters[sym(name)] = method;
		}
Пример #13
0
		void
		reg(const char* str)
		{
			_ctors[sym(str)] = &construct<T>;
		}
Пример #14
0
		Component*
		create(const char* str)
		{
			return create(sym(str));
		}
Пример #15
0
			RegisterComponent(const char* name)
			{
				ComponentFactory::instance().reg<T>(name);
				T::setId(sym(name));
			}
Пример #16
0
		void
		(Component::*getMessage(size_t id, const char* name))()
		{
			return _bindings[id].messages[sym(name)];
		}