blob: 2a67368bf915c4b0ea2b6190019237620fdb29e6 [file] [log] [blame]
Shinichiro Hamaji1d545aa2015-06-23 15:29:13 +09001// 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 Hamaji776ca302015-06-06 03:52:48 +090015#ifndef RULE_H_
16#define RULE_H_
17
18#include <vector>
19
20#include "loc.h"
21#include "log.h"
Shinichiro Hamaji645cca72015-09-24 17:04:21 +090022#include "stmt.h"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090023#include "string_piece.h"
Shinichiro Hamajie7992752015-06-29 18:38:35 +090024#include "symtab.h"
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090025
26using namespace std;
27
28class Value;
29
30class Rule {
31 public:
32 Rule();
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090033
Shinichiro Hamajie30b3be2015-06-19 16:15:42 +090034 Loc cmd_loc() const { return Loc(loc.filename, cmd_lineno); }
35
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090036 string DebugString() const;
37
Shinichiro Hamajie7992752015-06-29 18:38:35 +090038 vector<Symbol> outputs;
39 vector<Symbol> inputs;
40 vector<Symbol> order_only_inputs;
41 vector<Symbol> output_patterns;
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090042 bool is_double_colon;
43 bool is_suffix_rule;
44 vector<Value*> cmds;
45 Loc loc;
46 int cmd_lineno;
47
48 private:
49 void Error(const string& msg) {
50 ERROR("%s:%d: %s", loc.filename, loc.lineno, msg.c_str());
51 }
52};
53
Shinichiro Hamajiffc52c32015-06-23 16:51:07 +090054struct RuleVarAssignment {
Shinichiro Hamajie7992752015-06-29 18:38:35 +090055 vector<Symbol> outputs;
Shinichiro Hamaji9b16bda2015-06-19 14:25:17 +090056 StringPiece lhs;
57 StringPiece rhs;
58 AssignOp op;
59};
60
Shinichiro Hamajiffc52c32015-06-23 16:51:07 +090061// If |rule| is not NULL, |rule_var| is filled.
Shinichiro Hamaji2928f462015-06-23 20:24:53 +090062void ParseRule(Loc& loc, StringPiece line, char term,
Shinichiro Hamajiffc52c32015-06-23 16:51:07 +090063 Rule** rule, RuleVarAssignment* rule_var);
Shinichiro Hamaji9b16bda2015-06-19 14:25:17 +090064
Shinichiro Hamaji776ca302015-06-06 03:52:48 +090065#endif // RULE_H_