Example #1
0
static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
  // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
  // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
  // TODO: add other combined directives in topological order.
  const OpenMPDirectiveKind F[][3] = {
    { OMPD_for, OMPD_simd, OMPD_for_simd },
    { OMPD_parallel, OMPD_for, OMPD_parallel_for },
    { OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd },
    { OMPD_parallel, OMPD_sections, OMPD_parallel_sections }
  };
  auto Tok = P.getCurToken();
  auto DKind =
      Tok.isAnnotation()
          ? OMPD_unknown
          : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
  for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
    if (DKind == F[i][0]) {
      Tok = P.getPreprocessor().LookAhead(0);
      auto SDKind =
          Tok.isAnnotation()
              ? OMPD_unknown
              : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
      if (SDKind == F[i][1]) {
        P.ConsumeToken();
        DKind = F[i][2];
      }
    }
  }
  return DKind;
}
Example #2
0
static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
  // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
  // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
  // TODO: add other combined directives in topological order.
  const OpenMPDirectiveKind F[][3] = {
      {OMPD_unknown /*cancellation*/, OMPD_unknown /*point*/,
       OMPD_cancellation_point},
      {OMPD_target, OMPD_unknown /*data*/, OMPD_target_data},
      {OMPD_for, OMPD_simd, OMPD_for_simd},
      {OMPD_parallel, OMPD_for, OMPD_parallel_for},
      {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd},
      {OMPD_parallel, OMPD_sections, OMPD_parallel_sections},
      {OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd}};
  auto Tok = P.getCurToken();
  auto DKind =
      Tok.isAnnotation()
          ? OMPD_unknown
          : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));

  bool TokenMatched = false;
  for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
    if (!Tok.isAnnotation() && DKind == OMPD_unknown) {
      TokenMatched =
          (i == 0) &&
          !P.getPreprocessor().getSpelling(Tok).compare("cancellation");
    } else {
      TokenMatched = DKind == F[i][0] && DKind != OMPD_unknown;
    }

    if (TokenMatched) {
      Tok = P.getPreprocessor().LookAhead(0);
      auto TokenIsAnnotation = Tok.isAnnotation();
      auto SDKind =
          TokenIsAnnotation
              ? OMPD_unknown
              : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));

      if (!TokenIsAnnotation && SDKind == OMPD_unknown) {
        TokenMatched =
            ((i == 0) &&
             !P.getPreprocessor().getSpelling(Tok).compare("point")) ||
            ((i == 1) && !P.getPreprocessor().getSpelling(Tok).compare("data"));
      } else {
        TokenMatched = SDKind == F[i][1] && SDKind != OMPD_unknown;
      }

      if (TokenMatched) {
        P.ConsumeToken();
        DKind = F[i][2];
      }
    }
  }
  return DKind;
}
Example #3
0
static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
    auto Tok = P.getCurToken();
    auto DKind =
        Tok.isAnnotation()
        ? OMPD_unknown
        : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
    if (DKind == OMPD_parallel) {
        Tok = P.getPreprocessor().LookAhead(0);
        auto SDKind =
            Tok.isAnnotation()
            ? OMPD_unknown
            : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
        if (SDKind == OMPD_for) {
            P.ConsumeToken();
            DKind = OMPD_parallel_for;
        } else if (SDKind == OMPD_sections) {
            P.ConsumeToken();
            DKind = OMPD_parallel_sections;
        }
    }
    return DKind;
}
Example #4
0
static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec,
                             UnqualifiedId &ReductionId) {
    SourceLocation TemplateKWLoc;
    if (ReductionIdScopeSpec.isEmpty()) {
        auto OOK = OO_None;
        switch (P.getCurToken().getKind()) {
        case tok::plus:
            OOK = OO_Plus;
            break;
        case tok::minus:
            OOK = OO_Minus;
            break;
        case tok::star:
            OOK = OO_Star;
            break;
        case tok::amp:
            OOK = OO_Amp;
            break;
        case tok::pipe:
            OOK = OO_Pipe;
            break;
        case tok::caret:
            OOK = OO_Caret;
            break;
        case tok::ampamp:
            OOK = OO_AmpAmp;
            break;
        case tok::pipepipe:
            OOK = OO_PipePipe;
            break;
        default:
            break;
        }
        if (OOK != OO_None) {
            SourceLocation OpLoc = P.ConsumeToken();
            SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()};
            ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations);
            return false;
        }
    }
    return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false,
                                /*AllowDestructorName*/ false,
                                /*AllowConstructorName*/ false, ParsedType(),
                                TemplateKWLoc, ReductionId);
}