OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/err.h" | 5 #include "tools/gn/err.h" |
6 #include "tools/gn/functions.h" | 6 #include "tools/gn/functions.h" |
7 #include "tools/gn/parse_tree.h" | 7 #include "tools/gn/parse_tree.h" |
8 #include "tools/gn/scope.h" | 8 #include "tools/gn/scope.h" |
9 | 9 |
10 namespace functions { | 10 namespace functions { |
11 | 11 |
12 const char kForEach[] = "foreach"; | 12 const char kForEach[] = "foreach"; |
13 const char kForEach_HelpShort[] = | 13 const char kForEach_HelpShort[] = |
14 "foreach: Iterate over a list."; | 14 "foreach: Iterate over a list."; |
15 const char kForEach_Help[] = | 15 const char kForEach_Help[] = |
16 "foreach: Iterate over a list.\n" | 16 "foreach: Iterate over a list.\n" |
17 "\n" | 17 "\n" |
18 " foreach(<loop_var>, <list>) {\n" | 18 " foreach(<loop_var>, <list>) {\n" |
19 " <loop contents>\n" | 19 " <loop contents>\n" |
20 " }\n" | 20 " }\n" |
21 "\n" | 21 "\n" |
22 " Executes the loop contents block over each item in the list,\n" | 22 " Executes the loop contents block over each item in the list,\n" |
23 " assigning the loop_var to each item in sequence.\n" | 23 " assigning the loop_var to each item in sequence. The loop_var will be\n" |
| 24 " a copy so assigning to it will not mutate the list.\n" |
24 "\n" | 25 "\n" |
25 " The block does not introduce a new scope, so that variable assignments\n" | 26 " The block does not introduce a new scope, so that variable assignments\n" |
26 " inside the loop will be visible once the loop terminates.\n" | 27 " inside the loop will be visible once the loop terminates.\n" |
27 "\n" | 28 "\n" |
28 " The loop variable will temporarily shadow any existing variables with\n" | 29 " The loop variable will temporarily shadow any existing variables with\n" |
29 " the same name for the duration of the loop. After the loop terminates\n" | 30 " the same name for the duration of the loop. After the loop terminates\n" |
30 " the loop variable will no longer be in scope, and the previous value\n" | 31 " the loop variable will no longer be in scope, and the previous value\n" |
31 " (if any) will be restored.\n" | 32 " (if any) will be restored.\n" |
32 "\n" | 33 "\n" |
33 "Example\n" | 34 "Example\n" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 scope->SetValue(loop_var, old_loop_value, old_loop_value.origin()); | 112 scope->SetValue(loop_var, old_loop_value, old_loop_value.origin()); |
112 } else { | 113 } else { |
113 // Loop variable was undefined before loop, delete it. | 114 // Loop variable was undefined before loop, delete it. |
114 scope->RemoveIdentifier(loop_var); | 115 scope->RemoveIdentifier(loop_var); |
115 } | 116 } |
116 | 117 |
117 return Value(); | 118 return Value(); |
118 } | 119 } |
119 | 120 |
120 } // namespace functions | 121 } // namespace functions |
OLD | NEW |