We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
Rated
Read 244 times

Contents

Related Categories

The use of the code analysis library OpenC++: modifications, improvements, error corrections - 11. Support of const A (a) type definitions.

AndreyKarpov

11. Support of const A (a) type definitions.

OpenC++ library doesn't support definition of variables of "const A (a)" type. To correct this defect a part of the code should be changed inside Parser::rOtherDeclaration function:

if(!rDeclarators(decl, type_encode, false))
  return false;

Instead of it the following code should be used:

if(!rDeclarators(decl, type_encode, false)) {
  // Support: const A (a);
  Lex::TokenIndex after_rDeclarators = lex->Save();
  lex->Restore(before_rDeclarators);
  if (lex->CanLookAhead(3) && lex->CanLookAhead(-2)) {
    ptrdiff_t c_2 = lex->LookAhead(-2);
    ptrdiff_t c_1 = lex->LookAhead(-1);
    ptrdiff_t c0 = lex->LookAhead(0);
    ptrdiff_t c1 = lex->LookAhead(1);
    ptrdiff_t c2 = lex->LookAhead(2);
    ptrdiff_t c3 = lex->LookAhead(3);
    if (c_2 == CONST && c_1 == Identifier &&
      c0 == '(' && c1 == Identifier && c2 == ')' &&
      (c3 == ';' || c3 == '='))
    {
      Lex::TokenContainer newEmptyContainer;
      ptrdiff_t pos = before_rDeclarators;
      lex->ReplaceTokens(pos + 2, pos + 3, newEmptyContainer);
      lex->ReplaceTokens(pos + 0, pos + 1, newEmptyContainer);
      lex->Restore(before_rDeclarators - 2);
      bool res = rDeclaration(statement);
      return res;
    }
  }
}

In this code some auxiliary functions are used which are not discussed in this article. But you can find them in VivaCore library.

Comments