<commit_before>//===--- ParseExprCXX.cpp - C++ Expression Parsing ------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the Expression parsing implementation for C++.
//
//===----------------------------------------------------------------------===//

#include "clang/Basic/Diagnostic.h"
#include "clang/Parse/Parser.h"
#include "clang/Parse/DeclSpec.h"
#include "AstGuard.h"
using namespace clang;

/// MaybeParseCXXScopeSpecifier - Parse global scope or nested-name-specifier.
/// Returns true if a nested-name-specifier was parsed from the token stream.
///
///       '::'[opt] nested-name-specifier
///       '::'
///
///       nested-name-specifier:
///         type-name '::'
///         namespace-name '::'
///         nested-name-specifier identifier '::'
///         nested-name-specifier 'template'[opt] simple-template-id '::' [TODO]
///
bool Parser::MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS) {
  assert(getLang().CPlusPlus &&
         "Call sites of this function should be guarded by checking for C++.");

  if (Tok.isNot(tok::coloncolon)     &&
      Tok.isNot(tok::annot_cxxscope) &&
      (Tok.isNot(tok::identifier) || NextToken().isNot(tok::coloncolon)))
    return false;

  // ::new and ::delete aren't nested-name-specifiers, so parsing the :: as
  // a scope specifier only makes things more complicated.
  if (Tok.is(tok::coloncolon) && (NextToken().is(tok::kw_new) ||
                                  NextToken().is(tok::kw_delete)))
    return false;

  if (Tok.is(tok::annot_cxxscope)) {
    SS.setScopeRep(Tok.getAnnotationValue());
    SS.setRange(Tok.getAnnotationRange());
    ConsumeToken();
    return true;
  }

  SS.setBeginLoc(Tok.getLocation());

  // '::'

  if (Tok.is(tok::coloncolon)) {
    // Global scope.
    SourceLocation CCLoc = ConsumeToken();
    SS.setScopeRep(Actions.ActOnCXXGlobalScopeSpecifier(CurScope, CCLoc));
    SS.setEndLoc(CCLoc);
  }

  // nested-name-specifier:
  //   type-name '::'
  //   namespace-name '::'
  //   nested-name-specifier identifier '::'
  //   nested-name-specifier 'template'[opt] simple-template-id '::' [TODO]

  while (Tok.is(tok::identifier) && NextToken().is(tok::coloncolon)) {
    IdentifierInfo *II = Tok.getIdentifierInfo();
    SourceLocation IdLoc = ConsumeToken();
    assert(Tok.is(tok::coloncolon) &&
           "NextToken() not working properly!");
    SourceLocation CCLoc = ConsumeToken();
    if (SS.isInvalid())
      continue;

    SS.setScopeRep(
         Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, *II) );
    SS.setEndLoc(CCLoc);
  }

  return true;
}
<commit_msg>minor simplifications.<commit_after>//===--- ParseExprCXX.cpp - C++ Expression Parsing ------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the Expression parsing implementation for C++.
//
//===----------------------------------------------------------------------===//

#include "clang/Basic/Diagnostic.h"
#include "clang/Parse/Parser.h"
#include "clang/Parse/DeclSpec.h"
#include "AstGuard.h"
using namespace clang;

/// MaybeParseCXXScopeSpecifier - Parse global scope or nested-name-specifier.
/// Returns true if a nested-name-specifier was parsed from the token stream.
///
///       '::'[opt] nested-name-specifier
///       '::'
///
///       nested-name-specifier:
///         type-name '::'
///         namespace-name '::'
///         nested-name-specifier identifier '::'
///         nested-name-specifier 'template'[opt] simple-template-id '::' [TODO]
///
bool Parser::MaybeParseCXXScopeSpecifier(CXXScopeSpec &SS) {
  assert(getLang().CPlusPlus &&
         "Call sites of this function should be guarded by checking for C++.");

  if (Tok.is(tok::annot_cxxscope)) {
    SS.setScopeRep(Tok.getAnnotationValue());
    SS.setRange(Tok.getAnnotationRange());
    ConsumeToken();
    return true;
  }
  
  if (Tok.isNot(tok::coloncolon) &&
      (Tok.isNot(tok::identifier) || NextToken().isNot(tok::coloncolon)))
    return false;

  // ::new and ::delete aren't nested-name-specifiers, so parsing the :: as
  // a scope specifier only makes things more complicated.
  if (Tok.is(tok::coloncolon)) {
    Token Next = NextToken();
    if (Next.is(tok::kw_new) || Next.is(tok::kw_delete))
      return false;
  }

  SS.setBeginLoc(Tok.getLocation());

  // '::'
  if (Tok.is(tok::coloncolon)) {
    // Global scope.
    SourceLocation CCLoc = ConsumeToken();
    SS.setScopeRep(Actions.ActOnCXXGlobalScopeSpecifier(CurScope, CCLoc));
    SS.setEndLoc(CCLoc);
  }

  // nested-name-specifier:
  //   type-name '::'
  //   namespace-name '::'
  //   nested-name-specifier identifier '::'
  //   nested-name-specifier 'template'[opt] simple-template-id '::' [TODO]
  while (Tok.is(tok::identifier) && NextToken().is(tok::coloncolon)) {
    IdentifierInfo *II = Tok.getIdentifierInfo();
    SourceLocation IdLoc = ConsumeToken();
    assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!");
    SourceLocation CCLoc = ConsumeToken();
    if (SS.isInvalid())
      continue;

    SS.setScopeRep(
         Actions.ActOnCXXNestedNameSpecifier(CurScope, SS, IdLoc, CCLoc, *II));
    SS.setEndLoc(CCLoc);
  }

  return true;
}

{'fraction_non_alphanumeric': 0.2164930248984637, 'fraction_numerical': 0.0, 'mean_word_length': 2.4038461538461537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '743153', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1687, 'n_words': 354}