Shinichiro Hamaji | 1d545aa | 2015-06-23 15:29:13 +0900 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 15 | #ifndef RULE_H_ |
| 16 | #define RULE_H_ |
| 17 | |
| 18 | #include <vector> |
| 19 | |
| 20 | #include "loc.h" |
| 21 | #include "log.h" |
Shinichiro Hamaji | 645cca7 | 2015-09-24 17:04:21 +0900 | [diff] [blame] | 22 | #include "stmt.h" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 23 | #include "string_piece.h" |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 24 | #include "symtab.h" |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 25 | |
| 26 | using namespace std; |
| 27 | |
| 28 | class Value; |
| 29 | |
| 30 | class Rule { |
| 31 | public: |
| 32 | Rule(); |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 33 | |
Shinichiro Hamaji | e30b3be | 2015-06-19 16:15:42 +0900 | [diff] [blame] | 34 | Loc cmd_loc() const { return Loc(loc.filename, cmd_lineno); } |
| 35 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 36 | string DebugString() const; |
| 37 | |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 38 | vector<Symbol> outputs; |
| 39 | vector<Symbol> inputs; |
| 40 | vector<Symbol> order_only_inputs; |
| 41 | vector<Symbol> output_patterns; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 42 | bool is_double_colon; |
| 43 | bool is_suffix_rule; |
| 44 | vector<Value*> cmds; |
| 45 | Loc loc; |
| 46 | int cmd_lineno; |
Colin Cross | 5b26db3 | 2015-09-29 16:51:02 -0700 | [diff] [blame] | 47 | bool is_default_target; |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | void Error(const string& msg) { |
| 51 | ERROR("%s:%d: %s", loc.filename, loc.lineno, msg.c_str()); |
| 52 | } |
| 53 | }; |
| 54 | |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 55 | struct RuleVarAssignment { |
Shinichiro Hamaji | e799275 | 2015-06-29 18:38:35 +0900 | [diff] [blame] | 56 | vector<Symbol> outputs; |
Shinichiro Hamaji | 9b16bda | 2015-06-19 14:25:17 +0900 | [diff] [blame] | 57 | StringPiece lhs; |
| 58 | StringPiece rhs; |
| 59 | AssignOp op; |
| 60 | }; |
| 61 | |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 62 | // If |rule| is not NULL, |rule_var| is filled. |
Shinichiro Hamaji | 2928f46 | 2015-06-23 20:24:53 +0900 | [diff] [blame] | 63 | void ParseRule(Loc& loc, StringPiece line, char term, |
Shinichiro Hamaji | ffc52c3 | 2015-06-23 16:51:07 +0900 | [diff] [blame] | 64 | Rule** rule, RuleVarAssignment* rule_var); |
Shinichiro Hamaji | 9b16bda | 2015-06-19 14:25:17 +0900 | [diff] [blame] | 65 | |
Shinichiro Hamaji | 776ca30 | 2015-06-06 03:52:48 +0900 | [diff] [blame] | 66 | #endif // RULE_H_ |