xref: /freebsd/contrib/llvm-project/clang/lib/Basic/MakeSupport.cpp (revision ebacd8013fe5f7fdf9f6a5b286f6680dd2891036)
1 //===-- MakeSuport.cpp --------------------------------------------------*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "clang/Basic/MakeSupport.h"
10 
11 void clang::quoteMakeTarget(StringRef Target, SmallVectorImpl<char> &Res) {
12   for (unsigned i = 0, e = Target.size(); i != e; ++i) {
13     switch (Target[i]) {
14     case ' ':
15     case '\t':
16       // Escape the preceding backslashes
17       for (int j = i - 1; j >= 0 && Target[j] == '\\'; --j)
18         Res.push_back('\\');
19 
20       // Escape the space/tab
21       Res.push_back('\\');
22       break;
23     case '$':
24       Res.push_back('$');
25       break;
26     case '#':
27       Res.push_back('\\');
28       break;
29     default:
30       break;
31     }
32 
33     Res.push_back(Target[i]);
34   }
35 }
36