1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gn/c_substitution_type.h"
6
7 #include <stddef.h>
8 #include <stdlib.h>
9
10 #include "gn/err.h"
11
12 const SubstitutionTypes CSubstitutions = {
13 &CSubstitutionAsmFlags, &CSubstitutionCFlags,
14 &CSubstitutionCFlagsC, &CSubstitutionCFlagsCc,
15 &CSubstitutionCFlagsObjC, &CSubstitutionCFlagsObjCc,
16 &CSubstitutionDefines, &CSubstitutionFrameworkDirs,
17 &CSubstitutionIncludeDirs,
18
19 &CSubstitutionLinkerInputs, &CSubstitutionLinkerInputsNewline,
20 &CSubstitutionLdFlags, &CSubstitutionLibs,
21 &CSubstitutionSoLibs, &CSubstitutionFrameworks,
22
23 &CSubstitutionArFlags,
24 };
25
26 // Valid for compiler tools.
27 const Substitution CSubstitutionAsmFlags = {"{{asmflags}}", "asmflags"};
28 const Substitution CSubstitutionCFlags = {"{{cflags}}", "cflags"};
29 const Substitution CSubstitutionCFlagsC = {"{{cflags_c}}", "cflags_c"};
30 const Substitution CSubstitutionCFlagsCc = {"{{cflags_cc}}", "cflags_cc"};
31 const Substitution CSubstitutionCFlagsObjC = {"{{cflags_objc}}", "cflags_objc"};
32 const Substitution CSubstitutionCFlagsObjCc = {"{{cflags_objcc}}",
33 "cflags_objcc"};
34 const Substitution CSubstitutionDefines = {"{{defines}}", "defines"};
35 const Substitution CSubstitutionFrameworkDirs = {"{{framework_dirs}}",
36 "framework_dirs"};
37 const Substitution CSubstitutionIncludeDirs = {"{{include_dirs}}",
38 "include_dirs"};
39
40 // Valid for linker tools.
41 const Substitution CSubstitutionLinkerInputs = {"{{inputs}}", "in"};
42 const Substitution CSubstitutionLinkerInputsNewline = {"{{inputs_newline}}",
43 "in_newline"};
44 const Substitution CSubstitutionLdFlags = {"{{ldflags}}", "ldflags"};
45 const Substitution CSubstitutionLibs = {"{{libs}}", "libs"};
46 const Substitution CSubstitutionSoLibs = {"{{solibs}}", "solibs"};
47 const Substitution CSubstitutionFrameworks = {"{{frameworks}}", "frameworks"};
48
49 // Valid for alink only.
50 const Substitution CSubstitutionArFlags = {"{{arflags}}", "arflags"};
51
IsValidCompilerSubstitution(const Substitution * type)52 bool IsValidCompilerSubstitution(const Substitution* type) {
53 return IsValidToolSubstitution(type) || IsValidSourceSubstitution(type) ||
54 type == &SubstitutionSource || type == &CSubstitutionAsmFlags ||
55 type == &CSubstitutionCFlags || type == &CSubstitutionCFlagsC ||
56 type == &CSubstitutionCFlagsCc || type == &CSubstitutionCFlagsObjC ||
57 type == &CSubstitutionCFlagsObjCc || type == &CSubstitutionDefines ||
58 type == &CSubstitutionFrameworkDirs ||
59 type == &CSubstitutionIncludeDirs;
60 }
61
IsValidCompilerOutputsSubstitution(const Substitution * type)62 bool IsValidCompilerOutputsSubstitution(const Substitution* type) {
63 // All tool types except "output" (which would be infinitely recursive).
64 return (IsValidToolSubstitution(type) && type != &SubstitutionOutput) ||
65 IsValidSourceSubstitution(type);
66 }
67
IsValidLinkerSubstitution(const Substitution * type)68 bool IsValidLinkerSubstitution(const Substitution* type) {
69 return IsValidToolSubstitution(type) || type == &SubstitutionOutputDir ||
70 type == &SubstitutionOutputExtension ||
71 type == &CSubstitutionLinkerInputs ||
72 type == &CSubstitutionLinkerInputsNewline ||
73 type == &CSubstitutionLdFlags || type == &CSubstitutionLibs ||
74 type == &CSubstitutionSoLibs || type == &CSubstitutionFrameworks;
75 }
76
IsValidLinkerOutputsSubstitution(const Substitution * type)77 bool IsValidLinkerOutputsSubstitution(const Substitution* type) {
78 // All valid compiler outputs plus the output extension.
79 return IsValidCompilerOutputsSubstitution(type) ||
80 type == &SubstitutionOutputDir || type == &SubstitutionOutputExtension;
81 }
82
IsValidALinkSubstitution(const Substitution * type)83 bool IsValidALinkSubstitution(const Substitution* type) {
84 return IsValidToolSubstitution(type) ||
85 type == &SubstitutionOutputDir ||
86 type == &SubstitutionOutputExtension ||
87 type == &CSubstitutionLinkerInputs ||
88 type == &CSubstitutionLinkerInputsNewline ||
89 type == &CSubstitutionArFlags;
90 }
91