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