From: <bl...@us...> - 2003-03-18 08:12:21
|
Update of /cvsroot/cpptool/rfta/src/rftaparser In directory sc8-pr-cvs1:/tmp/cvs-serv702/src/rftaparser Modified Files: ForIterationExpressionParser.cpp ForIterationExpressionParser.h Log Message: * modified to match not structure (null expression instead of no node) * refactored a bit Index: ForIterationExpressionParser.cpp =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ForIterationExpressionParser.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ForIterationExpressionParser.cpp 20 Dec 2002 19:41:14 -0000 1.1 --- ForIterationExpressionParser.cpp 18 Mar 2003 08:12:18 -0000 1.2 *************** *** 15,139 **** ! ForIterationExpressionParser::ForIterationExpressionParser( ParseContext &context, ! const char *start, ! const char *end ) ! : Parser( context, start, end ) ! { ! } ! ! ! ForIterationExpressionParser::~ForIterationExpressionParser() ! { ! } ! ! bool ! ForIterationExpressionParser::parse( ) ! { ! Tracker tracker( "ForIterationExpressionParser::parse", *this ); ! ASTNodePtr iterationExpression = ! Parser::createASTNode( ASTNodeTypes::forIterationExpression, ! getParentNode(), ! getStartIndex()+1, ! getCurrentLength() ); ! // set up root node created by this parser ! context_.addNode( iterationExpression ); ! ! // ! // PARSE FOR-DECLARATION-EXPRESSION ! // ! // get to the beginning of the for-declaration ! expect( '(' ); ! skipSpaces(); ! // check if the for-declaration is not empty ! // (no property node will be added in case of an empty declaration element) ! if (*current_ !=';') ! { ! int startIndex = getCurrentIndex(); ! // find the end of the condition property: ! if ( !tryReadUntilNext( ';' ) ) ! return false; ! int declarationLength = getCurrentIndex() - startIndex; ! ASTNodePtr declarationNode = ! Parser::createASTNode( ASTNodeTypes::declarationOrExpression, ! iterationExpression, ! startIndex, ! declarationLength ); ! iterationExpression->setPropertyNode( ASTNodeProperties::declarationProperty, ! declarationNode ); ! } else ! { // this is an empty declaration, so skip only the ';' ! current_++; ! } ! // ! // CREATE NODE FOR 'FOR-CONDITION-EXPRESSION' ! // ! // start a sub parser to get the condition-property ! current_--; // just to make sure that we got all... ! expect( ';' ); ! skipSpaces(); - if (*current_ !=';') - { - int startIndex = getCurrentIndex(); - // find the end of the condition property: - if ( !tryReadUntilNext( ';' ) ) - return false; - int conditionLength = getCurrentIndex() - startIndex; ! ASTNodePtr conditionNode = ! Parser::createASTNode( ASTNodeTypes::unparsedConditionExpression, ! iterationExpression, ! startIndex, ! conditionLength ); - iterationExpression->setPropertyNode( ASTNodeProperties::conditionProperty, - conditionNode ); - } else - { // this is an empty condition, so skip only the ';' - current_++; - } ! // ! // PARSE FOR-NEXT-EXPRESSION ! // ! // start a sub parser to get the next-step-property ! current_--; // just to make sure that we got all... ! expect( ';' ); ! skipSpaces(); - if (*current_ !=')') - { - int startIndex = getCurrentIndex(); - // find the end of the next-step property: - if ( !tryReadUntilNext( ')' ) ) - return false; - int nextStepLength = getCurrentIndex() - startIndex - 1; // "-1" because ')' is not part of the next step ! ! //@todo: [AB] is this really a "declarationOrExpression" ? ! ASTNodePtr nextStepNode = ! Parser::createASTNode( ASTNodeTypes::declarationOrExpression, ! iterationExpression, ! startIndex, ! nextStepLength ); - iterationExpression->setPropertyNode( ASTNodeProperties::nextStepProperty, - nextStepNode ); - - } else - { // this is an empty next-step-expression, so skip only the ')' - current_++; - } - // current-length minus 2 because of the '(' and ')' we do not count - iterationExpression->setLength( getCurrentLength() - 2 ); ! return true; ! } ! } // namespace Refactoring --- 15,129 ---- ! ForIterationExpressionParser::ForIterationExpressionParser( ParseContext &context, ! const char *start, ! const char *end ) ! : Parser( context, start, end ) ! { ! } ! ! ! ForIterationExpressionParser::~ForIterationExpressionParser() ! { ! } ! ! ! bool ! ForIterationExpressionParser::parse( ) ! { ! Tracker tracker( "ForIterationExpressionParser::parse", *this ); ! ! ASTNodePtr iterationExpression = ! Parser::createASTNode( ASTNodeTypes::forIterationExpression, ! getParentNode(), ! getStartIndex()+1, ! getCurrentLength() ); ! // set up root node created by this parser ! context_.addNode( iterationExpression ); ! expect( '(' ); ! skipSpaces(); ! int declarationStartIndex = getCurrentIndex(); ! if ( !tryReadUntilNext( ';' ) ) ! return false; ! addDeclarationNode( declarationStartIndex, getCurrentIndex()-1, iterationExpression ); ! skipSpaces(); ! int conditionStartIndex = getCurrentIndex(); ! if ( !tryReadUntilNext( ';' ) ) ! return false; ! addConditionNode( conditionStartIndex, getCurrentIndex()-1, iterationExpression ); ! skipSpaces(); ! int iterationStartIndex = getCurrentIndex(); ! if ( !tryReadUntilNext( ')' ) ) ! return false; ! //@todo: [AB] is this really a "declarationOrExpression" ? ! addIterationNode( iterationStartIndex, getCurrentIndex()-1, iterationExpression ); ! // current-length minus 2 because of the '(' and ')' we do not count ! iterationExpression->setLength( getCurrentLength() - 2 ); ! return true; ! } ! void ! ForIterationExpressionParser::addDeclarationNode( int startIndex, ! int endIndex, ! const ASTNodePtr &iterationExpression ) ! { ! addNode( startIndex, ! endIndex, ! iterationExpression, ! ASTNodeTypes::declarationOrExpression, ! ASTNodeProperties::declarationProperty ); ! } ! void ! ForIterationExpressionParser::addConditionNode( int startIndex, ! int endIndex, ! const ASTNodePtr &iterationExpression ) ! { ! addNode( startIndex, ! endIndex, ! iterationExpression, ! ASTNodeTypes::unparsedConditionExpression, ! ASTNodeProperties::conditionProperty ); ! } ! void ! ForIterationExpressionParser::addIterationNode( int startIndex, ! int endIndex, ! const ASTNodePtr &iterationExpression ) ! { ! addNode( startIndex, ! endIndex, ! iterationExpression, ! ASTNodeTypes::declarationOrExpression, ! ASTNodeProperties::nextStepProperty ); ! } ! void ! ForIterationExpressionParser::addNode( int startIndex, ! int endIndex, ! const ASTNodePtr &iterationExpression, ! const ASTNodeType &nodeType, ! const ASTNodeProperty &nodeProperty ) ! { ! int length = endIndex - startIndex; ! ASTNodeType actualNodeType = (length == 0) ? ASTNodeTypes::nullExpression ! : nodeType; ! ASTNodePtr node = Parser::createASTNode( actualNodeType, ! iterationExpression, ! startIndex, ! length ); ! ! iterationExpression->setPropertyNode( nodeProperty, node ); ! } ! } // namespace Refactoring Index: ForIterationExpressionParser.h =================================================================== RCS file: /cvsroot/cpptool/rfta/src/rftaparser/ForIterationExpressionParser.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ForIterationExpressionParser.h 20 Dec 2002 19:41:12 -0000 1.1 --- ForIterationExpressionParser.h 18 Mar 2003 08:12:18 -0000 1.2 *************** *** 28,31 **** --- 28,48 ---- bool parse(); + + private: + void addDeclarationNode( int startIndex, + int endIndex, + const ASTNodePtr &iterationExpression ); + void addConditionNode( int startIndex, + int endIndex, + const ASTNodePtr &iterationExpression ); + void addIterationNode( int startIndex, + int endIndex, + const ASTNodePtr &iterationExpression ); + + void addNode( int startIndex, + int endIndex, + const ASTNodePtr &iterationExpression, + const ASTNodeType &nodeType, + const ASTNodeProperty &nodeProperty ); }; |