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
3// found in the LICENSE file.
4
5#ifndef TOOLS_GN_VISIBILITY_H_
6#define TOOLS_GN_VISIBILITY_H_
7
8#include <vector>
9
10#include "base/basictypes.h"
11#include "base/strings/string_piece.h"
12#include "tools/gn/label_pattern.h"
13#include "tools/gn/source_dir.h"
14
15class Err;
16class Item;
17class Label;
18class Scope;
19class Value;
20
21class Visibility {
22 public:
23  // Defaults to private visibility (only the current file).
24  Visibility();
25  ~Visibility();
26
27  // Set the visibility to the thing specified by the given value. On failure,
28  // returns false and sets the error.
29  bool Set(const SourceDir& current_dir, const Value& value, Err* err);
30
31  // Sets the visibility to be public.
32  void SetPublic();
33
34  // Sets the visibility to be private to the given directory.
35  void SetPrivate(const SourceDir& current_dir);
36
37  // Returns true if the target with the given label can depend on one with the
38  // current visibility.
39  bool CanSeeMe(const Label& label) const;
40
41  // Returns a string listing the visibility. |indent| number of spaces will
42  // be added on the left side of the output. If |include_brackets| is set, the
43  // result will be wrapped in "[ ]" and the contents further indented. The
44  // result will end in a newline.
45  std::string Describe(int indent, bool include_brackets) const;
46
47  // Helper function to check visibility between the given two items. If
48  // to is invisible to from, returns false and sets the error.
49  static bool CheckItemVisibility(const Item* from, const Item* to, Err* err);
50
51  // Helper function to fill an item's visibility from the "visibility" value
52  // in the current scope.
53  static bool FillItemVisibility(Item* item, Scope* scope, Err* err);
54
55 private:
56  std::vector<LabelPattern> patterns_;
57
58  DISALLOW_COPY_AND_ASSIGN(Visibility);
59};
60
61#endif  // TOOLS_GN_VISIBILITY_H_
62