OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef TOOLS_GN_PARSE_TREE_H_ | 5 #ifndef TOOLS_GN_PARSE_TREE_H_ |
6 #define TOOLS_GN_PARSE_TREE_H_ | 6 #define TOOLS_GN_PARSE_TREE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "tools/gn/err.h" | 14 #include "tools/gn/err.h" |
15 #include "tools/gn/token.h" | 15 #include "tools/gn/token.h" |
16 #include "tools/gn/value.h" | 16 #include "tools/gn/value.h" |
17 | 17 |
18 class AccessorNode; | 18 class AccessorNode; |
19 class BinaryOpNode; | 19 class BinaryOpNode; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 const std::string& help = std::string()) const override; | 143 const std::string& help = std::string()) const override; |
144 void Print(std::ostream& out, int indent) const override; | 144 void Print(std::ostream& out, int indent) const override; |
145 | 145 |
146 // Base is the thing on the left of the [] or dot, currently always required | 146 // Base is the thing on the left of the [] or dot, currently always required |
147 // to be an identifier token. | 147 // to be an identifier token. |
148 const Token& base() const { return base_; } | 148 const Token& base() const { return base_; } |
149 void set_base(const Token& b) { base_ = b; } | 149 void set_base(const Token& b) { base_ = b; } |
150 | 150 |
151 // Index is the expression inside the []. Will be null if member is set. | 151 // Index is the expression inside the []. Will be null if member is set. |
152 const ParseNode* index() const { return index_.get(); } | 152 const ParseNode* index() const { return index_.get(); } |
153 void set_index(scoped_ptr<ParseNode> i) { index_ = i.Pass(); } | 153 void set_index(scoped_ptr<ParseNode> i) { index_ = std::move(i); } |
154 | 154 |
155 // The member is the identifier on the right hand side of the dot. Will be | 155 // The member is the identifier on the right hand side of the dot. Will be |
156 // null if the index is set. | 156 // null if the index is set. |
157 const IdentifierNode* member() const { return member_.get(); } | 157 const IdentifierNode* member() const { return member_.get(); } |
158 void set_member(scoped_ptr<IdentifierNode> i) { member_ = i.Pass(); } | 158 void set_member(scoped_ptr<IdentifierNode> i) { member_ = std::move(i); } |
159 | 159 |
160 void SetNewLocation(int line_number); | 160 void SetNewLocation(int line_number); |
161 | 161 |
162 private: | 162 private: |
163 Value ExecuteArrayAccess(Scope* scope, Err* err) const; | 163 Value ExecuteArrayAccess(Scope* scope, Err* err) const; |
164 Value ExecuteScopeAccess(Scope* scope, Err* err) const; | 164 Value ExecuteScopeAccess(Scope* scope, Err* err) const; |
165 | 165 |
166 Token base_; | 166 Token base_; |
167 | 167 |
168 // Either index or member will be set according to what type of access this | 168 // Either index or member will be set according to what type of access this |
(...skipping 16 matching lines...) Expand all Loading... |
185 LocationRange GetRange() const override; | 185 LocationRange GetRange() const override; |
186 Err MakeErrorDescribing( | 186 Err MakeErrorDescribing( |
187 const std::string& msg, | 187 const std::string& msg, |
188 const std::string& help = std::string()) const override; | 188 const std::string& help = std::string()) const override; |
189 void Print(std::ostream& out, int indent) const override; | 189 void Print(std::ostream& out, int indent) const override; |
190 | 190 |
191 const Token& op() const { return op_; } | 191 const Token& op() const { return op_; } |
192 void set_op(const Token& t) { op_ = t; } | 192 void set_op(const Token& t) { op_ = t; } |
193 | 193 |
194 const ParseNode* left() const { return left_.get(); } | 194 const ParseNode* left() const { return left_.get(); } |
195 void set_left(scoped_ptr<ParseNode> left) { | 195 void set_left(scoped_ptr<ParseNode> left) { left_ = std::move(left); } |
196 left_ = left.Pass(); | |
197 } | |
198 | 196 |
199 const ParseNode* right() const { return right_.get(); } | 197 const ParseNode* right() const { return right_.get(); } |
200 void set_right(scoped_ptr<ParseNode> right) { | 198 void set_right(scoped_ptr<ParseNode> right) { right_ = std::move(right); } |
201 right_ = right.Pass(); | |
202 } | |
203 | 199 |
204 private: | 200 private: |
205 scoped_ptr<ParseNode> left_; | 201 scoped_ptr<ParseNode> left_; |
206 Token op_; | 202 Token op_; |
207 scoped_ptr<ParseNode> right_; | 203 scoped_ptr<ParseNode> right_; |
208 | 204 |
209 DISALLOW_COPY_AND_ASSIGN(BinaryOpNode); | 205 DISALLOW_COPY_AND_ASSIGN(BinaryOpNode); |
210 }; | 206 }; |
211 | 207 |
212 // BlockNode ------------------------------------------------------------------- | 208 // BlockNode ------------------------------------------------------------------- |
213 | 209 |
214 class BlockNode : public ParseNode { | 210 class BlockNode : public ParseNode { |
215 public: | 211 public: |
216 BlockNode(); | 212 BlockNode(); |
217 ~BlockNode() override; | 213 ~BlockNode() override; |
218 | 214 |
219 const BlockNode* AsBlock() const override; | 215 const BlockNode* AsBlock() const override; |
220 Value Execute(Scope* scope, Err* err) const override; | 216 Value Execute(Scope* scope, Err* err) const override; |
221 LocationRange GetRange() const override; | 217 LocationRange GetRange() const override; |
222 Err MakeErrorDescribing( | 218 Err MakeErrorDescribing( |
223 const std::string& msg, | 219 const std::string& msg, |
224 const std::string& help = std::string()) const override; | 220 const std::string& help = std::string()) const override; |
225 void Print(std::ostream& out, int indent) const override; | 221 void Print(std::ostream& out, int indent) const override; |
226 | 222 |
227 void set_begin_token(const Token& t) { begin_token_ = t; } | 223 void set_begin_token(const Token& t) { begin_token_ = t; } |
228 void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); } | 224 void set_end(scoped_ptr<EndNode> e) { end_ = std::move(e); } |
229 const EndNode* End() const { return end_.get(); } | 225 const EndNode* End() const { return end_.get(); } |
230 | 226 |
231 const std::vector<ParseNode*>& statements() const { return statements_; } | 227 const std::vector<ParseNode*>& statements() const { return statements_; } |
232 void append_statement(scoped_ptr<ParseNode> s) { | 228 void append_statement(scoped_ptr<ParseNode> s) { |
233 statements_.push_back(s.release()); | 229 statements_.push_back(s.release()); |
234 } | 230 } |
235 | 231 |
236 private: | 232 private: |
237 // Tokens corresponding to { and }, if any (may be NULL). The end is stored | 233 // Tokens corresponding to { and }, if any (may be NULL). The end is stored |
238 // in a custom parse node so that it can have comments hung off of it. | 234 // in a custom parse node so that it can have comments hung off of it. |
(...skipping 17 matching lines...) Expand all Loading... |
256 Value Execute(Scope* scope, Err* err) const override; | 252 Value Execute(Scope* scope, Err* err) const override; |
257 LocationRange GetRange() const override; | 253 LocationRange GetRange() const override; |
258 Err MakeErrorDescribing( | 254 Err MakeErrorDescribing( |
259 const std::string& msg, | 255 const std::string& msg, |
260 const std::string& help = std::string()) const override; | 256 const std::string& help = std::string()) const override; |
261 void Print(std::ostream& out, int indent) const override; | 257 void Print(std::ostream& out, int indent) const override; |
262 | 258 |
263 void set_if_token(const Token& token) { if_token_ = token; } | 259 void set_if_token(const Token& token) { if_token_ = token; } |
264 | 260 |
265 const ParseNode* condition() const { return condition_.get(); } | 261 const ParseNode* condition() const { return condition_.get(); } |
266 void set_condition(scoped_ptr<ParseNode> c) { | 262 void set_condition(scoped_ptr<ParseNode> c) { condition_ = std::move(c); } |
267 condition_ = c.Pass(); | |
268 } | |
269 | 263 |
270 const BlockNode* if_true() const { return if_true_.get(); } | 264 const BlockNode* if_true() const { return if_true_.get(); } |
271 void set_if_true(scoped_ptr<BlockNode> t) { | 265 void set_if_true(scoped_ptr<BlockNode> t) { if_true_ = std::move(t); } |
272 if_true_ = t.Pass(); | |
273 } | |
274 | 266 |
275 // This is either empty, a block (for the else clause), or another | 267 // This is either empty, a block (for the else clause), or another |
276 // condition. | 268 // condition. |
277 const ParseNode* if_false() const { return if_false_.get(); } | 269 const ParseNode* if_false() const { return if_false_.get(); } |
278 void set_if_false(scoped_ptr<ParseNode> f) { | 270 void set_if_false(scoped_ptr<ParseNode> f) { if_false_ = std::move(f); } |
279 if_false_ = f.Pass(); | |
280 } | |
281 | 271 |
282 private: | 272 private: |
283 // Token corresponding to the "if" string. | 273 // Token corresponding to the "if" string. |
284 Token if_token_; | 274 Token if_token_; |
285 | 275 |
286 scoped_ptr<ParseNode> condition_; // Always non-null. | 276 scoped_ptr<ParseNode> condition_; // Always non-null. |
287 scoped_ptr<BlockNode> if_true_; // Always non-null. | 277 scoped_ptr<BlockNode> if_true_; // Always non-null. |
288 scoped_ptr<ParseNode> if_false_; // May be null. | 278 scoped_ptr<ParseNode> if_false_; // May be null. |
289 | 279 |
290 DISALLOW_COPY_AND_ASSIGN(ConditionNode); | 280 DISALLOW_COPY_AND_ASSIGN(ConditionNode); |
(...skipping 11 matching lines...) Expand all Loading... |
302 LocationRange GetRange() const override; | 292 LocationRange GetRange() const override; |
303 Err MakeErrorDescribing( | 293 Err MakeErrorDescribing( |
304 const std::string& msg, | 294 const std::string& msg, |
305 const std::string& help = std::string()) const override; | 295 const std::string& help = std::string()) const override; |
306 void Print(std::ostream& out, int indent) const override; | 296 void Print(std::ostream& out, int indent) const override; |
307 | 297 |
308 const Token& function() const { return function_; } | 298 const Token& function() const { return function_; } |
309 void set_function(Token t) { function_ = t; } | 299 void set_function(Token t) { function_ = t; } |
310 | 300 |
311 const ListNode* args() const { return args_.get(); } | 301 const ListNode* args() const { return args_.get(); } |
312 void set_args(scoped_ptr<ListNode> a) { args_ = a.Pass(); } | 302 void set_args(scoped_ptr<ListNode> a) { args_ = std::move(a); } |
313 | 303 |
314 const BlockNode* block() const { return block_.get(); } | 304 const BlockNode* block() const { return block_.get(); } |
315 void set_block(scoped_ptr<BlockNode> b) { block_ = b.Pass(); } | 305 void set_block(scoped_ptr<BlockNode> b) { block_ = std::move(b); } |
316 | 306 |
317 private: | 307 private: |
318 Token function_; | 308 Token function_; |
319 scoped_ptr<ListNode> args_; | 309 scoped_ptr<ListNode> args_; |
320 scoped_ptr<BlockNode> block_; // May be null. | 310 scoped_ptr<BlockNode> block_; // May be null. |
321 | 311 |
322 DISALLOW_COPY_AND_ASSIGN(FunctionCallNode); | 312 DISALLOW_COPY_AND_ASSIGN(FunctionCallNode); |
323 }; | 313 }; |
324 | 314 |
325 // IdentifierNode -------------------------------------------------------------- | 315 // IdentifierNode -------------------------------------------------------------- |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 348 |
359 const ListNode* AsList() const override; | 349 const ListNode* AsList() const override; |
360 Value Execute(Scope* scope, Err* err) const override; | 350 Value Execute(Scope* scope, Err* err) const override; |
361 LocationRange GetRange() const override; | 351 LocationRange GetRange() const override; |
362 Err MakeErrorDescribing( | 352 Err MakeErrorDescribing( |
363 const std::string& msg, | 353 const std::string& msg, |
364 const std::string& help = std::string()) const override; | 354 const std::string& help = std::string()) const override; |
365 void Print(std::ostream& out, int indent) const override; | 355 void Print(std::ostream& out, int indent) const override; |
366 | 356 |
367 void set_begin_token(const Token& t) { begin_token_ = t; } | 357 void set_begin_token(const Token& t) { begin_token_ = t; } |
368 void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); } | 358 void set_end(scoped_ptr<EndNode> e) { end_ = std::move(e); } |
369 const EndNode* End() const { return end_.get(); } | 359 const EndNode* End() const { return end_.get(); } |
370 | 360 |
371 void append_item(scoped_ptr<ParseNode> s) { | 361 void append_item(scoped_ptr<ParseNode> s) { |
372 contents_.push_back(s.release()); | 362 contents_.push_back(s.release()); |
373 } | 363 } |
374 const std::vector<const ParseNode*>& contents() const { return contents_; } | 364 const std::vector<const ParseNode*>& contents() const { return contents_; } |
375 | 365 |
376 void SortAsStringsList(); | 366 void SortAsStringsList(); |
377 void SortAsDepsList(); | 367 void SortAsDepsList(); |
378 | 368 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 Err MakeErrorDescribing( | 438 Err MakeErrorDescribing( |
449 const std::string& msg, | 439 const std::string& msg, |
450 const std::string& help = std::string()) const override; | 440 const std::string& help = std::string()) const override; |
451 void Print(std::ostream& out, int indent) const override; | 441 void Print(std::ostream& out, int indent) const override; |
452 | 442 |
453 const Token& op() const { return op_; } | 443 const Token& op() const { return op_; } |
454 void set_op(const Token& t) { op_ = t; } | 444 void set_op(const Token& t) { op_ = t; } |
455 | 445 |
456 const ParseNode* operand() const { return operand_.get(); } | 446 const ParseNode* operand() const { return operand_.get(); } |
457 void set_operand(scoped_ptr<ParseNode> operand) { | 447 void set_operand(scoped_ptr<ParseNode> operand) { |
458 operand_ = operand.Pass(); | 448 operand_ = std::move(operand); |
459 } | 449 } |
460 | 450 |
461 private: | 451 private: |
462 Token op_; | 452 Token op_; |
463 scoped_ptr<ParseNode> operand_; | 453 scoped_ptr<ParseNode> operand_; |
464 | 454 |
465 DISALLOW_COPY_AND_ASSIGN(UnaryOpNode); | 455 DISALLOW_COPY_AND_ASSIGN(UnaryOpNode); |
466 }; | 456 }; |
467 | 457 |
468 // BlockCommentNode ------------------------------------------------------------ | 458 // BlockCommentNode ------------------------------------------------------------ |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 const Token& value() const { return value_; } | 506 const Token& value() const { return value_; } |
517 void set_value(const Token& t) { value_ = t; } | 507 void set_value(const Token& t) { value_ = t; } |
518 | 508 |
519 private: | 509 private: |
520 Token value_; | 510 Token value_; |
521 | 511 |
522 DISALLOW_COPY_AND_ASSIGN(EndNode); | 512 DISALLOW_COPY_AND_ASSIGN(EndNode); |
523 }; | 513 }; |
524 | 514 |
525 #endif // TOOLS_GN_PARSE_TREE_H_ | 515 #endif // TOOLS_GN_PARSE_TREE_H_ |
OLD | NEW |