void
CSegmentFileStorage::addToRecentlyUsed( CTransaction const & _transaction )
{
	boost::lock_guard<boost::mutex> lock(m_locationTobuddy);

	m_locationUsedFromLastUpdate.insert( _transaction.m_location );

	BOOST_FOREACH( CTxIn const & txIn, _transaction.vin )
	{
		uint64_t location;

		if ( !txIn.prevout.IsNull() )
		{
			if ( !CSupportTransactionsDatabase::getInstance()->getTransactionLocation( txIn.prevout.hash, location ) )
				assert( !"serious problem" );

			m_locationUsedFromLastUpdate.insert( CLocation( location ) );
		}
	}
}
Example #2
0
// creates a new empty map.
CMap::CMap(domain_type domain)
{
	int y = MAP_SIZE / 2, x = MAP_SIZE / 2;

	key_used = false;
	tiles = 1;
	xoffset = yoffset = 0;

	yx.insert(yx.begin(), MAP_SIZE, std::deque<CMapTile*>());

	for(int i = 0; i < MAP_SIZE; i++)
		for(int j = 0; j < MAP_SIZE; j++)
			yx[i].push_back(new CMapTile());

	yx[y][x]->exits = EXIT_ALL;
	yx[y][x]->explored = true;

	if (domain == DOM_OVERWORLD)
	{
		yx[y][x]->terrain = TRN_GRASS;
		yx[y][x]->Feature = new CTown;
		Party.SaveSpots.push_back(CLocation(0, 0, y, x));

		for(int i = 0; i < 4; i++)
		{
			yx[y + move_vec[i][0]][x + move_vec[i][1]]->terrain = TRN_GRASS;
			unexplored_tile.insert(yx[y + move_vec[i][0]][x + move_vec[i][1]]);
		}
	}
	else
	{
		for(int i = 0; i < 4; i++)
			unexplored_tile.insert(yx[y + move_vec[i][0]][x + move_vec[i][1]]);
		yx[y][x]->terrain = TRN_DUNGEON;
		yx[y][x]->Feature = new CPortal(FEA_STAIRS_UP);
	}
#ifdef _DEBUG_MAP
	message("Map has %d unexplored tiles.", unexplored_tile.size());
#endif
}
Example #3
0
    static void DisplayRecognitionError(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *tokenNames)
    {
      pANTLR3_EXCEPTION ex = recognizer->state->exception;
      
      freettcn::translator::CTranslator &translator = freettcn::translator::CTranslator::Instance();
      unsigned line = ex->line;
      unsigned line2;
      unsigned pos = ex->charPositionInLine + 1;
      unsigned pos2;
      std::stringstream msg;
      std::stringstream msg2;
      std::string note;
      
      // How we determine the next piece is dependent on which thing raised the error.
      switch(recognizer->type) {
      case ANTLR3_TYPE_LEXER:
        {
          pANTLR3_LEXER lexer = (pANTLR3_LEXER)recognizer->super;
          
          if(ex->type == ANTLR3_NO_VIABLE_ALT_EXCEPTION)
            msg << "Cannot match to any predicted input";
          else
            msg << (pANTLR3_UINT8)ex->message;

          ANTLR3_INT32 width;
          
          width = ANTLR3_UINT32_CAST(( (pANTLR3_UINT8)lexer->input->data + (lexer->input->size(lexer->input) )) - (pANTLR3_UINT8)(ex->index));

          if(width >= 1) {
            if(isprint(ex->c))
              msg << " near '" << (char)ex->c << "'";
            else
              msg << " near char(0x" << std::hex << std::setw(2) << (int)ex->c << std::dec << ")";
          }
          else {
            msg << " '<EOF>'";
            
            // prepare second error
            line2 = lexer->rec->state->tokenStartLine;
            pos2 = lexer->rec->state->tokenStartCharPositionInLine;
            //            msg << fileName << ":" << (ANTLR3_UINT32)(lexer->rec->state->tokenStartLine) <<
            //              ":" << (ANTLR3_UINT32)(lexer->rec->state->tokenStartCharPositionInLine) << ": ";
            width = ANTLR3_UINT32_CAST(((pANTLR3_UINT8)lexer->input->data + (lexer->input->size(lexer->input))) - (pANTLR3_UINT8)lexer->rec->state->tokenStartCharIndex);
            if(width >= 1)
              msg2 << "The lexer was matching from: " << std::string((char *)lexer->rec->state->tokenStartCharIndex, 0, 20) << std::endl;
            else
              msg2 << "The lexer was matching from the end of the line" << std::endl;
            
            note = "Above errors indicates a poorly specified lexer RULE or unterminated input element such as: \"STRING[\"]";
          }
        }
        break;

      case ANTLR3_TYPE_PARSER:
        {
          pANTLR3_COMMON_TOKEN token = (pANTLR3_COMMON_TOKEN)ex->token;
          
          if(ex->type == ANTLR3_NO_VIABLE_ALT_EXCEPTION)
            msg << "Cannot match '" << token->getText(token)->chars << "' to any predicted input";
          else {
            msg << (pANTLR3_UINT8)ex->message;
            
            if(token) {
              if (token->type == ANTLR3_TOKEN_EOF)
                msg << " at '<EOF>'";
              else {
                if(ex->type == ANTLR3_MISSING_TOKEN_EXCEPTION) {
                  if(!tokenNames)
                    msg << " [" << ex->expecting << "]";
                  else {
                    if(ex->expecting == ANTLR3_TOKEN_EOF)
                      msg << " '<EOF>'";
                    else
                      msg << " '" << tokenNames[ex->expecting] << "'";
                  }
                }
                else {
                  msg << " near '" << token->getText(token)->chars << "'";
                }
              }
            }
            
            if(ex->type == ANTLR3_UNWANTED_TOKEN_EXCEPTION) {
              if(tokenNames) {
                if(ex->expecting == ANTLR3_TOKEN_EOF)
                  msg << " ('<EOF>' expected)";
                else
                  msg << " ('" << tokenNames[ex->expecting] << "' expected)";
              }
            }
          }
        }
        break;
        
      default:
        std::cerr << "DisplayRecognitionError() called by unknown parser type - provide override for this function" << std::endl;
        return;
      }
      
      switch(ex->type) {
      case ANTLR3_UNWANTED_TOKEN_EXCEPTION:
        // Indicates that the recognizer was fed a token which seesm to be
        // spurious input. We can detect this when the token that follows
        // this unwanted token would normally be part of the syntactically
        // correct stream. Then we can see that the token we are looking at
        // is just something that should not be there and throw this exception.
        //
        if(recognizer->type != ANTLR3_TYPE_PARSER) {
          if(tokenNames == NULL)
            ANTLR3_FPRINTF(stderr, " : Extraneous input...");
          else {
            if(ex->expecting == ANTLR3_TOKEN_EOF)
              ANTLR3_FPRINTF(stderr, " : Extraneous input - expected <EOF>\n");
            else
              ANTLR3_FPRINTF(stderr, " : Extraneous input - expected %s ...\n", tokenNames[ex->expecting]);
          }
        }
        break;
        
      case ANTLR3_MISSING_TOKEN_EXCEPTION:
        // Indicates that the recognizer detected that the token we just
        // hit would be valid syntactically if preceeded by a particular 
        // token. Perhaps a missing ';' at line end or a missing ',' in an
        // expression list, and such like.
        break;
        
      case ANTLR3_RECOGNITION_EXCEPTION:
        // Indicates that the recognizer received a token
        // in the input that was not predicted. This is the basic exception type 
        // from which all others are derived. So we assume it was a syntax error.
        // You may get this if there are not more tokens and more are needed
        // to complete a parse for instance.
        break;
        
      case ANTLR3_MISMATCHED_TOKEN_EXCEPTION:
        // We were expecting to see one thing and got another. This is the
        // most common error if we coudl not detect a missing or unwanted token.
        // Here you can spend your efforts to
        // derive more useful error messages based on the expected
        // token set and the last token and so on. The error following
        // bitmaps do a good job of reducing the set that we were looking
        // for down to something small. Knowing what you are parsing may be
        // able to allow you to be even more specific about an error.
        //
        if(!tokenNames)
          ANTLR3_FPRINTF(stderr, " : syntax error...\n");
        else {
          if(ex->expecting == ANTLR3_TOKEN_EOF)
            ANTLR3_FPRINTF(stderr, " : expected <EOF>\n");
          else
            ANTLR3_FPRINTF(stderr, " : expected %s ...\n", tokenNames[ex->expecting]);
        }
        break;
        
      case ANTLR3_NO_VIABLE_ALT_EXCEPTION:
        // We could not pick any alt decision from the input given
        // so god knows what happened - however when you examine your grammar,
        // you should. It means that at the point where the current token occurred
        // that the DFA indicates nowhere to go from here.
        //
        if(recognizer->type != ANTLR3_TYPE_LEXER && recognizer->type != ANTLR3_TYPE_PARSER)
          ANTLR3_FPRINTF(stderr, " : cannot match to any predicted input...\n");
        break;
        
      case ANTLR3_MISMATCHED_SET_EXCEPTION:
        {
          ANTLR3_UINT32 count;
          ANTLR3_UINT32 bit;
          ANTLR3_UINT32 size;
          ANTLR3_UINT32 numbits;
          pANTLR3_BITSET errBits;
          
          // This means we were able to deal with one of a set of
          // possible tokens at this point, but we did not see any
          // member of that set.
          //
          ANTLR3_FPRINTF(stderr, " : unexpected input...\n  expected one of : ");
          
          // What tokens could we have accepted at this point in the
          // parse?
          //
          count   = 0;
          errBits = antlr3BitsetLoad(ex->expectingSet);
          numbits = errBits->numBits(errBits);
          size    = errBits->size(errBits);
          
          if(size > 0) {
            // However many tokens we could have dealt with here, it is usually
            // not useful to print ALL of the set here. I arbitrarily chose 8
            // here, but you should do whatever makes sense for you of course.
            // No token number 0, so look for bit 1 and on.
            //
            for(bit = 1; bit < numbits && count < 8 && count < size; bit++) {
              // TODO: This doesn;t look right - should be asking if the bit is set!!
              //
              if  (tokenNames[bit]) {
                ANTLR3_FPRINTF(stderr, "%s%s", count > 0 ? ", " : nullptr, tokenNames[bit]); 
                count++;
              }
            }
            ANTLR3_FPRINTF(stderr, "\n");
          }
          else {
            ANTLR3_FPRINTF(stderr, "Actually dude, we didn't seem to be expecting anything here, or at least\n");
            ANTLR3_FPRINTF(stderr, "I could not work out what I was expecting, like so many of us these days!\n");
          }
        }
        break;
        
      case ANTLR3_EARLY_EXIT_EXCEPTION:
        // We entered a loop requiring a number of token sequences
        // but found a token that ended that sequence earlier than
        // we should have done.
        //
        ANTLR3_FPRINTF(stderr, " : missing elements...\n");
        break;
        
      default:
        
        // We don't handle any other exceptions here, but you can
        // if you wish. If we get an exception that hits this point
        // then we are just going to report what we know about the
        // token.
        //
        ANTLR3_FPRINTF(stderr, " : syntax not recognized...\n");
        std::cout << "Unknown exception type: " << ex->type << std::endl;
        break;
      }
      
      translator.Error(CLocation(translator.File(), line, pos), msg.str());
      if(!msg2.str().empty())
        translator.Error(CLocation(translator.File(), line2, pos2), msg2.str());
      if(!note.empty())
        translator.Note(CLocation(translator.File(), line2, pos2), note);
    }
Example #4
0
CLocation CChartArea::GetLocation()
{
	LPDISPATCH pDispatch;
	GetProperty(0x3, VT_DISPATCH, (void*)&pDispatch);
	return CLocation(pDispatch);
}