Home | History | Annotate | Download | only in kati
      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 <functional>
     19 #include <string>
     20 #include <vector>
     21 
     22 #include "loc.h"
     23 #include "log.h"
     24 #include "stmt.h"
     25 #include "string_piece.h"
     26 #include "symtab.h"
     27 
     28 using namespace std;
     29 
     30 class Value;
     31 
     32 class Rule {
     33  public:
     34   Rule();
     35 
     36   Loc cmd_loc() const { return Loc(loc.filename, cmd_lineno); }
     37 
     38   string DebugString() const;
     39 
     40   vector<Symbol> outputs;
     41   vector<Symbol> inputs;
     42   vector<Symbol> order_only_inputs;
     43   vector<Symbol> output_patterns;
     44   bool is_double_colon;
     45   bool is_suffix_rule;
     46   vector<Value*> cmds;
     47   Loc loc;
     48   int cmd_lineno;
     49 
     50  private:
     51   void Error(const string& msg) {
     52     ERROR_LOC(loc, "%s", msg.c_str());
     53   }
     54 };
     55 
     56 struct RuleVarAssignment {
     57   vector<Symbol> outputs;
     58   StringPiece lhs;
     59   StringPiece rhs;
     60   AssignOp op;
     61 };
     62 
     63 // If |rule| is not NULL, |rule_var| is filled. If the expression
     64 // after the terminator |term| is needed (this happens only when
     65 // |term| is '='), |after_term_fn| will be called to obtain the right
     66 // hand side.
     67 void ParseRule(Loc& loc, StringPiece line, char term,
     68                const function<string()> &after_term_fn,
     69                Rule** rule, RuleVarAssignment* rule_var);
     70 
     71 #endif  // RULE_H_
     72