Exemplo n.º 1
0
void pp::handle_include(bool skip_current_path, Stream& input, Stream& output)
{
  if (isLetter(input.current()) || input == '_') {
    pp_macro_expander expand_include(this);

    Anchor inputPosition = input.inputPosition();
    SimpleCursor originalInputPosition = input.originalInputPosition();
    PreprocessedContents includeString;
    {
      Stream cs(&includeString);
      expand_include(input, cs);
    }

    skip_blanks(input, devnull());
    RETURN_ON_FAIL(!includeString.isEmpty() && (includeString.first() == indexFromCharacter('<') || includeString.first() == indexFromCharacter('"')));

    Stream newInput(&includeString, inputPosition);
    newInput.setOriginalInputPosition(originalInputPosition);
    handle_include(skip_current_path, newInput, output);
    return;
  }

  RETURN_ON_FAIL(input == '<' || input == '"');
  char quote((input == '"') ? '"' : '>');
  ++input;

  PreprocessedContents includeNameB;

  while (!input.atEnd() && input != quote) {
    RETURN_ON_FAIL(input != '\n');

    includeNameB.append(input);
    ++input;
  }

  QString includeName(QString::fromUtf8(stringFromContents(includeNameB)));

  Stream* include = m_preprocessor->sourceNeeded(includeName, quote == '"' ? Preprocessor::IncludeLocal : Preprocessor::IncludeGlobal, input.inputPosition().line, skip_current_path);

  if (include && !include->atEnd()) {
//     m_files.push(IndexedString(includeName));

//     output.mark(Anchor(0, 0));

    operator()(*include, output);

    // restore the file name and sync the buffer
//     output.mark(input.inputPosition());
  }

  delete include;
}
Exemplo n.º 2
0
void pp::handle_include(bool skip_current_path, Stream& input, Stream& output)
{
  if (input.atEnd()) {
    createProblem(input, i18n("invalid include directive"));
    return;
  }
  QByteArray bytes = KDevelop::IndexedString::fromIndex(input.current()).byteArray();
  if (bytes.size() > 0 && (isLetter(bytes.at(0)) || bytes.at(0) == '_')) {
    pp_macro_expander expand_include(this);

    Anchor inputPosition = input.inputPosition();
    KDevelop::CursorInRevision originalInputPosition = input.originalInputPosition();
    PreprocessedContents includeString;
    {
      Stream cs(&includeString);
      expand_include(input, cs);
    }

    skip_blanks(input, devnull());
    RETURN_ON_FAIL(!includeString.isEmpty() && (includeString.first() == indexFromCharacter('<') || includeString.first() == indexFromCharacter('"')));

    // Filter out whitespaces
    PreprocessedContents filteredIncludeString;
    if(!includeString.empty() && includeString.front() == indexFromCharacter('"'))
    {
      // Don't filter if it is a string token
      filteredIncludeString = includeString;
    }
    else
    {
      // Filter out whitespaces, as the preprocessor adds them in random places to prevent implicit token merging
      foreach(uint index, includeString)
          if(index != indexFromCharacter(' '))
            filteredIncludeString.push_back(index);
    }
    
    Stream newInput(&filteredIncludeString, inputPosition);
    newInput.setOriginalInputPosition(originalInputPosition);
    handle_include(skip_current_path, newInput, output);
    return;
  }