Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / tools / gn / visibility.h
blob52ec73ca15915811980d464f7d228c57dc671a6e
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/basictypes.h"
11 #include "base/strings/string_piece.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 class VisPattern {
23 public:
24 enum Type {
25 MATCH = 1, // Exact match for a given target.
26 DIRECTORY, // Only targets in the file in the given directory.
27 RECURSIVE_DIRECTORY // The given directory and any subdir.
28 // (also indicates "public" when dir is empty).
31 VisPattern();
32 VisPattern(Type type, const SourceDir& dir, const base::StringPiece& name);
33 ~VisPattern();
35 bool Matches(const Label& label) const;
37 Type type() const { return type_; }
38 const SourceDir& dir() const { return dir_; }
39 const std::string& name() const { return name_; }
41 private:
42 Type type_;
44 // Used when type_ == PRIVATE and PRIVATE_RECURSIVE. This specifies the
45 // directory that to which the pattern is private to.
46 SourceDir dir_;
48 // Empty name means match everything. Otherwise the name must match
49 // exactly.
50 std::string name_;
53 // Defaults to private visibility (only the current file).
54 Visibility();
55 ~Visibility();
57 // Set the visibility to the thing specified by the given value. On failure,
58 // returns false and sets the error.
59 bool Set(const SourceDir& current_dir, const Value& value, Err* err);
61 // Sets the visibility to be public.
62 void SetPublic();
64 // Sets the visibility to be private to the given directory.
65 void SetPrivate(const SourceDir& current_dir);
67 // Returns true if the target with the given label can depend on one with the
68 // current visibility.
69 bool CanSeeMe(const Label& label) const;
71 // Returns a string listing the visibility.
72 std::string Describe() const;
74 // Converts the given input string to a pattern. This does special stuff
75 // to treat the pattern as a label. Sets the error on failure.
76 static VisPattern GetPattern(const SourceDir& current_dir,
77 const Value& value,
78 Err* err);
80 // Helper function to check visibility between the given two items. If
81 // to is invisible to from, returns false and sets the error.
82 static bool CheckItemVisibility(const Item* from, const Item* to, Err* err);
84 // Helper function to fill an item's visibility from the "visibility" value
85 // in the current scope.
86 static bool FillItemVisibility(Item* item, Scope* scope, Err* err);
88 private:
89 std::vector<VisPattern> patterns_;
91 DISALLOW_COPY_AND_ASSIGN(Visibility);
94 #endif // TOOLS_GN_VISIBILITY_H_