1effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 2effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// found in the LICENSE file. 4effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 5effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#ifndef TOOLS_GN_TEMPLATE_H_ 6effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#define TOOLS_GN_TEMPLATE_H_ 7effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 8effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include <vector> 9effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 10effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/basictypes.h" 11010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/memory/ref_counted.h" 12effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/memory/scoped_ptr.h" 13effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 14effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass BlockNode; 15effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass Err; 16effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass FunctionCallNode; 17effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass LocationRange; 18effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass Scope; 19effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass Value; 20effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 21010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Represents the information associated with a template() call in GN, which 22010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// includes a closure and the code to run when the template is invoked. 23010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// 24010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// This class is immutable so we can reference it from multiple threads without 25010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// locking. Normally, this will be assocated with a .gni file and then a 26010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// reference will be taken by each .gn file that imports it. These files might 27010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// execute the template in parallel. 28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class Template : public base::RefCountedThreadSafe<Template> { 29effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch public: 30effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Makes a new closure based on the given scope. 31effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Template(const Scope* scope, const FunctionCallNode* def); 32effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 33effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Takes ownership of a previously-constructed closure. 34effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Template(scoped_ptr<Scope> closure, const FunctionCallNode* def); 35effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 36effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Invoke the template. The values correspond to the state of the code 37effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // invoking the template. 38effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Value Invoke(Scope* scope, 39effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const FunctionCallNode* invocation, 40effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const std::vector<Value>& args, 41effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch BlockNode* block, 42effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Err* err) const; 43effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 44effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Returns the location range where this template was defined. 45effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch LocationRange GetDefinitionRange() const; 46effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 47effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch private: 48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) friend class base::RefCountedThreadSafe<Template>; 49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Template(); 51010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) ~Template(); 52effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 53effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch scoped_ptr<Scope> closure_; 54effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch const FunctionCallNode* definition_; 55effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch}; 56effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 57effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#endif // TOOLS_GN_TEMPLATE_H_ 58