Commit Graph

25 Commits

Author SHA1 Message Date
Kitware Robot d9fd2f5402 Revise C++ coding style using clang-format
Run the `Utilities/Scripts/clang-format.bash` script to update
all our C++ code to a new style defined by `.clang-format`.
Use `clang-format` version 3.8.

* If you reached this commit for a line in `git blame`, re-run the blame
  operation starting at the parent of this commit to see older history
  for the content.

* See the parent commit for instructions to rebase a change across this
  style transition commit.
2016-05-16 16:05:19 -04:00
Brad King e1c7747253 Format include directive blocks and ordering with clang-format
Sort include directives within each block (separated by a blank line) in
lexicographic order (except to prioritize `sys/types.h` first).  First
run `clang-format` with the config file:

    ---
    SortIncludes: false
    ...

Commit the result temporarily.  Then run `clang-format` again with:

    ---
    SortIncludes: true
    IncludeCategories:
      - Regex:    'sys/types.h'
        Priority: -1
    ...

Commit the result temporarily.  Start a new branch and cherry-pick the
second commit.  Manually resolve conflicts to preserve indentation of
re-ordered includes.  This cleans up the include ordering without
changing any other style.

Use the following command to run `clang-format`:

    $ git ls-files -z -- \
        '*.c' '*.cc' '*.cpp' '*.cxx' '*.h' '*.hh' '*.hpp' '*.hxx' |
      egrep -z -v '(Lexer|Parser|ParserHelper)\.' |
      egrep -z -v '^Source/cm_sha2' |
      egrep -z -v '^Source/(kwsys|CursesDialog/form)/' |
      egrep -z -v '^Utilities/(KW|cm).*/' |
      egrep -z -v '^Tests/Module/GenerateExportHeader' |
      egrep -z -v '^Tests/RunCMake/CommandLine/cmake_depends/test_UTF-16LE.h' |
      xargs -0 clang-format -i

This selects source files that do not come from a third-party.

Inspired-by: Daniel Pfeifer <daniel@pfeifer-mail.de>
2016-04-29 13:58:54 -04:00
Brad King 180538c706 Source: Stabilize include order
Each source file has a logical first include file.  Include it in an
isolated block so that tools that sort includes do not move them.
2016-04-29 13:58:31 -04:00
Brad King 3a556f005d Merge topic 'preallocate-condition-keywords'
aff4a5fa cmConditionEvaluator: Use pre-allocated keywords in more places
2016-04-11 09:38:58 -04:00
Brad King aff4a5fab5 cmConditionEvaluator: Use pre-allocated keywords in more places
Inspired-by: Harry Mallon <Harry@codexdigital.com>
2016-04-08 10:45:43 -04:00
Brad King e2465c19c6 Merge topic 'preallocate-condition-keywords'
5c324294 cmConditionEvaluator: Pre-allocate keyword strings
2016-03-31 08:45:56 -04:00
Brad King 5c324294ce cmConditionEvaluator: Pre-allocate keyword strings
Calls to `IsKeyword("...")` cause runtime construction of std::string.
Avoid possible repeated allocation by pre-allocating keyword strings
during initialization.
2016-03-29 10:32:28 -04:00
Brad King 2379b3ae31 cmConditionEvaluator: Remove GetConditionContext method
All it does is call cmListFileContext::FromCommandContext, so move this
to the call sites.
2016-03-29 10:10:20 -04:00
Brad King 02fce523a1 cmConditionEvaluator: Drop unnecessary path conversion
In commit v3.4.0-rc2~1^2 (cmIfCommand: Issue CMP0054 warning with
appropriate context, 2015-10-20) we added construction of a
cmListFileContext with conversion of the calling file path.  This code
path runs on every condition (e.g. `if()`) and so the path conversion
has a noticeable performance cost.  Fortunately the only use of this
context is for insertion into cmMakefile::CMP0054ReportedIds so we do
not need to convert the path.  Simply drop the conversion.
2016-03-29 10:02:17 -04:00
Brad King 6ffc432367 cmConditionEvaluator: Fix matching of `CMAKE_MATCH_*` values (#15944)
While evaluating `if(MATCHES)` we get a `const char*` pointer to the
string to be matched.  On code like

    if(CMAKE_MATCH_COUNT MATCHES "Y")

the string to be matched may be owned by our own result variables.
We must move the value to our own buffer before clearing them.
Otherwise we risk reading freed storage.
2016-02-01 10:05:10 -05:00
Stephen Kelly d6a03b475e cmIfCommand: Issue CMP0054 warning with appropriate context. (#15802)
Commit v3.4.0-rc1~494^2~4 (cmMakefile: Add API for elseif to create
backtrace., 2015-05-29) removed the use of cmMakefileCall to push/pop
execution context in favor of a new way to create backtraces.

However, a call to cmMakefile::GetExecutionContext is still invoked to
issue a contextual CMP0054 warning through cmConditionEvaluator.  As
the elseif is not part of the call stack, this resulted in trying to
access an empty vector.

Avoid the attempt at getting execution context when evaluating elseif by
constructing a context and backtrace on behalf of the cmConditionEvaluator
in all cases.
2015-10-20 23:40:12 +02:00
Matt McCormick 14e49ed156 if: Add "TEST <test>" condition
if(TEST TestNameThatExists) will return true if a test with the name
TestNameThatExists has been added with add_test.  The syntax is similar
to if(TARGET TargetName).  Since use of "TEST" as an argument to if()
could previously be interpreted as a non-keyword argument, add policy
CMP0064 to treat it as a keyword as NEW behavior.
2015-08-03 09:22:25 -04:00
Sebastian Schuberth e7d5c142c6 cmConditionEvaluator: Remove superfluous spaces in expressions 2015-07-27 17:24:59 +02:00
Stephen Kelly f9785e0cb6 cmMakefile: Simplify CMP0054 handling. 2015-05-18 23:55:43 +02:00
Stephen Kelly e17b5e4262 cmMakefile: Add access to the top-level execution context.
This is cheaper than getting the whole backtrace, and the cmListFileBacktrace
will not always be composed of cmListFileContext objects.
2015-05-18 23:55:41 +02:00
Stephen Kelly de21168612 Port to static cmPolicies API. 2015-05-04 22:32:20 +02:00
Nils Gladitz aed6239e40 if: Implement new IN_LIST operator 2015-04-30 10:21:19 -04:00
Stephen Kelly 0aec491328 Port cmCommand consumers to cmState. 2015-04-15 11:43:49 -04:00
Brad King b5a467262b Merge topic 'drop-ancient-workarounds'
0f7bdd61 Remove VS 6 special case.
5e92c826 Remove some obsolete stuff.
15e42bb2 cmStandardIncludes: Remove obsolete cmOStringStream.
931e055d Port all cmOStringStream to std::ostringstream.
f194a009 Remove unused cmIStringStream class.
3ec1bb15 cmStandardIncludes: Remove std namespace hack.
bb3bce70 cmStandardIncludes: Remove ANSI_FOR_SCOPE hack.
28fa4923 cmStandardIncludes: Remove iostreams workaround for obsolete Compaq compiler.
837a8a63 cmStandardIncludes: Drop Comeau-related workaround.
4030ddfd Remove Borland-related undef.
17d6a6fd cmStandardIncludes: Remove comment about Borland.
26fb5011 Drop SGI as a CMake host compiler.
2015-01-12 08:57:39 -05:00
Stephen Kelly 931e055d8c Port all cmOStringStream to std::ostringstream.
All compilers hosting CMake support the std class.
2015-01-11 17:06:03 +01:00
Stephen Kelly 238dd2fbab Use insert instead of a loop in some cases.
Limit this change to inserting into a vector from a vector.

A follow up change can use insert for inserting into a set.
2015-01-11 17:00:55 +01:00
Ben Boeckel ceecd7902f cmMakefile: store the number of last matches in a CMake var
With PushScope and PopScope, keeping track of another bit of data for
each scope isn't easy. Instead, store it as another CMake variable so it
gets implicitly tracked along with everything else.

This works in a revert of commit
7d674b5f0b.
2014-12-03 11:06:44 -05:00
Ben Boeckel 7d674b5f0b Revert "ClearMatches: Only clear matches which were actually set" (#15261)
This reverts commit v3.1.0-rc1~557^2~2 (ClearMatches: Only clear matches
which were actually set, 2014-03-12).  The optimization did not track
the match count in the same scope as the variables, allowing possible
inconsistency.

Resolve conflicts in Source/cmIfCommand.cxx, Source/cmMakefile.cxx,
and Source/cmMakefile.h by moving the changes to the new location
of the code involved.
2014-11-26 13:45:06 -05:00
Nils Gladitz 188a1f236e If: Introduce policy CMP0054 - don't dereference quoted variables in if() 2014-09-11 21:23:17 +02:00
Nils Gladitz b900c1ccaa If: Extract cmConditionEvaluator from if() implementation 2014-09-11 21:17:09 +02:00