[Kde-bindings] Review Request 119500: Make the parser accept preprocessor lines with no directives.

Raphael Kubo da Costa rakuco at FreeBSD.org
Fri Aug 1 08:17:03 UTC 2014


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://git.reviewboard.kde.org/r/119500/
-----------------------------------------------------------

(Updated Aug. 1, 2014, 8:17 a.m.)


Status
------

This change has been marked as submitted.


Review request for KDE Bindings, Arno Rehn and Luca Beltrame.


Repository: smokegen


Description
-------

A null directive such as
  #
or
  # // some comment
is valid in C++ and should just be ignored (and it is actually present
in qglobal.h in Qt versions past 4.8.6).

Support for lines like those already worked in some cases, by only by
accident:

- The parser code currently contains several global objects that are
  either IndexedStrings or data types created by a function that creates
  IndexedStrings (this on its own is wrong and dangerous, but a fix
  requires a lot more work and is a broader issue than the one at hand).
- The initialization order of those global objects spread across
  different files is undefined: in some cases, createIndicesForTokens()
  would be called first, while in others the preprocessor directives in
  pp-engine.cpp would be the ones created first.
- An IndexedString with index 0 can mean either the first string in the
  list of strings in the index or a string with length 0, with is never
  indexed.

So when a null directive is found, skip_identifier() does not have
anything to skip over, creates an empty IndexedString and returns its
index (0). If createIndicesForTokens() is called first when globals are
being initialized, the first string in the index is "K_DCOP", which does
not match any directive in handle_directive() and allows the parsing to
continue (there does not seem to be any bad effects caused by the wrong
match).

However, if the preprocessor directives are the first globals to be
initialized, the string corresponding to #if would be the string with
index 0 in IndexedString. handle_directive() gets this directive with
index 0, assume it corresponds to an #if and parsing would fail.

We now properly recognize null directives by verifying if
skip_identifier() managed to advance in its input stream or not, since
this is the difference between its return value meaning an empty string
or the first string in the index. If it returned an empty string, there
was no directive in the line, we then assume it is a null directive and
just move on to the next line.

(KDeveloper's version of the parser is not affected by the bug fixed
here; the copies have diverged too much for it to be feasible to easily
sync from KDevelop again though)


Diffs
-----

  parser/rpp/pp-engine.cpp e8c3b965ea42f098ce9519a213beb0d3360636ca 

Diff: https://git.reviewboard.kde.org/r/119500/diff/


Testing
-------

Building smokeqt with Qt past df35604ff944e935bd07c8ca417ae24ed458908b works


Thanks,

Raphael Kubo da Costa

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-bindings/attachments/20140801/fe22450d/attachment.html>


More information about the Kde-bindings mailing list