Home | History | Annotate | Download | only in gn
      1 // Copyright (c) 2013 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_ITEM_H_
      6 #define TOOLS_GN_ITEM_H_
      7 
      8 #include <string>
      9 
     10 #include "tools/gn/label.h"
     11 #include "tools/gn/visibility.h"
     12 
     13 class Config;
     14 class ParseNode;
     15 class Settings;
     16 class Target;
     17 class Toolchain;
     18 
     19 // A named item (target, config, etc.) that participates in the dependency
     20 // graph.
     21 class Item {
     22  public:
     23   Item(const Settings* settings, const Label& label);
     24   virtual ~Item();
     25 
     26   const Settings* settings() const { return settings_; }
     27 
     28   // This is guaranteed to never change after construction so this can be
     29   // accessed from any thread with no locking once the item is constructed.
     30   const Label& label() const { return label_; }
     31 
     32   const ParseNode* defined_from() const { return defined_from_; }
     33   void set_defined_from(const ParseNode* df) { defined_from_ = df; }
     34 
     35   Visibility& visibility() { return visibility_; }
     36   const Visibility& visibility() const { return visibility_; }
     37 
     38   // Manual RTTI.
     39   virtual Config* AsConfig();
     40   virtual const Config* AsConfig() const;
     41   virtual Target* AsTarget();
     42   virtual const Target* AsTarget() const;
     43   virtual Toolchain* AsToolchain();
     44   virtual const Toolchain* AsToolchain() const;
     45 
     46   // Returns a name like "target" or "config" for the type of item this is, to
     47   // be used in logging and error messages.
     48   std::string GetItemTypeName() const;
     49 
     50   // Called when this item is resolved, meaning it and all of its dependents
     51   // have no unresolved deps. Returns true on success. Sets the error and
     52   // returns false on failure.
     53   virtual bool OnResolved(Err* err);
     54 
     55  private:
     56   const Settings* settings_;
     57   Label label_;
     58   const ParseNode* defined_from_;
     59 
     60   Visibility visibility_;
     61 };
     62 
     63 #endif  // TOOLS_GN_ITEM_H_
     64