commsfwtools/commstools/utracedecoder/src/messagedefparser/constprocessor.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "messagedefparser\constprocessor.h"
       
    17 #include "messagedefparser\initialstate.h"
       
    18 #include "messagedefparser\definitiontokenizer.h"
       
    19 #include "util.h"
       
    20 
       
    21 namespace Parser
       
    22 {
       
    23 
       
    24 void CConstProcessor::ProcessState()
       
    25     {
       
    26     Tokens::TTokenType tokenType = CurrentTokenType();
       
    27     iResult = Parser::EUnexpectedToken;
       
    28 
       
    29     switch (iInternalState)
       
    30         {
       
    31         case EStateExpectConstIdentifier:
       
    32             // Expect an identifier for the new const
       
    33             if (tokenType == Tokens::EIdentifier)
       
    34                 {
       
    35                 CreateTempConst();
       
    36                 }
       
    37             break;
       
    38 
       
    39         case EStateExpectEquals:
       
    40             if (tokenType == Tokens::EEquals)
       
    41                 {
       
    42                 iInternalState = EStateExpectValue;
       
    43                 iResult = Parser::ENoError;
       
    44                 }
       
    45             break;
       
    46 
       
    47         case EStateExpectValue:
       
    48             {
       
    49             // Expect a value formatted as decimal or hex
       
    50             if (tokenType == Tokens::ENumberHex)
       
    51                 {
       
    52                 iIdentifier->iValue = HexToVal(CurrentToken());
       
    53                 CommitConst();
       
    54                 }
       
    55             else if (tokenType == Tokens::ENumberDec)
       
    56                 {
       
    57                 iIdentifier->iValue = atol(CurrentToken());
       
    58                 CommitConst();
       
    59                 }
       
    60             break;
       
    61             }
       
    62         }
       
    63 
       
    64     if (iResult != Parser::ENoError)
       
    65         {
       
    66         ParserSM().SetError(iResult);
       
    67         }
       
    68     }
       
    69 
       
    70 void CConstProcessor::CreateTempConst()
       
    71     {
       
    72     if (!ParserSM().FindIdentifier(CurrentToken()))
       
    73         {
       
    74         iIdentifier = new CConstIdentifier(CurrentToken());
       
    75         iInternalState = EStateExpectEquals;
       
    76         iResult = Parser::ENoError;
       
    77         }
       
    78     else
       
    79         {
       
    80         iResult = Parser::EDuplicateIdentifier;
       
    81         }
       
    82     }
       
    83 
       
    84 void CConstProcessor::CommitConst()
       
    85     {
       
    86     ParserSM().AddIdentifier(iIdentifier);
       
    87     iIdentifier = NULL;
       
    88     ParserSM().SetState(new CInitialState(ParserSM()));
       
    89     iResult = Parser::ENoError;
       
    90     }
       
    91 
       
    92 } // namespace Parser
       
    93