180 lines
6.6 KiB
C++
180 lines
6.6 KiB
C++
// Filename: ppScope.h
|
|
// Created by: drose (25Sep00)
|
|
//
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef PPSCOPE_H
|
|
#define PPSCOPE_H
|
|
|
|
#include "ppremake.h"
|
|
|
|
#include <map>
|
|
#include <vector>
|
|
|
|
class PPNamedScopes;
|
|
class PPDirectory;
|
|
class PPSubroutine;
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
// Class : PPScope
|
|
// Description : Defines a (possibly nested) scope for variable
|
|
// definitions. Variables may be defined in a
|
|
// system-wide variable file, in a template file, or in
|
|
// an individual source file.
|
|
////////////////////////////////////////////////////////////////////
|
|
class PPScope {
|
|
public:
|
|
typedef map<string, PPScope *> MapVariableDefinition;
|
|
|
|
PPScope(PPNamedScopes *named_scopes);
|
|
|
|
PPNamedScopes *get_named_scopes();
|
|
|
|
void set_parent(PPScope *parent);
|
|
PPScope *get_parent();
|
|
|
|
void define_variable(const string &varname, const string &definition);
|
|
bool set_variable(const string &varname, const string &definition);
|
|
void define_map_variable(const string &varname, const string &definition);
|
|
void define_map_variable(const string &varname, const string &key_varname,
|
|
const string &scope_names);
|
|
void add_to_map_variable(const string &varname, const string &key,
|
|
PPScope *scope);
|
|
void define_formals(const string &subroutine_name,
|
|
const vector<string> &formals, const string &actuals);
|
|
|
|
string get_variable(const string &varname);
|
|
string expand_variable(const string &varname);
|
|
MapVariableDefinition &find_map_variable(const string &varname);
|
|
|
|
PPDirectory *get_directory();
|
|
void set_directory(PPDirectory *directory);
|
|
|
|
string expand_string(const string &str);
|
|
string expand_self_reference(const string &str, const string &varname);
|
|
|
|
static void push_scope(PPScope *scope);
|
|
static PPScope *pop_scope();
|
|
static PPScope *get_bottom_scope();
|
|
static PPScope *get_enclosing_scope(int n);
|
|
|
|
void tokenize_params(const string &str, vector<string> &tokens,
|
|
bool expand);
|
|
bool tokenize_numeric_pair(const string &str, double &a, double &b);
|
|
bool tokenize_ints(const string &str, vector<int> &tokens);
|
|
size_t scan_to_whitespace(const string &str, size_t start = 0);
|
|
static string format_int(int num);
|
|
|
|
static MapVariableDefinition _null_map_def;
|
|
|
|
private:
|
|
class ExpandedVariable {
|
|
public:
|
|
string _varname;
|
|
ExpandedVariable *_next;
|
|
};
|
|
|
|
bool p_set_variable(const string &varname, const string &definition);
|
|
bool p_get_variable(const string &varname, string &result);
|
|
|
|
string r_expand_string(const string &str, ExpandedVariable *expanded);
|
|
string r_scan_variable(const string &str, size_t &vp);
|
|
string r_expand_variable(const string &str, size_t &vp,
|
|
PPScope::ExpandedVariable *expanded);
|
|
string expand_variable_nested(const string &varname,
|
|
const string &scope_names);
|
|
|
|
string expand_isfullpath(const string ¶ms);
|
|
string expand_osfilename(const string ¶ms);
|
|
string expand_unixfilename(const string ¶ms);
|
|
string expand_unixshortname(const string ¶ms);
|
|
string expand_cygpath_w(const string ¶ms);
|
|
string expand_cygpath_p(const string ¶ms);
|
|
string expand_wildcard(const string ¶ms);
|
|
string expand_isdir(const string ¶ms);
|
|
string expand_isfile(const string ¶ms);
|
|
string expand_libtest(const string ¶ms);
|
|
string expand_bintest(const string ¶ms);
|
|
string expand_shell(const string ¶ms);
|
|
string expand_standardize(const string ¶ms);
|
|
string expand_canonical(const string ¶ms);
|
|
string expand_length(const string ¶ms);
|
|
string expand_substr(const string ¶ms);
|
|
string expand_findstring(const string ¶ms);
|
|
string expand_dir(const string ¶ms);
|
|
string expand_notdir(const string ¶ms);
|
|
string expand_suffix(const string ¶ms);
|
|
string expand_basename(const string ¶ms);
|
|
string expand_makeguid(const string ¶ms);
|
|
string expand_word(const string ¶ms);
|
|
string expand_wordlist(const string ¶ms);
|
|
string expand_words(const string ¶ms);
|
|
string expand_firstword(const string ¶ms);
|
|
string expand_patsubst(const string ¶ms, bool separate_words);
|
|
string expand_filter(const string ¶ms);
|
|
string expand_filter_out(const string ¶ms);
|
|
string expand_wordsubst(const string ¶ms);
|
|
string expand_subst(const string ¶ms);
|
|
string expand_join(const string ¶ms);
|
|
string expand_sort(const string ¶ms);
|
|
string expand_unique(const string ¶ms);
|
|
string expand_matrix(const string ¶ms);
|
|
string expand_if(const string ¶ms);
|
|
string expand_defined(const string ¶ms);
|
|
string expand_eq(const string ¶ms);
|
|
string expand_ne(const string ¶ms);
|
|
string expand_eqn(const string ¶ms);
|
|
string expand_nen(const string ¶ms);
|
|
string expand_ltn(const string ¶ms);
|
|
string expand_len(const string ¶ms);
|
|
string expand_gtn(const string ¶ms);
|
|
string expand_gen(const string ¶ms);
|
|
string expand_plus(const string ¶ms);
|
|
string expand_minus(const string ¶ms);
|
|
string expand_times(const string ¶ms);
|
|
string expand_divide(const string ¶ms);
|
|
string expand_modulo(const string ¶ms);
|
|
string expand_not(const string ¶ms);
|
|
string expand_or(const string ¶ms);
|
|
string expand_and(const string ¶ms);
|
|
string expand_upcase(const string ¶ms);
|
|
string expand_downcase(const string ¶ms);
|
|
string expand_cdefine(const string ¶ms);
|
|
string expand_closure(const string ¶ms);
|
|
string expand_unmapped(const string ¶ms);
|
|
string expand_dependencies(const string ¶ms);
|
|
string expand_foreach(const string ¶ms);
|
|
string expand_forscopes(const string ¶ms);
|
|
string expand_function(const string &funcname, const PPSubroutine *sub,
|
|
const string ¶ms);
|
|
string expand_map_variable(const string &varname, const string ¶ms);
|
|
string expand_map_variable(const string &varname, const string &expression,
|
|
const vector<string> &keys);
|
|
|
|
void
|
|
r_expand_matrix(vector<string> &results,
|
|
const vector<vector<string> > &words,
|
|
int index, const string &prefix);
|
|
|
|
MapVariableDefinition &
|
|
p_find_map_variable(const string &varname);
|
|
|
|
void glob_string(const string &str, vector<string> &results);
|
|
|
|
PPNamedScopes *_named_scopes;
|
|
|
|
PPDirectory *_directory;
|
|
|
|
typedef map<string, string> Variables;
|
|
Variables _variables;
|
|
|
|
typedef map<string, MapVariableDefinition> MapVariables;
|
|
MapVariables _map_variables;
|
|
|
|
PPScope *_parent_scope;
|
|
typedef vector<PPScope *> ScopeStack;
|
|
static ScopeStack _scope_stack;
|
|
};
|
|
|
|
|
|
#endif
|