]> gitweb.hamatoma.de Git - reqt/commitdiff
recform: formatting var decl
authorhama <hama@siduction.net>
Tue, 29 Dec 2015 23:24:30 +0000 (00:24 +0100)
committerhama <hama@siduction.net>
Tue, 29 Dec 2015 23:24:30 +0000 (00:24 +0100)
appl/recform/CFormatter.cpp
appl/recform/cuReCFormatter.cpp
base/ReTest.cpp
base/ReTest.hpp
expr/ReSource.cpp

index 10affda5d2213a6275658e080453cde14d65855d..fd14e84c482b5f63c6ddedffba8735a1ca36423e 100644 (file)
@@ -114,6 +114,43 @@ void CFormatter::findTypeLists()
                        }
                }
        }
+       // 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;
+               }
+       }
 }
 
 /**
@@ -138,6 +175,7 @@ void CFormatter::flush(bool isPart)
                        m_lexer->textOfToken(item, buffer);
                        lastItem = item;
                }
+               ReStringUtils::chomp(buffer, ' ');
                m_writer->writeLine(buffer);
                m_logicalLine.clear();
        }
@@ -259,6 +297,8 @@ bool CFormatter::needsBlank(ReToken* first, ReToken* second, bool isDeclaration)
                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;
index 03964a4cc12adb85bcfaeca31d5d0670a6ab234b..9d3af70ec49f81b2c6a37bb97c8e6dac45fab36e 100644 (file)
@@ -51,6 +51,12 @@ public:
                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());
index 0c708e33ff58705cbbb94b178f5115a8139409ed..831279cf2754483eca9ce633bb7074fd616e563b 100644 (file)
@@ -168,6 +168,8 @@ bool ReTest::assertEquals(const ReString& expected, const ReString& current,
  */
 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')) {
@@ -186,11 +188,15 @@ bool ReTest::assertEquals(const char* expected, const char* current,
                        *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);
                }
        }
index f76e7c35999e4deadcce20bf448680eb8452cd05..cb96c2281a4a20f05bc8ea7db62c3b4d5324f8f9 100644 (file)
@@ -64,6 +64,10 @@ public:
                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;
index 33c4c360958bd2e689c9ef8aac6d5c76e1cee71d..ce925ee93cb651b827db26d5e8e9a141118140af 100644 (file)
@@ -506,8 +506,7 @@ const ReSourcePosition* ReSource::newPosition(int colNo) {
        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;
@@ -706,6 +705,7 @@ void ReStringReader::replaceSource(ReSourceUnitName name,
                unit->setCurrentPosition(0);
                if (source().currentReader() == NULL)
                        source().addReader(this);
+               m_currentSourceUnit = unit;
        }
 }