| 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 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 const ParseNode* index() const { return index_.get(); } | 153 const ParseNode* index() const { return index_.get(); } |
| 154 void set_index(std::unique_ptr<ParseNode> i) { index_ = std::move(i); } | 154 void set_index(std::unique_ptr<ParseNode> i) { index_ = std::move(i); } |
| 155 | 155 |
| 156 // The member is the identifier on the right hand side of the dot. Will be | 156 // The member is the identifier on the right hand side of the dot. Will be |
| 157 // null if the index is set. | 157 // null if the index is set. |
| 158 const IdentifierNode* member() const { return member_.get(); } | 158 const IdentifierNode* member() const { return member_.get(); } |
| 159 void set_member(std::unique_ptr<IdentifierNode> i) { member_ = std::move(i); } | 159 void set_member(std::unique_ptr<IdentifierNode> i) { member_ = std::move(i); } |
| 160 | 160 |
| 161 void SetNewLocation(int line_number); | 161 void SetNewLocation(int line_number); |
| 162 | 162 |
| 163 // Evaluates the index for list accessor operations and range checks it |
| 164 // against the max length of the list. If the index is OK, sets |
| 165 // |*computed_index| and returns true. Otherwise sets the |*err| and returns |
| 166 // false. |
| 167 bool ComputeAndValidateListIndex(Scope* scope, |
| 168 size_t max_len, |
| 169 size_t* computed_index, |
| 170 Err* err) const; |
| 171 |
| 163 private: | 172 private: |
| 164 Value ExecuteArrayAccess(Scope* scope, Err* err) const; | 173 Value ExecuteArrayAccess(Scope* scope, Err* err) const; |
| 165 Value ExecuteScopeAccess(Scope* scope, Err* err) const; | 174 Value ExecuteScopeAccess(Scope* scope, Err* err) const; |
| 166 | 175 |
| 167 Token base_; | 176 Token base_; |
| 168 | 177 |
| 169 // Either index or member will be set according to what type of access this | 178 // Either index or member will be set according to what type of access this |
| 170 // is. | 179 // is. |
| 171 std::unique_ptr<ParseNode> index_; | 180 std::unique_ptr<ParseNode> index_; |
| 172 std::unique_ptr<IdentifierNode> member_; | 181 std::unique_ptr<IdentifierNode> member_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 Token op_; | 214 Token op_; |
| 206 std::unique_ptr<ParseNode> right_; | 215 std::unique_ptr<ParseNode> right_; |
| 207 | 216 |
| 208 DISALLOW_COPY_AND_ASSIGN(BinaryOpNode); | 217 DISALLOW_COPY_AND_ASSIGN(BinaryOpNode); |
| 209 }; | 218 }; |
| 210 | 219 |
| 211 // BlockNode ------------------------------------------------------------------- | 220 // BlockNode ------------------------------------------------------------------- |
| 212 | 221 |
| 213 class BlockNode : public ParseNode { | 222 class BlockNode : public ParseNode { |
| 214 public: | 223 public: |
| 215 BlockNode(); | 224 // How Execute manages the scopes and results. |
| 225 enum ResultMode { |
| 226 // Creates a new scope for the execution of this block and returns it as |
| 227 // a Value from Execute(). |
| 228 RETURNS_SCOPE, |
| 229 |
| 230 // Executes in the context of the calling scope (variables set will go |
| 231 // into the invoking scope) and Execute will return an empty Value. |
| 232 DISCARDS_RESULT |
| 233 }; |
| 234 |
| 235 BlockNode(ResultMode result_mode); |
| 216 ~BlockNode() override; | 236 ~BlockNode() override; |
| 217 | 237 |
| 218 const BlockNode* AsBlock() const override; | 238 const BlockNode* AsBlock() const override; |
| 219 Value Execute(Scope* scope, Err* err) const override; | 239 Value Execute(Scope* scope, Err* err) const override; |
| 220 LocationRange GetRange() const override; | 240 LocationRange GetRange() const override; |
| 221 Err MakeErrorDescribing( | 241 Err MakeErrorDescribing( |
| 222 const std::string& msg, | 242 const std::string& msg, |
| 223 const std::string& help = std::string()) const override; | 243 const std::string& help = std::string()) const override; |
| 224 void Print(std::ostream& out, int indent) const override; | 244 void Print(std::ostream& out, int indent) const override; |
| 225 | 245 |
| 226 void set_begin_token(const Token& t) { begin_token_ = t; } | 246 void set_begin_token(const Token& t) { begin_token_ = t; } |
| 227 void set_end(std::unique_ptr<EndNode> e) { end_ = std::move(e); } | 247 void set_end(std::unique_ptr<EndNode> e) { end_ = std::move(e); } |
| 228 const EndNode* End() const { return end_.get(); } | 248 const EndNode* End() const { return end_.get(); } |
| 229 | 249 |
| 250 ResultMode result_mode() const { return result_mode_; } |
| 251 |
| 230 const std::vector<std::unique_ptr<ParseNode>>& statements() const { | 252 const std::vector<std::unique_ptr<ParseNode>>& statements() const { |
| 231 return statements_; | 253 return statements_; |
| 232 } | 254 } |
| 233 void append_statement(std::unique_ptr<ParseNode> s) { | 255 void append_statement(std::unique_ptr<ParseNode> s) { |
| 234 statements_.push_back(std::move(s)); | 256 statements_.push_back(std::move(s)); |
| 235 } | 257 } |
| 236 | 258 |
| 237 private: | 259 private: |
| 260 const ResultMode result_mode_; |
| 261 |
| 238 // Tokens corresponding to { and }, if any (may be NULL). The end is stored | 262 // Tokens corresponding to { and }, if any (may be NULL). The end is stored |
| 239 // in a custom parse node so that it can have comments hung off of it. | 263 // in a custom parse node so that it can have comments hung off of it. |
| 240 Token begin_token_; | 264 Token begin_token_; |
| 241 std::unique_ptr<EndNode> end_; | 265 std::unique_ptr<EndNode> end_; |
| 242 | 266 |
| 243 std::vector<std::unique_ptr<ParseNode>> statements_; | 267 std::vector<std::unique_ptr<ParseNode>> statements_; |
| 244 | 268 |
| 245 DISALLOW_COPY_AND_ASSIGN(BlockNode); | 269 DISALLOW_COPY_AND_ASSIGN(BlockNode); |
| 246 }; | 270 }; |
| 247 | 271 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 const Token& value() const { return value_; } | 537 const Token& value() const { return value_; } |
| 514 void set_value(const Token& t) { value_ = t; } | 538 void set_value(const Token& t) { value_ = t; } |
| 515 | 539 |
| 516 private: | 540 private: |
| 517 Token value_; | 541 Token value_; |
| 518 | 542 |
| 519 DISALLOW_COPY_AND_ASSIGN(EndNode); | 543 DISALLOW_COPY_AND_ASSIGN(EndNode); |
| 520 }; | 544 }; |
| 521 | 545 |
| 522 #endif // TOOLS_GN_PARSE_TREE_H_ | 546 #endif // TOOLS_GN_PARSE_TREE_H_ |
| OLD | NEW |