Exemplo n.º 1
0
def parse_foreach(ctx, tokens, breakstack):
  """
  ``parse_foreach()`` has a couple of forms:

  * the usual form
  * range form
  * in (lists/items) form

  This function is just the dispatcher

  :see: https://cmake.org/cmake/help/latest/command/foreach.html
  """

  semantic_iter = iter_semantic_tokens(tokens)
  # first token is always the loop variable
  _ = next(semantic_iter, None)
  # Second token is usually the descriminator
  second_token = next(semantic_iter, None)

  if second_token is None:
    # All foreach() statements should have at least two arguments
    logger.warning("Invalid foreach() statement at %s",
                   tokens[0].get_location())
    return StandardArgTree.parse(
        ctx, tokens, npargs='*', kwargs={}, flags=[], breakstack=breakstack)

  descriminator = second_token.spelling.upper()
  dispatchee = {
      "RANGE": parse_foreach_range,
      "IN": parse_foreach_in
  }.get(descriminator, None)
  if dispatchee is not None:
    return dispatchee(ctx, tokens, breakstack)

  return parse_foreach_standard(ctx, tokens, breakstack)
Exemplo n.º 2
0
def parse_add_library(ctx, tokens, breakstack):
    """
  ``add_library()`` has several forms:

  * normal libraires
  * imported libraries
  * object libraries
  * alias libraries
  * interface libraries

  This function is just the dispatcher

  :see: https://cmake.org/cmake/help/latest/command/add_library.html
  """

    semantic_iter = iter_semantic_tokens(tokens)
    # NOTE(josh): first token is always the name of the library
    _ = next(semantic_iter, None)
    # Second token is usually the descriminator, except for INTERFACE
    second_token = next(semantic_iter, None)

    if second_token is None:
        # All add_library() commands should have at least two arguments
        logger.warning("Invalid add_library() command at %s",
                       tokens[0].get_location())
        return StandardArgTree.parse(ctx,
                                     tokens,
                                     npargs='*',
                                     kwargs={},
                                     flags=[],
                                     breakstack=breakstack)

    descriminator = second_token.spelling.upper()
    parsemap = {
        "OBJECT": parse_add_library_object,
        "ALIAS": parse_add_library_alias,
        "INTERFACE": parse_add_library_interface,
        "IMPORTED": parse_add_library_imported
    }
    if descriminator in parsemap:
        return parsemap[descriminator](ctx, tokens, breakstack)

    third_token = next(semantic_iter, None)
    if third_token is not None:
        descriminator = third_token.spelling.upper()
        if descriminator == "IMPORTED":
            return parse_add_library_imported(ctx, tokens, breakstack)

    # If the descriminator token might be a variable dereference, then it
    # might be hiding the descriminator... so we shouldn't infer
    # sortability unless it is a word that doesn't match any of the descriminator
    # flags
    sortable = True
    if "${" in second_token.spelling or "${" in third_token.spelling:
        sortable = False
    return parse_add_library_standard(ctx, tokens, breakstack, sortable)
Exemplo n.º 3
0
def parse_ctest_sleep(ctx, tokens, breakstack):
  """
  ::

    ctest_sleep(<seconds>)
    ctest_sleep(<time1> <duration> <time2>)

  :see: https://cmake.org/cmake/help/latest/command/ctest_sleep.html
  """
  semantic_tokens = list(iter_semantic_tokens(tokens))
  if len(semantic_tokens) == 1:
    return StandardArgTree.parse(ctx, tokens, 1, {}, [], breakstack)
  return StandardArgTree.parse(ctx, tokens, 3, {}, [], breakstack)