}
}
}
+ // Search for variable definition:
+ // examples: char* const x; String* x[8*10]; List<String&> z = 1+2;
+ int maxIx = count - 1;
+ CppOperator op;
+ for (int ix = 0; ix < count; ix++){
+ const FormatToken& item = m_logicalLine.constData()[ix];
+ if (item.isOperator(OP_ASSIGN)){
+ maxIx = ix - 1;
+ break;
+ }
+ if (item.isTokenType(TOKEN_OPERATOR)){
+ op = (CppOperator) item.id();
+ if (op == OP_LBRACKET){
+ while(++ix < count){
+ const FormatToken& item2 = m_logicalLine.constData()[maxIx];
+ if (item2.isOperator(OP_RBRACKET))
+ break;
+ }
+ } else if (! (op == OP_STAR || op == OP_BIT_AND || op == OP_LT
+ || op == OP_GT)){
+ maxIx = -1;
+ break;
+ }
+ }
+ }
+ while(--maxIx >= 0){
+ FormatToken const& item = m_logicalLine.constData()[maxIx];
+ if (item.isOperator(OP_RBRACKET)){
+ while(--maxIx >= 0){
+ FormatToken const& item2 = m_logicalLine.constData()[maxIx];
+ if (item2.isOperator(OP_LBRACKET))
+ break;
+ }
+ } else {
+ m_isInTypeList[maxIx] = true;
+ }
+ }
}
/**
m_lexer->textOfToken(item, buffer);
lastItem = item;
}
+ ReStringUtils::chomp(buffer, ' ');
m_writer->writeLine(buffer);
m_logicalLine.clear();
}
case TOKEN_ID:
if ( (op = (CppOperator) first->id()) == OP_RPARENTH)
rc = true;
+ else if (isDeclaration && op == OP_GT)
+ rc = false;
else
rc = needsTrailingBlank((CppOperator) first->id());
break;
line = "const char* ptr = (const char*) abc(1 + 2) * 3 / 4;\n";
setTokens(line);
m_writer.buffer().clear();
+ m_formatter.flush(true);
+ checkEqu(line, m_writer.buffer());
+
+ line = "String<int&> ptr[3+(4/8)] = x(z[ix++ - 1] + 1 - 2 * 5);\n";
+ setTokens(line);
+ m_writer.buffer().clear();
m_formatter.setLastDeclToken(4);
m_formatter.flush(true);
checkEqu(line, m_writer.buffer());
*/
bool ReTest::assertEquals(const char* expected, const char* current,
const char* file, int lineNo) {
+ int len1 = strlen(expected);
+ int len2 = strlen(current);
bool equal = strcmp(expected, current) == 0;
if (!equal) {
if (strchr(expected, '\n') != NULL || strchr(current, '\n')) {
*ptr++ = '^';
*ptr = '\0';
if (ix < 10)
- error("%s-%d: error: diff at index %d\n%s\n%s\n%s", file,
- lineNo, ix, expected, current, pointer);
+ error("%s-%d: error: diff at index %d (%c/%c 0x%x/0x%x)\n%s\n%s\n%s", file,
+ lineNo, ix, printChar(expected[ix]), printChar(current[ix]),
+ expected[ix], current[ix],
+ expected, current, pointer);
else
- error("%s-%d: error: diff at index %d\n%s\n...%s\n...%s\n%s",
- file, lineNo, ix, current, expected + ix - 10 + 3,
+ error("%s-%d: error: diff at index %d (%c/%c 0x%x/0x%x)\n%s\n...%s\n...%s\n%s",
+ file, lineNo, ix, printChar(expected[ix]), printChar(current[ix]),
+ expected[ix], current[ix],
+ current, expected + ix - 10 + 3,
current + ix - 10 + 3, pointer);
}
}
bool deleteIfExists = true);
bool logContains(const char* pattern);
virtual void runTests(void) = 0;
+public:
+ inline static char printChar(char cc){
+ return cc < ' ' ? '.' : cc;
+ }
protected:
int m_errors;
unsigned offset = m_countPositionBlock * sizeof(ReSourcePosition);
m_countPositionBlock++;
char* posInBlock = &m_sourcePositionBlock->m_positions[offset];
- ReSourceUnit* unit = dynamic_cast<ReSourceUnit*>(m_currentReader
- ->currentSourceUnit());
+ ReSourceUnit* unit = m_currentReader->currentSourceUnit();
ReSourcePosition* rc = new (posInBlock) ReSourcePosition(unit,
unit->lineNo(), colNo);
return rc;
unit->setCurrentPosition(0);
if (source().currentReader() == NULL)
source().addReader(this);
+ m_currentSourceUnit = unit;
}
}