1d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 3d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// found in the LICENSE file. 4d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 5d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#ifndef TOOLS_GN_FUNCTIONS_H_ 6d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#define TOOLS_GN_FUNCTIONS_H_ 7d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 8e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch#include <map> 9d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#include <string> 10d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#include <vector> 11d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 12a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/strings/string_piece.h" 13a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 14d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass Err; 15d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass BlockNode; 16d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass FunctionCallNode; 17d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass Label; 18d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass ListNode; 19d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass ParseNode; 20d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass Scope; 21d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass Token; 22d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass Value; 23d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 24a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// ----------------------------------------------------------------------------- 25d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 26a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)namespace functions { 27d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// This type of function invocation has no block and evaluates its arguments 293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// itself rather than taking a pre-executed list. This allows us to implement 303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// certain built-in functions. 313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)typedef Value (*SelfEvaluatingArgsFunction)(Scope* scope, 323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const FunctionCallNode* function, 333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const ListNode* args_list, 343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) Err* err); 353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 36a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// This type of function invocation takes a block node that it will execute. 37a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)typedef Value (*GenericBlockFunction)(Scope* scope, 38a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 39a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 40a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) BlockNode* block, 41a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 42a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 43a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// This type of function takes a block, but does not need to control execution 44a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// of it. The dispatch function will pre-execute the block and pass the 45a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// resulting block_scope to the function. 46a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)typedef Value(*ExecutedBlockFunction)(const FunctionCallNode* function, 47a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 48a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Scope* block_scope, 49a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 51a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// This type of function does not take a block. It just has arguments. 52a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)typedef Value (*NoBlockFunction)(Scope* scope, 53d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const FunctionCallNode* function, 54d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::vector<Value>& args, 55d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Err* err); 56a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 5723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)extern const char kAction[]; 58e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kAction_HelpShort[]; 5923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)extern const char kAction_Help[]; 6023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)Value RunAction(Scope* scope, 6123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const FunctionCallNode* function, 6223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const std::vector<Value>& args, 6323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) BlockNode* block, 6423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) Err* err); 6523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 6623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)extern const char kActionForEach[]; 67e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kActionForEach_HelpShort[]; 6823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)extern const char kActionForEach_Help[]; 6923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)Value RunActionForEach(Scope* scope, 7023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const FunctionCallNode* function, 7123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) const std::vector<Value>& args, 7223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) BlockNode* block, 7323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) Err* err); 7423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kAssert[]; 76e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kAssert_HelpShort[]; 77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kAssert_Help[]; 78a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunAssert(Scope* scope, 79a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 80a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 81a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 82a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 83a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kConfig[]; 84e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kConfig_HelpShort[]; 85a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kConfig_Help[]; 86a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunConfig(const FunctionCallNode* function, 87a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Scope* block_scope, 89a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 90a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 91a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kCopy[]; 92e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kCopy_HelpShort[]; 93a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kCopy_Help[]; 94a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunCopy(const FunctionCallNode* function, 95a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 96a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Scope* block_scope, 97a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 98a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 99a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kDeclareArgs[]; 100e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kDeclareArgs_HelpShort[]; 101a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kDeclareArgs_Help[]; 1023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)Value RunDeclareArgs(Scope* scope, 1033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const FunctionCallNode* function, 104a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 1053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) BlockNode* block, 106a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 107a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 1083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)extern const char kDefined[]; 109e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kDefined_HelpShort[]; 1103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)extern const char kDefined_Help[]; 1113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)Value RunDefined(Scope* scope, 1123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const FunctionCallNode* function, 1133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const ListNode* args_list, 1143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) Err* err); 1153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 116a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kExecScript[]; 117e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kExecScript_HelpShort[]; 118a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kExecScript_Help[]; 119a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunExecScript(Scope* scope, 120a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 121a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 122a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 123a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 124a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kExecutable[]; 125e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kExecutable_HelpShort[]; 126a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kExecutable_Help[]; 127a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunExecutable(Scope* scope, 128a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 129a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 130a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) BlockNode* block, 131a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 132a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 133cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)extern const char kForEach[]; 134cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)extern const char kForEach_HelpShort[]; 135cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)extern const char kForEach_Help[]; 136cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)Value RunForEach(Scope* scope, 137cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const FunctionCallNode* function, 138cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const ListNode* args_list, 139cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) Err* err); 140cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)extern const char kGetEnv[]; 142e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kGetEnv_HelpShort[]; 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)extern const char kGetEnv_Help[]; 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)Value RunGetEnv(Scope* scope, 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const FunctionCallNode* function, 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::vector<Value>& args, 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Err* err); 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 149cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)extern const char kGetLabelInfo[]; 150cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)extern const char kGetLabelInfo_HelpShort[]; 151cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)extern const char kGetLabelInfo_Help[]; 152cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)Value RunGetLabelInfo(Scope* scope, 153cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const FunctionCallNode* function, 154cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) const std::vector<Value>& args, 155cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) Err* err); 156cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 15746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)extern const char kGetPathInfo[]; 15846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)extern const char kGetPathInfo_HelpShort[]; 15946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)extern const char kGetPathInfo_Help[]; 16046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)Value RunGetPathInfo(Scope* scope, 16146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) const FunctionCallNode* function, 16246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) const std::vector<Value>& args, 16346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) Err* err); 16446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 165010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)extern const char kGetTargetOutputs[]; 166010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)extern const char kGetTargetOutputs_HelpShort[]; 167010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)extern const char kGetTargetOutputs_Help[]; 168010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)Value RunGetTargetOutputs(Scope* scope, 169010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const FunctionCallNode* function, 170010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const std::vector<Value>& args, 171010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) Err* err); 172010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 173a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kGroup[]; 174e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kGroup_HelpShort[]; 175a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kGroup_Help[]; 176a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunGroup(Scope* scope, 177a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 178a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 179a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) BlockNode* block, 180a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 181a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 182a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kImport[]; 183e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kImport_HelpShort[]; 184a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kImport_Help[]; 185a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunImport(Scope* scope, 186a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 187a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 188a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 189a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 190a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kPrint[]; 191e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kPrint_HelpShort[]; 192a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kPrint_Help[]; 193a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunPrint(Scope* scope, 194a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 195a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 196a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 197a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 198a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kProcessFileTemplate[]; 199e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kProcessFileTemplate_HelpShort[]; 200a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kProcessFileTemplate_Help[]; 201a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunProcessFileTemplate(Scope* scope, 202a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 203a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 204a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 205a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 206a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kReadFile[]; 207e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kReadFile_HelpShort[]; 208a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kReadFile_Help[]; 209a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunReadFile(Scope* scope, 210d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const FunctionCallNode* function, 211d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::vector<Value>& args, 212d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Err* err); 213a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 21468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)extern const char kRebasePath[]; 215e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kRebasePath_HelpShort[]; 21668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)extern const char kRebasePath_Help[]; 21768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)Value RunRebasePath(Scope* scope, 21868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const FunctionCallNode* function, 21968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) const std::vector<Value>& args, 22068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) Err* err); 22168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 222a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kSetDefaults[]; 223e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kSetDefaults_HelpShort[]; 224a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kSetDefaults_Help[]; 225a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunSetDefaults(Scope* scope, 226a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 227a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 228a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) BlockNode* block, 229a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 230a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 231a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kSetDefaultToolchain[]; 232e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kSetDefaultToolchain_HelpShort[]; 233a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kSetDefaultToolchain_Help[]; 234a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunSetDefaultToolchain(Scope* scope, 235a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 236a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 237a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 238a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 239a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kSetSourcesAssignmentFilter[]; 240e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kSetSourcesAssignmentFilter_HelpShort[]; 241a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kSetSourcesAssignmentFilter_Help[]; 242a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunSetSourcesAssignmentFilter(Scope* scope, 243a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 244a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 245a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 246a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 247a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kSharedLibrary[]; 248e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kSharedLibrary_HelpShort[]; 249a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kSharedLibrary_Help[]; 250a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunSharedLibrary(Scope* scope, 251d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const FunctionCallNode* function, 252d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::vector<Value>& args, 253d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch BlockNode* block, 254d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Err* err); 255d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 2564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)extern const char kSourceSet[]; 257e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kSourceSet_HelpShort[]; 2584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)extern const char kSourceSet_Help[]; 2594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)Value RunSourceSet(Scope* scope, 2604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const FunctionCallNode* function, 2614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const std::vector<Value>& args, 2624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) BlockNode* block, 2634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) Err* err); 2644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 265a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kStaticLibrary[]; 266e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kStaticLibrary_HelpShort[]; 267a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kStaticLibrary_Help[]; 268a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunStaticLibrary(Scope* scope, 269d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const FunctionCallNode* function, 270d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::vector<Value>& args, 271d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch BlockNode* block, 272d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Err* err); 273a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 274a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kTemplate[]; 275e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kTemplate_HelpShort[]; 276a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kTemplate_Help[]; 277a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunTemplate(Scope* scope, 278d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const FunctionCallNode* function, 279d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::vector<Value>& args, 280a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) BlockNode* block, 281d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Err* err); 282a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 283a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kTool[]; 284e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kTool_HelpShort[]; 285a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kTool_Help[]; 286a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunTool(Scope* scope, 287a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 288a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 289a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) BlockNode* block, 290a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 291a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 292a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kToolchain[]; 293e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kToolchain_HelpShort[]; 294a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kToolchain_Help[]; 295a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunToolchain(Scope* scope, 296d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const FunctionCallNode* function, 297d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::vector<Value>& args, 298d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch BlockNode* block, 299d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Err* err); 300d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 3013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)extern const char kToolchainArgs[]; 302e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kToolchainArgs_HelpShort[]; 3033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)extern const char kToolchainArgs_Help[]; 3043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)Value RunToolchainArgs(Scope* scope, 3053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const FunctionCallNode* function, 3063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::vector<Value>& args, 3073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) BlockNode* block, 3083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) Err* err); 3093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 310a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kWriteFile[]; 311e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochextern const char kWriteFile_HelpShort[]; 312a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)extern const char kWriteFile_Help[]; 313a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunWriteFile(Scope* scope, 314a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 315a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::vector<Value>& args, 316a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 317a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 318a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// ----------------------------------------------------------------------------- 319a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 320a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// One function record. Only one of the given runner types will be non-null 321a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// which indicates the type of function it is. 322a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)struct FunctionInfo { 323a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) FunctionInfo(); 324e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch FunctionInfo(SelfEvaluatingArgsFunction seaf, 325e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const char* in_help_short, 326e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const char* in_help, 327e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch bool in_is_target); 328e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch FunctionInfo(GenericBlockFunction gbf, 329e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const char* in_help_short, 330e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const char* in_help, 331e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch bool in_is_target); 332e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch FunctionInfo(ExecutedBlockFunction ebf, 333e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const char* in_help_short, 334e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const char* in_help, 335e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch bool in_is_target); 336e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch FunctionInfo(NoBlockFunction nbf, 337e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const char* in_help_short, 338e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const char* in_help, 339e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch bool in_is_target); 340a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 3413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) SelfEvaluatingArgsFunction self_evaluating_args_runner; 342a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) GenericBlockFunction generic_block_runner; 343a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ExecutedBlockFunction executed_block_runner; 344a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) NoBlockFunction no_block_runner; 345a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 346e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch const char* help_short; 347a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const char* help; 348e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch 349e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch bool is_target; 350a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}; 351a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 352e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochtypedef std::map<base::StringPiece, FunctionInfo> FunctionInfoMap; 353a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 354a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Returns the mapping of all built-in functions. 355a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)const FunctionInfoMap& GetFunctions(); 356a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 357a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Runs the given function. 358a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)Value RunFunction(Scope* scope, 359a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const FunctionCallNode* function, 3603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const ListNode* args_list, 361a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) BlockNode* block, // Optional. 362a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Err* err); 363a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 364a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} // namespace functions 365a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 366d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Helper functions ----------------------------------------------------------- 367d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 368d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Verifies that the current scope is not processing an import. If it is, it 369d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// will set the error, blame the given parse node for it, and return false. 370d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochbool EnsureNotProcessingImport(const ParseNode* node, 371d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const Scope* scope, 372d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Err* err); 373d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 374d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Like EnsureNotProcessingImport but checks for running the build config. 375d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochbool EnsureNotProcessingBuildConfig(const ParseNode* node, 376d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const Scope* scope, 377d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Err* err); 378d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 379d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Sets up the |block_scope| for executing a target (or something like it). 380d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// The |scope| is the containing scope. It should have been already set as the 381d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// parent for the |block_scope| when the |block_scope| was created. 382d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// 383d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// This will set up the target defaults and set the |target_name| variable in 384d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// the block scope to the current target name, which is assumed to be the first 385d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// argument to the function. 386d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// 387d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// On success, returns true. On failure, sets the error and returns false. 388d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochbool FillTargetBlockScope(const Scope* scope, 389d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const FunctionCallNode* function, 3903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) const std::string& target_type, 391d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const BlockNode* block, 392d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::vector<Value>& args, 393d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Scope* block_scope, 394d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Err* err); 395d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 3963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Sets the given error to a message explaining that the function call requires 3973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// a block. 3983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void FillNeedsBlockError(const FunctionCallNode* function, Err* err); 3993551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 400d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Validates that the given function call has one string argument. This is 401d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// the most common function signature, so it saves space to have this helper. 402d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Returns false and sets the error on failure. 403d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochbool EnsureSingleStringArg(const FunctionCallNode* function, 404d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::vector<Value>& args, 405d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch Err* err); 406d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 407d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Returns the name of the toolchain for the given scope. 408d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochconst Label& ToolchainLabelForScope(const Scope* scope); 409d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 410d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Generates a label for the given scope, using the current directory and 411d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// toolchain, and the given name. 412d3868032626d59662ff73b372b5d584c1d144c53Ben MurdochLabel MakeLabelForScope(const Scope* scope, 413d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const FunctionCallNode* function, 414d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::string& name); 415d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 416d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#endif // TOOLS_GN_FUNCTIONS_H_ 417