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 15 #ifndef RULE_H_ 16 #define RULE_H_ 17 18 #include <vector> 19 20 #include "loc.h" 21 #include "log.h" 22 #include "stmt.h" 23 #include "string_piece.h" 24 #include "symtab.h" 25 26 using namespace std; 27 28 class Value; 29 30 class Rule { 31 public: 32 Rule(); 33 cmd_loc()34 Loc cmd_loc() const { return Loc(loc.filename, cmd_lineno); } 35 36 string DebugString() const; 37 38 vector<Symbol> outputs; 39 vector<Symbol> inputs; 40 vector<Symbol> order_only_inputs; 41 vector<Symbol> output_patterns; 42 bool is_double_colon; 43 bool is_suffix_rule; 44 vector<Value*> cmds; 45 Loc loc; 46 int cmd_lineno; 47 48 private: Error(const string & msg)49 void Error(const string& msg) { 50 ERROR("%s:%d: %s", loc.filename, loc.lineno, msg.c_str()); 51 } 52 }; 53 54 struct RuleVarAssignment { 55 vector<Symbol> outputs; 56 StringPiece lhs; 57 StringPiece rhs; 58 AssignOp op; 59 }; 60 61 // If |rule| is not NULL, |rule_var| is filled. 62 void ParseRule(Loc& loc, StringPiece line, char term, 63 Rule** rule, RuleVarAssignment* rule_var); 64 65 #endif // RULE_H_ 66