From: <sve...@us...> - 2003-04-21 03:06:31
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv6288/src/rftaparser Modified Files: VariableDeclMutatorTest.h VariableDeclMutatorTest.cpp VariableDeclMutator.h VariableDeclMutator.cpp Log Message: improved declaration parsing Index: VariableDeclMutatorTest.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/VariableDeclMutatorTest.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** VariableDeclMutatorTest.h 30 Dec 2002 15:01:57 -0000 1.5 --- VariableDeclMutatorTest.h 21 Apr 2003 03:06:26 -0000 1.6 *************** *** 19,22 **** --- 19,23 ---- CPPUNIT_TEST_SUITE( VariableDeclMutatorTest ); CPPUNIT_TEST( testIntDecl ); + CPPUNIT_TEST( testPointerDecl ); CPPUNIT_TEST( testIntArrayDecl ); CPPUNIT_TEST( testTemplatedMapDecl ); *************** *** 48,51 **** --- 49,53 ---- void testIntDecl(); + void testPointerDecl(); void testIntArrayDecl(); void testTemplatedMapDecl(); Index: VariableDeclMutatorTest.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/VariableDeclMutatorTest.cpp,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** VariableDeclMutatorTest.cpp 6 Apr 2003 16:17:20 -0000 1.14 --- VariableDeclMutatorTest.cpp 21 Apr 2003 03:06:27 -0000 1.15 *************** *** 222,225 **** --- 222,237 ---- "int ", "", "xyz", "" ); } + void + VariableDeclMutatorTest::testPointerDecl() + { + + const std::string typePrefix( "int *" ); + //int variableNameIndex = typePrefix.length(); + const std::string source( typePrefix + "xyz;" ); + SourceASTNodePtr sourceAST = RFTA_ASSERT_VARIABLE_DECL_MUTATOR_PASS( source ); + RFTA_ASSERT_VARIABLE_DECL( sourceAST, 0, + "int ", "*", "xyz", "" ); + } + Index: VariableDeclMutator.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/VariableDeclMutator.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** VariableDeclMutator.h 6 Apr 2003 16:17:20 -0000 1.7 --- VariableDeclMutator.h 21 Apr 2003 03:06:27 -0000 1.8 *************** *** 36,39 **** --- 36,40 ---- bool backtrackSkippingOverArrayBrackets(); bool backtrackSkippingOverVariableIdentifier(); + bool backtrackSkippingOverTypeModifiers(); bool isValidTypePrefix( const char *prefixEnd ); static bool isValidSecondaryTypePrefix( const char *prefixStart, Index: VariableDeclMutator.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/VariableDeclMutator.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** VariableDeclMutator.cpp 6 Apr 2003 16:17:19 -0000 1.16 --- VariableDeclMutator.cpp 21 Apr 2003 03:06:27 -0000 1.17 *************** *** 50,53 **** --- 50,60 ---- // - type is not a keyword that may come before an identifier (new, sizeof) // (there might be other, we'll find out the hard way). + //////////////////////////////////////// + // TODO: IMO, type modifiers like "*", "&", and "* const" belong to the + // secondary prefix (this property is always left empty so far) + // The reason why we have to separate them from the primary prefix lies + // in declarations like + // int *x, y; + // where y is not a pointer. bool VariableDeclMutator::tryMutate() *************** *** 75,79 **** --- 82,92 ---- if ( current_ == start_ ) // no type before identifier ! return false; + // secondary prefix (*,&,*const) + const int secondaryPrefixEndIndex = getCurrentIndex(); + const char *secondaryPrefixEnd = current_; + if (! backtrackSkippingOverTypeModifiers() ) + return false; + int prefixEndIndex = getCurrentIndex(); const char *prefixEnd = current_; *************** *** 94,98 **** prefixEndIndex, // prefix end prefixEndIndex, // secondary prefix start ! prefixEndIndex, // variable name start suffixStartIndex, suffixEndIndex ); // position of last white space after ',' if many variable --- 107,111 ---- prefixEndIndex, // prefix end prefixEndIndex, // secondary prefix start ! secondaryPrefixEndIndex, // variable name start suffixStartIndex, suffixEndIndex ); // position of last white space after ',' if many variable *************** *** 170,173 **** --- 183,200 ---- } + + bool + VariableDeclMutator::backtrackSkippingOverTypeModifiers() + { + if (! hasPrevious()) + return false; + do current_ --; + while (isSymbolChar(*current_) && hasPrevious()); + current_++; + // track back to the first non-white character + while (*current_ == ' ') + ++current_; + return true; + }; bool |