From 37222d65dc4c3c8d883756d80adff0956fbad884 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sat, 17 Mar 2018 23:31:52 +0100 Subject: [PATCH] F #1792: Greatly improve concurrency by: Remove big lock on pool control class. Increase number of MySQL connections (new configuration variable). Make all parser reentrants. This commit also simplifies the pool references. (cherry picked from commit a3d3ceb771034794c4fb453dcd9aaff64c53baed) --- SConstruct | 3 + include/AuthManager.h | 8 + include/Callbackable.h | 124 +- include/ClusterPool.h | 42 +- include/DatastorePool.h | 31 +- include/DispatchManager.h | 2 +- include/DocumentPool.h | 4 +- include/GroupPool.h | 42 +- include/HostPool.h | 13 +- include/ImagePool.h | 8 +- include/MarketPlaceAppPool.h | 8 +- include/MarketPlacePool.h | 29 +- include/MySqlDB.h | 8 +- include/Nebula.h | 4 +- include/PoolObjectSQL.h | 57 +- include/PoolSQL.h | 100 +- include/PoolSQLCache.h | 149 +++ include/RequestManagerChown.h | 50 +- include/RequestManagerClone.h | 2 +- include/RequestManagerCluster.h | 10 +- include/RequestManagerDropDB.h | 2 +- include/RequestManagerRename.h | 91 +- include/RequestManagerUpdateDB.h | 2 +- include/SecurityGroupPool.h | 18 +- include/Template.h | 5 - include/UserPool.h | 33 +- include/VMGroupPool.h | 8 +- include/VMTemplatePool.h | 18 +- include/VdcPool.h | 31 +- include/VirtualMachine.h | 4 - include/VirtualMachinePool.h | 10 +- include/VirtualNetworkPool.h | 8 +- include/VirtualRouterPool.h | 18 +- include/ZonePool.h | 31 +- share/etc/oned.conf | 4 +- share/scons/lex_bison.py | 2 +- src/cluster/Cluster.cc | 2 +- src/cluster/ClusterPool.cc | 45 +- src/common/SConstruct | 1 - src/datastore/DatastorePool.cc | 11 +- src/dm/DispatchManagerActions.cc | 46 +- src/dm/DispatchManagerStates.cc | 12 +- src/group/GroupPool.cc | 40 +- src/hm/HookManagerDriver.cc | 2 +- src/host/HostPool.cc | 41 +- src/im/InformationManager.cc | 2 +- src/im/MonitorThread.cc | 14 +- src/image/ImageManager.cc | 2 +- src/image/ImageManagerActions.cc | 50 +- src/image/ImageManagerDriver.cc | 22 +- src/image/ImagePool.cc | 16 +- src/lcm/LifeCycleActions.cc | 34 +- src/lcm/LifeCycleStates.cc | 92 +- src/market/MarketPlaceAppPool.cc | 13 +- src/market/MarketPlaceManager.cc | 2 +- src/market/MarketPlaceManagerActions.cc | 14 +- src/market/MarketPlaceManagerDriver.cc | 16 +- src/market/MarketPlacePool.cc | 13 +- src/nebula/Nebula.cc | 73 +- src/nebula/SConstruct | 1 + src/parsers/SConstruct | 74 ++ src/{xml => parsers}/expr_arith.cc | 196 +-- src/{xml => parsers}/expr_arith.h | 33 +- src/{xml => parsers}/expr_arith.y | 82 +- src/{xml => parsers}/expr_bool.cc | 232 ++-- src/{xml => parsers}/expr_bool.h | 35 +- src/{xml => parsers}/expr_bool.y | 85 +- .../expr_parser.c => parsers/expr_parser.cc} | 1026 +++++++++------- src/parsers/expr_parser.h | 717 +++++++++++ src/{xml => parsers}/expr_parser.l | 22 +- .../mem_collector.cc} | 0 .../template_parser.cc} | 1048 ++++++++++------- src/parsers/template_parser.h | 718 +++++++++++ src/{template => parsers}/template_parser.l | 35 +- src/{template => parsers}/template_syntax.cc | 153 +-- src/{template => parsers}/template_syntax.h | 29 +- src/{template => parsers}/template_syntax.y | 87 +- src/{vm => parsers}/vm_file_var_syntax.cc | 184 ++- src/{vm => parsers}/vm_file_var_syntax.h | 35 +- src/{vm => parsers}/vm_file_var_syntax.y | 86 +- .../vm_var_parser.cc} | 1042 +++++++++------- src/parsers/vm_var_parser.h | 719 +++++++++++ src/{vm => parsers}/vm_var_parser.l | 28 +- src/{vm => parsers}/vm_var_syntax.cc | 189 ++- src/{vm => parsers}/vm_var_syntax.h | 34 +- src/{vm => parsers}/vm_var_syntax.y | 91 +- src/pool/PoolObjectSQL.cc | 79 +- src/pool/PoolSQL.cc | 203 +--- src/pool/PoolSQLCache.cc | 152 +++ src/pool/SConstruct | 1 + src/raft/FedReplicaManager.cc | 4 +- src/rm/Request.cc | 12 +- src/rm/RequestManagerAllocate.cc | 22 +- src/rm/RequestManagerChmod.cc | 6 +- src/rm/RequestManagerChown.cc | 23 +- src/rm/RequestManagerClone.cc | 6 +- src/rm/RequestManagerCluster.cc | 18 +- src/rm/RequestManagerDatastore.cc | 2 +- src/rm/RequestManagerDelete.cc | 18 +- src/rm/RequestManagerGroup.cc | 4 +- src/rm/RequestManagerHost.cc | 2 +- src/rm/RequestManagerImage.cc | 16 +- src/rm/RequestManagerInfo.cc | 6 +- src/rm/RequestManagerLock.cc | 4 +- src/rm/RequestManagerMarketPlaceApp.cc | 2 +- src/rm/RequestManagerRename.cc | 27 +- src/rm/RequestManagerSecurityGroup.cc | 2 +- src/rm/RequestManagerUpdateTemplate.cc | 2 +- src/rm/RequestManagerUser.cc | 27 +- src/rm/RequestManagerVMTemplate.cc | 4 +- src/rm/RequestManagerVdc.cc | 4 +- src/rm/RequestManagerVirtualMachine.cc | 56 +- src/rm/RequestManagerVirtualNetwork.cc | 18 +- src/rm/RequestManagerVirtualRouter.cc | 14 +- src/rm/RequestManagerZone.cc | 6 +- src/scheduler/src/sched/SConstruct | 1 + src/secgroup/SecurityGroupPool.cc | 18 +- src/sql/MySqlDB.cc | 34 +- src/template/SConstruct | 18 +- src/template/Template.cc | 84 +- src/tm/TransferManager.cc | 34 +- src/tm/TransferManagerDriver.cc | 2 +- src/um/Quotas.cc | 6 +- src/um/UserPool.cc | 71 +- src/vdc/VdcPool.cc | 10 +- src/vm/SConstruct | 21 - src/vm/VirtualMachineContext.cc | 2 +- src/vm/VirtualMachineDisk.cc | 8 +- src/vm/VirtualMachineNic.cc | 6 +- src/vm/VirtualMachineParser.cc | 92 +- src/vm/VirtualMachinePool.cc | 40 +- src/vm_group/VMGroupPool.cc | 14 +- src/vm_template/VMTemplatePool.cc | 10 +- src/vmm/VirtualMachineManager.cc | 54 +- src/vmm/VirtualMachineManagerDriver.cc | 8 +- src/vnm/VirtualNetworkPool.cc | 28 +- src/vrouter/VirtualRouter.cc | 2 +- src/xml/ObjectXML.cc | 67 +- src/xml/SConstruct | 25 +- src/zone/ZonePool.cc | 10 +- 140 files changed, 6346 insertions(+), 3582 deletions(-) create mode 100644 include/PoolSQLCache.h create mode 100644 src/parsers/SConstruct rename src/{xml => parsers}/expr_arith.cc (93%) rename src/{xml => parsers}/expr_arith.h (77%) rename src/{xml => parsers}/expr_arith.y (75%) rename src/{xml => parsers}/expr_bool.cc (92%) rename src/{xml => parsers}/expr_bool.h (79%) rename src/{xml => parsers}/expr_bool.y (84%) rename src/{xml/expr_parser.c => parsers/expr_parser.cc} (63%) create mode 100644 src/parsers/expr_parser.h rename src/{xml => parsers}/expr_parser.l (76%) rename src/{common/mem_collector.c => parsers/mem_collector.cc} (100%) rename src/{template/template_parser.c => parsers/template_parser.cc} (66%) create mode 100644 src/parsers/template_parser.h rename src/{template => parsers}/template_parser.l (82%) rename src/{template => parsers}/template_syntax.cc (94%) rename src/{template => parsers}/template_syntax.h (81%) rename src/{template => parsers}/template_syntax.y (81%) rename src/{vm => parsers}/vm_file_var_syntax.cc (94%) rename src/{vm => parsers}/vm_file_var_syntax.h (76%) rename src/{vm => parsers}/vm_file_var_syntax.y (81%) rename src/{vm/vm_var_parser.c => parsers/vm_var_parser.cc} (64%) create mode 100644 src/parsers/vm_var_parser.h rename src/{vm => parsers}/vm_var_parser.l (80%) rename src/{vm => parsers}/vm_var_syntax.cc (94%) rename src/{vm => parsers}/vm_var_syntax.h (77%) rename src/{vm => parsers}/vm_var_syntax.y (88%) create mode 100644 src/pool/PoolSQLCache.cc diff --git a/SConstruct b/SConstruct index 8c805103b3..0973194b4f 100644 --- a/SConstruct +++ b/SConstruct @@ -49,10 +49,12 @@ add_bison(main_env) # Include dirs main_env.Append(CPPPATH=[ cwd+'/include', + cwd+'/src/parsers' ]) # Library dirs main_env.Append(LIBPATH=[ + cwd+'/src/parsers', cwd+'/src/common', cwd+'/src/log', cwd+'/src/raft', @@ -219,6 +221,7 @@ main_env.ParseConfig('xml2-config --libs --cflags') # SCONS scripts to build build_scripts=[ + 'src/parsers/SConstruct', 'src/sql/SConstruct', 'src/log/SConstruct', 'src/raft/SConstruct', diff --git a/include/AuthManager.h b/include/AuthManager.h index 354ec6463c..4a276c5a3c 100644 --- a/include/AuthManager.h +++ b/include/AuthManager.h @@ -110,6 +110,14 @@ public: */ int start(); + /** + * + */ + void finalize() + { + am.finalize(); + }; + /** * Loads Virtual Machine Manager Mads defined in configuration file * @param uid of the user executing the driver. When uid is 0 the nebula diff --git a/include/Callbackable.h b/include/Callbackable.h index 0d7d75346f..c9a14478fd 100644 --- a/include/Callbackable.h +++ b/include/Callbackable.h @@ -19,12 +19,13 @@ #include #include +#include +#include using namespace std; /** - * ObjectSQL class. Provides a SQL backend interface, it should be implemented - * by persistent objects. + * This class represents a SQL callback */ class Callbackable { @@ -141,6 +142,8 @@ private: T * value; }; +/* -------------------------------------------------------------------------- */ + template<> class single_cb : public Callbackable { @@ -169,4 +172,121 @@ private: std::string * value; }; +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +template +class set_cb : public Callbackable +{ +public: + void set_callback(std::set * _ids) + { + ids = _ids; + + Callbackable::set_callback( + static_cast(&set_cb::callback)); + }; + + int callback(void * nil, int num, char **values, char **names) + { + if ( num == 0 || values == 0 || values[0] == 0 ) + { + return -1; + } + + std::istringstream iss(values[0]); + + T value; + + iss >> value; + + ids->insert(value); + + return 0; + }; + +private: + + set * ids; +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +template +class vector_cb : public Callbackable +{ +public: + void set_callback(vector * _oids) + { + oids = _oids; + + Callbackable::set_callback( + static_cast(&vector_cb::callback)); + }; + + int callback(void * nil, int num, char **values, char **names) + { + if ( num == 0 || values == 0 || values[0] == 0 ) + { + return -1; + } + + std::istringstream iss(values[0]); + + T value; + + iss >> value; + + oids->push_back(value); + + return 0; + }; + +private: + + vector * oids; +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +class stream_cb : public Callbackable +{ +public: + stream_cb(int _total): total_values(_total){}; + + void set_callback(ostringstream * _oss) + { + oss = _oss; + + Callbackable::set_callback( + static_cast(&stream_cb::callback)); + }; + + int callback(void * nil, int num, char **values, char **names) + { + if ( (!values[0]) || (num != total_values) ) + { + return -1; + } + + for (int i=0; i < total_values; i++) + { + if ( values[i] != NULL ) + { + *oss << values[i]; + } + } + + return 0; + }; + +private: + + int total_values; + + ostringstream * oss; +}; + #endif /*CALLBACKABLE_H_*/ diff --git a/include/ClusterPool.h b/include/ClusterPool.h index f0c4d6605d..898de8f4e7 100644 --- a/include/ClusterPool.h +++ b/include/ClusterPool.h @@ -67,7 +67,7 @@ public: { int rc = -1; - Cluster * cluster = get(oid, true); + Cluster * cluster = get(oid); if ( cluster != 0 ) { @@ -88,7 +88,7 @@ public: */ void release_vnc_port(int oid, unsigned int port) { - Cluster * cluster = get(oid, true); + Cluster * cluster = get(oid); if ( cluster != 0 ) { @@ -111,7 +111,7 @@ public: { int rc = -1; - Cluster * cluster = get(oid, true); + Cluster * cluster = get(oid); if ( cluster != 0 ) { @@ -147,36 +147,9 @@ public: * @param lock locks the cluster mutex * @return a pointer to the cluster, 0 if the cluster could not be loaded */ - Cluster * get(int oid, bool lock) + Cluster * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); - }; - - /** - * Gets an object from the pool (if needed the object is loaded from the - * database). - * @param name of the object - * @param lock locks the object if true - * - * @return a pointer to the object, 0 in case of failure - */ - Cluster * get(const string& name, bool lock) - { - // The owner is set to -1, because it is not used in the key() method - return static_cast(PoolSQL::get(name,-1,lock)); - }; - - /** - * Generate an index key for the object - * @param name of the object - * @param uid owner of the object, only used if needed - * - * @return the key, a string - */ - string key(const string& name, int uid) - { - // Name is enough key because Clusters can't repeat names. - return name; + return static_cast(PoolSQL::get(oid)); }; /** @@ -262,11 +235,6 @@ private: { return new Cluster(-1,"",0, &vnc_conf); }; - - - int get_clusters_cb( - void * _cluster_ids, int num, char **values, char **names); - }; #endif /*CLUSTER_POOL_H_*/ diff --git a/include/DatastorePool.h b/include/DatastorePool.h index 670d779b83..3b791603f5 100644 --- a/include/DatastorePool.h +++ b/include/DatastorePool.h @@ -101,36 +101,9 @@ public: * @param lock locks the Datastore mutex * @return a pointer to the Datastore, 0 if the Datastore could not be loaded */ - Datastore * get(int oid, bool lock) + Datastore * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); - }; - - /** - * Gets an object from the pool (if needed the object is loaded from the - * database). - * @param name of the object - * @param lock locks the object if true - * - * @return a pointer to the object, 0 in case of failure - */ - Datastore * get(const string& name, bool lock) - { - // The owner is set to -1, because it is not used in the key() method - return static_cast(PoolSQL::get(name,-1,lock)); - }; - - /** - * Generate an index key for the object - * @param name of the object - * @param uid owner of the object, only used if needed - * - * @return the key, a string - */ - string key(const string& name, int uid) - { - // Name is enough key because Datastores can't repeat names. - return name; + return static_cast(PoolSQL::get(oid)); }; /** diff --git a/include/DispatchManager.h b/include/DispatchManager.h index fe90252a2b..d1cfc580c7 100644 --- a/include/DispatchManager.h +++ b/include/DispatchManager.h @@ -275,7 +275,7 @@ public: { VirtualMachine * vm; - vm = vmpool->get(vid, true); + vm = vmpool->get(vid); if ( vm == 0 ) { diff --git a/include/DocumentPool.h b/include/DocumentPool.h index e967aa13ca..285f94d047 100644 --- a/include/DocumentPool.h +++ b/include/DocumentPool.h @@ -71,9 +71,9 @@ public: * * @return a pointer to the object, 0 in case of failure */ - Document * get(int oid, bool lock) + Document * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); + return static_cast(PoolSQL::get(oid)); }; /** diff --git a/include/GroupPool.h b/include/GroupPool.h index 7258fc97f2..e9cdfcaedb 100644 --- a/include/GroupPool.h +++ b/include/GroupPool.h @@ -79,36 +79,9 @@ public: * @param lock locks the group mutex * @return a pointer to the group, 0 if the group could not be loaded */ - Group * get(int oid, bool lock) + Group * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); - }; - - /** - * Gets an object from the pool (if needed the object is loaded from the - * database). - * @param name of the object - * @param lock locks the object if true - * - * @return a pointer to the object, 0 in case of failure - */ - Group * get(const string& name, bool lock) - { - // The owner is set to -1, because it is not used in the key() method - return static_cast(PoolSQL::get(name,-1,lock)); - }; - - /** - * Generate an index key for the object - * @param name of the object - * @param uid owner of the object, only used if needed - * - * @return the key, a string - */ - string key(const string& name, int uid) - { - // Name is enough key because Groups can't repeat names. - return name; + return static_cast(PoolSQL::get(oid)); }; /** @@ -120,7 +93,7 @@ public: { static string error_str = ""; - Group * group = get(gid, true); + Group * group = get(gid); if ( group == 0 ) { @@ -190,15 +163,6 @@ private: { return new Group(-1,""); }; - - /** - * Callback function to get output in XML format - * @param num the number of columns read from the DB - * @param names the column names - * @param vaues the column values - * @return 0 on success - */ - int dump_cb(void * _oss, int num, char **values, char **names); }; #endif /*GROUP_POOL_H_*/ diff --git a/include/HostPool.h b/include/HostPool.h index fc578001a8..69a7041efe 100644 --- a/include/HostPool.h +++ b/include/HostPool.h @@ -64,10 +64,9 @@ public: * @return a pointer to the Host, 0 if the Host could not be loaded */ Host * get( - int oid, - bool lock) + int oid) { - Host * h = static_cast(PoolSQL::get(oid,lock)); + Host * h = static_cast(PoolSQL::get(oid)); if ( h != 0 ) { @@ -89,10 +88,10 @@ public: * @param lock locks the Host mutex * @return a pointer to the Host, 0 if the Host could not be loaded */ - Host * get(string name, bool lock) + Host * get(string name) { // The owner is set to -1, because it is not used in the key() method - Host * h = static_cast(PoolSQL::get(name,-1,lock)); + Host * h = static_cast(PoolSQL::get(name,-1)); if ( h != 0 ) { @@ -153,7 +152,7 @@ public: vector pci) { int rc = 0; - Host * host = get(oid, true); + Host * host = get(oid); if ( host != 0 ) { @@ -183,7 +182,7 @@ public: void del_capacity(int oid, int vm_id, int cpu, int mem, int disk, vector pci) { - Host * host = get(oid, true); + Host * host = get(oid); if ( host != 0 ) { diff --git a/include/ImagePool.h b/include/ImagePool.h index 96c453282d..621bffbea2 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -100,9 +100,9 @@ public: * @param lock locks the Image mutex * @return a pointer to the Image, 0 if the Image could not be loaded */ - Image * get(int oid, bool lock) + Image * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); + return static_cast(PoolSQL::get(oid)); }; /** @@ -114,9 +114,9 @@ public: * * @return a pointer to the object, 0 in case of failure */ - Image * get(const string& name, int uid, bool lock) + Image * get(const string& name, int uid) { - return static_cast(PoolSQL::get(name,uid,lock)); + return static_cast(PoolSQL::get(name,uid)); }; /** diff --git a/include/MarketPlaceAppPool.h b/include/MarketPlaceAppPool.h index 885b573d6d..3d998ae45c 100644 --- a/include/MarketPlaceAppPool.h +++ b/include/MarketPlaceAppPool.h @@ -88,9 +88,9 @@ public: * @param lock locks the MarketPlaceApp mutex * @return a pointer to the MarketPlaceApp, 0 if not loaded */ - MarketPlaceApp * get(int oid, bool lock) + MarketPlaceApp * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); + return static_cast(PoolSQL::get(oid)); }; /** @@ -102,9 +102,9 @@ public: * * @return a pointer to the object, 0 in case of failure */ - MarketPlaceApp * get(const std::string& name, int uid, bool lock) + MarketPlaceApp * get(const std::string& name, int uid) { - return static_cast(PoolSQL::get(name, uid, lock)); + return static_cast(PoolSQL::get(name, uid)); }; /** diff --git a/include/MarketPlacePool.h b/include/MarketPlacePool.h index 0dfef1b290..daaf6b0605 100644 --- a/include/MarketPlacePool.h +++ b/include/MarketPlacePool.h @@ -67,34 +67,9 @@ public: * @param lock locks the MarketPlace mutex * @return a pointer to the MarketPlace, 0 if not loaded */ - MarketPlace * get(int oid, bool lock) + MarketPlace * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); - }; - - /** - * Gets an object from the pool (if needed the object is loaded from the - * database). - * @param name of the object - * @param lock locks the object if true - * - * @return a pointer to the object, 0 in case of failure - */ - MarketPlace * get(const std::string& name, bool lock) - { - return static_cast(PoolSQL::get(name,-1,lock)); - }; - - /** - * Generate an index key for the object - * @param name of the object - * @param uid owner of the object, only used if needed - * - * @return the key, a string - */ - string key(const std::string& name, int uid) - { - return name; + return static_cast(PoolSQL::get(oid)); }; /** Update a particular MarketPlace diff --git a/include/MySqlDB.h b/include/MySqlDB.h index 1fc600f548..ad77b26450 100644 --- a/include/MySqlDB.h +++ b/include/MySqlDB.h @@ -48,7 +48,8 @@ public: int _port, const string& _user, const string& _password, - const string& _database); + const string& _database, + int _connections); ~MySqlDB(); @@ -89,7 +90,7 @@ private: /** * Number of concurrent DB connections. */ - static const int DB_CONNECT_SIZE; + int max_connections; /** * The MySql connection pool handler @@ -145,7 +146,8 @@ public: int port, string user, string password, - string database) + string database, + int connections) { throw runtime_error("Aborting oned, MySQL support not compiled!"); }; diff --git a/include/Nebula.h b/include/Nebula.h index ff2eeb28dd..5a9599dc80 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -458,7 +458,7 @@ public: { if ( uid != -1 ) { - User * user = upool->get(uid, true); + User * user = upool->get(uid); if ( user == 0 ) { @@ -481,7 +481,7 @@ public: user->unlock(); } - Group * group = gpool->get(gid, true); + Group * group = gpool->get(gid); if ( group == 0 ) { diff --git a/include/PoolObjectSQL.h b/include/PoolObjectSQL.h index cd130d8ee4..d7e1ee73b5 100644 --- a/include/PoolObjectSQL.h +++ b/include/PoolObjectSQL.h @@ -140,7 +140,6 @@ public: gid(_gid), uname(_uname), gname(_gname), - valid(true), owner_u(1), owner_m(1), owner_a(0), @@ -296,24 +295,6 @@ public: /* --------------------------------------------------------------------- */ - /** - * Check if the object is valid - * @return true if object is valid - */ - const bool& isValid() const - { - return valid; - }; - - /** - * Set the object valid flag - * @param _valid new valid flag - */ - void set_valid(const bool _valid) - { - valid = _valid; - }; - /** * Function to lock the object */ @@ -330,6 +311,15 @@ public: pthread_mutex_unlock(&mutex); }; + /** + * Try to lock the object + * @return 0 on success or error_code + */ + int trylock() + { + return pthread_mutex_trylock(&mutex); + }; + /** * Function to print the object into a string in XML format * base64 encoded @@ -562,7 +552,8 @@ public: * * @param owner String to identify who requested the lock */ - LockStates get_lock_state(){ + LockStates get_lock_state() + { return locked; } @@ -599,6 +590,27 @@ protected: */ virtual int select(SqlDB *db, const string& _name, int _uid); + /** + * Search oid by its name and owner + * @param db pointer to the db + * @param _table for the objects + * @param _name of the object + * @param _uid of owner + * @return -1 if not found or oid otherwise + */ + static int select_oid(SqlDB *db, const char * _table, const string& _name, + int _uid); + + /** + * Check if the object exists + * @param db pointer to the db + * @param _table for the objects + * @param _oid of the object + * + * @return -1 if not found or oid otherwise + */ + static int exist(SqlDB *db, const char * _table, int _oid); + /** * Drops object from the database * @param db pointer to the db @@ -732,11 +744,6 @@ protected: */ string gname; - /** - * The contents of this object are valid - */ - bool valid; - /** * Permissions for the owner user */ diff --git a/include/PoolSQL.h b/include/PoolSQL.h index 0f0ece7af2..275f19508d 100644 --- a/include/PoolSQL.h +++ b/include/PoolSQL.h @@ -17,13 +17,11 @@ #ifndef POOL_SQL_H_ #define POOL_SQL_H_ -#include #include -#include -#include #include "SqlDB.h" #include "PoolObjectSQL.h" +#include "PoolSQLCache.h" #include "Log.h" #include "Hook.h" @@ -35,7 +33,7 @@ using namespace std; * multithreaded applications. Any modification or access function to the pool * SHOULD block the mutex. */ -class PoolSQL: public Callbackable, public Hookable +class PoolSQL: public Hookable { public: /** @@ -68,21 +66,29 @@ public: * * @return a pointer to the object, 0 in case of failure */ - PoolObjectSQL * get(int oid, bool lock); + PoolObjectSQL * get(int oid); /** - * Updates the cache name index. Must be called when the owner of an object - * is changed + * Check if there is an object with the same for a given user + * @param name of object + * @param ouid of user * - * @param old_name Object's name before the change - * @param old_uid Object's owner ID before the change - * @param new_name Object's name after the change - * @param new_uid Object's owner ID after the change + * @return oid of the object if it exists, -1 otherwise */ - void update_cache_index(string& old_name, - int old_uid, - string& new_name, - int new_uid); + int exist(const string& name, int ouid) + { + return PoolObjectSQL::select_oid(db, table.c_str(), name, ouid); + } + + int exist(const string& name) + { + return PoolObjectSQL::select_oid(db, table.c_str(), name, -1); + } + + int exist(int oid) + { + return PoolObjectSQL::exist(db, table.c_str(), oid); + } /** * Finds a set objects that satisfies a given condition @@ -142,7 +148,7 @@ public: */ virtual int drop(PoolObjectSQL * objsql, string& error_msg) { - int rc = objsql->drop(db); + int rc = objsql->drop(db); if ( rc != 0 ) { @@ -157,11 +163,6 @@ public: return 0; }; - /** - * Removes all the elements from the pool - */ - void clean(); - /** * Dumps the pool in XML format. A filter can be also added to the * query @@ -260,7 +261,7 @@ protected: * * @return a pointer to the object, 0 in case of failure */ - PoolObjectSQL * get(const string& name, int uid, bool lock); + PoolObjectSQL * get(const string& name, int uid); /** * Pointer to the database. @@ -348,10 +349,10 @@ private: string table; /** - * The pool is implemented with a Map of SQL object pointers, using the - * OID as key. + * The pool cache is implemented with a Map of SQL object pointers, + * using the OID as key. */ - vector pool; + PoolSQLCache cache; /** * Factory method, must return an ObjectSQL pointer to an allocated pool @@ -374,55 +375,6 @@ private: { pthread_mutex_unlock(&mutex); }; - - /** - * Cleans all the objects in the cache, except the ones locked. - * The object with the given oid will not be ignored if locked, the - * method will wait for it to be unlocked and ensure it is erased from - * the cache - * - * @param oid - */ - void flush_cache(int oid); - - /** - * Same as flush_cache(int), but with the object name-uid key - * - * @param name_key - */ - void flush_cache(const string& name_key); - - /** - * Generate an index key for the object - * @param name of the object - * @param uid owner of the object, only used if needed - * - * @return the key, a string - */ - virtual string key(const string& name, int uid) - { - ostringstream key; - - key << name << ':' << uid; - - return key.str(); - }; - - /* ---------------------------------------------------------------------- */ - /* ---------------------------------------------------------------------- */ - /** - * Callback to store the IDs of pool objects (PoolSQL::search) - */ - int search_cb(void *_oids, int num, char **values, char **names); - - /** - * Callback function to get output in XML format - * @param num the number of columns read from the DB - * @param names the column names - * @param vaues the column values - * @return 0 on success - */ - int dump_cb(void * _oss, int num, char **values, char **names); }; #endif /*POOL_SQL_H_*/ diff --git a/include/PoolSQLCache.h b/include/PoolSQLCache.h new file mode 100644 index 0000000000..de828f32c3 --- /dev/null +++ b/include/PoolSQLCache.h @@ -0,0 +1,149 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +#ifndef POOL_SQL_CACHE_H_ +#define POOL_SQL_CACHE_H_ + +#include +#include +#include +#include + +#include "PoolObjectSQL.h" + +/** + * This class stores the active reference to pool objects. It can also + * cache to not reload object state from the DB. + * + * Access to the cache needs to happen in a critical section. + */ +class PoolSQLCache +{ +public: + + PoolSQLCache(); + + virtual ~PoolSQLCache() + { + pthread_mutex_destroy(&mutex); + }; + + /** + * Allocates a new cache line to hold an active pool object. If the line + * does not exist it is created. Any active reference is deallocated to + * load a fresh copy of the object. + * + * The cache line is locked to sync access to the given object. + * + * @param oid of the object + */ + void lock_line(int oid); + + /** + * Sets the reference of the active object and unlocks the cache line. The + * mutex of the object MUST be locked + * + * @param oid of the object + * @param object to be inserted int the cache + * + * @return 0 on success + * + */ + int set_line(int oid, PoolObjectSQL * object); + +private: + /** + * This class represents a cache line. It stores a reference to the pool + * object and a mutex to control concurrent access to the object + */ + struct CacheLine + { + CacheLine(PoolObjectSQL * o):active(0), object(o) + { + pthread_mutex_init(&mutex, 0); + }; + + ~CacheLine() + { + delete object; + + pthread_mutex_destroy(&mutex); + } + + void lock() + { + pthread_mutex_lock(&mutex); + }; + + void unlock() + { + pthread_mutex_unlock(&mutex); + } + + int trylock() + { + return pthread_mutex_trylock(&mutex); + } + + /** + * Concurrent access to cache line + */ + pthread_mutex_t mutex; + + /** + * Number of threads waiting on the line mutex + */ + int active; + + /** + * Reference to the object + */ + PoolObjectSQL * object; + }; + + /** + * Max number of references in the cache. + */ + static unsigned int MAX_ELEMENTS; + + /** + * Cache of pool objects indexed by their oid + */ + std::map cache; + + /** + * Deletes all cache lines if they are not in use. + */ + void flush_cache_lines(); + + /** + * Controls concurrent access to the cache map. + */ + pthread_mutex_t mutex; + + void lock() + { + pthread_mutex_lock(&mutex); + }; + + void unlock() + { + pthread_mutex_unlock(&mutex); + } +}; + +#endif /*POOL_SQL_CACHE_H_*/ + diff --git a/include/RequestManagerChown.h b/include/RequestManagerChown.h index b77691dc19..84b3b4aaf4 100644 --- a/include/RequestManagerChown.h +++ b/include/RequestManagerChown.h @@ -69,8 +69,6 @@ protected: * @return 0 if the operation is allowed, -1 otherwise */ virtual int check_name_unique(int oid, int noid, RequestAttributes& att); - - virtual PoolObjectSQL * get(const string& name, int uid, bool lock) = 0; }; /* ------------------------------------------------------------------------- */ @@ -94,11 +92,6 @@ public: { return 0; }; - - PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return 0; - }; }; /* ------------------------------------------------------------------------- */ @@ -117,11 +110,6 @@ public: }; ~TemplateChown(){}; - - PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return static_cast(pool)->get(name, uid, lock); - }; }; /* ------------------------------------------------------------------------- */ @@ -141,11 +129,6 @@ public: }; ~VirtualNetworkChown(){}; - - PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return static_cast(pool)->get(name, uid, lock); - }; }; /* ------------------------------------------------------------------------- */ @@ -164,11 +147,6 @@ public: }; ~ImageChown(){}; - - PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return static_cast(pool)->get(name, uid, lock); - }; }; /* ------------------------------------------------------------------------- */ @@ -194,7 +172,7 @@ public: virtual void request_execute(xmlrpc_c::paramList const& _paramList, RequestAttributes& att); - PoolObjectSQL * get(const string& name, int uid, bool lock) + int check_name_unique(int oid, int noid, RequestAttributes& att) { return 0; }; @@ -217,7 +195,7 @@ public: ~DatastoreChown(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int check_name_unique(int oid, int noid, RequestAttributes& att) { return 0; }; @@ -240,7 +218,7 @@ public: ~DocumentChown(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int check_name_unique(int oid, int noid, RequestAttributes& att) { return 0; }; @@ -262,11 +240,6 @@ public: }; ~SecurityGroupChown(){}; - - PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return static_cast(pool)->get(name, uid, lock); - }; }; /* ------------------------------------------------------------------------- */ @@ -285,11 +258,6 @@ public: }; ~VirtualRouterChown(){}; - - PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return static_cast(pool)->get(name, uid, lock); - }; }; /* ------------------------------------------------------------------------- */ @@ -309,7 +277,7 @@ public: ~MarketPlaceChown(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int check_name_unique(int oid, int noid, RequestAttributes& att) { return 0; }; @@ -331,11 +299,6 @@ public: }; ~MarketPlaceAppChown(){}; - - PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return static_cast(pool)->get(name, uid, lock); - }; }; /* -------------------------------------------------------------------------- */ @@ -354,11 +317,6 @@ public: }; ~VMGroupChown(){}; - - PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return static_cast(pool)->get(name, uid, lock); - }; }; #endif diff --git a/include/RequestManagerClone.h b/include/RequestManagerClone.h index 653dda479e..4497209c27 100644 --- a/include/RequestManagerClone.h +++ b/include/RequestManagerClone.h @@ -153,7 +153,7 @@ protected: int pool_allocate(int sid, Template * tmpl, int& id, RequestAttributes& att) { DocumentPool * docpool = static_cast(pool); - Document * doc = docpool->get(sid, true); + Document * doc = docpool->get(sid); if ( doc == 0 ) { diff --git a/include/RequestManagerCluster.h b/include/RequestManagerCluster.h index c43a01517a..6d52714cb6 100644 --- a/include/RequestManagerCluster.h +++ b/include/RequestManagerCluster.h @@ -99,7 +99,7 @@ protected: virtual int del_object(Cluster* cluster, int id, string& error_msg) = 0; - virtual void get(int oid, bool lock, PoolObjectSQL ** object, Clusterable ** cluster_obj) = 0; + virtual void get(int oid, PoolObjectSQL ** object, Clusterable ** cluster_obj) = 0; }; /* ------------------------------------------------------------------------- */ @@ -212,9 +212,9 @@ public: return cluster->del_datastore(id, error_msg); }; - virtual void get(int oid, bool lock, PoolObjectSQL ** object, Clusterable ** cluster_obj) + virtual void get(int oid, PoolObjectSQL ** object, Clusterable ** cluster_obj) { - Datastore * ds = dspool->get(oid, lock); + Datastore * ds = dspool->get(oid); *object = static_cast(ds); *cluster_obj = static_cast(ds); @@ -297,9 +297,9 @@ public: return cluster->del_vnet(id, error_msg); }; - virtual void get(int oid, bool lock, PoolObjectSQL ** object, Clusterable ** cluster_obj) + virtual void get(int oid, PoolObjectSQL ** object, Clusterable ** cluster_obj) { - VirtualNetwork * vnet = vnpool->get(oid, lock); + VirtualNetwork * vnet = vnpool->get(oid); *object = static_cast(vnet); *cluster_obj = static_cast(vnet); diff --git a/include/RequestManagerDropDB.h b/include/RequestManagerDropDB.h index 8032eea5c3..8737d9803d 100644 --- a/include/RequestManagerDropDB.h +++ b/include/RequestManagerDropDB.h @@ -46,7 +46,7 @@ protected: return; } - PoolObjectSQL * object = pool->get(oid,true); + PoolObjectSQL * object = pool->get(oid); if ( object == 0 ) { diff --git a/include/RequestManagerRename.h b/include/RequestManagerRename.h index 4f82bac54f..f7bbe7bc48 100644 --- a/include/RequestManagerRename.h +++ b/include/RequestManagerRename.h @@ -50,10 +50,7 @@ protected: * Gets and object by name and owner. Default implementation returns no * object */ - virtual PoolObjectSQL * get(const string& name, int uid, bool lock) - { - return 0; - } + virtual int exist(const string& name, int uid) = 0; /** * Batch rename of related objects. Default implementation does nothing @@ -119,6 +116,11 @@ public: }; ~VirtualMachineRename(){}; + + int exist(const string& name, int uid) + { + return -1; + } }; /* ------------------------------------------------------------------------- */ @@ -138,10 +140,10 @@ public: ~TemplateRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, uid, lock); - }; + return pool->exist(name, uid); + } }; /* ------------------------------------------------------------------------- */ @@ -161,10 +163,10 @@ public: ~VirtualNetworkRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, uid, lock); - }; + return pool->exist(name, uid); + } }; /* ------------------------------------------------------------------------- */ @@ -183,10 +185,10 @@ public: ~ImageRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, uid, lock); - }; + return pool->exist(name, uid); + } }; /* ------------------------------------------------------------------------- */ @@ -204,6 +206,11 @@ public: }; ~DocumentRename(){}; + + int exist(const string& name, int uid) + { + return -1; + } }; /* ------------------------------------------------------------------------- */ @@ -222,10 +229,10 @@ public: ~ClusterRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, lock); - }; + return pool->exist(name); + } void batch_rename(int oid); }; @@ -246,10 +253,10 @@ public: ~DatastoreRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, lock); - }; + return pool->exist(name); + } void batch_rename(int oid); }; @@ -272,10 +279,10 @@ public: ~HostRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, lock); - }; + return pool->exist(name); + } void batch_rename(int oid); }; @@ -295,6 +302,11 @@ public: }; ~ZoneRename(){}; + + int exist(const string& name, int uid) + { + return pool->exist(name); + } }; /* ------------------------------------------------------------------------- */ @@ -313,10 +325,10 @@ public: ~SecurityGroupRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, uid, lock); - }; + return pool->exist(name, uid); + } }; /* ------------------------------------------------------------------------- */ @@ -334,6 +346,11 @@ public: }; ~VdcRename(){}; + + int exist(const string& name, int uid) + { + return pool->exist(name); + } }; /* ------------------------------------------------------------------------- */ @@ -352,10 +369,10 @@ public: ~VirtualRouterRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, uid, lock); - }; + return -1; + } }; /* ------------------------------------------------------------------------- */ @@ -374,10 +391,10 @@ public: ~MarketPlaceRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, lock); - }; + return pool->exist(name); + } void batch_rename(int oid); }; @@ -398,10 +415,10 @@ public: ~MarketPlaceAppRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, uid, lock); - }; + return pool->exist(name, uid); + } }; /* -------------------------------------------------------------------------- */ @@ -420,10 +437,10 @@ public: ~VMGroupRename(){}; - PoolObjectSQL * get(const string& name, int uid, bool lock) + int exist(const string& name, int uid) { - return static_cast(pool)->get(name, uid, lock); - }; + return pool->exist(name, uid); + } }; #endif diff --git a/include/RequestManagerUpdateDB.h b/include/RequestManagerUpdateDB.h index 256223fa2f..943c642f8f 100644 --- a/include/RequestManagerUpdateDB.h +++ b/include/RequestManagerUpdateDB.h @@ -65,7 +65,7 @@ protected: ErrorCode request_execute(int oid, const std::string& xml, RequestAttributes& att) { - PoolObjectSQL * object = pool->get(oid,true); + PoolObjectSQL * object = pool->get(oid); if ( object == 0 ) { diff --git a/include/SecurityGroupPool.h b/include/SecurityGroupPool.h index ddb672336f..f7df849acc 100644 --- a/include/SecurityGroupPool.h +++ b/include/SecurityGroupPool.h @@ -67,23 +67,9 @@ public: * @param lock locks the SecurityGroup mutex * @return a pointer to the SecurityGroup, 0 if the SecurityGroup could not be loaded */ - SecurityGroup * get(int oid, bool lock) + SecurityGroup * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); - }; - - /** - * Gets an object from the pool (if needed the object is loaded from the - * database). - * @param name of the object - * @param uid id of owner - * @param lock locks the object if true - * - * @return a pointer to the object, 0 in case of failure - */ - SecurityGroup * get(const string& name, int uid, bool lock) - { - return static_cast(PoolSQL::get(name,uid,lock)); + return static_cast(PoolSQL::get(oid)); }; /** Update a particular SecurityGroup diff --git a/include/Template.h b/include/Template.h index 98df48ed76..a747718ccb 100644 --- a/include/Template.h +++ b/include/Template.h @@ -505,12 +505,7 @@ protected: }; private: - bool replace_mode; - /** - * Mutex to perform just one flex-bison parsing at a time - */ - static pthread_mutex_t mutex; /** * Character to separate key from value when dump onto a string diff --git a/include/UserPool.h b/include/UserPool.h index a02aec751a..170dc8a394 100644 --- a/include/UserPool.h +++ b/include/UserPool.h @@ -80,9 +80,9 @@ public: * @param lock locks the User mutex * @return a pointer to the User, 0 if the User could not be loaded */ - User * get(int oid, bool lock) + User * get(int oid) { - User * u = static_cast(PoolSQL::get(oid,lock)); + User * u = static_cast(PoolSQL::get(oid)); if ( u != 0 ) { @@ -99,10 +99,10 @@ public: * @param lock locks the User mutex * @return a pointer to the User, 0 if the User could not be loaded */ - User * get(string name, bool lock) + User * get(string name) { // The owner is set to -1, because it is not used in the key() method - User * u = static_cast(PoolSQL::get(name,-1,lock)); + User * u = static_cast(PoolSQL::get(name,-1)); if ( u != 0 ) { @@ -112,19 +112,6 @@ public: return u; }; - /** - * Generate an index key for the object - * @param name of the object - * @param uid owner of the object, only used if needed - * - * @return the key, a string - */ - string key(const string& name, int uid) - { - // Name is enough key because Users can't repeat names. - return name; - }; - /** * Function to get the token password of an user from the pool * @param uid creator of the object @@ -296,18 +283,6 @@ private: { return new User(-1,-1,"","","",UserPool::CORE_AUTH,true); }; - - //-------------------------------------------------------------------------- - //-------------------------------------------------------------------------- - - /** - * Callback function to output in XML format - * @param num the number of columns read from the DB - * @param names the column names - * @param vaues the column values - * @return 0 on success - */ - int dump_cb(void * _oss, int num, char **values, char **names); }; #endif /*USER_POOL_H_*/ diff --git a/include/VMGroupPool.h b/include/VMGroupPool.h index 6f626a9fb1..e965395e90 100644 --- a/include/VMGroupPool.h +++ b/include/VMGroupPool.h @@ -58,9 +58,9 @@ public: * @param lock locks the VMGroup mutex * @return a pointer to the VMGroup, 0 if the VMGroup could not be loaded */ - VMGroup * get(int oid, bool lock) + VMGroup * get(int oid) { - return static_cast(PoolSQL::get(oid, lock)); + return static_cast(PoolSQL::get(oid)); }; /** @@ -72,9 +72,9 @@ public: * * @return a pointer to the object, 0 in case of failure */ - VMGroup * get(const std::string& name, int uid, bool lock) + VMGroup * get(const std::string& name, int uid) { - return static_cast(PoolSQL::get(name, uid, lock)); + return static_cast(PoolSQL::get(name, uid)); }; /** Update a VMGroup diff --git a/include/VMTemplatePool.h b/include/VMTemplatePool.h index 7b55974cfc..a60a8e006d 100644 --- a/include/VMTemplatePool.h +++ b/include/VMTemplatePool.h @@ -62,23 +62,9 @@ public: * * @return a pointer to the object, 0 in case of failure */ - VMTemplate * get(int oid, bool lock) + VMTemplate * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); - }; - - /** - * Gets an object from the pool (if needed the object is loaded from the - * database). - * @param name of the object - * @param uid id of owner - * @param lock locks the object if true - * - * @return a pointer to the object, 0 in case of failure - */ - VMTemplate * get(const string& name, int uid, bool lock) - { - return static_cast(PoolSQL::get(name,uid,lock)); + return static_cast(PoolSQL::get(oid)); }; /** diff --git a/include/VdcPool.h b/include/VdcPool.h index f3fdb610ef..55d6848612 100644 --- a/include/VdcPool.h +++ b/include/VdcPool.h @@ -54,36 +54,9 @@ public: * @param lock locks the Vdc mutex * @return a pointer to the Vdc, 0 if the Vdc could not be loaded */ - Vdc * get(int oid, bool lock) + Vdc * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); - }; - - /** - * Gets an object from the pool (if needed the object is loaded from the - * database). - * @param name of the object - * @param lock locks the object if true - * - * @return a pointer to the object, 0 in case of failure - */ - Vdc * get(const string& name, bool lock) - { - // The owner is set to -1, because it is not used in the key() method - return static_cast(PoolSQL::get(name,-1,lock)); - }; - - /** - * Generate an index key for the object - * @param name of the object - * @param uid owner of the object, only used if needed - * - * @return the key, a string - */ - string key(const string& name, int uid) - { - // Name is enough key because Vdcs can't repeat names. - return name; + return static_cast(PoolSQL::get(oid)); }; /** Update a particular Vdc diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 7ac20e4883..9f2d66b913 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1824,10 +1824,6 @@ private: // ------------------------------------------------------------------------- // Attribute Parser // ------------------------------------------------------------------------- - /** - * Mutex to perform just one attribute parse at a time - */ - static pthread_mutex_t lex_mutex; /** * Attributes not allowed in NIC_DEFAULT to avoid authorization bypass and diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index 7c30c7d0c5..5c4a83f95e 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -78,18 +78,16 @@ public: * @return a pointer to the VM, 0 if the VM could not be loaded */ VirtualMachine * get( - int oid, - bool lock) + int oid) { - return static_cast(PoolSQL::get(oid,lock)); + return static_cast(PoolSQL::get(oid)); }; /** * Function to get a VM from the pool, string version for VM ID */ VirtualMachine * get( - const string& oid_s, - bool lock) + const string& oid_s) { istringstream iss(oid_s); int oid; @@ -101,7 +99,7 @@ public: return 0; } - return static_cast(PoolSQL::get(oid,lock)); + return static_cast(PoolSQL::get(oid)); }; /** diff --git a/include/VirtualNetworkPool.h b/include/VirtualNetworkPool.h index b4c2daedd4..637c041812 100644 --- a/include/VirtualNetworkPool.h +++ b/include/VirtualNetworkPool.h @@ -92,9 +92,9 @@ public: * @param lock locks the VN mutex * @return a pointer to the VN, 0 if the VN could not be loaded */ - VirtualNetwork * get(int oid, bool lock) + VirtualNetwork * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); + return static_cast(PoolSQL::get(oid)); }; /** @@ -106,9 +106,9 @@ public: * * @return a pointer to the object, 0 in case of failure */ - VirtualNetwork * get(const string& name, int uid, bool lock) + VirtualNetwork * get(const string& name, int uid) { - return static_cast(PoolSQL::get(name,uid,lock)); + return static_cast(PoolSQL::get(name,uid)); }; /** diff --git a/include/VirtualRouterPool.h b/include/VirtualRouterPool.h index 151680eb51..b26b49fb35 100644 --- a/include/VirtualRouterPool.h +++ b/include/VirtualRouterPool.h @@ -73,23 +73,9 @@ public: * * @return a pointer to the object, 0 in case of failure */ - VirtualRouter * get(int oid, bool lock) + VirtualRouter * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); - }; - - /** - * Gets an object from the pool (if needed the object is loaded from the - * database). - * @param name of the object - * @param uid id of owner - * @param lock locks the object if true - * - * @return a pointer to the object, 0 in case of failure - */ - VirtualRouter * get(const string& name, int uid, bool lock) - { - return static_cast(PoolSQL::get(name,uid,lock)); + return static_cast(PoolSQL::get(oid)); }; /** diff --git a/include/ZonePool.h b/include/ZonePool.h index f18387238e..b78ab12063 100644 --- a/include/ZonePool.h +++ b/include/ZonePool.h @@ -55,36 +55,9 @@ public: * @param lock locks the Zone mutex * @return a pointer to the Zone, 0 if the Zone could not be loaded */ - Zone * get(int oid, bool lock) + Zone * get(int oid) { - return static_cast(PoolSQL::get(oid,lock)); - }; - - /** - * Gets an object from the pool (if needed the object is loaded from the - * database). - * @param name of the object - * @param lock locks the object if true - * - * @return a pointer to the object, 0 in case of failure - */ - Zone * get(const string& name, bool lock) - { - // The owner is set to -1, because it is not used in the key() method - return static_cast(PoolSQL::get(name,-1,lock)); - }; - - /** - * Generate an index key for the object - * @param name of the object - * @param uid owner of the object, only used if needed - * - * @return the key, a string - */ - string key(const string& name, int uid) - { - // Name is enough key because Zones can't repeat names. - return name; + return static_cast(PoolSQL::get(oid)); }; /** Update a particular Zone diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 0ea3ace8fb..f2ad628278 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -38,6 +38,7 @@ # user : (mysql) user's MySQL login ID # passwd : (mysql) the password for user # db_name : (mysql) the database name +# connections: (mysql) number of max. connections to mysql server # # VNC_PORTS: VNC port pool for automatic VNC port assignment, if possible the # port will be set to ``START`` + ``VMID`` @@ -87,7 +88,8 @@ DB = [ BACKEND = "sqlite" ] # PORT = 0, # USER = "oneadmin", # PASSWD = "oneadmin", -# DB_NAME = "opennebula" ] +# DB_NAME = "opennebula", +# CONNECTIONS = 50 ] VNC_PORTS = [ START = 5900 diff --git a/share/scons/lex_bison.py b/share/scons/lex_bison.py index 9d2742e917..dbe1a67863 100644 --- a/share/scons/lex_bison.py +++ b/share/scons/lex_bison.py @@ -43,7 +43,7 @@ def emitter_lex(target, source, env): def add_lex(environment): lex_bld=SCons.Builder.Builder(action=build_lex, - suffix='.c', + suffix='.cc', src_suffix='.l', emitter=emitter_lex) environment.Append(BUILDERS={'Lex':lex_bld}) diff --git a/src/cluster/Cluster.cc b/src/cluster/Cluster.cc index 6a7ed25ac5..402c9b9f47 100644 --- a/src/cluster/Cluster.cc +++ b/src/cluster/Cluster.cc @@ -157,7 +157,7 @@ int Cluster::get_default_system_ds(const set& ds_set) for (set::const_iterator it = ds_set.begin(); it != ds_set.end(); it++) { - ds = dspool->get(*it, true); + ds = dspool->get(*it); if (ds == 0) { diff --git a/src/cluster/ClusterPool.cc b/src/cluster/ClusterPool.cc index 21c6a33026..1d3afeaf27 100644 --- a/src/cluster/ClusterPool.cc +++ b/src/cluster/ClusterPool.cc @@ -56,7 +56,7 @@ ClusterPool::ClusterPool(SqlDB * db, const VectorAttribute * _vnc_conf): goto error_bootstrap; } - Cluster* cluster = get(DEFAULT_CLUSTER_ID, true); + Cluster* cluster = get(DEFAULT_CLUSTER_ID); if (cluster == 0) { @@ -95,6 +95,8 @@ int ClusterPool::allocate(string name, int * oid, string& error_str) ostringstream oss; + int db_oid; + // Check name if ( !PoolObjectSQL::name_is_valid(name, error_str) ) { @@ -102,9 +104,9 @@ int ClusterPool::allocate(string name, int * oid, string& error_str) } // Check for duplicates - cluster = get(name, false); + db_oid = exist(name); - if( cluster != 0 ) + if( db_oid != -1 ) { goto error_duplicated; } @@ -119,7 +121,7 @@ int ClusterPool::allocate(string name, int * oid, string& error_str) error_duplicated: - oss << "NAME is already taken by CLUSTER " << cluster->get_oid() << "."; + oss << "NAME is already taken by CLUSTER " << db_oid << "."; error_str = oss.str(); error_name: @@ -217,15 +219,16 @@ void ClusterPool::cluster_acl_filter(ostringstream& filter, int ClusterPool::query_datastore_clusters(int oid, set &cluster_ids) { ostringstream oss; + set_cb cb; - set_callback(static_cast(&ClusterPool::get_clusters_cb), - static_cast(&cluster_ids)); + cb.set_callback(&cluster_ids); - oss << "SELECT cid FROM " << Cluster::datastore_table << " WHERE oid = " << oid; + oss << "SELECT cid FROM " << Cluster::datastore_table << " WHERE oid = " + << oid; - int rc = db->exec_rd(oss, this); + int rc = db->exec_rd(oss, &cb); - unset_callback(); + cb.unset_callback(); if ( rc != 0 ) { @@ -241,15 +244,15 @@ int ClusterPool::query_datastore_clusters(int oid, set &cluster_ids) int ClusterPool::query_vnet_clusters(int oid, set &cluster_ids) { ostringstream oss; + set_cb cb; - set_callback(static_cast(&ClusterPool::get_clusters_cb), - static_cast(&cluster_ids)); + cb.set_callback(&cluster_ids); - oss << "SELECT cid FROM " << Cluster::network_table << " WHERE oid = " << oid; + oss << "SELECT cid FROM " << Cluster::network_table << " WHERE oid = "<exec_rd(oss, this); + int rc = db->exec_rd(oss, &cb); - unset_callback(); + cb.unset_callback(); if ( rc != 0 ) { @@ -261,17 +264,3 @@ int ClusterPool::query_vnet_clusters(int oid, set &cluster_ids) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ - -int ClusterPool::get_clusters_cb( - void * _cluster_ids, int num, char **values, char **names) -{ - if ( num == 0 || values == 0 || values[0] == 0 ) - { - return -1; - } - - int cluster_id = atoi(values[0]); - static_cast*>(_cluster_ids)->insert(cluster_id); - - return 0; -} diff --git a/src/common/SConstruct b/src/common/SConstruct index 7b21e7b410..fdf064a0aa 100644 --- a/src/common/SConstruct +++ b/src/common/SConstruct @@ -25,7 +25,6 @@ source_files=[ 'ActionManager.cc', 'Attribute.cc', 'ExtendedAttribute.cc', - 'mem_collector.c', 'NebulaUtil.cc' ] diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc index a83c855046..0880455057 100644 --- a/src/datastore/DatastorePool.cc +++ b/src/datastore/DatastorePool.cc @@ -188,8 +188,8 @@ int DatastorePool::allocate( string& error_str) { Datastore * ds; - Datastore * ds_aux = 0; + int db_oid; string name; ostringstream oss; @@ -208,9 +208,10 @@ int DatastorePool::allocate( goto error_name; } - ds_aux = get(name,false); + // Check for duplicates + db_oid = exist(name); - if( ds_aux != 0 ) + if( db_oid != -1 ) { goto error_duplicated; } @@ -231,7 +232,7 @@ int DatastorePool::allocate( return *oid; error_duplicated: - oss << "NAME is already taken by DATASTORE " << ds_aux->get_oid() << "."; + oss << "NAME is already taken by DATASTORE " << db_oid << "."; error_str = oss.str(); error_name: @@ -276,7 +277,7 @@ int DatastorePool::drop(PoolObjectSQL * objsql, string& error_msg) int DatastorePool::disk_attribute(int ds_id, VirtualMachineDisk * disk) { - Datastore * ds = get(ds_id, true); + Datastore * ds = get(ds_id); if (ds == 0) { diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index ffb263874f..0f86bdaaea 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -276,7 +276,7 @@ void DispatchManager::free_vm_resources(VirtualMachine * vm) if (vrid != -1) { - VirtualRouter* vr = vrouterpool->get(vrid, true); + VirtualRouter* vr = vrouterpool->get(vrid); if (vr != 0) { @@ -298,7 +298,7 @@ int DispatchManager::terminate(int vid, bool hard, const RequestAttributes& ra, int rc = 0; ostringstream oss; - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -389,7 +389,7 @@ int DispatchManager::undeploy(int vid, bool hard, const RequestAttributes& ra, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -444,7 +444,7 @@ int DispatchManager::poweroff (int vid, bool hard, const RequestAttributes& ra, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -499,7 +499,7 @@ int DispatchManager::hold(int vid, const RequestAttributes& ra, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -547,7 +547,7 @@ int DispatchManager::release(int vid, const RequestAttributes& ra, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -615,7 +615,7 @@ int DispatchManager::stop(int vid, const RequestAttributes& ra, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -662,7 +662,7 @@ int DispatchManager::suspend(int vid, const RequestAttributes& ra, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -708,7 +708,7 @@ int DispatchManager::resume(int vid, const RequestAttributes& ra, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -787,7 +787,7 @@ int DispatchManager::reboot(int vid, bool hard, const RequestAttributes& ra, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -845,7 +845,7 @@ int DispatchManager::resched(int vid, bool do_resched, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1005,7 +1005,7 @@ int DispatchManager::delete_vm(VirtualMachine * vm, const RequestAttributes& ra, if(host_id != -1) { - Host * host = hpool->get(host_id,true); + Host * host = hpool->get(host_id); if ( host == 0 ) { @@ -1192,7 +1192,7 @@ int DispatchManager::attach(int vid, VirtualMachineTemplate * tmpl, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1297,7 +1297,7 @@ int DispatchManager::detach(int vid, int disk_id, const RequestAttributes& ra, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1392,7 +1392,7 @@ int DispatchManager::snapshot_create(int vid, string& name, int& snap_id, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1443,7 +1443,7 @@ int DispatchManager::snapshot_revert(int vid, int snap_id, int rc; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1506,7 +1506,7 @@ int DispatchManager::snapshot_delete(int vid, int snap_id, int rc; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1569,7 +1569,7 @@ int DispatchManager::attach_nic(int vid, VirtualMachineTemplate* tmpl, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1671,7 +1671,7 @@ int DispatchManager::detach_nic(int vid, int nic_id,const RequestAttributes& ra, ostringstream oss; string tmp_error; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1770,7 +1770,7 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name, ostringstream oss; time_t the_time; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1884,7 +1884,7 @@ int DispatchManager::disk_snapshot_revert(int vid, int did, int snap_id, { ostringstream oss; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1960,7 +1960,7 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id, ostringstream oss; time_t the_time; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -2083,7 +2083,7 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size, ostringstream oss; time_t the_time; - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { diff --git a/src/dm/DispatchManagerStates.cc b/src/dm/DispatchManagerStates.cc index 7e7462bd46..f35d8ebc95 100644 --- a/src/dm/DispatchManagerStates.cc +++ b/src/dm/DispatchManagerStates.cc @@ -23,7 +23,7 @@ void DispatchManager::suspend_success_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -65,7 +65,7 @@ void DispatchManager::stop_success_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -111,7 +111,7 @@ void DispatchManager::undeploy_success_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -158,7 +158,7 @@ void DispatchManager::poweroff_success_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -206,7 +206,7 @@ void DispatchManager::done_action(int vid) VirtualMachine::LcmState lcm_state; VirtualMachine::VmState dm_state; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -242,7 +242,7 @@ void DispatchManager::resubmit_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { diff --git a/src/group/GroupPool.cc b/src/group/GroupPool.cc index 61a7fe112d..192457d44c 100644 --- a/src/group/GroupPool.cc +++ b/src/group/GroupPool.cc @@ -96,6 +96,8 @@ error_groups: int GroupPool::allocate(string name, int * oid, string& error_str) { + int db_oid; + Group * group; ostringstream oss; @@ -116,9 +118,9 @@ int GroupPool::allocate(string name, int * oid, string& error_str) } // Check for duplicates - group = get(name, false); + db_oid = exist(name); - if( group != 0 ) + if( db_oid != -1 ) { goto error_duplicated; } @@ -132,7 +134,7 @@ int GroupPool::allocate(string name, int * oid, string& error_str) return *oid; error_duplicated: - oss << "NAME is already taken by GROUP " << group->get_oid() << "."; + oss << "NAME is already taken by GROUP " << db_oid << "."; error_str = oss.str(); error_name: @@ -246,12 +248,13 @@ int GroupPool::dump(ostringstream& oss, const string& where, const string& limit oss << ""; - set_callback(static_cast(&GroupPool::dump_cb), - static_cast(&oss)); + stream_cb cb(2); - rc = db->exec_rd(cmd, this); + cb.set_callback(&oss); - unset_callback(); + rc = db->exec_rd(cmd, &cb); + + cb.unset_callback(); oss << Nebula::instance().get_default_group_quota().to_xml(def_quota_xml); @@ -260,29 +263,6 @@ int GroupPool::dump(ostringstream& oss, const string& where, const string& limit return rc; } -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -int GroupPool::dump_cb(void * _oss, int num, char **values, char **names) -{ - ostringstream * oss; - - oss = static_cast(_oss); - - if ( (!values[0]) || (num != 2) ) - { - return -1; - } - - *oss << values[0]; - - if (values[1] != NULL) - { - *oss << values[1]; - } - - return 0; -} /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/hm/HookManagerDriver.cc b/src/hm/HookManagerDriver.cc index 67d595e5a8..94d0d10be1 100644 --- a/src/hm/HookManagerDriver.cc +++ b/src/hm/HookManagerDriver.cc @@ -135,7 +135,7 @@ void HookManagerDriver::protocol(const string& message) const return; } - vm = vmpool->get(id,true); + vm = vmpool->get(id); if ( vm == 0 ) { diff --git a/src/host/HostPool.cc b/src/host/HostPool.cc index e084238cfa..7d3f643190 100644 --- a/src/host/HostPool.cc +++ b/src/host/HostPool.cc @@ -157,6 +157,8 @@ int HostPool::allocate ( Host * host; ostringstream oss; + int db_oid; + if ( !PoolObjectSQL::name_is_valid(hostname, error_str) ) { goto error_name; @@ -172,9 +174,9 @@ int HostPool::allocate ( goto error_vmm; } - host = get(hostname,false); + db_oid = exist(hostname); - if ( host !=0) + if ( db_oid != -1 ) { goto error_duplicated; } @@ -204,7 +206,7 @@ error_vmm: goto error_common; error_duplicated: - oss << "NAME is already taken by HOST " << host->get_oid() << "."; + oss << "NAME is already taken by HOST " << db_oid << "."; error_str = oss.str(); error_name: @@ -217,46 +219,23 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int HostPool::discover_cb(void * _set, int num, char **values, char **names) -{ - set * discovered_hosts; - string im_mad; - int hid; - - discovered_hosts = static_cast *>(_set); - - if ( (num<1) || (values[0] == 0) ) - { - return -1; - } - - hid = atoi(values[0]); - - discovered_hosts->insert(hid); - - return 0; -} - -/* -------------------------------------------------------------------------- */ - int HostPool::discover( set * discovered_hosts, int host_limit, time_t target_time) { - ostringstream sql; - int rc; + ostringstream sql; + set_cb cb; - set_callback(static_cast(&HostPool::discover_cb), - static_cast(discovered_hosts)); + cb.set_callback(discovered_hosts); sql << "SELECT oid FROM " << Host::table << " WHERE last_mon_time <= " << target_time << " ORDER BY last_mon_time ASC LIMIT " << host_limit; - rc = db->exec_rd(sql,this); + int rc = db->exec_rd(sql, &cb); - unset_callback(); + cb.unset_callback(); return rc; } diff --git a/src/im/InformationManager.cc b/src/im/InformationManager.cc index 00f8a73950..731e360b38 100644 --- a/src/im/InformationManager.cc +++ b/src/im/InformationManager.cc @@ -202,7 +202,7 @@ void InformationManager::timer_action(const ActionRequest& ar) for( it=discovered_hosts.begin() ; it!=discovered_hosts.end() ; ++it ) { - host = hpool->get(*it,true); + host = hpool->get(*it); if (host == 0) { diff --git a/src/im/MonitorThread.cc b/src/im/MonitorThread.cc index 4be3341634..6c8cae6fdc 100644 --- a/src/im/MonitorThread.cc +++ b/src/im/MonitorThread.cc @@ -78,7 +78,7 @@ void MonitorThread::do_message() hinfo = zinfo; } - Host* host = hpool->get(host_id,true); + Host* host = hpool->get(host_id); if ( host == 0 ) { @@ -148,7 +148,7 @@ void MonitorThread::do_message() if (cid != -1) { - Cluster *cluster = cpool->get(cid, true); + Cluster *cluster = cpool->get(cid); if (cluster != 0) { @@ -160,7 +160,7 @@ void MonitorThread::do_message() for (itm = datastores.begin(); itm != datastores.end(); itm++) { - ds = dspool->get(itm->first, true); + ds = dspool->get(itm->first); if (ds == 0) { @@ -186,7 +186,7 @@ void MonitorThread::do_message() ostringstream oss; - host = hpool->get(host_id,true); + host = hpool->get(host_id); if ( host == 0 ) { @@ -227,7 +227,7 @@ void MonitorThread::do_message() for (its = lost.begin(); its != lost.end(); its++) { - VirtualMachine * vm = vmpool->get(*its, true); + VirtualMachine * vm = vmpool->get(*its); if (vm == 0) { @@ -263,7 +263,7 @@ void MonitorThread::do_message() for (itm = found.begin(); itm != found.end(); itm++) { - VirtualMachine * vm = vmpool->get(itm->first, true); + VirtualMachine * vm = vmpool->get(itm->first); if (vm == 0) { @@ -289,7 +289,7 @@ void MonitorThread::do_message() // The rediscovered set is not stored in the DB, the update method // is not needed - host = hpool->get(host_id,true); + host = hpool->get(host_id); if ( host != 0 ) { diff --git a/src/image/ImageManager.cc b/src/image/ImageManager.cc index f918470997..7294b3e3e1 100644 --- a/src/image/ImageManager.cc +++ b/src/image/ImageManager.cc @@ -191,7 +191,7 @@ void ImageManager::monitor_datastore(int ds_id) return; } - Datastore * ds = dspool->get(ds_id, true); + Datastore * ds = dspool->get(ds_id); if ( ds == 0 ) { diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index 9af29d6f14..3439cad2d8 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -31,7 +31,7 @@ Image * ImageManager::acquire_image(int vm_id, int image_id, bool attach, Image * img; int rc; - img = ipool->get(image_id,true); + img = ipool->get(image_id); if ( img == 0 ) { @@ -61,7 +61,7 @@ Image * ImageManager::acquire_image(int vm_id, const string& name, int uid, Image * img; int rc; - img = ipool->get(name,uid,true); + img = ipool->get(name,uid); if ( img == 0 ) { @@ -206,7 +206,7 @@ void ImageManager::release_image(int vm_id, int iid, bool failed) { ostringstream oss; - Image * img = ipool->get(iid,true); + Image * img = ipool->get(iid); if ( img == 0 ) { @@ -318,7 +318,7 @@ void ImageManager::release_image(int vm_id, int iid, bool failed) void ImageManager::release_cloning_resource( int iid, PoolObjectSQL::ObjectType ot, int clone_oid) { - Image * img = ipool->get(iid,true); + Image * img = ipool->get(iid); if ( img == 0 ) { @@ -380,7 +380,7 @@ int ImageManager::enable_image(int iid, bool to_enable, string& error_str) ostringstream oss; - img = ipool->get(iid,true); + img = ipool->get(iid); if ( img == 0 ) { @@ -459,7 +459,7 @@ int ImageManager::delete_image(int iid, string& error_str) ostringstream oss; - img = ipool->get(iid,true); + img = ipool->get(iid); if ( img == 0 ) { @@ -471,7 +471,7 @@ int ImageManager::delete_image(int iid, string& error_str) img->unlock(); - ds = dspool->get(ds_id, true); + ds = dspool->get(ds_id); if ( ds == 0 ) { @@ -483,7 +483,7 @@ int ImageManager::delete_image(int iid, string& error_str) ds->unlock(); - img = ipool->get(iid,true); + img = ipool->get(iid); if ( img == 0 ) { @@ -604,7 +604,7 @@ int ImageManager::delete_image(int iid, string& error_str) release_cloning_image(cloning_id, iid); } - ds = dspool->get(ds_id, true); + ds = dspool->get(ds_id); if ( ds != 0 ) { @@ -624,7 +624,7 @@ int ImageManager::delete_image(int iid, string& error_str) VirtualMachine* vm; VirtualMachinePool* vmpool = Nebula::instance().get_vmpool(); - if ((vm = vmpool->get(vm_saving_id, true)) != 0) + if ((vm = vmpool->get(vm_saving_id)) != 0) { vm->clear_saveas_state(); @@ -646,7 +646,7 @@ int ImageManager::can_clone_image(int cloning_id, ostringstream& oss_error) { Image * img; - img = ipool->get(cloning_id, true); + img = ipool->get(cloning_id); if (img == 0) { @@ -690,7 +690,7 @@ int ImageManager::set_clone_state( PoolObjectSQL::ObjectType ot, int new_id, int cloning_id, string& error) { int rc = 0; - Image * img = ipool->get(cloning_id, true); + Image * img = ipool->get(cloning_id); if (img == 0) { @@ -770,7 +770,7 @@ int ImageManager::clone_image(int new_id, return -1; } - img = ipool->get(new_id,true); + img = ipool->get(new_id); if (img == 0) { @@ -821,7 +821,7 @@ int ImageManager::register_image(int iid, return -1; } - img = ipool->get(iid,true); + img = ipool->get(iid); if (img == 0) { @@ -1000,7 +1000,7 @@ string * ImageManager::format_message( void ImageManager::set_image_snapshots(int iid, const Snapshots& s) { - Image * img = ipool->get(iid,true); + Image * img = ipool->get(iid); if ( img == 0 ) { @@ -1039,7 +1039,7 @@ void ImageManager::set_image_snapshots(int iid, const Snapshots& s) void ImageManager::set_image_size(int iid, long long size) { - Image * img = ipool->get(iid,true); + Image * img = ipool->get(iid); if ( img == 0 ) { @@ -1088,7 +1088,7 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error) return -1; } - Image * img = ipool->get(iid,true); + Image * img = ipool->get(iid); if ( img == 0 ) { @@ -1105,7 +1105,7 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error) string ds_data; - Datastore * ds = dspool->get(ds_id, true); + Datastore * ds = dspool->get(ds_id); if ( ds == 0 ) { @@ -1122,7 +1122,7 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error) /* state is READY */ /* snapshot can be deleted (not active, no childs, exists) */ /* ---------------------------------------------------------------------- */ - img = ipool->get(iid,true); + img = ipool->get(iid); if ( img == 0 ) { @@ -1181,7 +1181,7 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error) return -1; } - Image * img = ipool->get(iid,true); + Image * img = ipool->get(iid); if ( img == 0 ) { @@ -1198,7 +1198,7 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error) string ds_data; - Datastore * ds = dspool->get(ds_id, true); + Datastore * ds = dspool->get(ds_id); if ( ds == 0 ) { @@ -1216,7 +1216,7 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error) /* snapshot exists */ /* snapshot is not the active one */ /* ---------------------------------------------------------------------- */ - img = ipool->get(iid,true); + img = ipool->get(iid); if ( img == 0 ) { @@ -1285,7 +1285,7 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error) return -1; } - Image * img = ipool->get(iid,true); + Image * img = ipool->get(iid); if ( img == 0 ) { @@ -1302,7 +1302,7 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error) string ds_data; - Datastore * ds = dspool->get(ds_id, true); + Datastore * ds = dspool->get(ds_id); if ( ds == 0 ) { @@ -1320,7 +1320,7 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error) /* snapshot exists */ /* ---------------------------------------------------------------------- */ - img = ipool->get(iid,true); + img = ipool->get(iid); if ( img == 0 ) { diff --git a/src/image/ImageManagerDriver.cc b/src/image/ImageManagerDriver.cc index cced157be2..a29d1a112f 100644 --- a/src/image/ImageManagerDriver.cc +++ b/src/image/ImageManagerDriver.cc @@ -179,7 +179,7 @@ static int cp_action(istringstream& is, ostringstream oss; - image = ipool->get(id,true); + image = ipool->get(id); if ( image == 0 ) { @@ -275,7 +275,7 @@ static int clone_action(istringstream& is, Nebula& nd = Nebula::instance(); ImageManager * im = nd.get_imagem(); - image = ipool->get(id, true); + image = ipool->get(id); if ( image == 0 ) { @@ -384,7 +384,7 @@ static int mkfs_action(istringstream& is, VirtualMachinePool * vmpool = nd.get_vmpool(); TransferManager * tm = nd.get_tm(); - image = ipool->get(id, true); + image = ipool->get(id); if ( image == 0 ) { @@ -457,7 +457,7 @@ static int mkfs_action(istringstream& is, return ds_id; } - vm = vmpool->get(vm_id, true); + vm = vmpool->get(vm_id); if ( vm == 0 ) { @@ -490,7 +490,7 @@ error_save_state: oss << "Image created to save as disk but VM is no longer running"; error_save: - image = ipool->get(id, true); + image = ipool->get(id); if ( image == 0 ) { @@ -517,7 +517,7 @@ error: if (is_saving && vm_id != -1) { - if ((vm = vmpool->get(vm_id, true)) != 0) + if ((vm = vmpool->get(vm_id)) != 0) { vm->clear_saveas_state(); @@ -549,7 +549,7 @@ static int rm_action(istringstream& is, ostringstream oss; - image = ipool->get(id, true); + image = ipool->get(id); if ( image == 0 ) { @@ -677,7 +677,7 @@ static void monitor_action(istringstream& is, monitor_data.get("FREE_MB", free); monitor_data.get("USED_MB", used); - Datastore * ds = dspool->get(id, true); + Datastore * ds = dspool->get(id); if (ds == 0 ) { @@ -739,7 +739,7 @@ static void snap_delete_action(istringstream& is, long long snap_size; int ds_id, uid, gid; - Image * image = ipool->get(id, true); + Image * image = ipool->get(id); if ( image == 0 ) { @@ -813,7 +813,7 @@ static void snap_revert_action(istringstream& is, ostringstream oss; string info; - Image * image = ipool->get(id, true); + Image * image = ipool->get(id); if ( image == 0 ) { @@ -874,7 +874,7 @@ static void snap_flatten_action(istringstream& is, long long snap_size; int ds_id, uid, gid; - Image * image = ipool->get(id, true); + Image * image = ipool->get(id); if ( image == 0 ) { diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index b15520e5b3..bab528f82f 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -98,13 +98,13 @@ int ImagePool::allocate ( ImageManager * imagem = nd.get_imagem(); Image * img; - Image * img_aux = 0; string name; string type; string fs_type; string driver; ostringstream oss; + int db_oid; int rc; img = new Image(uid, gid, uname, gname, umask, img_template); @@ -142,9 +142,9 @@ int ImagePool::allocate ( break; } - img_aux = get(name,uid,false); + db_oid = exist(name, uid); - if( img_aux != 0 ) + if( db_oid != -1 ) { goto error_duplicated; } @@ -217,7 +217,7 @@ int ImagePool::allocate ( if ( rc == -1 ) { - img = get(*oid, true); + img = get(*oid); if ( img != 0 ) { @@ -242,7 +242,7 @@ int ImagePool::allocate ( if (rc == -1) { - img = get(*oid, true); + img = get(*oid); if ( img != 0 ) { @@ -272,7 +272,7 @@ error_types_missmatch_image: goto error_common; error_duplicated: - oss << "NAME is already taken by IMAGE " << img_aux->get_oid() << "."; + oss << "NAME is already taken by IMAGE " << db_oid << "."; error_str = oss.str(); goto error_common; @@ -485,7 +485,7 @@ void ImagePool::disk_attribute( if ( disk->vector_value("IMAGE_ID", iid) == 0 ) { - img = get(iid, true); + img = get(iid); } else if ( disk->vector_value("IMAGE", source) == 0 ) { @@ -493,7 +493,7 @@ void ImagePool::disk_attribute( if ( uiid != -1) { - img = get(source, uiid, true); + img = get(source, uiid); } } diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index c5d3f576a4..3b2e7fd30e 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -27,7 +27,7 @@ void LifeCycleManager::deploy_action(const LCMAction& la) int vid = la.vm_id(); - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -106,7 +106,7 @@ void LifeCycleManager::suspend_action(const LCMAction& la) { int vid = la.vm_id(); - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -151,7 +151,7 @@ void LifeCycleManager::stop_action(const LCMAction& la) { int vid = la.vm_id(); - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -221,7 +221,7 @@ void LifeCycleManager::migrate_action(const LCMAction& la) int vid = la.vm_id(); - VirtualMachine * vm = vmpool->get(vid, true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -346,7 +346,7 @@ void LifeCycleManager::live_migrate_action(const LCMAction& la) int vid = la.vm_id(); - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -405,7 +405,7 @@ void LifeCycleManager::live_migrate_action(const LCMAction& la) void LifeCycleManager::shutdown_action(const LCMAction& la, bool hard) { int vid = la.vm_id(); - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -498,7 +498,7 @@ void LifeCycleManager::undeploy_action(const LCMAction& la, bool hard) { int vid = la.vm_id(); unsigned int port; - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -602,7 +602,7 @@ void LifeCycleManager::poweroff_hard_action(const LCMAction& la) void LifeCycleManager::poweroff_action(int vid, bool hard, const LCMAction& la) { - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -659,7 +659,7 @@ void LifeCycleManager::restore_action(const LCMAction& la) int vid = la.vm_id(); - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -714,7 +714,7 @@ void LifeCycleManager::restart_action(const LCMAction& la) { int vid = la.vm_id(); - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -772,7 +772,7 @@ void LifeCycleManager::delete_action(const LCMAction& la) int image_id = -1; int vid = la.vm_id(); - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -807,7 +807,7 @@ void LifeCycleManager::delete_action(const LCMAction& la) if ( image_id != -1 ) { - Image * image = ipool->get(image_id, true); + Image * image = ipool->get(image_id); if ( image != 0 ) { @@ -839,7 +839,7 @@ void LifeCycleManager::delete_recreate_action(const LCMAction& la) int vid = la.vm_id(); - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -884,7 +884,7 @@ void LifeCycleManager::delete_recreate_action(const LCMAction& la) if ( image_id != -1 ) { - Image* image = ipool->get(image_id, true); + Image* image = ipool->get(image_id); if ( image != 0 ) { @@ -1665,7 +1665,7 @@ void LifeCycleManager::updatesg_action(const LCMAction& la) VirtualMachine * vm; int sgid = la.vm_id(); - SecurityGroup * sg = sgpool->get(sgid, true); + SecurityGroup * sg = sgpool->get(sgid); if ( sg == 0 ) { @@ -1692,7 +1692,7 @@ void LifeCycleManager::updatesg_action(const LCMAction& la) return; } - vm = vmpool->get(vmid, true); + vm = vmpool->get(vmid); if ( vm == 0 ) { @@ -1809,7 +1809,7 @@ void LifeCycleManager::updatesg_action(const LCMAction& la) vm->unlock(); - sg = sgpool->get(sgid, true); + sg = sgpool->get(sgid); if ( sg == 0 ) { diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index e6ba33126b..b3888512f6 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -28,7 +28,7 @@ void LifeCycleManager::save_success_action(int vid) VirtualMachine * vm; ostringstream os; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -150,7 +150,7 @@ void LifeCycleManager::save_failure_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -246,7 +246,7 @@ void LifeCycleManager::deploy_success_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -327,7 +327,7 @@ void LifeCycleManager::deploy_failure_action(int vid) VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -460,7 +460,7 @@ void LifeCycleManager::shutdown_success_action(int vid) VirtualMachine * vm; time_t the_time = time(0); - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -563,7 +563,7 @@ void LifeCycleManager::shutdown_failure_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -612,7 +612,7 @@ void LifeCycleManager::prolog_success_action(int vid) VMMAction::Actions action; - vm = vmpool->get(vid, true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -738,7 +738,7 @@ void LifeCycleManager::prolog_failure_action(int vid) time_t t = time(0); - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -864,7 +864,7 @@ void LifeCycleManager::epilog_success_action(int vid) VirtualMachine::LcmState state; DMAction::Actions action; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -961,7 +961,7 @@ void LifeCycleManager::cleanup_callback_action(int vid) VirtualMachine::LcmState state; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -994,7 +994,7 @@ void LifeCycleManager::epilog_failure_action(int vid) VirtualMachine::LcmState state; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1044,7 +1044,7 @@ void LifeCycleManager::monitor_suspend_action(int vid) time_t the_time = time(0); - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1102,7 +1102,7 @@ void LifeCycleManager::monitor_done_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1135,7 +1135,7 @@ void LifeCycleManager::monitor_poweroff_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1198,7 +1198,7 @@ void LifeCycleManager::monitor_poweron_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1268,7 +1268,7 @@ void LifeCycleManager::attach_success_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1307,7 +1307,7 @@ void LifeCycleManager::attach_failure_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1321,7 +1321,7 @@ void LifeCycleManager::attach_failure_action(int vid) vmpool->delete_attach_disk(vid); - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1357,7 +1357,7 @@ void LifeCycleManager::detach_success_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1371,7 +1371,7 @@ void LifeCycleManager::detach_success_action(int vid) vmpool->delete_attach_disk(vid); - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1407,7 +1407,7 @@ void LifeCycleManager::detach_failure_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1446,7 +1446,7 @@ void LifeCycleManager::snapshot_create_success(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1476,7 +1476,7 @@ void LifeCycleManager::snapshot_create_failure(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1509,7 +1509,7 @@ void LifeCycleManager::snapshot_revert_success(int vid) VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1547,7 +1547,7 @@ void LifeCycleManager::snapshot_delete_success(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1577,7 +1577,7 @@ void LifeCycleManager::snapshot_delete_failure(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1607,7 +1607,7 @@ void LifeCycleManager::attach_nic_success_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1637,7 +1637,7 @@ void LifeCycleManager::attach_nic_failure_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1650,7 +1650,7 @@ void LifeCycleManager::attach_nic_failure_action(int vid) vmpool->attach_nic_failure(vid); - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1677,7 +1677,7 @@ void LifeCycleManager::detach_nic_success_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1690,7 +1690,7 @@ void LifeCycleManager::detach_nic_success_action(int vid) vmpool->detach_nic_success(vid); - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1717,7 +1717,7 @@ void LifeCycleManager::detach_nic_failure_action(int vid) { VirtualMachine * vm; - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1752,7 +1752,7 @@ void LifeCycleManager::saveas_success_action(int vid) string ds_id; string src; - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1783,7 +1783,7 @@ void LifeCycleManager::saveas_success_action(int vid) return; } - Image * image = ipool->get(image_id, true); + Image * image = ipool->get(image_id); if (image == 0) { @@ -1809,7 +1809,7 @@ void LifeCycleManager::saveas_failure_action(int vid) string ds_id; string src; - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1840,7 +1840,7 @@ void LifeCycleManager::saveas_failure_action(int vid) return; } - Image * image = ipool->get(image_id, true); + Image * image = ipool->get(image_id); if (image == 0) { @@ -1874,7 +1874,7 @@ void LifeCycleManager::disk_snapshot_success(int vid) bool has_snaps = false; string error_str; - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -1947,7 +1947,7 @@ void LifeCycleManager::disk_snapshot_success(int vid) { if ( img_owner ) { - Image* img = ipool->get(img_id, true); + Image* img = ipool->get(img_id); if(img != 0) { @@ -2022,7 +2022,7 @@ void LifeCycleManager::disk_snapshot_failure(int vid) bool img_owner, vm_owner; - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -2094,7 +2094,7 @@ void LifeCycleManager::disk_snapshot_failure(int vid) { if ( img_owner ) { - Image* img = ipool->get(img_id, true); + Image* img = ipool->get(img_id); if(img != 0) { @@ -2153,7 +2153,7 @@ void LifeCycleManager::disk_snapshot_failure(int vid) void LifeCycleManager::disk_lock_success(int vid) { - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); Image * image; if ( vm == 0 ) @@ -2181,7 +2181,7 @@ void LifeCycleManager::disk_lock_success(int vid) for (set::iterator id = ids.begin(); id != ids.end(); id++) { - image = ipool->get(*id, true); + image = ipool->get(*id); if (image != 0) { @@ -2210,7 +2210,7 @@ void LifeCycleManager::disk_lock_success(int vid) } } - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -2269,7 +2269,7 @@ void LifeCycleManager::disk_resize_success(int vid) int img_id = -1; long long size; - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -2348,7 +2348,7 @@ void LifeCycleManager::disk_resize_failure(int vid) int img_id = -1; long long size_prev; - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if ( vm == 0 ) { @@ -2401,7 +2401,7 @@ void LifeCycleManager::disk_resize_failure(int vid) // Restore quotas if ( img_quota && img_id != -1 ) { - Image* img = ipool->get(img_id, true); + Image* img = ipool->get(img_id); if(img != 0) { diff --git a/src/market/MarketPlaceAppPool.cc b/src/market/MarketPlaceAppPool.cc index e32d173371..87c0b667ff 100644 --- a/src/market/MarketPlaceAppPool.cc +++ b/src/market/MarketPlaceAppPool.cc @@ -78,7 +78,8 @@ int MarketPlaceAppPool:: allocate( std::string& error_str) { MarketPlaceApp * mp; - MarketPlaceApp * mp_aux = 0; + + int db_oid; std::string name; @@ -102,9 +103,9 @@ int MarketPlaceAppPool:: allocate( goto error_name; } - mp_aux = get(name, uid, false); + db_oid = exist(name, uid); - if( mp_aux != 0 ) + if( db_oid != -1 ) { goto error_duplicated; } @@ -131,7 +132,7 @@ int MarketPlaceAppPool:: allocate( return *oid; error_duplicated: - oss << "NAME is already taken by MARKETPLACEAPP " << mp_aux->get_oid(); + oss << "NAME is already taken by MARKETPLACEAPP " << db_oid; error_str = oss.str(); error_name: @@ -225,7 +226,7 @@ int MarketPlaceAppPool::import(const std::string& t64, int mp_id, } } - MarketPlaceApp * mp_aux = get(app->name, 0, true); + MarketPlaceApp * mp_aux = get(app->name, 0); if( mp_aux != 0 ) //Marketplace app already imported { @@ -329,7 +330,7 @@ bool MarketPlaceAppPool::test_map_check(int app_id) if ( to_delete ) { - map_check.erase(it); + map_check.erase(it); } return to_delete; diff --git a/src/market/MarketPlaceManager.cc b/src/market/MarketPlaceManager.cc index e8fe7f5f54..919a0e277c 100644 --- a/src/market/MarketPlaceManager.cc +++ b/src/market/MarketPlaceManager.cc @@ -239,7 +239,7 @@ void MarketPlaceManager::monitor_market(int mp_id) return; } - MarketPlace * mp = mppool->get(mp_id, true); + MarketPlace * mp = mppool->get(mp_id); if ( mp == 0 ) { diff --git a/src/market/MarketPlaceManagerActions.cc b/src/market/MarketPlaceManagerActions.cc index af210972c5..693d788b21 100644 --- a/src/market/MarketPlaceManagerActions.cc +++ b/src/market/MarketPlaceManagerActions.cc @@ -45,7 +45,7 @@ int MarketPlaceManager::import_app( const MarketPlaceManagerDriver* mpmd; - MarketPlaceApp * app = apppool->get(appid, true); + MarketPlaceApp * app = apppool->get(appid); if ( app == 0 ) { @@ -65,7 +65,7 @@ int MarketPlaceManager::import_app( switch (type) { case MarketPlaceApp::IMAGE: - image = ipool->get(origin_id, true); + image = ipool->get(origin_id); if ( image == 0 ) { @@ -78,7 +78,7 @@ int MarketPlaceManager::import_app( image->unlock(); - ds = dspool->get(ds_id, true); + ds = dspool->get(ds_id); if ( ds == 0 ) { @@ -133,7 +133,7 @@ error_type: error_clone: error_common: - app = apppool->get(appid, true); + app = apppool->get(appid); if ( app == 0 ) { @@ -158,7 +158,7 @@ error_common: void MarketPlaceManager::release_app_resources(int appid) { - MarketPlaceApp * app = apppool->get(appid, true); + MarketPlaceApp * app = apppool->get(appid); if (app == 0) { @@ -204,7 +204,7 @@ int MarketPlaceManager::delete_app(int appid, const std::string& market_data, return -1; } - app = apppool->get(appid, true); + app = apppool->get(appid); if (app == 0) { @@ -243,7 +243,7 @@ int MarketPlaceManager::delete_app(int appid, const std::string& market_data, return -1; } - mp = mppool->get(market_id, true); + mp = mppool->get(market_id); if ( mp != 0 ) { diff --git a/src/market/MarketPlaceManagerDriver.cc b/src/market/MarketPlaceManagerDriver.cc index 6a7c7d9cf0..e0c4719b69 100644 --- a/src/market/MarketPlaceManagerDriver.cc +++ b/src/market/MarketPlaceManagerDriver.cc @@ -120,7 +120,7 @@ static void monitor_action( return; } - MarketPlace * market = marketpool->get(id, true); + MarketPlace * market = marketpool->get(id); if (market == 0 ) { @@ -152,7 +152,7 @@ static void monitor_action( } else if ( rc >= 0 ) //-2 means app already imported { - MarketPlace * market = marketpool->get(id, true); + MarketPlace * market = marketpool->get(id); if ( market != 0 ) { @@ -172,10 +172,10 @@ static void monitor_action( for (set::iterator i = apps_mp.begin(); i != apps_mp.end(); ++i) { if (apppool->test_map_check(*i)) //delete app - { + { std::string error; - MarketPlaceApp * app = apppool->get(*i, true); + MarketPlaceApp * app = apppool->get(*i); if ( app == 0 ) { @@ -186,7 +186,7 @@ static void monitor_action( app->unlock(); - market = marketpool->get(id, true); + market = marketpool->get(id); market->del_marketapp(*i); @@ -238,7 +238,7 @@ static void app_failure_action( int id, const std::string& msg) { - MarketPlaceApp * app = apppool->get(id, true); + MarketPlaceApp * app = apppool->get(id); if (app == 0) { @@ -329,7 +329,7 @@ static int import_action( goto error_attributes; } - app = apppool->get(id, true); + app = apppool->get(id); if (app == 0) { @@ -394,7 +394,7 @@ static int delete_action( std::ostringstream eoss("Error removing app from marketplace", std::ios::ate); - MarketPlaceApp * app = apppool->get(id, true); + MarketPlaceApp * app = apppool->get(id); if ( app == 0 ) { diff --git a/src/market/MarketPlacePool.cc b/src/market/MarketPlacePool.cc index c8ff5c5998..b193a8764d 100644 --- a/src/market/MarketPlacePool.cc +++ b/src/market/MarketPlacePool.cc @@ -41,7 +41,7 @@ MarketPlacePool::MarketPlacePool(SqlDB * db, bool is_federation_slave) Nebula& nd = Nebula::instance(); UserPool * upool = nd.get_upool(); - User * oneadmin = upool->get(0, false); + User * oneadmin = upool->get(0); string error; @@ -58,6 +58,8 @@ MarketPlacePool::MarketPlacePool(SqlDB * db, bool is_federation_slave) oneadmin->get_umask(), default_tmpl); + oneadmin->unlock(); + marketplace->set_permissions(1,1,1, 1,0,0, 1,0,0, error); marketplace->zone_id = Nebula::instance().get_zone_id(); @@ -96,7 +98,8 @@ int MarketPlacePool::allocate( std::string& error_str) { MarketPlace * mp; - MarketPlace * mp_aux = 0; + + int db_oid; std::string name; std::ostringstream oss; @@ -115,9 +118,9 @@ int MarketPlacePool::allocate( mp->zone_id = Nebula::instance().get_zone_id(); - mp_aux = get(name, false); + db_oid = exist(name); - if( mp_aux != 0 ) + if( db_oid != -1 ) { goto error_duplicated; } @@ -178,7 +181,7 @@ int MarketPlacePool::allocate( return *oid; error_duplicated: - oss << "NAME is already taken by MARKETPLACE " << mp_aux->get_oid(); + oss << "NAME is already taken by MARKETPLACE " << db_oid; error_str = oss.str(); error_name: diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 9f37be549e..f71e301d96 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -252,12 +252,12 @@ void Nebula::start(bool bootstrap_only) { bool db_is_sqlite = true; - string server = "localhost"; - string port_str; - int port = 0; - string user = "oneadmin"; - string passwd = "oneadmin"; - string db_name = "opennebula"; + string server; + int port; + string user; + string passwd; + string db_name; + int connections; const VectorAttribute * _db = nebula_configuration->get("DB"); @@ -268,42 +268,36 @@ void Nebula::start(bool bootstrap_only) if (value == "mysql") { db_is_sqlite = false; + } - value = _db->vector_value("SERVER"); - if (!value.empty()) - { - server = value; - } + if (_db->vector_value("SERVER", server) == -1) + { + server = "localhost"; + } - istringstream is; + if (_db->vector_value("PORT", port) == -1) + { + port = 0; + } - port_str = _db->vector_value("PORT"); + if (_db->vector_value("USER", user) == -1) + { + user = "oneadmin"; + } - is.str(port_str); - is >> port; + if (_db->vector_value("PASSWD", passwd) == -1) + { + passwd = "oneadmin"; + } - if( is.fail() ) - { - port = 0; - } + if (_db->vector_value("DB_NAME", db_name) == -1) + { + db_name = "opennebula"; + } - value = _db->vector_value("USER"); - if (!value.empty()) - { - user = value; - } - - value = _db->vector_value("PASSWD"); - if (!value.empty()) - { - passwd = value; - } - - value = _db->vector_value("DB_NAME"); - if (!value.empty()) - { - db_name = value; - } + if (_db->vector_value("CONNECTIONS", connections) == -1) + { + connections = 50; } } @@ -313,7 +307,8 @@ void Nebula::start(bool bootstrap_only) } else { - db_backend = new MySqlDB(server, port, user, passwd, db_name); + db_backend = new MySqlDB(server, port, user, passwd, db_name, + connections); } // --------------------------------------------------------------------- @@ -758,7 +753,7 @@ void Nebula::start(bool bootstrap_only) if ( is_federation_master() && solo ) { // Replica threads are started on master in solo mode. - // HA start/stop the replica threads on leader/follower states + // HA start/stop the replica threads on leader/follower states frm->start_replica_threads(); } @@ -1124,6 +1119,7 @@ void Nebula::start(bool bootstrap_only) im->finalize(); rm->finalize(); + authm->finalize(); hm->finalize(); imagem->finalize(); marketm->finalize(); @@ -1142,6 +1138,7 @@ void Nebula::start(bool bootstrap_only) pthread_join(im->get_thread_id(),0); pthread_join(rm->get_thread_id(),0); pthread_join(hm->get_thread_id(),0); + pthread_join(authm->get_thread_id(),0); pthread_join(imagem->get_thread_id(),0); pthread_join(marketm->get_thread_id(),0); pthread_join(ipamm->get_thread_id(),0); diff --git a/src/nebula/SConstruct b/src/nebula/SConstruct index 7e3adaf336..190f385475 100644 --- a/src/nebula/SConstruct +++ b/src/nebula/SConstruct @@ -62,6 +62,7 @@ env.Prepend(LIBS=[ 'nebula_log', 'nebula_client', 'nebula_xml', + 'nebula_parsers', 'nebula_secgroup', 'nebula_vdc', 'nebula_vrouter', diff --git a/src/parsers/SConstruct b/src/parsers/SConstruct new file mode 100644 index 0000000000..51c67c474a --- /dev/null +++ b/src/parsers/SConstruct @@ -0,0 +1,74 @@ +# SConstruct for src/template + +# -------------------------------------------------------------------------- # +# Copyright 2002-2018, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +Import('env') + +lib_name='nebula_parsers' + +if env['parsers']=='yes': + # LEX + parser=env.Lex( + source='template_parser.l' + ) + + parser=env.Lex( + source='vm_var_parser.l' + ) + + parser=env.Lex( + source='expr_parser.l' + ) + env.NoClean(parser) + + # BISON + parser=env.Bison( + source='template_syntax.y' + ) + + parser=env.Bison( + source='vm_var_syntax.y' + ) + + parser=env.Bison( + source='vm_file_var_syntax.y' + ) + + parser=env.Bison( + source='expr_arith.y' + ) + + parser=env.Bison( + source='expr_bool.y' + ) + env.NoClean(parser) + +# Sources to generate the library +source_files=[ + 'template_parser.cc', + 'template_syntax.cc', + 'vm_var_parser.cc', + 'vm_var_syntax.cc', + 'vm_file_var_syntax.cc', + 'expr_parser.cc', + 'expr_bool.cc', + 'expr_arith.cc', + 'mem_collector.cc' +] + +# Build library +env.StaticLibrary(lib_name, source_files) diff --git a/src/xml/expr_arith.cc b/src/parsers/expr_arith.cc similarity index 93% rename from src/xml/expr_arith.cc rename to src/parsers/expr_arith.cc index 0d846fa727..608e34c122 100644 --- a/src/xml/expr_arith.cc +++ b/src/parsers/expr_arith.cc @@ -60,69 +60,45 @@ /* Substitute the variable and function names. */ -#define yyparse expr_arith__parse -#define yylex expr_arith__lex -#define yyerror expr_arith__error -#define yydebug expr_arith__debug -#define yynerrs expr_arith__nerrs +#define yyparse expr_arith_parse +#define yylex expr_arith_lex +#define yyerror expr_arith_error +#define yydebug expr_arith_debug +#define yynerrs expr_arith_nerrs /* Copy the first part of user declarations. */ #line 17 "expr_arith.y" /* yacc.c:339 */ -#include -#include -#include -#include -#include -#include - -#include -#include -#include - #include "expr_arith.h" -#include "ObjectXML.h" +#include "expr_parser.h" #define YYERROR_VERBOSE -#define expr_arith__lex expr_lex +#define expr_arith_lex expr_lex -extern "C" + +void expr_arith_error(YYLTYPE * llocp, mem_collector * mc, ObjectXML * oxml, + int& result, char ** error_msg, yyscan_t scanner, const char * str); + +int expr_arith_lex(YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc, + yyscan_t scanner); + +int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg, + yyscan_t scanner) { - #include "mem_collector.h" + mem_collector mc; + int rc; - void expr_arith__error( - YYLTYPE * llocp, - mem_collector * mc, - ObjectXML * oxml, - int& result, - char ** error_msg, - const char * str); + mem_collector_init(&mc); - int expr_arith__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + rc = expr_arith_parse(&mc, oxml, result, errmsg, scanner); - int expr_arith__parse(mem_collector * mc, - ObjectXML * oxml, - int& result, - char ** errmsg); + mem_collector_cleanup(&mc); - int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg) - { - mem_collector mc; - int rc; - - mem_collector_init(&mc); - - rc = expr_arith__parse(&mc,oxml,result,errmsg); - - mem_collector_cleanup(&mc); - - return rc; - } + return rc; } - -#line 126 "expr_arith.cc" /* yacc.c:339 */ +#line 102 "expr_arith.cc" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -149,8 +125,31 @@ extern "C" # define YYDEBUG 0 #endif #if YYDEBUG -extern int expr_arith__debug; +extern int expr_arith_debug; #endif +/* "%code requires" blocks. */ +#line 47 "expr_arith.y" /* yacc.c:355 */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mem_collector.h" +#include "ObjectXML.h" + +typedef void * yyscan_t; + +int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg, + yyscan_t scanner); + +#line 153 "expr_arith.cc" /* yacc.c:355 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -168,13 +167,13 @@ extern int expr_arith__debug; union YYSTYPE { -#line 78 "expr_arith.y" /* yacc.c:355 */ +#line 77 "expr_arith.y" /* yacc.c:355 */ char * val_str; int val_int; float val_float; -#line 178 "expr_arith.cc" /* yacc.c:355 */ +#line 177 "expr_arith.cc" /* yacc.c:355 */ }; typedef union YYSTYPE YYSTYPE; @@ -198,13 +197,13 @@ struct YYLTYPE -int expr_arith__parse (mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg); +int expr_arith_parse (mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, yyscan_t scanner); #endif /* !YY_EXPR_ARITH_EXPR_ARITH_HH_INCLUDED */ /* Copy the second part of user declarations. */ -#line 208 "expr_arith.cc" /* yacc.c:358 */ +#line 207 "expr_arith.cc" /* yacc.c:358 */ #ifdef short # undef short @@ -504,8 +503,8 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 100, 100, 101, 104, 105, 106, 107, 108, 109, - 110, 111, 112 + 0, 99, 99, 100, 103, 104, 105, 106, 107, 108, + 109, 110, 111 }; #endif @@ -632,7 +631,7 @@ do \ } \ else \ { \ - yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error: cannot back up")); \ + yyerror (&yylloc, mc, oxml, result, error_msg, scanner, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (0) @@ -734,7 +733,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, Location, mc, oxml, result, error_msg); \ + Type, Value, Location, mc, oxml, result, error_msg, scanner); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -745,7 +744,7 @@ do { \ `----------------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, yyscan_t scanner) { FILE *yyo = yyoutput; YYUSE (yyo); @@ -754,6 +753,7 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue YYUSE (oxml); YYUSE (result); YYUSE (error_msg); + YYUSE (scanner); if (!yyvaluep) return; # ifdef YYPRINT @@ -769,14 +769,14 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue `--------------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, yyscan_t scanner) { YYFPRINTF (yyoutput, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); YY_LOCATION_PRINT (yyoutput, *yylocationp); YYFPRINTF (yyoutput, ": "); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg, scanner); YYFPRINTF (yyoutput, ")"); } @@ -809,7 +809,7 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg) +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, yyscan_t scanner) { unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; @@ -823,7 +823,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule yy_symbol_print (stderr, yystos[yyssp[yyi + 1 - yynrhs]], &(yyvsp[(yyi + 1) - (yynrhs)]) - , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, oxml, result, error_msg); + , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, oxml, result, error_msg, scanner); YYFPRINTF (stderr, "\n"); } } @@ -831,7 +831,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, yylsp, Rule, mc, oxml, result, error_msg); \ + yy_reduce_print (yyssp, yyvsp, yylsp, Rule, mc, oxml, result, error_msg, scanner); \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that @@ -1089,7 +1089,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, yyscan_t scanner) { YYUSE (yyvaluep); YYUSE (yylocationp); @@ -1097,6 +1097,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio YYUSE (oxml); YYUSE (result); YYUSE (error_msg); + YYUSE (scanner); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); @@ -1114,7 +1115,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio `----------*/ int -yyparse (mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg) +yyparse (mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, yyscan_t scanner) { /* The lookahead symbol. */ int yychar; @@ -1308,7 +1309,7 @@ yybackup: if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (&yylval, &yylloc, mc); + yychar = yylex (&yylval, &yylloc, mc, scanner); } if (yychar <= YYEOF) @@ -1388,73 +1389,73 @@ yyreduce: switch (yyn) { case 2: -#line 100 "expr_arith.y" /* yacc.c:1646 */ +#line 99 "expr_arith.y" /* yacc.c:1646 */ { result = static_cast((yyvsp[0].val_float));} -#line 1394 "expr_arith.cc" /* yacc.c:1646 */ +#line 1395 "expr_arith.cc" /* yacc.c:1646 */ break; case 3: -#line 101 "expr_arith.y" /* yacc.c:1646 */ +#line 100 "expr_arith.y" /* yacc.c:1646 */ { result = 0; } -#line 1400 "expr_arith.cc" /* yacc.c:1646 */ +#line 1401 "expr_arith.cc" /* yacc.c:1646 */ break; case 4: -#line 104 "expr_arith.y" /* yacc.c:1646 */ +#line 103 "expr_arith.y" /* yacc.c:1646 */ { float val; oxml->search((yyvsp[0].val_str), val); (yyval.val_float) = val; } -#line 1406 "expr_arith.cc" /* yacc.c:1646 */ +#line 1407 "expr_arith.cc" /* yacc.c:1646 */ break; case 5: -#line 105 "expr_arith.y" /* yacc.c:1646 */ +#line 104 "expr_arith.y" /* yacc.c:1646 */ { (yyval.val_float) = (yyvsp[0].val_float); } -#line 1412 "expr_arith.cc" /* yacc.c:1646 */ +#line 1413 "expr_arith.cc" /* yacc.c:1646 */ break; case 6: -#line 106 "expr_arith.y" /* yacc.c:1646 */ +#line 105 "expr_arith.y" /* yacc.c:1646 */ { (yyval.val_float) = static_cast((yyvsp[0].val_int)); } -#line 1418 "expr_arith.cc" /* yacc.c:1646 */ +#line 1419 "expr_arith.cc" /* yacc.c:1646 */ break; case 7: -#line 107 "expr_arith.y" /* yacc.c:1646 */ +#line 106 "expr_arith.y" /* yacc.c:1646 */ { (yyval.val_float) = (yyvsp[-2].val_float) + (yyvsp[0].val_float);} -#line 1424 "expr_arith.cc" /* yacc.c:1646 */ +#line 1425 "expr_arith.cc" /* yacc.c:1646 */ break; case 8: -#line 108 "expr_arith.y" /* yacc.c:1646 */ +#line 107 "expr_arith.y" /* yacc.c:1646 */ { (yyval.val_float) = (yyvsp[-2].val_float) - (yyvsp[0].val_float);} -#line 1430 "expr_arith.cc" /* yacc.c:1646 */ +#line 1431 "expr_arith.cc" /* yacc.c:1646 */ break; case 9: -#line 109 "expr_arith.y" /* yacc.c:1646 */ +#line 108 "expr_arith.y" /* yacc.c:1646 */ { (yyval.val_float) = (yyvsp[-2].val_float) * (yyvsp[0].val_float);} -#line 1436 "expr_arith.cc" /* yacc.c:1646 */ +#line 1437 "expr_arith.cc" /* yacc.c:1646 */ break; case 10: -#line 110 "expr_arith.y" /* yacc.c:1646 */ +#line 109 "expr_arith.y" /* yacc.c:1646 */ { (yyval.val_float) = (yyvsp[-2].val_float) / (yyvsp[0].val_float);} -#line 1442 "expr_arith.cc" /* yacc.c:1646 */ +#line 1443 "expr_arith.cc" /* yacc.c:1646 */ break; case 11: -#line 111 "expr_arith.y" /* yacc.c:1646 */ +#line 110 "expr_arith.y" /* yacc.c:1646 */ { (yyval.val_float) = - (yyvsp[0].val_float);} -#line 1448 "expr_arith.cc" /* yacc.c:1646 */ +#line 1449 "expr_arith.cc" /* yacc.c:1646 */ break; case 12: -#line 112 "expr_arith.y" /* yacc.c:1646 */ +#line 111 "expr_arith.y" /* yacc.c:1646 */ { (yyval.val_float) = (yyvsp[-1].val_float);} -#line 1454 "expr_arith.cc" /* yacc.c:1646 */ +#line 1455 "expr_arith.cc" /* yacc.c:1646 */ break; -#line 1458 "expr_arith.cc" /* yacc.c:1646 */ +#line 1459 "expr_arith.cc" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1505,7 +1506,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error")); + yyerror (&yylloc, mc, oxml, result, error_msg, scanner, YY_("syntax error")); #else # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ yyssp, yytoken) @@ -1532,7 +1533,7 @@ yyerrlab: yymsgp = yymsg; } } - yyerror (&yylloc, mc, oxml, result, error_msg, yymsgp); + yyerror (&yylloc, mc, oxml, result, error_msg, scanner, yymsgp); if (yysyntax_error_status == 2) goto yyexhaustedlab; } @@ -1556,7 +1557,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); + yytoken, &yylval, &yylloc, mc, oxml, result, error_msg, scanner); yychar = YYEMPTY; } } @@ -1613,7 +1614,7 @@ yyerrlab1: yyerror_range[1] = *yylsp; yydestruct ("Error: popping", - yystos[yystate], yyvsp, yylsp, mc, oxml, result, error_msg); + yystos[yystate], yyvsp, yylsp, mc, oxml, result, error_msg, scanner); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1655,7 +1656,7 @@ yyabortlab: | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (&yylloc, mc, oxml, result, error_msg, YY_("memory exhausted")); + yyerror (&yylloc, mc, oxml, result, error_msg, scanner, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif @@ -1667,7 +1668,7 @@ yyreturn: user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); + yytoken, &yylval, &yylloc, mc, oxml, result, error_msg, scanner); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ @@ -1676,7 +1677,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yylsp, mc, oxml, result, error_msg); + yystos[*yyssp], yyvsp, yylsp, mc, oxml, result, error_msg, scanner); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1689,15 +1690,16 @@ yyreturn: #endif return yyresult; } -#line 115 "expr_arith.y" /* yacc.c:1906 */ +#line 114 "expr_arith.y" /* yacc.c:1906 */ -extern "C" void expr_arith__error( +void expr_arith_error( YYLTYPE * llocp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, + yyscan_t scanner, const char * str) { int length; diff --git a/src/xml/expr_arith.h b/src/parsers/expr_arith.h similarity index 77% rename from src/xml/expr_arith.h rename to src/parsers/expr_arith.h index 9ca01cd30d..5e443284a5 100644 --- a/src/xml/expr_arith.h +++ b/src/parsers/expr_arith.h @@ -37,8 +37,31 @@ # define YYDEBUG 0 #endif #if YYDEBUG -extern int expr_arith__debug; +extern int expr_arith_debug; #endif +/* "%code requires" blocks. */ +#line 47 "expr_arith.y" /* yacc.c:1909 */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mem_collector.h" +#include "ObjectXML.h" + +typedef void * yyscan_t; + +int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg, + yyscan_t scanner); + +#line 65 "expr_arith.hh" /* yacc.c:1909 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -56,13 +79,13 @@ extern int expr_arith__debug; union YYSTYPE { -#line 78 "expr_arith.y" /* yacc.c:1909 */ +#line 77 "expr_arith.y" /* yacc.c:1909 */ char * val_str; int val_int; float val_float; -#line 66 "expr_arith.hh" /* yacc.c:1909 */ +#line 89 "expr_arith.hh" /* yacc.c:1909 */ }; typedef union YYSTYPE YYSTYPE; @@ -84,4 +107,8 @@ struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif + + +int expr_arith_parse (mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, yyscan_t scanner); + #endif /* !YY_EXPR_ARITH_EXPR_ARITH_HH_INCLUDED */ diff --git a/src/xml/expr_arith.y b/src/parsers/expr_arith.y similarity index 75% rename from src/xml/expr_arith.y rename to src/parsers/expr_arith.y index 32d411d44e..1cdfeceb45 100644 --- a/src/xml/expr_arith.y +++ b/src/parsers/expr_arith.y @@ -15,6 +15,36 @@ /* -------------------------------------------------------------------------- */ %{ +#include "expr_arith.h" +#include "expr_parser.h" + +#define YYERROR_VERBOSE +#define expr_arith_lex expr_lex + + +void expr_arith_error(YYLTYPE * llocp, mem_collector * mc, ObjectXML * oxml, + int& result, char ** error_msg, yyscan_t scanner, const char * str); + +int expr_arith_lex(YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc, + yyscan_t scanner); + +int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg, + yyscan_t scanner) +{ + mem_collector mc; + int rc; + + mem_collector_init(&mc); + + rc = expr_arith_parse(&mc, oxml, result, errmsg, scanner); + + mem_collector_cleanup(&mc); + + return rc; +} +%} + +%code requires { #include #include #include @@ -26,54 +56,23 @@ #include #include -#include "expr_arith.h" +#include "mem_collector.h" #include "ObjectXML.h" -#define YYERROR_VERBOSE -#define expr_arith__lex expr_lex +typedef void * yyscan_t; -extern "C" -{ - #include "mem_collector.h" - - void expr_arith__error( - YYLTYPE * llocp, - mem_collector * mc, - ObjectXML * oxml, - int& result, - char ** error_msg, - const char * str); - - int expr_arith__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); - - int expr_arith__parse(mem_collector * mc, - ObjectXML * oxml, - int& result, - char ** errmsg); - - int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg) - { - mem_collector mc; - int rc; - - mem_collector_init(&mc); - - rc = expr_arith__parse(&mc,oxml,result,errmsg); - - mem_collector_cleanup(&mc); - - return rc; - } +int expr_arith_parse(ObjectXML *oxml, int& result, char ** errmsg, + yyscan_t scanner); } -%} - %parse-param {mem_collector * mc} %parse-param {ObjectXML * oxml} -%parse-param {int& result} -%parse-param {char ** error_msg} +%parse-param {int& result} +%parse-param {char ** error_msg} +%parse-param {yyscan_t scanner} %lex-param {mem_collector * mc} +%lex-param {yyscan_t scanner} %union { char * val_str; @@ -84,7 +83,7 @@ extern "C" %defines %locations %pure-parser -%name-prefix "expr_arith__" +%name-prefix "expr_arith_" %output "expr_arith.cc" %left '+' '-' @@ -114,12 +113,13 @@ expr: STRING { float val; oxml->search($1, val); $$ = val; } %% -extern "C" void expr_arith__error( +void expr_arith_error( YYLTYPE * llocp, mem_collector * mc, ObjectXML * oxml, int& result, char ** error_msg, + yyscan_t scanner, const char * str) { int length; diff --git a/src/xml/expr_bool.cc b/src/parsers/expr_bool.cc similarity index 92% rename from src/xml/expr_bool.cc rename to src/parsers/expr_bool.cc index 6589823726..fe4c37d02b 100644 --- a/src/xml/expr_bool.cc +++ b/src/parsers/expr_bool.cc @@ -60,68 +60,45 @@ /* Substitute the variable and function names. */ -#define yyparse expr_bool__parse -#define yylex expr_bool__lex -#define yyerror expr_bool__error -#define yydebug expr_bool__debug -#define yynerrs expr_bool__nerrs +#define yyparse expr_bool_parse +#define yylex expr_bool_lex +#define yyerror expr_bool_error +#define yydebug expr_bool_debug +#define yynerrs expr_bool_nerrs /* Copy the first part of user declarations. */ -#line 17 "expr_bool.y" /* yacc.c:339 */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include +#line 18 "expr_bool.y" /* yacc.c:339 */ #include "expr_bool.h" -#include "ObjectXML.h" +#include "expr_parser.h" #define YYERROR_VERBOSE -#define expr_bool__lex expr_lex +#define expr_bool_lex expr_lex -extern "C" +void expr_bool_error(YYLTYPE * llocp, mem_collector * mc, ObjectXML * oxml, + bool& result, char ** error_msg, yyscan_t scanner, const char * str); + +int expr_bool_lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc, + yyscan_t scanner); + +int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg, + yyscan_t scanner) { - #include "mem_collector.h" + mem_collector mc; + int rc; - void expr_bool__error( - YYLTYPE * llocp, - mem_collector * mc, - ObjectXML * oxml, - bool& result, - char ** error_msg, - const char * str); + mem_collector_init(&mc); - int expr_bool__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + rc = expr_bool_parse(&mc, oxml, result, errmsg, scanner); - int expr_bool__parse(mem_collector * mc, - ObjectXML * oxml, - bool& result, - char ** errmsg); + mem_collector_cleanup(&mc); - int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg) - { - mem_collector mc; - int rc; - - mem_collector_init(&mc); - - rc = expr_bool__parse(&mc,oxml,result,errmsg); - - mem_collector_cleanup(&mc); - - return rc; - } + return rc; } -#line 125 "expr_bool.cc" /* yacc.c:339 */ + +#line 102 "expr_bool.cc" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -148,8 +125,32 @@ extern "C" # define YYDEBUG 0 #endif #if YYDEBUG -extern int expr_bool__debug; +extern int expr_bool_debug; #endif +/* "%code requires" blocks. */ +#line 48 "expr_bool.y" /* yacc.c:355 */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mem_collector.h" + +#include "ObjectXML.h" + +typedef void * yyscan_t; + +int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg, + yyscan_t scanner); + +#line 154 "expr_bool.cc" /* yacc.c:355 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -167,13 +168,13 @@ extern int expr_bool__debug; union YYSTYPE { -#line 77 "expr_bool.y" /* yacc.c:355 */ +#line 79 "expr_bool.y" /* yacc.c:355 */ char * val_str; int val_int; float val_float; -#line 177 "expr_bool.cc" /* yacc.c:355 */ +#line 178 "expr_bool.cc" /* yacc.c:355 */ }; typedef union YYSTYPE YYSTYPE; @@ -197,13 +198,13 @@ struct YYLTYPE -int expr_bool__parse (mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg); +int expr_bool_parse (mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, yyscan_t scanner); #endif /* !YY_EXPR_BOOL_EXPR_BOOL_HH_INCLUDED */ /* Copy the second part of user declarations. */ -#line 207 "expr_bool.cc" /* yacc.c:358 */ +#line 208 "expr_bool.cc" /* yacc.c:358 */ #ifdef short # undef short @@ -503,9 +504,9 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { - 0, 97, 97, 98, 101, 110, 119, 126, 133, 151, - 158, 165, 172, 179, 197, 205, 213, 234, 235, 236, - 237 + 0, 99, 99, 100, 103, 112, 121, 128, 135, 153, + 160, 167, 174, 181, 199, 207, 215, 236, 237, 238, + 239 }; #endif @@ -643,7 +644,7 @@ do \ } \ else \ { \ - yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error: cannot back up")); \ + yyerror (&yylloc, mc, oxml, result, error_msg, scanner, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (0) @@ -745,7 +746,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, Location, mc, oxml, result, error_msg); \ + Type, Value, Location, mc, oxml, result, error_msg, scanner); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -756,7 +757,7 @@ do { \ `----------------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, yyscan_t scanner) { FILE *yyo = yyoutput; YYUSE (yyo); @@ -765,6 +766,7 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue YYUSE (oxml); YYUSE (result); YYUSE (error_msg); + YYUSE (scanner); if (!yyvaluep) return; # ifdef YYPRINT @@ -780,14 +782,14 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue `--------------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, yyscan_t scanner) { YYFPRINTF (yyoutput, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); YY_LOCATION_PRINT (yyoutput, *yylocationp); YYFPRINTF (yyoutput, ": "); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, oxml, result, error_msg, scanner); YYFPRINTF (yyoutput, ")"); } @@ -820,7 +822,7 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg) +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, yyscan_t scanner) { unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; @@ -834,7 +836,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule yy_symbol_print (stderr, yystos[yyssp[yyi + 1 - yynrhs]], &(yyvsp[(yyi + 1) - (yynrhs)]) - , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, oxml, result, error_msg); + , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, oxml, result, error_msg, scanner); YYFPRINTF (stderr, "\n"); } } @@ -842,7 +844,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, yylsp, Rule, mc, oxml, result, error_msg); \ + yy_reduce_print (yyssp, yyvsp, yylsp, Rule, mc, oxml, result, error_msg, scanner); \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that @@ -1100,7 +1102,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, yyscan_t scanner) { YYUSE (yyvaluep); YYUSE (yylocationp); @@ -1108,6 +1110,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio YYUSE (oxml); YYUSE (result); YYUSE (error_msg); + YYUSE (scanner); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); @@ -1125,7 +1128,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio `----------*/ int -yyparse (mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg) +yyparse (mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, yyscan_t scanner) { /* The lookahead symbol. */ int yychar; @@ -1319,7 +1322,7 @@ yybackup: if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (&yylval, &yylloc, mc); + yychar = yylex (&yylval, &yylloc, mc, scanner); } if (yychar <= YYEOF) @@ -1399,19 +1402,19 @@ yyreduce: switch (yyn) { case 2: -#line 97 "expr_bool.y" /* yacc.c:1646 */ +#line 99 "expr_bool.y" /* yacc.c:1646 */ { result=(yyvsp[0].val_int); } -#line 1405 "expr_bool.cc" /* yacc.c:1646 */ +#line 1408 "expr_bool.cc" /* yacc.c:1646 */ break; case 3: -#line 98 "expr_bool.y" /* yacc.c:1646 */ +#line 100 "expr_bool.y" /* yacc.c:1646 */ { result=true; } -#line 1411 "expr_bool.cc" /* yacc.c:1646 */ +#line 1414 "expr_bool.cc" /* yacc.c:1646 */ break; case 4: -#line 101 "expr_bool.y" /* yacc.c:1646 */ +#line 103 "expr_bool.y" /* yacc.c:1646 */ { int val = (yyvsp[0].val_int); int rc; @@ -1420,11 +1423,11 @@ yyreduce: (yyval.val_int) = (rc == 0 && val == (yyvsp[0].val_int)); } -#line 1424 "expr_bool.cc" /* yacc.c:1646 */ +#line 1427 "expr_bool.cc" /* yacc.c:1646 */ break; case 5: -#line 110 "expr_bool.y" /* yacc.c:1646 */ +#line 112 "expr_bool.y" /* yacc.c:1646 */ { int val = (yyvsp[0].val_int); int rc; @@ -1433,33 +1436,33 @@ yyreduce: (yyval.val_int) = (rc == 0 && val != (yyvsp[0].val_int)); } -#line 1437 "expr_bool.cc" /* yacc.c:1646 */ +#line 1440 "expr_bool.cc" /* yacc.c:1646 */ break; case 6: -#line 119 "expr_bool.y" /* yacc.c:1646 */ +#line 121 "expr_bool.y" /* yacc.c:1646 */ { int val, rc; rc = oxml->search((yyvsp[-2].val_str),val); (yyval.val_int) = (rc == 0 && val > (yyvsp[0].val_int)); } -#line 1448 "expr_bool.cc" /* yacc.c:1646 */ +#line 1451 "expr_bool.cc" /* yacc.c:1646 */ break; case 7: -#line 126 "expr_bool.y" /* yacc.c:1646 */ +#line 128 "expr_bool.y" /* yacc.c:1646 */ { int val, rc; rc = oxml->search((yyvsp[-2].val_str),val); (yyval.val_int) = (rc == 0 && val < (yyvsp[0].val_int)); } -#line 1459 "expr_bool.cc" /* yacc.c:1646 */ +#line 1462 "expr_bool.cc" /* yacc.c:1646 */ break; case 8: -#line 133 "expr_bool.y" /* yacc.c:1646 */ +#line 135 "expr_bool.y" /* yacc.c:1646 */ { std::vector val; std::vector::iterator it; @@ -1477,55 +1480,55 @@ yyreduce: } } } -#line 1481 "expr_bool.cc" /* yacc.c:1646 */ +#line 1484 "expr_bool.cc" /* yacc.c:1646 */ break; case 9: -#line 151 "expr_bool.y" /* yacc.c:1646 */ +#line 153 "expr_bool.y" /* yacc.c:1646 */ { float val, rc; rc = oxml->search((yyvsp[-2].val_str),val); (yyval.val_int) = (rc == 0 && val == (yyvsp[0].val_float)); } -#line 1492 "expr_bool.cc" /* yacc.c:1646 */ +#line 1495 "expr_bool.cc" /* yacc.c:1646 */ break; case 10: -#line 158 "expr_bool.y" /* yacc.c:1646 */ +#line 160 "expr_bool.y" /* yacc.c:1646 */ { float val, rc; rc = oxml->search((yyvsp[-3].val_str),val); (yyval.val_int) = (rc == 0 && val != (yyvsp[0].val_float)); } -#line 1503 "expr_bool.cc" /* yacc.c:1646 */ +#line 1506 "expr_bool.cc" /* yacc.c:1646 */ break; case 11: -#line 165 "expr_bool.y" /* yacc.c:1646 */ +#line 167 "expr_bool.y" /* yacc.c:1646 */ { float val, rc; rc = oxml->search((yyvsp[-2].val_str),val); (yyval.val_int) = (rc == 0 && val > (yyvsp[0].val_float)); } -#line 1514 "expr_bool.cc" /* yacc.c:1646 */ +#line 1517 "expr_bool.cc" /* yacc.c:1646 */ break; case 12: -#line 172 "expr_bool.y" /* yacc.c:1646 */ +#line 174 "expr_bool.y" /* yacc.c:1646 */ { float val, rc; rc = oxml->search((yyvsp[-2].val_str),val); (yyval.val_int) = (rc == 0 && val < (yyvsp[0].val_float)); } -#line 1525 "expr_bool.cc" /* yacc.c:1646 */ +#line 1528 "expr_bool.cc" /* yacc.c:1646 */ break; case 13: -#line 179 "expr_bool.y" /* yacc.c:1646 */ +#line 181 "expr_bool.y" /* yacc.c:1646 */ { std::vector val; std::vector::iterator it; @@ -1543,11 +1546,11 @@ yyreduce: } } } -#line 1547 "expr_bool.cc" /* yacc.c:1646 */ +#line 1550 "expr_bool.cc" /* yacc.c:1646 */ break; case 14: -#line 197 "expr_bool.y" /* yacc.c:1646 */ +#line 199 "expr_bool.y" /* yacc.c:1646 */ { std::string val; int rc; @@ -1555,11 +1558,11 @@ yyreduce: rc = oxml->search((yyvsp[-2].val_str),val); (yyval.val_int) = (rc != 0 || (yyvsp[0].val_str)==0) ? false : fnmatch((yyvsp[0].val_str),val.c_str(),0)==0; } -#line 1559 "expr_bool.cc" /* yacc.c:1646 */ +#line 1562 "expr_bool.cc" /* yacc.c:1646 */ break; case 15: -#line 205 "expr_bool.y" /* yacc.c:1646 */ +#line 207 "expr_bool.y" /* yacc.c:1646 */ { std::string val; int rc; @@ -1567,11 +1570,11 @@ yyreduce: rc = oxml->search((yyvsp[-3].val_str),val); (yyval.val_int) = (rc != 0 || (yyvsp[0].val_str)==0) ? false : fnmatch((yyvsp[0].val_str),val.c_str(),0)!=0; } -#line 1571 "expr_bool.cc" /* yacc.c:1646 */ +#line 1574 "expr_bool.cc" /* yacc.c:1646 */ break; case 16: -#line 213 "expr_bool.y" /* yacc.c:1646 */ +#line 215 "expr_bool.y" /* yacc.c:1646 */ { std::vector val; std::vector::iterator it; @@ -1592,35 +1595,35 @@ yyreduce: } } } -#line 1596 "expr_bool.cc" /* yacc.c:1646 */ +#line 1599 "expr_bool.cc" /* yacc.c:1646 */ break; case 17: -#line 234 "expr_bool.y" /* yacc.c:1646 */ +#line 236 "expr_bool.y" /* yacc.c:1646 */ { (yyval.val_int) = (yyvsp[-2].val_int) && (yyvsp[0].val_int); } -#line 1602 "expr_bool.cc" /* yacc.c:1646 */ +#line 1605 "expr_bool.cc" /* yacc.c:1646 */ break; case 18: -#line 235 "expr_bool.y" /* yacc.c:1646 */ +#line 237 "expr_bool.y" /* yacc.c:1646 */ { (yyval.val_int) = (yyvsp[-2].val_int) || (yyvsp[0].val_int); } -#line 1608 "expr_bool.cc" /* yacc.c:1646 */ +#line 1611 "expr_bool.cc" /* yacc.c:1646 */ break; case 19: -#line 236 "expr_bool.y" /* yacc.c:1646 */ +#line 238 "expr_bool.y" /* yacc.c:1646 */ { (yyval.val_int) = ! (yyvsp[0].val_int); } -#line 1614 "expr_bool.cc" /* yacc.c:1646 */ +#line 1617 "expr_bool.cc" /* yacc.c:1646 */ break; case 20: -#line 237 "expr_bool.y" /* yacc.c:1646 */ +#line 239 "expr_bool.y" /* yacc.c:1646 */ { (yyval.val_int) = (yyvsp[-1].val_int); } -#line 1620 "expr_bool.cc" /* yacc.c:1646 */ +#line 1623 "expr_bool.cc" /* yacc.c:1646 */ break; -#line 1624 "expr_bool.cc" /* yacc.c:1646 */ +#line 1627 "expr_bool.cc" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1671,7 +1674,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (&yylloc, mc, oxml, result, error_msg, YY_("syntax error")); + yyerror (&yylloc, mc, oxml, result, error_msg, scanner, YY_("syntax error")); #else # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ yyssp, yytoken) @@ -1698,7 +1701,7 @@ yyerrlab: yymsgp = yymsg; } } - yyerror (&yylloc, mc, oxml, result, error_msg, yymsgp); + yyerror (&yylloc, mc, oxml, result, error_msg, scanner, yymsgp); if (yysyntax_error_status == 2) goto yyexhaustedlab; } @@ -1722,7 +1725,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); + yytoken, &yylval, &yylloc, mc, oxml, result, error_msg, scanner); yychar = YYEMPTY; } } @@ -1779,7 +1782,7 @@ yyerrlab1: yyerror_range[1] = *yylsp; yydestruct ("Error: popping", - yystos[yystate], yyvsp, yylsp, mc, oxml, result, error_msg); + yystos[yystate], yyvsp, yylsp, mc, oxml, result, error_msg, scanner); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1821,7 +1824,7 @@ yyabortlab: | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (&yylloc, mc, oxml, result, error_msg, YY_("memory exhausted")); + yyerror (&yylloc, mc, oxml, result, error_msg, scanner, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif @@ -1833,7 +1836,7 @@ yyreturn: user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, mc, oxml, result, error_msg); + yytoken, &yylval, &yylloc, mc, oxml, result, error_msg, scanner); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ @@ -1842,7 +1845,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yylsp, mc, oxml, result, error_msg); + yystos[*yyssp], yyvsp, yylsp, mc, oxml, result, error_msg, scanner); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1855,15 +1858,16 @@ yyreturn: #endif return yyresult; } -#line 240 "expr_bool.y" /* yacc.c:1906 */ +#line 242 "expr_bool.y" /* yacc.c:1906 */ -extern "C" void expr_bool__error( +void expr_bool_error( YYLTYPE * llocp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, + yyscan_t scanner, const char * str) { int length; diff --git a/src/xml/expr_bool.h b/src/parsers/expr_bool.h similarity index 79% rename from src/xml/expr_bool.h rename to src/parsers/expr_bool.h index 2359b630c0..e2e4f1abcf 100644 --- a/src/xml/expr_bool.h +++ b/src/parsers/expr_bool.h @@ -37,8 +37,32 @@ # define YYDEBUG 0 #endif #if YYDEBUG -extern int expr_bool__debug; +extern int expr_bool_debug; #endif +/* "%code requires" blocks. */ +#line 48 "expr_bool.y" /* yacc.c:1909 */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "mem_collector.h" + +#include "ObjectXML.h" + +typedef void * yyscan_t; + +int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg, + yyscan_t scanner); + +#line 66 "expr_bool.hh" /* yacc.c:1909 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -56,13 +80,13 @@ extern int expr_bool__debug; union YYSTYPE { -#line 77 "expr_bool.y" /* yacc.c:1909 */ +#line 79 "expr_bool.y" /* yacc.c:1909 */ char * val_str; int val_int; float val_float; -#line 66 "expr_bool.hh" /* yacc.c:1909 */ +#line 90 "expr_bool.hh" /* yacc.c:1909 */ }; typedef union YYSTYPE YYSTYPE; @@ -83,4 +107,9 @@ struct YYLTYPE # define YYLTYPE_IS_DECLARED 1 # define YYLTYPE_IS_TRIVIAL 1 #endif + + + +int expr_bool_parse (mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, yyscan_t scanner); + #endif /* !YY_EXPR_BOOL_EXPR_BOOL_HH_INCLUDED */ diff --git a/src/xml/expr_bool.y b/src/parsers/expr_bool.y similarity index 84% rename from src/xml/expr_bool.y rename to src/parsers/expr_bool.y index b84027a6f4..2f4879cbcc 100644 --- a/src/xml/expr_bool.y +++ b/src/parsers/expr_bool.y @@ -14,7 +14,38 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ + %{ +#include "expr_bool.h" +#include "expr_parser.h" + +#define YYERROR_VERBOSE +#define expr_bool_lex expr_lex + +void expr_bool_error(YYLTYPE * llocp, mem_collector * mc, ObjectXML * oxml, + bool& result, char ** error_msg, yyscan_t scanner, const char * str); + +int expr_bool_lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc, + yyscan_t scanner); + +int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg, + yyscan_t scanner) +{ + mem_collector mc; + int rc; + + mem_collector_init(&mc); + + rc = expr_bool_parse(&mc, oxml, result, errmsg, scanner); + + mem_collector_cleanup(&mc); + + return rc; +} + +%} + +%code requires { #include #include #include @@ -26,53 +57,24 @@ #include #include -#include "expr_bool.h" +#include "mem_collector.h" + #include "ObjectXML.h" -#define YYERROR_VERBOSE -#define expr_bool__lex expr_lex +typedef void * yyscan_t; -extern "C" -{ - #include "mem_collector.h" - - void expr_bool__error( - YYLTYPE * llocp, - mem_collector * mc, - ObjectXML * oxml, - bool& result, - char ** error_msg, - const char * str); - - int expr_bool__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); - - int expr_bool__parse(mem_collector * mc, - ObjectXML * oxml, - bool& result, - char ** errmsg); - - int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg) - { - mem_collector mc; - int rc; - - mem_collector_init(&mc); - - rc = expr_bool__parse(&mc,oxml,result,errmsg); - - mem_collector_cleanup(&mc); - - return rc; - } +int expr_bool_parse(ObjectXML *oxml, bool& result, char ** errmsg, + yyscan_t scanner); } -%} %parse-param {mem_collector * mc} -%parse-param {ObjectXML * oxml} -%parse-param {bool& result} -%parse-param {char ** error_msg} +%parse-param {ObjectXML * oxml} +%parse-param {bool& result} +%parse-param {char ** error_msg} +%parse-param {yyscan_t scanner} %lex-param {mem_collector * mc} +%lex-param {yyscan_t scanner} %union { char * val_str; @@ -83,7 +85,7 @@ extern "C" %defines %locations %pure-parser -%name-prefix "expr_bool__" +%name-prefix "expr_bool_" %output "expr_bool.cc" %left '!' '&' '|' @@ -239,12 +241,13 @@ expr: STRING '=' INTEGER { %% -extern "C" void expr_bool__error( +void expr_bool_error( YYLTYPE * llocp, mem_collector * mc, ObjectXML * oxml, bool& result, char ** error_msg, + yyscan_t scanner, const char * str) { int length; diff --git a/src/xml/expr_parser.c b/src/parsers/expr_parser.cc similarity index 63% rename from src/xml/expr_parser.c rename to src/parsers/expr_parser.cc index 2e4c1e8654..9e5e7adde7 100644 --- a/src/xml/expr_parser.c +++ b/src/parsers/expr_parser.cc @@ -1,36 +1,11 @@ -#line 1 "expr_parser.c" +#line 1 "expr_parser.cc" -#line 3 "expr_parser.c" +#line 3 "expr_parser.cc" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ -#define yy_create_buffer expr__create_buffer -#define yy_delete_buffer expr__delete_buffer -#define yy_scan_buffer expr__scan_buffer -#define yy_scan_string expr__scan_string -#define yy_scan_bytes expr__scan_bytes -#define yy_init_buffer expr__init_buffer -#define yy_flush_buffer expr__flush_buffer -#define yy_load_buffer_state expr__load_buffer_state -#define yy_switch_to_buffer expr__switch_to_buffer -#define yypush_buffer_state expr_push_buffer_state -#define yypop_buffer_state expr_pop_buffer_state -#define yyensure_buffer_stack expr_ensure_buffer_stack -#define yy_flex_debug expr__flex_debug -#define yyin expr_in -#define yyleng expr_leng -#define yylex expr_lex -#define yylineno expr_lineno -#define yyout expr_out -#define yyrestart expr_restart -#define yytext expr_text -#define yywrap expr_wrap -#define yyalloc expr_alloc -#define yyrealloc expr_realloc -#define yyfree expr_free - #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 6 @@ -213,12 +188,36 @@ #define yyset_lineno expr_set_lineno #endif +#ifdef yyget_column +#define expr_get_column_ALREADY_DEFINED +#else +#define yyget_column expr_get_column +#endif + +#ifdef yyset_column +#define expr_set_column_ALREADY_DEFINED +#else +#define yyset_column expr_set_column +#endif + #ifdef yywrap #define expr_wrap_ALREADY_DEFINED #else #define yywrap expr_wrap #endif +#ifdef yyget_lval +#define expr_get_lval_ALREADY_DEFINED +#else +#define yyget_lval expr_get_lval +#endif + +#ifdef yyset_lval +#define expr_set_lval_ALREADY_DEFINED +#else +#define yyset_lval expr_set_lval +#endif + #ifdef yyalloc #define expr_alloc_ALREADY_DEFINED #else @@ -237,42 +236,6 @@ #define yyfree expr_free #endif -#ifdef yytext -#define expr_text_ALREADY_DEFINED -#else -#define yytext expr_text -#endif - -#ifdef yyleng -#define expr_leng_ALREADY_DEFINED -#else -#define yyleng expr_leng -#endif - -#ifdef yyin -#define expr_in_ALREADY_DEFINED -#else -#define yyin expr_in -#endif - -#ifdef yyout -#define expr_out_ALREADY_DEFINED -#else -#define yyout expr_out -#endif - -#ifdef yy_flex_debug -#define expr__flex_debug_ALREADY_DEFINED -#else -#define yy_flex_debug expr__flex_debug -#endif - -#ifdef yylineno -#define expr_lineno_ALREADY_DEFINED -#else -#define yylineno expr_lineno -#endif - /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ @@ -370,21 +333,38 @@ typedef unsigned int flex_uint32_t; */ #define YY_SC_TO_UI(c) ((YY_CHAR) (c)) +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ -#define BEGIN (yy_start) = 1 + 2 * +#define BEGIN yyg->yy_start = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ -#define YY_START (((yy_start) - 1) / 2) +#define YY_START ((yyg->yy_start - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) +#define YY_NEW_FILE yyrestart( yyin , yyscanner ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ @@ -414,10 +394,6 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; typedef size_t yy_size_t; #endif -extern int yyleng; - -extern FILE *yyin, *yyout; - #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 @@ -451,13 +427,13 @@ extern FILE *yyin, *yyout; /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ + *yy_cp = yyg->yy_hold_char; \ YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) -#define unput(c) yyunput( c, (yytext_ptr) ) +#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE @@ -524,77 +500,57 @@ struct yy_buffer_state }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ - /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ +#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ + ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] +#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; +void yyrestart ( FILE *input_file , yyscan_t yyscanner ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner ); +void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +void yypop_buffer_state ( yyscan_t yyscanner ); -/* Points to current character in buffer. */ -static char *yy_c_buf_p = NULL; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ +static void yyensure_buffer_stack ( yyscan_t yyscanner ); +static void yy_load_buffer_state ( yyscan_t yyscanner ); +static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , yyscanner) -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner ); -void yyrestart ( FILE *input_file ); -void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); -void yy_delete_buffer ( YY_BUFFER_STATE b ); -void yy_flush_buffer ( YY_BUFFER_STATE b ); -void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state ( void ); - -static void yyensure_buffer_stack ( void ); -static void yy_load_buffer_state ( void ); -static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); -#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); -YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); - -void *yyalloc ( yy_size_t ); -void *yyrealloc ( void *, yy_size_t ); -void yyfree ( void * ); +void *yyalloc ( yy_size_t , yyscan_t yyscanner ); +void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner ); +void yyfree ( void * , yyscan_t yyscanner ); #define yy_new_buffer yy_create_buffer #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ + yyensure_buffer_stack (yyscanner); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ + yyensure_buffer_stack (yyscanner); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } @@ -603,33 +559,24 @@ void yyfree ( void * ); /* Begin user sect3 */ typedef flex_uint8_t YY_CHAR; -FILE *yyin = NULL, *yyout = NULL; - typedef int yy_state_type; -extern int yylineno; -int yylineno = 1; +#define yytext_ptr yytext_r -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state ( void ); -static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); -static int yy_get_next_buffer ( void ); -static void yynoreturn yy_fatal_error ( const char* msg ); +static yy_state_type yy_get_previous_state ( yyscan_t yyscanner ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state , yyscan_t yyscanner); +static int yy_get_next_buffer ( yyscan_t yyscanner ); +static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ + yyg->yytext_ptr = yy_bp; \ yyleng = (int) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ + yyg->yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; + yyg->yy_c_buf_p = yy_cp; #define YY_NUM_RULES 8 #define YY_END_OF_BUFFER 9 /* This struct is not used in this scanner, @@ -717,12 +664,6 @@ static const flex_int32_t yy_rule_can_match_eol[9] = { 0, 0, 0, 0, 1, 0, 0, 0, 0, }; -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ @@ -730,7 +671,6 @@ int yy_flex_debug = 0; #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET -char *yytext; #line 1 "expr_parser.l" /* -------------------------------------------------------------------------- */ /* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */ @@ -757,13 +697,14 @@ char *yytext; #define YY_NO_INPUT -#define YY_DECL int expr_lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector *mc) +#define YY_DECL int expr_lex (YYSTYPE *yylval_param, YYLTYPE *llocp, \ + mem_collector *mc, yyscan_t yyscanner) #define YY_USER_ACTION llocp->first_line = yylineno; \ llocp->first_column = llocp->last_column; \ llocp->last_column += yyleng; -#line 765 "expr_parser.c" -#line 766 "expr_parser.c" +#line 706 "expr_parser.cc" +#line 707 "expr_parser.cc" #define INITIAL 0 @@ -779,36 +720,88 @@ char *yytext; #define YY_EXTRA_TYPE void * #endif -static int yy_init_globals ( void ); +/* Holds the entire state of the reentrant scanner. */ +struct yyguts_t + { + + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; + + /* The rest are the same as the globals declared in the non-reentrant scanner. */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + int yylineno_r; + int yy_flex_debug_r; + + char *yytext_r; + int yy_more_flag; + int yy_more_len; + + YYSTYPE * yylval_r; + + }; /* end struct yyguts_t */ + +static int yy_init_globals ( yyscan_t yyscanner ); + + /* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ + # define yylval yyg->yylval_r + +int yylex_init (yyscan_t* scanner); + +int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy ( void ); +int yylex_destroy ( yyscan_t yyscanner ); -int yyget_debug ( void ); +int yyget_debug ( yyscan_t yyscanner ); -void yyset_debug ( int debug_flag ); +void yyset_debug ( int debug_flag , yyscan_t yyscanner ); -YY_EXTRA_TYPE yyget_extra ( void ); +YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner ); -void yyset_extra ( YY_EXTRA_TYPE user_defined ); +void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); -FILE *yyget_in ( void ); +FILE *yyget_in ( yyscan_t yyscanner ); -void yyset_in ( FILE * _in_str ); +void yyset_in ( FILE * _in_str , yyscan_t yyscanner ); -FILE *yyget_out ( void ); +FILE *yyget_out ( yyscan_t yyscanner ); -void yyset_out ( FILE * _out_str ); +void yyset_out ( FILE * _out_str , yyscan_t yyscanner ); - int yyget_leng ( void ); + int yyget_leng ( yyscan_t yyscanner ); -char *yyget_text ( void ); +char *yyget_text ( yyscan_t yyscanner ); -int yyget_lineno ( void ); +int yyget_lineno ( yyscan_t yyscanner ); -void yyset_lineno ( int _line_number ); +void yyset_lineno ( int _line_number , yyscan_t yyscanner ); + +int yyget_column ( yyscan_t yyscanner ); + +void yyset_column ( int _column_no , yyscan_t yyscanner ); + +YYSTYPE * yyget_lval ( yyscan_t yyscanner ); + +void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -816,9 +809,9 @@ void yyset_lineno ( int _line_number ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap ( void ); +extern "C" int yywrap ( yyscan_t yyscanner ); #else -extern int yywrap ( void ); +extern int yywrap ( yyscan_t yyscanner ); #endif #endif @@ -827,18 +820,18 @@ extern int yywrap ( void ); #endif #ifndef yytext_ptr -static void yy_flex_strncpy ( char *, const char *, int ); +static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen ( const char * ); +static int yy_flex_strlen ( const char * , yyscan_t yyscanner); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput ( void ); +static int yyinput ( yyscan_t yyscanner ); #else -static int input ( void ); +static int input ( yyscan_t yyscanner ); #endif #endif @@ -912,7 +905,7 @@ static int input ( void ); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) #endif /* end tables serialization structures and prototypes */ @@ -923,9 +916,11 @@ static int input ( void ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int yylex (void); +extern int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner); -#define YY_DECL int yylex (void) +#define YY_DECL int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -950,17 +945,20 @@ YY_DECL yy_state_type yy_current_state; char *yy_cp, *yy_bp; int yy_act; - - if ( !(yy_init) ) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yylval = yylval_param; + + if ( !yyg->yy_init ) { - (yy_init) = 1; + yyg->yy_init = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ + if ( ! yyg->yy_start ) + yyg->yy_start = 1; /* first start state */ if ( ! yyin ) yyin = stdin; @@ -969,43 +967,43 @@ YY_DECL yyout = stdout; if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); } - yy_load_buffer_state( ); + yy_load_buffer_state( yyscanner ); } { -#line 39 "expr_parser.l" +#line 43 "expr_parser.l" -#line 41 "expr_parser.l" +#line 45 "expr_parser.l" /* --- Tokens --- */ -#line 986 "expr_parser.c" +#line 984 "expr_parser.cc" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { - yy_cp = (yy_c_buf_p); + yy_cp = yyg->yy_c_buf_p; /* Support of yytext. */ - *yy_cp = (yy_hold_char); + *yy_cp = yyg->yy_hold_char; /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; - yy_current_state = (yy_start); + yy_current_state = yyg->yy_start; yy_match: do { YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1022,8 +1020,8 @@ yy_find_action: yy_act = yy_accept[yy_current_state]; if ( yy_act == 0 ) { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; yy_act = yy_accept[yy_current_state]; } @@ -1035,7 +1033,9 @@ yy_find_action: for ( yyl = 0; yyl < yyleng; ++yyl ) if ( yytext[yyl] == '\n' ) - yylineno++; + do{ yylineno++; + yycolumn=0; + }while(0) ; } @@ -1045,72 +1045,72 @@ do_action: /* This label is used only to access EOF actions. */ { /* beginning of action switch */ case 0: /* must back up */ /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; goto yy_find_action; case 1: YY_RULE_SETUP -#line 43 "expr_parser.l" +#line 47 "expr_parser.l" { return *yytext;} YY_BREAK /* --- Strings, also quoted form --- */ case 2: YY_RULE_SETUP -#line 47 "expr_parser.l" -{ lvalp->val_str = mem_collector_strdup(mc,yytext); +#line 51 "expr_parser.l" +{ yylval_param->val_str = mem_collector_strdup(mc,yytext); return STRING;} YY_BREAK case 3: YY_RULE_SETUP -#line 50 "expr_parser.l" -{ lvalp->val_str = NULL; +#line 54 "expr_parser.l" +{ yylval_param->val_str = NULL; return STRING;} YY_BREAK case 4: /* rule 4 can match eol */ YY_RULE_SETUP -#line 53 "expr_parser.l" -{ lvalp->val_str = mem_collector_strdup(mc,yytext+1); - lvalp->val_str[yyleng-2] = '\0'; +#line 57 "expr_parser.l" +{ yylval_param->val_str = mem_collector_strdup(mc,yytext+1); + yylval_param->val_str[yyleng-2] = '\0'; return STRING;} YY_BREAK /* --- Numbers --- */ case 5: YY_RULE_SETUP -#line 59 "expr_parser.l" -{ lvalp->val_int = atoi(yytext); +#line 63 "expr_parser.l" +{ yylval_param->val_int = atoi(yytext); return INTEGER;} YY_BREAK case 6: YY_RULE_SETUP -#line 62 "expr_parser.l" -{ lvalp->val_float = atof(yytext); +#line 66 "expr_parser.l" +{ yylval_param->val_float = atof(yytext); return FLOAT;} YY_BREAK /* --- blanks --- */ case 7: YY_RULE_SETUP -#line 67 "expr_parser.l" +#line 71 "expr_parser.l" YY_BREAK case 8: YY_RULE_SETUP -#line 69 "expr_parser.l" +#line 73 "expr_parser.l" ECHO; YY_BREAK -#line 1103 "expr_parser.c" +#line 1103 "expr_parser.cc" case YY_STATE_EOF(INITIAL): yyterminate(); case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); + *yy_cp = yyg->yy_hold_char; YY_RESTORE_YY_MORE_OFFSET if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) @@ -1124,7 +1124,7 @@ case YY_STATE_EOF(INITIAL): * this is the first action (other than possibly a * back-up) that will match for the new input source. */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } @@ -1136,13 +1136,13 @@ case YY_STATE_EOF(INITIAL): * end-of-buffer state). Contrast this with the test * in input(). */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) { /* This was really a NUL. */ yy_state_type yy_next_state; - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have @@ -1153,32 +1153,32 @@ case YY_STATE_EOF(INITIAL): * will run more slowly). */ - yy_next_state = yy_try_NUL_trans( yy_current_state ); + yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); + yy_cp = ++yyg->yy_c_buf_p; yy_current_state = yy_next_state; goto yy_match; } else { - yy_cp = (yy_c_buf_p); + yy_cp = yyg->yy_c_buf_p; goto yy_find_action; } } - else switch ( yy_get_next_buffer( ) ) + else switch ( yy_get_next_buffer( yyscanner ) ) { case EOB_ACT_END_OF_FILE: { - (yy_did_buffer_switch_on_eof) = 0; + yyg->yy_did_buffer_switch_on_eof = 0; - if ( yywrap( ) ) + if ( yywrap( yyscanner ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up @@ -1189,7 +1189,7 @@ case YY_STATE_EOF(INITIAL): * YY_NULL, it'll still work - another * YY_NULL will get returned. */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; @@ -1197,30 +1197,30 @@ case YY_STATE_EOF(INITIAL): else { - if ( ! (yy_did_buffer_switch_on_eof) ) + if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; + yyg->yy_c_buf_p = + yyg->yytext_ptr + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; goto yy_find_action; } break; @@ -1241,20 +1241,21 @@ case YY_STATE_EOF(INITIAL): * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer (void) +static int yy_get_next_buffer (yyscan_t yyscanner) { - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = yyg->yytext_ptr; int number_to_move, i; int ret_val; - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so * treat this as a final EOF. @@ -1274,7 +1275,7 @@ static int yy_get_next_buffer (void) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -1283,7 +1284,7 @@ static int yy_get_next_buffer (void) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; else { @@ -1297,7 +1298,7 @@ static int yy_get_next_buffer (void) YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); + (int) (yyg->yy_c_buf_p - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { @@ -1311,7 +1312,7 @@ static int yy_get_next_buffer (void) b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ yyrealloc( (void *) b->yy_ch_buf, - (yy_size_t) (b->yy_buf_size + 2) ); + (yy_size_t) (b->yy_buf_size + 2) , yyscanner ); } else /* Can't grow it, we don't own it. */ @@ -1321,7 +1322,7 @@ static int yy_get_next_buffer (void) YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; @@ -1333,17 +1334,17 @@ static int yy_get_next_buffer (void) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); + yyg->yy_n_chars, num_to_read ); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } - if ( (yy_n_chars) == 0 ) + if ( yyg->yy_n_chars == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); + yyrestart( yyin , yyscanner); } else @@ -1357,42 +1358,43 @@ static int yy_get_next_buffer (void) else ret_val = EOB_ACT_CONTINUE_SCAN; - if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( - (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); /* "- 2" to take care of EOB's */ YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); } - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ - static yy_state_type yy_get_previous_state (void) + static yy_state_type yy_get_previous_state (yyscan_t yyscanner) { yy_state_type yy_current_state; char *yy_cp; - - yy_current_state = (yy_start); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + yy_current_state = yyg->yy_start; + + for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) { YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1411,16 +1413,17 @@ static int yy_get_next_buffer (void) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) { int yy_is_jam; - char *yy_cp = (yy_c_buf_p); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ + char *yy_cp = yyg->yy_c_buf_p; YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1431,7 +1434,8 @@ static int yy_get_next_buffer (void) yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; yy_is_jam = (yy_current_state == 19); - return yy_is_jam ? 0 : yy_current_state; + (void)yyg; + return yy_is_jam ? 0 : yy_current_state; } #ifndef YY_NO_UNPUT @@ -1440,32 +1444,33 @@ static int yy_get_next_buffer (void) #ifndef YY_NO_INPUT #ifdef __cplusplus - static int yyinput (void) + static int yyinput (yyscan_t yyscanner) #else - static int input (void) + static int input (yyscan_t yyscanner) #endif { int c; - - *(yy_c_buf_p) = (yy_hold_char); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; + *yyg->yy_c_buf_p = '\0'; else { /* need more input */ - int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); - ++(yy_c_buf_p); + int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr); + ++yyg->yy_c_buf_p; - switch ( yy_get_next_buffer( ) ) + switch ( yy_get_next_buffer( yyscanner ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() @@ -1479,38 +1484,40 @@ static int yy_get_next_buffer (void) */ /* Reset buffer status. */ - yyrestart( yyin ); + yyrestart( yyin , yyscanner); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { - if ( yywrap( ) ) + if ( yywrap( yyscanner ) ) return 0; - if ( ! (yy_did_buffer_switch_on_eof) ) + if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; #ifdef __cplusplus - return yyinput(); + return yyinput(yyscanner); #else - return input(); + return input(yyscanner); #endif } case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; break; } } } - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; if ( c == '\n' ) - yylineno++; + do{ yylineno++; + yycolumn=0; + }while(0) ; return c; @@ -1519,76 +1526,79 @@ static int yy_get_next_buffer (void) /** Immediately switch to a different input stream. * @param input_file A readable stream. - * + * @param yyscanner The scanner object. * @note This function does not reset the start condition to @c INITIAL . */ - void yyrestart (FILE * input_file ) + void yyrestart (FILE * input_file , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); } - yy_init_buffer( YY_CURRENT_BUFFER, input_file ); - yy_load_buffer_state( ); + yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner); + yy_load_buffer_state( yyscanner ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. - * + * @param yyscanner The scanner object. */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* TODO. We should be able to replace this entire function body * with * yypop_buffer_state(); * yypush_buffer_state(new_buffer); */ - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); if ( YY_CURRENT_BUFFER == new_buffer ) return; if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); + yy_load_buffer_state( yyscanner ); /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag * is looked at is after yywrap() is called, so it's safe * to go ahead and always set it. */ - (yy_did_buffer_switch_on_eof) = 1; + yyg->yy_did_buffer_switch_on_eof = 1; } -static void yy_load_buffer_state (void) +static void yy_load_buffer_state (yyscan_t yyscanner) { - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); + yyg->yy_hold_char = *yyg->yy_c_buf_p; } /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * + * @param yyscanner The scanner object. * @return the allocated buffer state. */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner) { YY_BUFFER_STATE b; - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1597,24 +1607,25 @@ static void yy_load_buffer_state (void) /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; - yy_init_buffer( b, file ); + yy_init_buffer( b, file , yyscanner); return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() - * + * @param yyscanner The scanner object. */ - void yy_delete_buffer (YY_BUFFER_STATE b ) + void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) return; @@ -1622,21 +1633,22 @@ static void yy_load_buffer_state (void) YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) - yyfree( (void *) b->yy_ch_buf ); + yyfree( (void *) b->yy_ch_buf , yyscanner ); - yyfree( (void *) b ); + yyfree( (void *) b , yyscanner ); } /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) { int oerrno = errno; - - yy_flush_buffer( b ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yy_flush_buffer( b , yyscanner); b->yy_input_file = file; b->yy_fill_buffer = 1; @@ -1657,11 +1669,12 @@ static void yy_load_buffer_state (void) /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * + * @param yyscanner The scanner object. */ - void yy_flush_buffer (YY_BUFFER_STATE b ) + void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) { - if ( ! b ) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) return; b->yy_n_chars = 0; @@ -1679,114 +1692,117 @@ static void yy_load_buffer_state (void) b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); + yy_load_buffer_state( yyscanner ); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. - * + * @param yyscanner The scanner object. */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) { - if (new_buffer == NULL) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (new_buffer == NULL) return; - yyensure_buffer_stack(); + yyensure_buffer_stack(yyscanner); /* This block is copied from yy_switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; + yyg->yy_buffer_stack_top++; YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + yy_load_buffer_state( yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. - * + * @param yyscanner The scanner object. */ -void yypop_buffer_state (void) +void yypop_buffer_state (yyscan_t yyscanner) { - if (!YY_CURRENT_BUFFER) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (!YY_CURRENT_BUFFER) return; - yy_delete_buffer(YY_CURRENT_BUFFER ); + yy_delete_buffer(YY_CURRENT_BUFFER , yyscanner); YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + yy_load_buffer_state( yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void yyensure_buffer_stack (void) +static void yyensure_buffer_stack (yyscan_t yyscanner) { yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (!yyg->yy_buffer_stack) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; return; } - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ /* Increase the buffer to prepare for a possible push. */ yy_size_t grow_size = 8 /* arbitrary grow size */; - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc + (yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; + memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); + yyg->yy_buffer_stack_max = num_to_alloc; } } /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) { YY_BUFFER_STATE b; @@ -1796,7 +1812,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /* They forgot to leave room for the EOB's. */ return NULL; - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); @@ -1810,7 +1826,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; - yy_switch_to_buffer( b ); + yy_switch_to_buffer( b , yyscanner ); return b; } @@ -1818,25 +1834,25 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /** Setup the input buffer state to scan a string. The next call to yylex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ -YY_BUFFER_STATE yy_scan_string (const char * yystr ) +YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner) { - return yy_scan_bytes( yystr, (int) strlen(yystr) ); + return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner); } /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner) { YY_BUFFER_STATE b; char *buf; @@ -1845,7 +1861,7 @@ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) /* Get memory for full buffer, including space for trailing EOB's. */ n = (yy_size_t) (_yybytes_len + 2); - buf = (char *) yyalloc( n ); + buf = (char *) yyalloc( n , yyscanner ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); @@ -1854,7 +1870,7 @@ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - b = yy_scan_buffer( buf, n ); + b = yy_scan_buffer( buf, n , yyscanner); if ( ! b ) YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); @@ -1870,9 +1886,11 @@ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) #define YY_EXIT_FAILURE 2 #endif -static void yynoreturn yy_fatal_error (const char* msg ) +static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner) { - fprintf( stderr, "%s\n", msg ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } @@ -1885,109 +1903,249 @@ static void yynoreturn yy_fatal_error (const char* msg ) /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ yyleng = yyless_macro_arg; \ } \ while ( 0 ) /* Accessor methods (get/set functions) to struct members. */ -/** Get the current line number. - * +/** Get the user-defined data for this scanner. + * @param yyscanner The scanner object. */ -int yyget_lineno (void) +YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyextra; +} + +/** Get the current line number. + * @param yyscanner The scanner object. + */ +int yyget_lineno (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; return yylineno; } -/** Get the input stream. - * +/** Get the current column number. + * @param yyscanner The scanner object. */ -FILE *yyget_in (void) +int yyget_column (yyscan_t yyscanner) { - return yyin; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yycolumn; +} + +/** Get the input stream. + * @param yyscanner The scanner object. + */ +FILE *yyget_in (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyin; } /** Get the output stream. - * + * @param yyscanner The scanner object. */ -FILE *yyget_out (void) +FILE *yyget_out (yyscan_t yyscanner) { - return yyout; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyout; } /** Get the length of the current token. - * + * @param yyscanner The scanner object. */ -int yyget_leng (void) +int yyget_leng (yyscan_t yyscanner) { - return yyleng; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyleng; } /** Get the current token. - * + * @param yyscanner The scanner object. */ -char *yyget_text (void) +char *yyget_text (yyscan_t yyscanner) { - return yytext; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yytext; +} + +/** Set the user-defined data. This data is never touched by the scanner. + * @param user_defined The data to be associated with this scanner. + * @param yyscanner The scanner object. + */ +void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyextra = user_defined ; } /** Set the current line number. * @param _line_number line number - * + * @param yyscanner The scanner object. */ -void yyset_lineno (int _line_number ) +void yyset_lineno (int _line_number , yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* lineno is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + YY_FATAL_ERROR( "yyset_lineno called with no buffer" ); yylineno = _line_number; } +/** Set the current column. + * @param _column_no column number + * @param yyscanner The scanner object. + */ +void yyset_column (int _column_no , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* column is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + YY_FATAL_ERROR( "yyset_column called with no buffer" ); + + yycolumn = _column_no; +} + /** Set the input stream. This does not discard the current * input buffer. * @param _in_str A readable stream. - * + * @param yyscanner The scanner object. * @see yy_switch_to_buffer */ -void yyset_in (FILE * _in_str ) +void yyset_in (FILE * _in_str , yyscan_t yyscanner) { - yyin = _in_str ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyin = _in_str ; } -void yyset_out (FILE * _out_str ) +void yyset_out (FILE * _out_str , yyscan_t yyscanner) { - yyout = _out_str ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyout = _out_str ; } -int yyget_debug (void) +int yyget_debug (yyscan_t yyscanner) { - return yy_flex_debug; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yy_flex_debug; } -void yyset_debug (int _bdebug ) +void yyset_debug (int _bdebug , yyscan_t yyscanner) { - yy_flex_debug = _bdebug ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_flex_debug = _bdebug ; } -static int yy_init_globals (void) +/* Accessor methods for yylval and yylloc */ + +YYSTYPE * yyget_lval (yyscan_t yyscanner) { - /* Initialization is the same as for the non-reentrant scanner. + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yylval; +} + +void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yylval = yylval_param; +} + +/* User-visible API */ + +/* yylex_init is special because it creates the scanner itself, so it is + * the ONLY reentrant function that doesn't take the scanner as the last argument. + * That's why we explicitly handle the declaration, instead of using our macros. + */ +int yylex_init(yyscan_t* ptr_yy_globals) +{ + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + return yy_init_globals ( *ptr_yy_globals ); +} + +/* yylex_init_extra has the same functionality as yylex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to yyalloc in + * the yyextra field. + */ +int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals ) +{ + struct yyguts_t dummy_yyguts; + + yyset_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + yyset_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); +} + +static int yy_init_globals (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Initialization is the same as for the non-reentrant scanner. * This function is called from yylex_destroy(), so don't allocate here. */ - /* We do not touch yylineno unless the option is enabled. */ - yylineno = 1; - - (yy_buffer_stack) = NULL; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = NULL; - (yy_init) = 0; - (yy_start) = 0; + yyg->yy_buffer_stack = NULL; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = NULL; + yyg->yy_init = 0; + yyg->yy_start = 0; + + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; /* Defined in main.c */ #ifdef YY_STDINIT @@ -2005,24 +2163,32 @@ static int yy_init_globals (void) } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) +int yylex_destroy (yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ - yy_delete_buffer( YY_CURRENT_BUFFER ); + yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner ); YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); + yypop_buffer_state(yyscanner); } /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; + yyfree(yyg->yy_buffer_stack , yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + yyfree( yyg->yy_start_stack , yyscanner ); + yyg->yy_start_stack = NULL; /* Reset the globals. This is important in a non-reentrant scanner so the next time * yylex() is called, initialization will occur. */ - yy_init_globals( ); + yy_init_globals( yyscanner); + /* Destroy the main struct (reentrant only). */ + yyfree ( yyscanner , yyscanner ); + yyscanner = NULL; return 0; } @@ -2031,9 +2197,11 @@ int yylex_destroy (void) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, const char * s2, int n ) +static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; @@ -2041,7 +2209,7 @@ static void yy_flex_strncpy (char* s1, const char * s2, int n ) #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (const char * s ) +static int yy_flex_strlen (const char * s , yyscan_t yyscanner) { int n; for ( n = 0; s[n]; ++n ) @@ -2051,14 +2219,18 @@ static int yy_flex_strlen (const char * s ) } #endif -void *yyalloc (yy_size_t size ) +void *yyalloc (yy_size_t size , yyscan_t yyscanner) { - return malloc(size); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + return malloc(size); } -void *yyrealloc (void * ptr, yy_size_t size ) +void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter @@ -2069,17 +2241,19 @@ void *yyrealloc (void * ptr, yy_size_t size ) return realloc(ptr, size); } -void yyfree (void * ptr ) +void yyfree (void * ptr , yyscan_t yyscanner) { - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" -#line 69 "expr_parser.l" +#line 73 "expr_parser.l" -int expr_wrap() +int expr_wrap(yyscan_t scanner) { return 1; } diff --git a/src/parsers/expr_parser.h b/src/parsers/expr_parser.h new file mode 100644 index 0000000000..dcb26baaa6 --- /dev/null +++ b/src/parsers/expr_parser.h @@ -0,0 +1,717 @@ +#ifndef expr_HEADER_H +#define expr_HEADER_H 1 +#define expr_IN_HEADER 1 + +#line 5 "expr_parser.h" + +#line 7 "expr_parser.h" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 4 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +#ifdef yy_create_buffer +#define expr__create_buffer_ALREADY_DEFINED +#else +#define yy_create_buffer expr__create_buffer +#endif + +#ifdef yy_delete_buffer +#define expr__delete_buffer_ALREADY_DEFINED +#else +#define yy_delete_buffer expr__delete_buffer +#endif + +#ifdef yy_scan_buffer +#define expr__scan_buffer_ALREADY_DEFINED +#else +#define yy_scan_buffer expr__scan_buffer +#endif + +#ifdef yy_scan_string +#define expr__scan_string_ALREADY_DEFINED +#else +#define yy_scan_string expr__scan_string +#endif + +#ifdef yy_scan_bytes +#define expr__scan_bytes_ALREADY_DEFINED +#else +#define yy_scan_bytes expr__scan_bytes +#endif + +#ifdef yy_init_buffer +#define expr__init_buffer_ALREADY_DEFINED +#else +#define yy_init_buffer expr__init_buffer +#endif + +#ifdef yy_flush_buffer +#define expr__flush_buffer_ALREADY_DEFINED +#else +#define yy_flush_buffer expr__flush_buffer +#endif + +#ifdef yy_load_buffer_state +#define expr__load_buffer_state_ALREADY_DEFINED +#else +#define yy_load_buffer_state expr__load_buffer_state +#endif + +#ifdef yy_switch_to_buffer +#define expr__switch_to_buffer_ALREADY_DEFINED +#else +#define yy_switch_to_buffer expr__switch_to_buffer +#endif + +#ifdef yypush_buffer_state +#define expr_push_buffer_state_ALREADY_DEFINED +#else +#define yypush_buffer_state expr_push_buffer_state +#endif + +#ifdef yypop_buffer_state +#define expr_pop_buffer_state_ALREADY_DEFINED +#else +#define yypop_buffer_state expr_pop_buffer_state +#endif + +#ifdef yyensure_buffer_stack +#define expr_ensure_buffer_stack_ALREADY_DEFINED +#else +#define yyensure_buffer_stack expr_ensure_buffer_stack +#endif + +#ifdef yylex +#define expr_lex_ALREADY_DEFINED +#else +#define yylex expr_lex +#endif + +#ifdef yyrestart +#define expr_restart_ALREADY_DEFINED +#else +#define yyrestart expr_restart +#endif + +#ifdef yylex_init +#define expr_lex_init_ALREADY_DEFINED +#else +#define yylex_init expr_lex_init +#endif + +#ifdef yylex_init_extra +#define expr_lex_init_extra_ALREADY_DEFINED +#else +#define yylex_init_extra expr_lex_init_extra +#endif + +#ifdef yylex_destroy +#define expr_lex_destroy_ALREADY_DEFINED +#else +#define yylex_destroy expr_lex_destroy +#endif + +#ifdef yyget_debug +#define expr_get_debug_ALREADY_DEFINED +#else +#define yyget_debug expr_get_debug +#endif + +#ifdef yyset_debug +#define expr_set_debug_ALREADY_DEFINED +#else +#define yyset_debug expr_set_debug +#endif + +#ifdef yyget_extra +#define expr_get_extra_ALREADY_DEFINED +#else +#define yyget_extra expr_get_extra +#endif + +#ifdef yyset_extra +#define expr_set_extra_ALREADY_DEFINED +#else +#define yyset_extra expr_set_extra +#endif + +#ifdef yyget_in +#define expr_get_in_ALREADY_DEFINED +#else +#define yyget_in expr_get_in +#endif + +#ifdef yyset_in +#define expr_set_in_ALREADY_DEFINED +#else +#define yyset_in expr_set_in +#endif + +#ifdef yyget_out +#define expr_get_out_ALREADY_DEFINED +#else +#define yyget_out expr_get_out +#endif + +#ifdef yyset_out +#define expr_set_out_ALREADY_DEFINED +#else +#define yyset_out expr_set_out +#endif + +#ifdef yyget_leng +#define expr_get_leng_ALREADY_DEFINED +#else +#define yyget_leng expr_get_leng +#endif + +#ifdef yyget_text +#define expr_get_text_ALREADY_DEFINED +#else +#define yyget_text expr_get_text +#endif + +#ifdef yyget_lineno +#define expr_get_lineno_ALREADY_DEFINED +#else +#define yyget_lineno expr_get_lineno +#endif + +#ifdef yyset_lineno +#define expr_set_lineno_ALREADY_DEFINED +#else +#define yyset_lineno expr_set_lineno +#endif + +#ifdef yyget_column +#define expr_get_column_ALREADY_DEFINED +#else +#define yyget_column expr_get_column +#endif + +#ifdef yyset_column +#define expr_set_column_ALREADY_DEFINED +#else +#define yyset_column expr_set_column +#endif + +#ifdef yywrap +#define expr_wrap_ALREADY_DEFINED +#else +#define yywrap expr_wrap +#endif + +#ifdef yyget_lval +#define expr_get_lval_ALREADY_DEFINED +#else +#define yyget_lval expr_get_lval +#endif + +#ifdef yyset_lval +#define expr_set_lval_ALREADY_DEFINED +#else +#define yyset_lval expr_set_lval +#endif + +#ifdef yyalloc +#define expr_alloc_ALREADY_DEFINED +#else +#define yyalloc expr_alloc +#endif + +#ifdef yyrealloc +#define expr_realloc_ALREADY_DEFINED +#else +#define yyrealloc expr_realloc +#endif + +#ifdef yyfree +#define expr_free_ALREADY_DEFINED +#else +#define yyfree expr_free +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ + +/* TODO: this is always defined, so inline it */ +#define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) +#else +#define yynoreturn +#endif + +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +void yyrestart ( FILE *input_file , yyscan_t yyscanner ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner ); +void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +void yypop_buffer_state ( yyscan_t yyscanner ); + +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner ); + +void *yyalloc ( yy_size_t , yyscan_t yyscanner ); +void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner ); +void yyfree ( void * , yyscan_t yyscanner ); + +/* Begin user sect3 */ + +#define yytext_ptr yytext_r + +#ifdef YY_HEADER_EXPORT_START_CONDITIONS +#define INITIAL 0 + +#endif + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +int yylex_init (yyscan_t* scanner); + +int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy ( yyscan_t yyscanner ); + +int yyget_debug ( yyscan_t yyscanner ); + +void yyset_debug ( int debug_flag , yyscan_t yyscanner ); + +YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner ); + +void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); + +FILE *yyget_in ( yyscan_t yyscanner ); + +void yyset_in ( FILE * _in_str , yyscan_t yyscanner ); + +FILE *yyget_out ( yyscan_t yyscanner ); + +void yyset_out ( FILE * _out_str , yyscan_t yyscanner ); + + int yyget_leng ( yyscan_t yyscanner ); + +char *yyget_text ( yyscan_t yyscanner ); + +int yyget_lineno ( yyscan_t yyscanner ); + +void yyset_lineno ( int _line_number , yyscan_t yyscanner ); + +int yyget_column ( yyscan_t yyscanner ); + +void yyset_column ( int _column_no , yyscan_t yyscanner ); + +YYSTYPE * yyget_lval ( yyscan_t yyscanner ); + +void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap ( yyscan_t yyscanner ); +#else +extern int yywrap ( yyscan_t yyscanner ); +#endif +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen ( const char * , yyscan_t yyscanner); +#endif + +#ifndef YY_NO_INPUT + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner); + +#define YY_DECL int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner) +#endif /* !YY_DECL */ + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +#undef YY_NEW_FILE +#undef YY_FLUSH_BUFFER +#undef yy_set_bol +#undef yy_new_buffer +#undef yy_set_interactive +#undef YY_DO_BEFORE_ACTION + +#ifdef YY_DECL_IS_OURS +#undef YY_DECL_IS_OURS +#undef YY_DECL +#endif + +#ifndef expr__create_buffer_ALREADY_DEFINED +#undef yy_create_buffer +#endif +#ifndef expr__delete_buffer_ALREADY_DEFINED +#undef yy_delete_buffer +#endif +#ifndef expr__scan_buffer_ALREADY_DEFINED +#undef yy_scan_buffer +#endif +#ifndef expr__scan_string_ALREADY_DEFINED +#undef yy_scan_string +#endif +#ifndef expr__scan_bytes_ALREADY_DEFINED +#undef yy_scan_bytes +#endif +#ifndef expr__init_buffer_ALREADY_DEFINED +#undef yy_init_buffer +#endif +#ifndef expr__flush_buffer_ALREADY_DEFINED +#undef yy_flush_buffer +#endif +#ifndef expr__load_buffer_state_ALREADY_DEFINED +#undef yy_load_buffer_state +#endif +#ifndef expr__switch_to_buffer_ALREADY_DEFINED +#undef yy_switch_to_buffer +#endif +#ifndef expr_push_buffer_state_ALREADY_DEFINED +#undef yypush_buffer_state +#endif +#ifndef expr_pop_buffer_state_ALREADY_DEFINED +#undef yypop_buffer_state +#endif +#ifndef expr_ensure_buffer_stack_ALREADY_DEFINED +#undef yyensure_buffer_stack +#endif +#ifndef expr_lex_ALREADY_DEFINED +#undef yylex +#endif +#ifndef expr_restart_ALREADY_DEFINED +#undef yyrestart +#endif +#ifndef expr_lex_init_ALREADY_DEFINED +#undef yylex_init +#endif +#ifndef expr_lex_init_extra_ALREADY_DEFINED +#undef yylex_init_extra +#endif +#ifndef expr_lex_destroy_ALREADY_DEFINED +#undef yylex_destroy +#endif +#ifndef expr_get_debug_ALREADY_DEFINED +#undef yyget_debug +#endif +#ifndef expr_set_debug_ALREADY_DEFINED +#undef yyset_debug +#endif +#ifndef expr_get_extra_ALREADY_DEFINED +#undef yyget_extra +#endif +#ifndef expr_set_extra_ALREADY_DEFINED +#undef yyset_extra +#endif +#ifndef expr_get_in_ALREADY_DEFINED +#undef yyget_in +#endif +#ifndef expr_set_in_ALREADY_DEFINED +#undef yyset_in +#endif +#ifndef expr_get_out_ALREADY_DEFINED +#undef yyget_out +#endif +#ifndef expr_set_out_ALREADY_DEFINED +#undef yyset_out +#endif +#ifndef expr_get_leng_ALREADY_DEFINED +#undef yyget_leng +#endif +#ifndef expr_get_text_ALREADY_DEFINED +#undef yyget_text +#endif +#ifndef expr_get_lineno_ALREADY_DEFINED +#undef yyget_lineno +#endif +#ifndef expr_set_lineno_ALREADY_DEFINED +#undef yyset_lineno +#endif +#ifndef expr_get_column_ALREADY_DEFINED +#undef yyget_column +#endif +#ifndef expr_set_column_ALREADY_DEFINED +#undef yyset_column +#endif +#ifndef expr_wrap_ALREADY_DEFINED +#undef yywrap +#endif +#ifndef expr_get_lval_ALREADY_DEFINED +#undef yyget_lval +#endif +#ifndef expr_set_lval_ALREADY_DEFINED +#undef yyset_lval +#endif +#ifndef expr_get_lloc_ALREADY_DEFINED +#undef yyget_lloc +#endif +#ifndef expr_set_lloc_ALREADY_DEFINED +#undef yyset_lloc +#endif +#ifndef expr_alloc_ALREADY_DEFINED +#undef yyalloc +#endif +#ifndef expr_realloc_ALREADY_DEFINED +#undef yyrealloc +#endif +#ifndef expr_free_ALREADY_DEFINED +#undef yyfree +#endif +#ifndef expr_text_ALREADY_DEFINED +#undef yytext +#endif +#ifndef expr_leng_ALREADY_DEFINED +#undef yyleng +#endif +#ifndef expr_in_ALREADY_DEFINED +#undef yyin +#endif +#ifndef expr_out_ALREADY_DEFINED +#undef yyout +#endif +#ifndef expr__flex_debug_ALREADY_DEFINED +#undef yy_flex_debug +#endif +#ifndef expr_lineno_ALREADY_DEFINED +#undef yylineno +#endif +#ifndef expr_tables_fload_ALREADY_DEFINED +#undef yytables_fload +#endif +#ifndef expr_tables_destroy_ALREADY_DEFINED +#undef yytables_destroy +#endif +#ifndef expr_TABLES_NAME_ALREADY_DEFINED +#undef yyTABLES_NAME +#endif + +#line 73 "expr_parser.l" + + +#line 715 "expr_parser.h" +#undef expr_IN_HEADER +#endif /* expr_HEADER_H */ diff --git a/src/xml/expr_parser.l b/src/parsers/expr_parser.l similarity index 76% rename from src/xml/expr_parser.l rename to src/parsers/expr_parser.l index 2189e2d2b4..bab4911f02 100644 --- a/src/xml/expr_parser.l +++ b/src/parsers/expr_parser.l @@ -24,7 +24,8 @@ #define YY_NO_INPUT -#define YY_DECL int expr_lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector *mc) +#define YY_DECL int expr_lex (YYSTYPE *yylval_param, YYLTYPE *llocp, \ + mem_collector *mc, yyscan_t yyscanner) #define YY_USER_ACTION llocp->first_line = yylineno; \ llocp->first_column = llocp->last_column; \ @@ -33,7 +34,10 @@ %option nounput %option prefix="expr_" -%option outfile="expr_parser.c" +%option outfile="expr_parser.cc" +%option header-file="expr_parser.h" +%option reentrant +%option bison-bridge %option yylineno %% @@ -43,22 +47,22 @@ /* --- Strings, also quoted form --- */ -[A-Za-z][0-9A-Za-z_]* { lvalp->val_str = mem_collector_strdup(mc,yytext); +[A-Za-z][0-9A-Za-z_]* { yylval_param->val_str = mem_collector_strdup(mc,yytext); return STRING;} -\"\" { lvalp->val_str = NULL; +\"\" { yylval_param->val_str = NULL; return STRING;} -\"[^\"]*\" { lvalp->val_str = mem_collector_strdup(mc,yytext+1); - lvalp->val_str[yyleng-2] = '\0'; +\"[^\"]*\" { yylval_param->val_str = mem_collector_strdup(mc,yytext+1); + yylval_param->val_str[yyleng-2] = '\0'; return STRING;} /* --- Numbers --- */ --?[0-9]+ { lvalp->val_int = atoi(yytext); +-?[0-9]+ { yylval_param->val_int = atoi(yytext); return INTEGER;} --?[0-9]+\.[0-9]+ { lvalp->val_float = atof(yytext); +-?[0-9]+\.[0-9]+ { yylval_param->val_float = atof(yytext); return FLOAT;} /* --- blanks --- */ @@ -67,7 +71,7 @@ %% -int expr_wrap() +int expr_wrap(yyscan_t scanner) { return 1; } diff --git a/src/common/mem_collector.c b/src/parsers/mem_collector.cc similarity index 100% rename from src/common/mem_collector.c rename to src/parsers/mem_collector.cc diff --git a/src/template/template_parser.c b/src/parsers/template_parser.cc similarity index 66% rename from src/template/template_parser.c rename to src/parsers/template_parser.cc index 9d4b182a01..6c3e4be2c6 100644 --- a/src/template/template_parser.c +++ b/src/parsers/template_parser.cc @@ -1,36 +1,11 @@ -#line 1 "template_parser.c" +#line 1 "template_parser.cc" -#line 3 "template_parser.c" +#line 3 "template_parser.cc" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ -#define yy_create_buffer template__create_buffer -#define yy_delete_buffer template__delete_buffer -#define yy_scan_buffer template__scan_buffer -#define yy_scan_string template__scan_string -#define yy_scan_bytes template__scan_bytes -#define yy_init_buffer template__init_buffer -#define yy_flush_buffer template__flush_buffer -#define yy_load_buffer_state template__load_buffer_state -#define yy_switch_to_buffer template__switch_to_buffer -#define yypush_buffer_state template_push_buffer_state -#define yypop_buffer_state template_pop_buffer_state -#define yyensure_buffer_stack template_ensure_buffer_stack -#define yy_flex_debug template__flex_debug -#define yyin template_in -#define yyleng template_leng -#define yylex template_lex -#define yylineno template_lineno -#define yyout template_out -#define yyrestart template_restart -#define yytext template_text -#define yywrap template_wrap -#define yyalloc template_alloc -#define yyrealloc template_realloc -#define yyfree template_free - #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 6 @@ -213,12 +188,36 @@ #define yyset_lineno template_set_lineno #endif +#ifdef yyget_column +#define template_get_column_ALREADY_DEFINED +#else +#define yyget_column template_get_column +#endif + +#ifdef yyset_column +#define template_set_column_ALREADY_DEFINED +#else +#define yyset_column template_set_column +#endif + #ifdef yywrap #define template_wrap_ALREADY_DEFINED #else #define yywrap template_wrap #endif +#ifdef yyget_lval +#define template_get_lval_ALREADY_DEFINED +#else +#define yyget_lval template_get_lval +#endif + +#ifdef yyset_lval +#define template_set_lval_ALREADY_DEFINED +#else +#define yyset_lval template_set_lval +#endif + #ifdef yyalloc #define template_alloc_ALREADY_DEFINED #else @@ -237,42 +236,6 @@ #define yyfree template_free #endif -#ifdef yytext -#define template_text_ALREADY_DEFINED -#else -#define yytext template_text -#endif - -#ifdef yyleng -#define template_leng_ALREADY_DEFINED -#else -#define yyleng template_leng -#endif - -#ifdef yyin -#define template_in_ALREADY_DEFINED -#else -#define yyin template_in -#endif - -#ifdef yyout -#define template_out_ALREADY_DEFINED -#else -#define yyout template_out -#endif - -#ifdef yy_flex_debug -#define template__flex_debug_ALREADY_DEFINED -#else -#define yy_flex_debug template__flex_debug -#endif - -#ifdef yylineno -#define template_lineno_ALREADY_DEFINED -#else -#define yylineno template_lineno -#endif - /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ @@ -370,21 +333,38 @@ typedef unsigned int flex_uint32_t; */ #define YY_SC_TO_UI(c) ((YY_CHAR) (c)) +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ -#define BEGIN (yy_start) = 1 + 2 * +#define BEGIN yyg->yy_start = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ -#define YY_START (((yy_start) - 1) / 2) +#define YY_START ((yyg->yy_start - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) +#define YY_NEW_FILE yyrestart( yyin , yyscanner ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ @@ -414,10 +394,6 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; typedef size_t yy_size_t; #endif -extern int yyleng; - -extern FILE *yyin, *yyout; - #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 @@ -451,13 +427,13 @@ extern FILE *yyin, *yyout; /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ + *yy_cp = yyg->yy_hold_char; \ YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) -#define unput(c) yyunput( c, (yytext_ptr) ) +#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE @@ -524,77 +500,57 @@ struct yy_buffer_state }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ - /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ +#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ + ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] +#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; +void yyrestart ( FILE *input_file , yyscan_t yyscanner ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner ); +void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +void yypop_buffer_state ( yyscan_t yyscanner ); -/* Points to current character in buffer. */ -static char *yy_c_buf_p = NULL; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ +static void yyensure_buffer_stack ( yyscan_t yyscanner ); +static void yy_load_buffer_state ( yyscan_t yyscanner ); +static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , yyscanner) -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner ); -void yyrestart ( FILE *input_file ); -void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); -void yy_delete_buffer ( YY_BUFFER_STATE b ); -void yy_flush_buffer ( YY_BUFFER_STATE b ); -void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state ( void ); - -static void yyensure_buffer_stack ( void ); -static void yy_load_buffer_state ( void ); -static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); -#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); -YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); - -void *yyalloc ( yy_size_t ); -void *yyrealloc ( void *, yy_size_t ); -void yyfree ( void * ); +void *yyalloc ( yy_size_t , yyscan_t yyscanner ); +void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner ); +void yyfree ( void * , yyscan_t yyscanner ); #define yy_new_buffer yy_create_buffer #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ + yyensure_buffer_stack (yyscanner); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ + yyensure_buffer_stack (yyscanner); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } @@ -603,33 +559,24 @@ void yyfree ( void * ); /* Begin user sect3 */ typedef flex_uint8_t YY_CHAR; -FILE *yyin = NULL, *yyout = NULL; - typedef int yy_state_type; -extern int yylineno; -int yylineno = 1; +#define yytext_ptr yytext_r -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state ( void ); -static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); -static int yy_get_next_buffer ( void ); -static void yynoreturn yy_fatal_error ( const char* msg ); +static yy_state_type yy_get_previous_state ( yyscan_t yyscanner ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state , yyscan_t yyscanner); +static int yy_get_next_buffer ( yyscan_t yyscanner ); +static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ + yyg->yytext_ptr = yy_bp; \ yyleng = (int) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ + yyg->yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; + yyg->yy_c_buf_p = yy_cp; #define YY_NUM_RULES 12 #define YY_END_OF_BUFFER 13 /* This struct is not used in this scanner, @@ -771,12 +718,6 @@ static const flex_int32_t yy_rule_can_match_eol[13] = { 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, }; -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ @@ -784,7 +725,6 @@ int yy_flex_debug = 0; #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET -char *yytext; #line 1 "template_parser.l" /* -------------------------------------------------------------------------- */ /* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */ @@ -812,15 +752,15 @@ char *yytext; #define YY_NO_INPUT -#define YY_DECL int template_lex (YYSTYPE *lvalp, YYLTYPE *llocp, \ - mem_collector *mc) +#define YY_DECL int template_lex (YYSTYPE *yylval_param, YYLTYPE *llocp, \ + mem_collector *mc, yyscan_t yyscanner) #define YY_USER_ACTION llocp->first_line = yylineno; \ llocp->first_column = llocp->last_column; \ llocp->last_column += yyleng; -#line 821 "template_parser.c" +#line 761 "template_parser.cc" -#line 823 "template_parser.c" +#line 763 "template_parser.cc" #define INITIAL 0 #define VALUE 1 @@ -837,36 +777,88 @@ char *yytext; #define YY_EXTRA_TYPE void * #endif -static int yy_init_globals ( void ); +/* Holds the entire state of the reentrant scanner. */ +struct yyguts_t + { + + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; + + /* The rest are the same as the globals declared in the non-reentrant scanner. */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + int yylineno_r; + int yy_flex_debug_r; + + char *yytext_r; + int yy_more_flag; + int yy_more_len; + + YYSTYPE * yylval_r; + + }; /* end struct yyguts_t */ + +static int yy_init_globals ( yyscan_t yyscanner ); + + /* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ + # define yylval yyg->yylval_r + +int yylex_init (yyscan_t* scanner); + +int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy ( void ); +int yylex_destroy ( yyscan_t yyscanner ); -int yyget_debug ( void ); +int yyget_debug ( yyscan_t yyscanner ); -void yyset_debug ( int debug_flag ); +void yyset_debug ( int debug_flag , yyscan_t yyscanner ); -YY_EXTRA_TYPE yyget_extra ( void ); +YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner ); -void yyset_extra ( YY_EXTRA_TYPE user_defined ); +void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); -FILE *yyget_in ( void ); +FILE *yyget_in ( yyscan_t yyscanner ); -void yyset_in ( FILE * _in_str ); +void yyset_in ( FILE * _in_str , yyscan_t yyscanner ); -FILE *yyget_out ( void ); +FILE *yyget_out ( yyscan_t yyscanner ); -void yyset_out ( FILE * _out_str ); +void yyset_out ( FILE * _out_str , yyscan_t yyscanner ); - int yyget_leng ( void ); + int yyget_leng ( yyscan_t yyscanner ); -char *yyget_text ( void ); +char *yyget_text ( yyscan_t yyscanner ); -int yyget_lineno ( void ); +int yyget_lineno ( yyscan_t yyscanner ); -void yyset_lineno ( int _line_number ); +void yyset_lineno ( int _line_number , yyscan_t yyscanner ); + +int yyget_column ( yyscan_t yyscanner ); + +void yyset_column ( int _column_no , yyscan_t yyscanner ); + +YYSTYPE * yyget_lval ( yyscan_t yyscanner ); + +void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -874,9 +866,9 @@ void yyset_lineno ( int _line_number ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap ( void ); +extern "C" int yywrap ( yyscan_t yyscanner ); #else -extern int yywrap ( void ); +extern int yywrap ( yyscan_t yyscanner ); #endif #endif @@ -885,18 +877,18 @@ extern int yywrap ( void ); #endif #ifndef yytext_ptr -static void yy_flex_strncpy ( char *, const char *, int ); +static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen ( const char * ); +static int yy_flex_strlen ( const char * , yyscan_t yyscanner); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput ( void ); +static int yyinput ( yyscan_t yyscanner ); #else -static int input ( void ); +static int input ( yyscan_t yyscanner ); #endif #endif @@ -970,7 +962,7 @@ static int input ( void ); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) #endif /* end tables serialization structures and prototypes */ @@ -981,9 +973,11 @@ static int input ( void ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int yylex (void); +extern int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner); -#define YY_DECL int yylex (void) +#define YY_DECL int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -1008,17 +1002,20 @@ YY_DECL yy_state_type yy_current_state; char *yy_cp, *yy_bp; int yy_act; - - if ( !(yy_init) ) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yylval = yylval_param; + + if ( !yyg->yy_init ) { - (yy_init) = 1; + yyg->yy_init = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ + if ( ! yyg->yy_start ) + yyg->yy_start = 1; /* first start state */ if ( ! yyin ) yyin = stdin; @@ -1027,45 +1024,45 @@ YY_DECL yyout = stdout; if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); } - yy_load_buffer_state( ); + yy_load_buffer_state( yyscanner ); } { -#line 46 "template_parser.l" - - #line 49 "template_parser.l" + + +#line 52 "template_parser.l" /* ------------------------------------------------------------------------- */ /* Comments (lines with an starting #), and empty lines */ /* ------------------------------------------------------------------------- */ -#line 1046 "template_parser.c" +#line 1043 "template_parser.cc" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { - yy_cp = (yy_c_buf_p); + yy_cp = yyg->yy_c_buf_p; /* Support of yytext. */ - *yy_cp = (yy_hold_char); + *yy_cp = yyg->yy_hold_char; /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; - yy_current_state = (yy_start); + yy_current_state = yyg->yy_start; yy_match: do { YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1082,8 +1079,8 @@ yy_find_action: yy_act = yy_accept[yy_current_state]; if ( yy_act == 0 ) { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; yy_act = yy_accept[yy_current_state]; } @@ -1095,7 +1092,9 @@ yy_find_action: for ( yyl = 0; yyl < yyleng; ++yyl ) if ( yytext[yyl] == '\n' ) - yylineno++; + do{ yylineno++; + yycolumn=0; + }while(0) ; } @@ -1105,21 +1104,21 @@ do_action: /* This label is used only to access EOF actions. */ { /* beginning of action switch */ case 0: /* must back up */ /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; goto yy_find_action; case 1: /* rule 1 can match eol */ YY_RULE_SETUP -#line 52 "template_parser.l" +#line 55 "template_parser.l" ; YY_BREAK case 2: /* rule 2 can match eol */ YY_RULE_SETUP -#line 53 "template_parser.l" +#line 56 "template_parser.l" ; YY_BREAK /* ------------------------------------------------------------------------- */ @@ -1127,8 +1126,8 @@ YY_RULE_SETUP /* ------------------------------------------------------------------------- */ case 3: YY_RULE_SETUP -#line 58 "template_parser.l" -{ lvalp->val_str = mem_collector_strdup(mc,yytext); +#line 61 "template_parser.l" +{ yylval_param->val_str = mem_collector_strdup(mc,yytext); return VARIABLE; } YY_BREAK /* ------------------------------------------------------------------------ */ @@ -1138,31 +1137,31 @@ YY_RULE_SETUP /* ------------------------------------------------------------------------ */ case 4: YY_RULE_SETUP -#line 66 "template_parser.l" +#line 69 "template_parser.l" { BEGIN VALUE; return EQUAL;} YY_BREAK case 5: /* rule 5 can match eol */ YY_RULE_SETUP -#line 68 "template_parser.l" +#line 71 "template_parser.l" { return EQUAL_EMPTY;} YY_BREAK case 6: /* rule 6 can match eol */ YY_RULE_SETUP -#line 70 "template_parser.l" +#line 73 "template_parser.l" { return COMMA;} YY_BREAK case 7: /* rule 7 can match eol */ YY_RULE_SETUP -#line 72 "template_parser.l" +#line 75 "template_parser.l" { return CBRACKET;} YY_BREAK case 8: /* rule 8 can match eol */ YY_RULE_SETUP -#line 74 "template_parser.l" +#line 77 "template_parser.l" { BEGIN(INITIAL); return OBRACKET;} YY_BREAK /* ------------------------------------------------------------------------ */ @@ -1172,29 +1171,38 @@ YY_RULE_SETUP /* ------------------------------------------------------------------------ */ case 9: YY_RULE_SETUP -#line 82 "template_parser.l" -{ BEGIN(INITIAL); return CCDATA;} +#line 85 "template_parser.l" +{ + BEGIN(INITIAL); + return CCDATA; +} YY_BREAK case 10: /* rule 10 can match eol */ YY_RULE_SETUP -#line 84 "template_parser.l" -{ lvalp->val_str = mem_collector_strdup(mc,yytext+1); - lvalp->val_str[yyleng-2] = '\0'; - BEGIN(INITIAL); return STRING; } +#line 90 "template_parser.l" +{ + yylval_param->val_str = mem_collector_strdup(mc,yytext+1); + yylval_param->val_str[yyleng-2] = '\0'; + BEGIN(INITIAL); + return STRING; +} YY_BREAK case 11: YY_RULE_SETUP -#line 88 "template_parser.l" -{ lvalp->val_str = mem_collector_strdup(mc,yytext); - BEGIN(INITIAL); return STRING;} +#line 97 "template_parser.l" +{ + yylval_param->val_str = mem_collector_strdup(mc,yytext); + BEGIN(INITIAL); + return STRING; +} YY_BREAK case 12: YY_RULE_SETUP -#line 90 "template_parser.l" +#line 103 "template_parser.l" ECHO; YY_BREAK -#line 1197 "template_parser.c" +#line 1205 "template_parser.cc" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(VALUE): yyterminate(); @@ -1202,10 +1210,10 @@ case YY_STATE_EOF(VALUE): case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); + *yy_cp = yyg->yy_hold_char; YY_RESTORE_YY_MORE_OFFSET if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) @@ -1219,7 +1227,7 @@ case YY_STATE_EOF(VALUE): * this is the first action (other than possibly a * back-up) that will match for the new input source. */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } @@ -1231,13 +1239,13 @@ case YY_STATE_EOF(VALUE): * end-of-buffer state). Contrast this with the test * in input(). */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) { /* This was really a NUL. */ yy_state_type yy_next_state; - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have @@ -1248,32 +1256,32 @@ case YY_STATE_EOF(VALUE): * will run more slowly). */ - yy_next_state = yy_try_NUL_trans( yy_current_state ); + yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); + yy_cp = ++yyg->yy_c_buf_p; yy_current_state = yy_next_state; goto yy_match; } else { - yy_cp = (yy_c_buf_p); + yy_cp = yyg->yy_c_buf_p; goto yy_find_action; } } - else switch ( yy_get_next_buffer( ) ) + else switch ( yy_get_next_buffer( yyscanner ) ) { case EOB_ACT_END_OF_FILE: { - (yy_did_buffer_switch_on_eof) = 0; + yyg->yy_did_buffer_switch_on_eof = 0; - if ( yywrap( ) ) + if ( yywrap( yyscanner ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up @@ -1284,7 +1292,7 @@ case YY_STATE_EOF(VALUE): * YY_NULL, it'll still work - another * YY_NULL will get returned. */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; @@ -1292,30 +1300,30 @@ case YY_STATE_EOF(VALUE): else { - if ( ! (yy_did_buffer_switch_on_eof) ) + if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; + yyg->yy_c_buf_p = + yyg->yytext_ptr + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; goto yy_find_action; } break; @@ -1336,20 +1344,21 @@ case YY_STATE_EOF(VALUE): * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer (void) +static int yy_get_next_buffer (yyscan_t yyscanner) { - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = yyg->yytext_ptr; int number_to_move, i; int ret_val; - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so * treat this as a final EOF. @@ -1369,7 +1378,7 @@ static int yy_get_next_buffer (void) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -1378,7 +1387,7 @@ static int yy_get_next_buffer (void) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; else { @@ -1392,7 +1401,7 @@ static int yy_get_next_buffer (void) YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); + (int) (yyg->yy_c_buf_p - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { @@ -1406,7 +1415,7 @@ static int yy_get_next_buffer (void) b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ yyrealloc( (void *) b->yy_ch_buf, - (yy_size_t) (b->yy_buf_size + 2) ); + (yy_size_t) (b->yy_buf_size + 2) , yyscanner ); } else /* Can't grow it, we don't own it. */ @@ -1416,7 +1425,7 @@ static int yy_get_next_buffer (void) YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; @@ -1428,17 +1437,17 @@ static int yy_get_next_buffer (void) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); + yyg->yy_n_chars, num_to_read ); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } - if ( (yy_n_chars) == 0 ) + if ( yyg->yy_n_chars == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); + yyrestart( yyin , yyscanner); } else @@ -1452,42 +1461,43 @@ static int yy_get_next_buffer (void) else ret_val = EOB_ACT_CONTINUE_SCAN; - if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( - (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); /* "- 2" to take care of EOB's */ YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); } - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ - static yy_state_type yy_get_previous_state (void) + static yy_state_type yy_get_previous_state (yyscan_t yyscanner) { yy_state_type yy_current_state; char *yy_cp; - - yy_current_state = (yy_start); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + yy_current_state = yyg->yy_start; + + for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) { YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1506,16 +1516,17 @@ static int yy_get_next_buffer (void) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) { int yy_is_jam; - char *yy_cp = (yy_c_buf_p); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ + char *yy_cp = yyg->yy_c_buf_p; YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1526,7 +1537,8 @@ static int yy_get_next_buffer (void) yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; yy_is_jam = (yy_current_state == 68); - return yy_is_jam ? 0 : yy_current_state; + (void)yyg; + return yy_is_jam ? 0 : yy_current_state; } #ifndef YY_NO_UNPUT @@ -1535,32 +1547,33 @@ static int yy_get_next_buffer (void) #ifndef YY_NO_INPUT #ifdef __cplusplus - static int yyinput (void) + static int yyinput (yyscan_t yyscanner) #else - static int input (void) + static int input (yyscan_t yyscanner) #endif { int c; - - *(yy_c_buf_p) = (yy_hold_char); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; + *yyg->yy_c_buf_p = '\0'; else { /* need more input */ - int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); - ++(yy_c_buf_p); + int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr); + ++yyg->yy_c_buf_p; - switch ( yy_get_next_buffer( ) ) + switch ( yy_get_next_buffer( yyscanner ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() @@ -1574,38 +1587,40 @@ static int yy_get_next_buffer (void) */ /* Reset buffer status. */ - yyrestart( yyin ); + yyrestart( yyin , yyscanner); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { - if ( yywrap( ) ) + if ( yywrap( yyscanner ) ) return 0; - if ( ! (yy_did_buffer_switch_on_eof) ) + if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; #ifdef __cplusplus - return yyinput(); + return yyinput(yyscanner); #else - return input(); + return input(yyscanner); #endif } case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; break; } } } - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; if ( c == '\n' ) - yylineno++; + do{ yylineno++; + yycolumn=0; + }while(0) ; return c; @@ -1614,76 +1629,79 @@ static int yy_get_next_buffer (void) /** Immediately switch to a different input stream. * @param input_file A readable stream. - * + * @param yyscanner The scanner object. * @note This function does not reset the start condition to @c INITIAL . */ - void yyrestart (FILE * input_file ) + void yyrestart (FILE * input_file , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); } - yy_init_buffer( YY_CURRENT_BUFFER, input_file ); - yy_load_buffer_state( ); + yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner); + yy_load_buffer_state( yyscanner ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. - * + * @param yyscanner The scanner object. */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* TODO. We should be able to replace this entire function body * with * yypop_buffer_state(); * yypush_buffer_state(new_buffer); */ - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); if ( YY_CURRENT_BUFFER == new_buffer ) return; if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); + yy_load_buffer_state( yyscanner ); /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag * is looked at is after yywrap() is called, so it's safe * to go ahead and always set it. */ - (yy_did_buffer_switch_on_eof) = 1; + yyg->yy_did_buffer_switch_on_eof = 1; } -static void yy_load_buffer_state (void) +static void yy_load_buffer_state (yyscan_t yyscanner) { - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); + yyg->yy_hold_char = *yyg->yy_c_buf_p; } /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * + * @param yyscanner The scanner object. * @return the allocated buffer state. */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner) { YY_BUFFER_STATE b; - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1692,24 +1710,25 @@ static void yy_load_buffer_state (void) /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; - yy_init_buffer( b, file ); + yy_init_buffer( b, file , yyscanner); return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() - * + * @param yyscanner The scanner object. */ - void yy_delete_buffer (YY_BUFFER_STATE b ) + void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) return; @@ -1717,21 +1736,22 @@ static void yy_load_buffer_state (void) YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) - yyfree( (void *) b->yy_ch_buf ); + yyfree( (void *) b->yy_ch_buf , yyscanner ); - yyfree( (void *) b ); + yyfree( (void *) b , yyscanner ); } /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) { int oerrno = errno; - - yy_flush_buffer( b ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yy_flush_buffer( b , yyscanner); b->yy_input_file = file; b->yy_fill_buffer = 1; @@ -1752,11 +1772,12 @@ static void yy_load_buffer_state (void) /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * + * @param yyscanner The scanner object. */ - void yy_flush_buffer (YY_BUFFER_STATE b ) + void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) { - if ( ! b ) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) return; b->yy_n_chars = 0; @@ -1774,114 +1795,117 @@ static void yy_load_buffer_state (void) b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); + yy_load_buffer_state( yyscanner ); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. - * + * @param yyscanner The scanner object. */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) { - if (new_buffer == NULL) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (new_buffer == NULL) return; - yyensure_buffer_stack(); + yyensure_buffer_stack(yyscanner); /* This block is copied from yy_switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; + yyg->yy_buffer_stack_top++; YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + yy_load_buffer_state( yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. - * + * @param yyscanner The scanner object. */ -void yypop_buffer_state (void) +void yypop_buffer_state (yyscan_t yyscanner) { - if (!YY_CURRENT_BUFFER) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (!YY_CURRENT_BUFFER) return; - yy_delete_buffer(YY_CURRENT_BUFFER ); + yy_delete_buffer(YY_CURRENT_BUFFER , yyscanner); YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + yy_load_buffer_state( yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void yyensure_buffer_stack (void) +static void yyensure_buffer_stack (yyscan_t yyscanner) { yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (!yyg->yy_buffer_stack) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; return; } - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ /* Increase the buffer to prepare for a possible push. */ yy_size_t grow_size = 8 /* arbitrary grow size */; - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc + (yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; + memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); + yyg->yy_buffer_stack_max = num_to_alloc; } } /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) { YY_BUFFER_STATE b; @@ -1891,7 +1915,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /* They forgot to leave room for the EOB's. */ return NULL; - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); @@ -1905,7 +1929,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; - yy_switch_to_buffer( b ); + yy_switch_to_buffer( b , yyscanner ); return b; } @@ -1913,25 +1937,25 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /** Setup the input buffer state to scan a string. The next call to yylex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ -YY_BUFFER_STATE yy_scan_string (const char * yystr ) +YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner) { - return yy_scan_bytes( yystr, (int) strlen(yystr) ); + return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner); } /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner) { YY_BUFFER_STATE b; char *buf; @@ -1940,7 +1964,7 @@ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) /* Get memory for full buffer, including space for trailing EOB's. */ n = (yy_size_t) (_yybytes_len + 2); - buf = (char *) yyalloc( n ); + buf = (char *) yyalloc( n , yyscanner ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); @@ -1949,7 +1973,7 @@ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - b = yy_scan_buffer( buf, n ); + b = yy_scan_buffer( buf, n , yyscanner); if ( ! b ) YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); @@ -1965,9 +1989,11 @@ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) #define YY_EXIT_FAILURE 2 #endif -static void yynoreturn yy_fatal_error (const char* msg ) +static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner) { - fprintf( stderr, "%s\n", msg ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } @@ -1980,109 +2006,249 @@ static void yynoreturn yy_fatal_error (const char* msg ) /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ yyleng = yyless_macro_arg; \ } \ while ( 0 ) /* Accessor methods (get/set functions) to struct members. */ -/** Get the current line number. - * +/** Get the user-defined data for this scanner. + * @param yyscanner The scanner object. */ -int yyget_lineno (void) +YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyextra; +} + +/** Get the current line number. + * @param yyscanner The scanner object. + */ +int yyget_lineno (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; return yylineno; } -/** Get the input stream. - * +/** Get the current column number. + * @param yyscanner The scanner object. */ -FILE *yyget_in (void) +int yyget_column (yyscan_t yyscanner) { - return yyin; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yycolumn; +} + +/** Get the input stream. + * @param yyscanner The scanner object. + */ +FILE *yyget_in (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyin; } /** Get the output stream. - * + * @param yyscanner The scanner object. */ -FILE *yyget_out (void) +FILE *yyget_out (yyscan_t yyscanner) { - return yyout; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyout; } /** Get the length of the current token. - * + * @param yyscanner The scanner object. */ -int yyget_leng (void) +int yyget_leng (yyscan_t yyscanner) { - return yyleng; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyleng; } /** Get the current token. - * + * @param yyscanner The scanner object. */ -char *yyget_text (void) +char *yyget_text (yyscan_t yyscanner) { - return yytext; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yytext; +} + +/** Set the user-defined data. This data is never touched by the scanner. + * @param user_defined The data to be associated with this scanner. + * @param yyscanner The scanner object. + */ +void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyextra = user_defined ; } /** Set the current line number. * @param _line_number line number - * + * @param yyscanner The scanner object. */ -void yyset_lineno (int _line_number ) +void yyset_lineno (int _line_number , yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* lineno is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + YY_FATAL_ERROR( "yyset_lineno called with no buffer" ); yylineno = _line_number; } +/** Set the current column. + * @param _column_no column number + * @param yyscanner The scanner object. + */ +void yyset_column (int _column_no , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* column is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + YY_FATAL_ERROR( "yyset_column called with no buffer" ); + + yycolumn = _column_no; +} + /** Set the input stream. This does not discard the current * input buffer. * @param _in_str A readable stream. - * + * @param yyscanner The scanner object. * @see yy_switch_to_buffer */ -void yyset_in (FILE * _in_str ) +void yyset_in (FILE * _in_str , yyscan_t yyscanner) { - yyin = _in_str ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyin = _in_str ; } -void yyset_out (FILE * _out_str ) +void yyset_out (FILE * _out_str , yyscan_t yyscanner) { - yyout = _out_str ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyout = _out_str ; } -int yyget_debug (void) +int yyget_debug (yyscan_t yyscanner) { - return yy_flex_debug; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yy_flex_debug; } -void yyset_debug (int _bdebug ) +void yyset_debug (int _bdebug , yyscan_t yyscanner) { - yy_flex_debug = _bdebug ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_flex_debug = _bdebug ; } -static int yy_init_globals (void) +/* Accessor methods for yylval and yylloc */ + +YYSTYPE * yyget_lval (yyscan_t yyscanner) { - /* Initialization is the same as for the non-reentrant scanner. + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yylval; +} + +void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yylval = yylval_param; +} + +/* User-visible API */ + +/* yylex_init is special because it creates the scanner itself, so it is + * the ONLY reentrant function that doesn't take the scanner as the last argument. + * That's why we explicitly handle the declaration, instead of using our macros. + */ +int yylex_init(yyscan_t* ptr_yy_globals) +{ + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + return yy_init_globals ( *ptr_yy_globals ); +} + +/* yylex_init_extra has the same functionality as yylex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to yyalloc in + * the yyextra field. + */ +int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals ) +{ + struct yyguts_t dummy_yyguts; + + yyset_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + yyset_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); +} + +static int yy_init_globals (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Initialization is the same as for the non-reentrant scanner. * This function is called from yylex_destroy(), so don't allocate here. */ - /* We do not touch yylineno unless the option is enabled. */ - yylineno = 1; - - (yy_buffer_stack) = NULL; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = NULL; - (yy_init) = 0; - (yy_start) = 0; + yyg->yy_buffer_stack = NULL; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = NULL; + yyg->yy_init = 0; + yyg->yy_start = 0; + + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; /* Defined in main.c */ #ifdef YY_STDINIT @@ -2100,24 +2266,32 @@ static int yy_init_globals (void) } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) +int yylex_destroy (yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ - yy_delete_buffer( YY_CURRENT_BUFFER ); + yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner ); YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); + yypop_buffer_state(yyscanner); } /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; + yyfree(yyg->yy_buffer_stack , yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + yyfree( yyg->yy_start_stack , yyscanner ); + yyg->yy_start_stack = NULL; /* Reset the globals. This is important in a non-reentrant scanner so the next time * yylex() is called, initialization will occur. */ - yy_init_globals( ); + yy_init_globals( yyscanner); + /* Destroy the main struct (reentrant only). */ + yyfree ( yyscanner , yyscanner ); + yyscanner = NULL; return 0; } @@ -2126,9 +2300,11 @@ int yylex_destroy (void) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, const char * s2, int n ) +static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; @@ -2136,7 +2312,7 @@ static void yy_flex_strncpy (char* s1, const char * s2, int n ) #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (const char * s ) +static int yy_flex_strlen (const char * s , yyscan_t yyscanner) { int n; for ( n = 0; s[n]; ++n ) @@ -2146,14 +2322,18 @@ static int yy_flex_strlen (const char * s ) } #endif -void *yyalloc (yy_size_t size ) +void *yyalloc (yy_size_t size , yyscan_t yyscanner) { - return malloc(size); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + return malloc(size); } -void *yyrealloc (void * ptr, yy_size_t size ) +void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter @@ -2164,17 +2344,19 @@ void *yyrealloc (void * ptr, yy_size_t size ) return realloc(ptr, size); } -void yyfree (void * ptr ) +void yyfree (void * ptr , yyscan_t yyscanner) { - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" -#line 90 "template_parser.l" +#line 103 "template_parser.l" -int template_wrap() +int template_wrap(yyscan_t scanner) { return 1; } diff --git a/src/parsers/template_parser.h b/src/parsers/template_parser.h new file mode 100644 index 0000000000..652c368757 --- /dev/null +++ b/src/parsers/template_parser.h @@ -0,0 +1,718 @@ +#ifndef template_HEADER_H +#define template_HEADER_H 1 +#define template_IN_HEADER 1 + +#line 5 "template_parser.h" + +#line 7 "template_parser.h" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 4 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +#ifdef yy_create_buffer +#define template__create_buffer_ALREADY_DEFINED +#else +#define yy_create_buffer template__create_buffer +#endif + +#ifdef yy_delete_buffer +#define template__delete_buffer_ALREADY_DEFINED +#else +#define yy_delete_buffer template__delete_buffer +#endif + +#ifdef yy_scan_buffer +#define template__scan_buffer_ALREADY_DEFINED +#else +#define yy_scan_buffer template__scan_buffer +#endif + +#ifdef yy_scan_string +#define template__scan_string_ALREADY_DEFINED +#else +#define yy_scan_string template__scan_string +#endif + +#ifdef yy_scan_bytes +#define template__scan_bytes_ALREADY_DEFINED +#else +#define yy_scan_bytes template__scan_bytes +#endif + +#ifdef yy_init_buffer +#define template__init_buffer_ALREADY_DEFINED +#else +#define yy_init_buffer template__init_buffer +#endif + +#ifdef yy_flush_buffer +#define template__flush_buffer_ALREADY_DEFINED +#else +#define yy_flush_buffer template__flush_buffer +#endif + +#ifdef yy_load_buffer_state +#define template__load_buffer_state_ALREADY_DEFINED +#else +#define yy_load_buffer_state template__load_buffer_state +#endif + +#ifdef yy_switch_to_buffer +#define template__switch_to_buffer_ALREADY_DEFINED +#else +#define yy_switch_to_buffer template__switch_to_buffer +#endif + +#ifdef yypush_buffer_state +#define template_push_buffer_state_ALREADY_DEFINED +#else +#define yypush_buffer_state template_push_buffer_state +#endif + +#ifdef yypop_buffer_state +#define template_pop_buffer_state_ALREADY_DEFINED +#else +#define yypop_buffer_state template_pop_buffer_state +#endif + +#ifdef yyensure_buffer_stack +#define template_ensure_buffer_stack_ALREADY_DEFINED +#else +#define yyensure_buffer_stack template_ensure_buffer_stack +#endif + +#ifdef yylex +#define template_lex_ALREADY_DEFINED +#else +#define yylex template_lex +#endif + +#ifdef yyrestart +#define template_restart_ALREADY_DEFINED +#else +#define yyrestart template_restart +#endif + +#ifdef yylex_init +#define template_lex_init_ALREADY_DEFINED +#else +#define yylex_init template_lex_init +#endif + +#ifdef yylex_init_extra +#define template_lex_init_extra_ALREADY_DEFINED +#else +#define yylex_init_extra template_lex_init_extra +#endif + +#ifdef yylex_destroy +#define template_lex_destroy_ALREADY_DEFINED +#else +#define yylex_destroy template_lex_destroy +#endif + +#ifdef yyget_debug +#define template_get_debug_ALREADY_DEFINED +#else +#define yyget_debug template_get_debug +#endif + +#ifdef yyset_debug +#define template_set_debug_ALREADY_DEFINED +#else +#define yyset_debug template_set_debug +#endif + +#ifdef yyget_extra +#define template_get_extra_ALREADY_DEFINED +#else +#define yyget_extra template_get_extra +#endif + +#ifdef yyset_extra +#define template_set_extra_ALREADY_DEFINED +#else +#define yyset_extra template_set_extra +#endif + +#ifdef yyget_in +#define template_get_in_ALREADY_DEFINED +#else +#define yyget_in template_get_in +#endif + +#ifdef yyset_in +#define template_set_in_ALREADY_DEFINED +#else +#define yyset_in template_set_in +#endif + +#ifdef yyget_out +#define template_get_out_ALREADY_DEFINED +#else +#define yyget_out template_get_out +#endif + +#ifdef yyset_out +#define template_set_out_ALREADY_DEFINED +#else +#define yyset_out template_set_out +#endif + +#ifdef yyget_leng +#define template_get_leng_ALREADY_DEFINED +#else +#define yyget_leng template_get_leng +#endif + +#ifdef yyget_text +#define template_get_text_ALREADY_DEFINED +#else +#define yyget_text template_get_text +#endif + +#ifdef yyget_lineno +#define template_get_lineno_ALREADY_DEFINED +#else +#define yyget_lineno template_get_lineno +#endif + +#ifdef yyset_lineno +#define template_set_lineno_ALREADY_DEFINED +#else +#define yyset_lineno template_set_lineno +#endif + +#ifdef yyget_column +#define template_get_column_ALREADY_DEFINED +#else +#define yyget_column template_get_column +#endif + +#ifdef yyset_column +#define template_set_column_ALREADY_DEFINED +#else +#define yyset_column template_set_column +#endif + +#ifdef yywrap +#define template_wrap_ALREADY_DEFINED +#else +#define yywrap template_wrap +#endif + +#ifdef yyget_lval +#define template_get_lval_ALREADY_DEFINED +#else +#define yyget_lval template_get_lval +#endif + +#ifdef yyset_lval +#define template_set_lval_ALREADY_DEFINED +#else +#define yyset_lval template_set_lval +#endif + +#ifdef yyalloc +#define template_alloc_ALREADY_DEFINED +#else +#define yyalloc template_alloc +#endif + +#ifdef yyrealloc +#define template_realloc_ALREADY_DEFINED +#else +#define yyrealloc template_realloc +#endif + +#ifdef yyfree +#define template_free_ALREADY_DEFINED +#else +#define yyfree template_free +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ + +/* TODO: this is always defined, so inline it */ +#define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) +#else +#define yynoreturn +#endif + +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +void yyrestart ( FILE *input_file , yyscan_t yyscanner ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner ); +void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +void yypop_buffer_state ( yyscan_t yyscanner ); + +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner ); + +void *yyalloc ( yy_size_t , yyscan_t yyscanner ); +void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner ); +void yyfree ( void * , yyscan_t yyscanner ); + +/* Begin user sect3 */ + +#define yytext_ptr yytext_r + +#ifdef YY_HEADER_EXPORT_START_CONDITIONS +#define INITIAL 0 +#define VALUE 1 + +#endif + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +int yylex_init (yyscan_t* scanner); + +int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy ( yyscan_t yyscanner ); + +int yyget_debug ( yyscan_t yyscanner ); + +void yyset_debug ( int debug_flag , yyscan_t yyscanner ); + +YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner ); + +void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); + +FILE *yyget_in ( yyscan_t yyscanner ); + +void yyset_in ( FILE * _in_str , yyscan_t yyscanner ); + +FILE *yyget_out ( yyscan_t yyscanner ); + +void yyset_out ( FILE * _out_str , yyscan_t yyscanner ); + + int yyget_leng ( yyscan_t yyscanner ); + +char *yyget_text ( yyscan_t yyscanner ); + +int yyget_lineno ( yyscan_t yyscanner ); + +void yyset_lineno ( int _line_number , yyscan_t yyscanner ); + +int yyget_column ( yyscan_t yyscanner ); + +void yyset_column ( int _column_no , yyscan_t yyscanner ); + +YYSTYPE * yyget_lval ( yyscan_t yyscanner ); + +void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap ( yyscan_t yyscanner ); +#else +extern int yywrap ( yyscan_t yyscanner ); +#endif +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen ( const char * , yyscan_t yyscanner); +#endif + +#ifndef YY_NO_INPUT + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner); + +#define YY_DECL int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner) +#endif /* !YY_DECL */ + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +#undef YY_NEW_FILE +#undef YY_FLUSH_BUFFER +#undef yy_set_bol +#undef yy_new_buffer +#undef yy_set_interactive +#undef YY_DO_BEFORE_ACTION + +#ifdef YY_DECL_IS_OURS +#undef YY_DECL_IS_OURS +#undef YY_DECL +#endif + +#ifndef template__create_buffer_ALREADY_DEFINED +#undef yy_create_buffer +#endif +#ifndef template__delete_buffer_ALREADY_DEFINED +#undef yy_delete_buffer +#endif +#ifndef template__scan_buffer_ALREADY_DEFINED +#undef yy_scan_buffer +#endif +#ifndef template__scan_string_ALREADY_DEFINED +#undef yy_scan_string +#endif +#ifndef template__scan_bytes_ALREADY_DEFINED +#undef yy_scan_bytes +#endif +#ifndef template__init_buffer_ALREADY_DEFINED +#undef yy_init_buffer +#endif +#ifndef template__flush_buffer_ALREADY_DEFINED +#undef yy_flush_buffer +#endif +#ifndef template__load_buffer_state_ALREADY_DEFINED +#undef yy_load_buffer_state +#endif +#ifndef template__switch_to_buffer_ALREADY_DEFINED +#undef yy_switch_to_buffer +#endif +#ifndef template_push_buffer_state_ALREADY_DEFINED +#undef yypush_buffer_state +#endif +#ifndef template_pop_buffer_state_ALREADY_DEFINED +#undef yypop_buffer_state +#endif +#ifndef template_ensure_buffer_stack_ALREADY_DEFINED +#undef yyensure_buffer_stack +#endif +#ifndef template_lex_ALREADY_DEFINED +#undef yylex +#endif +#ifndef template_restart_ALREADY_DEFINED +#undef yyrestart +#endif +#ifndef template_lex_init_ALREADY_DEFINED +#undef yylex_init +#endif +#ifndef template_lex_init_extra_ALREADY_DEFINED +#undef yylex_init_extra +#endif +#ifndef template_lex_destroy_ALREADY_DEFINED +#undef yylex_destroy +#endif +#ifndef template_get_debug_ALREADY_DEFINED +#undef yyget_debug +#endif +#ifndef template_set_debug_ALREADY_DEFINED +#undef yyset_debug +#endif +#ifndef template_get_extra_ALREADY_DEFINED +#undef yyget_extra +#endif +#ifndef template_set_extra_ALREADY_DEFINED +#undef yyset_extra +#endif +#ifndef template_get_in_ALREADY_DEFINED +#undef yyget_in +#endif +#ifndef template_set_in_ALREADY_DEFINED +#undef yyset_in +#endif +#ifndef template_get_out_ALREADY_DEFINED +#undef yyget_out +#endif +#ifndef template_set_out_ALREADY_DEFINED +#undef yyset_out +#endif +#ifndef template_get_leng_ALREADY_DEFINED +#undef yyget_leng +#endif +#ifndef template_get_text_ALREADY_DEFINED +#undef yyget_text +#endif +#ifndef template_get_lineno_ALREADY_DEFINED +#undef yyget_lineno +#endif +#ifndef template_set_lineno_ALREADY_DEFINED +#undef yyset_lineno +#endif +#ifndef template_get_column_ALREADY_DEFINED +#undef yyget_column +#endif +#ifndef template_set_column_ALREADY_DEFINED +#undef yyset_column +#endif +#ifndef template_wrap_ALREADY_DEFINED +#undef yywrap +#endif +#ifndef template_get_lval_ALREADY_DEFINED +#undef yyget_lval +#endif +#ifndef template_set_lval_ALREADY_DEFINED +#undef yyset_lval +#endif +#ifndef template_get_lloc_ALREADY_DEFINED +#undef yyget_lloc +#endif +#ifndef template_set_lloc_ALREADY_DEFINED +#undef yyset_lloc +#endif +#ifndef template_alloc_ALREADY_DEFINED +#undef yyalloc +#endif +#ifndef template_realloc_ALREADY_DEFINED +#undef yyrealloc +#endif +#ifndef template_free_ALREADY_DEFINED +#undef yyfree +#endif +#ifndef template_text_ALREADY_DEFINED +#undef yytext +#endif +#ifndef template_leng_ALREADY_DEFINED +#undef yyleng +#endif +#ifndef template_in_ALREADY_DEFINED +#undef yyin +#endif +#ifndef template_out_ALREADY_DEFINED +#undef yyout +#endif +#ifndef template__flex_debug_ALREADY_DEFINED +#undef yy_flex_debug +#endif +#ifndef template_lineno_ALREADY_DEFINED +#undef yylineno +#endif +#ifndef template_tables_fload_ALREADY_DEFINED +#undef yytables_fload +#endif +#ifndef template_tables_destroy_ALREADY_DEFINED +#undef yytables_destroy +#endif +#ifndef template_TABLES_NAME_ALREADY_DEFINED +#undef yyTABLES_NAME +#endif + +#line 103 "template_parser.l" + + +#line 716 "template_parser.h" +#undef template_IN_HEADER +#endif /* template_HEADER_H */ diff --git a/src/template/template_parser.l b/src/parsers/template_parser.l similarity index 82% rename from src/template/template_parser.l rename to src/parsers/template_parser.l index b0a4ba6eeb..1ce4d6784b 100644 --- a/src/template/template_parser.l +++ b/src/parsers/template_parser.l @@ -25,8 +25,8 @@ #define YY_NO_INPUT -#define YY_DECL int template_lex (YYSTYPE *lvalp, YYLTYPE *llocp, \ - mem_collector *mc) +#define YY_DECL int template_lex (YYSTYPE *yylval_param, YYLTYPE *llocp, \ + mem_collector *mc, yyscan_t yyscanner) #define YY_USER_ACTION llocp->first_line = yylineno; \ llocp->first_column = llocp->last_column; \ @@ -35,8 +35,11 @@ %option nounput %option prefix="template_" -%option outfile="template_parser.c" +%option outfile="template_parser.cc" +%option header-file="template_parser.h" +%option bison-bridge %option yylineno +%option reentrant %x VALUE @@ -54,7 +57,7 @@ CDATA "\]\]\>" /* ------------------------------------------------------------------------- */ /* Variable: Alpha numeric charatcers and '_' */ /* ------------------------------------------------------------------------- */ -[[:alnum:]_]+ { lvalp->val_str = mem_collector_strdup(mc,yytext); +[[:alnum:]_]+ { yylval_param->val_str = mem_collector_strdup(mc,yytext); return VARIABLE; } /* ------------------------------------------------------------------------ */ @@ -78,17 +81,27 @@ CDATA "\]\]\>" /* - Anything but =,][# and blanks */ /* ------------------------------------------------------------------------ */ -.*{CDATA}.* { BEGIN(INITIAL); return CCDATA;} +.*{CDATA}.* { + BEGIN(INITIAL); + return CCDATA; +} -\"{VALUE_STRING}\" { lvalp->val_str = mem_collector_strdup(mc,yytext+1); - lvalp->val_str[yyleng-2] = '\0'; - BEGIN(INITIAL); return STRING; } +\"{VALUE_STRING}\" { + yylval_param->val_str = mem_collector_strdup(mc,yytext+1); + yylval_param->val_str[yyleng-2] = '\0'; + BEGIN(INITIAL); + return STRING; +} + +{STRING} { + yylval_param->val_str = mem_collector_strdup(mc,yytext); + BEGIN(INITIAL); + return STRING; +} -{STRING} { lvalp->val_str = mem_collector_strdup(mc,yytext); - BEGIN(INITIAL); return STRING;} %% -int template_wrap() +int template_wrap(yyscan_t scanner) { return 1; } diff --git a/src/template/template_syntax.cc b/src/parsers/template_syntax.cc similarity index 94% rename from src/template/template_syntax.cc rename to src/parsers/template_syntax.cc index f138c8dc48..0a0183e147 100644 --- a/src/template/template_syntax.cc +++ b/src/parsers/template_syntax.cc @@ -60,66 +60,45 @@ /* Substitute the variable and function names. */ -#define yyparse template__parse -#define yylex template__lex -#define yyerror template__error -#define yydebug template__debug -#define yynerrs template__nerrs +#define yyparse template_parse +#define yylex template_lex +#define yyerror template_error +#define yydebug template_debug +#define yynerrs template_nerrs /* Copy the first part of user declarations. */ #line 17 "template_syntax.y" /* yacc.c:339 */ -#include -#include -#include -#include - -#include -#include -#include #include "template_syntax.h" -#include "Template.h" - -#define template__lex template_lex +#include "template_parser.h" +#include "NebulaUtil.h" #define YYERROR_VERBOSE -#define TEMPLATE_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \ -(int(*)(int))toupper) -extern "C" + +void template_error( YYLTYPE * llocp, mem_collector * mc, Template * tmpl, + char ** error_msg, yyscan_t scanner, const char * str); + +int template_lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc, + yyscan_t scanner); + +int template_parse(Template * tmpl, char ** errmsg, yyscan_t scanner) { - #include "mem_collector.h" + mem_collector mc; + int rc; - void template__error( - YYLTYPE * llocp, - mem_collector * mc, - Template * tmpl, - char ** error_msg, - const char * str); + mem_collector_init(&mc); - int template__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + rc = template_parse(&mc, tmpl, errmsg, scanner); - int template__parse(mem_collector * mc, Template * tmpl, char ** errmsg); + mem_collector_cleanup(&mc); - int template_parse(Template * tmpl, char ** errmsg) - { - mem_collector mc; - int rc; - - mem_collector_init(&mc); - - rc = template__parse(&mc, tmpl, errmsg); - - mem_collector_cleanup(&mc); - - return rc; - } - - static string& unescape (string &str); + return rc; } +static string& unescape (string &str); -#line 123 "template_syntax.cc" /* yacc.c:339 */ +#line 102 "template_syntax.cc" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -146,8 +125,29 @@ extern "C" # define YYDEBUG 0 #endif #if YYDEBUG -extern int template__debug; +extern int template_debug; #endif +/* "%code requires" blocks. */ +#line 47 "template_syntax.y" /* yacc.c:355 */ + +#include +#include +#include +#include + +#include +#include +#include + +#include "mem_collector.h" + +#include "Template.h" + +typedef void * yyscan_t; + +int template_parse(Template * tmpl, char ** errmsg, yyscan_t scanner); + +#line 151 "template_syntax.cc" /* yacc.c:355 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -199,7 +199,7 @@ struct YYLTYPE -int template__parse (mem_collector * mc, Template * tmpl, char ** error_msg); +int template_parse (mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner); #endif /* !YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED */ @@ -635,7 +635,7 @@ do \ } \ else \ { \ - yyerror (&yylloc, mc, tmpl, error_msg, YY_("syntax error: cannot back up")); \ + yyerror (&yylloc, mc, tmpl, error_msg, scanner, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (0) @@ -737,7 +737,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, Location, mc, tmpl, error_msg); \ + Type, Value, Location, mc, tmpl, error_msg, scanner); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -748,7 +748,7 @@ do { \ `----------------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) { FILE *yyo = yyoutput; YYUSE (yyo); @@ -756,6 +756,7 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue YYUSE (mc); YYUSE (tmpl); YYUSE (error_msg); + YYUSE (scanner); if (!yyvaluep) return; # ifdef YYPRINT @@ -771,14 +772,14 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue `--------------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) { YYFPRINTF (yyoutput, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); YY_LOCATION_PRINT (yyoutput, *yylocationp); YYFPRINTF (yyoutput, ": "); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, tmpl, error_msg); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, tmpl, error_msg, scanner); YYFPRINTF (yyoutput, ")"); } @@ -811,7 +812,7 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, Template * tmpl, char ** error_msg) +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) { unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; @@ -825,7 +826,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule yy_symbol_print (stderr, yystos[yyssp[yyi + 1 - yynrhs]], &(yyvsp[(yyi + 1) - (yynrhs)]) - , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, tmpl, error_msg); + , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, tmpl, error_msg, scanner); YYFPRINTF (stderr, "\n"); } } @@ -833,7 +834,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, yylsp, Rule, mc, tmpl, error_msg); \ + yy_reduce_print (yyssp, yyvsp, yylsp, Rule, mc, tmpl, error_msg, scanner); \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that @@ -1091,13 +1092,14 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) { YYUSE (yyvaluep); YYUSE (yylocationp); YYUSE (mc); YYUSE (tmpl); YYUSE (error_msg); + YYUSE (scanner); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); @@ -1115,7 +1117,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio `----------*/ int -yyparse (mem_collector * mc, Template * tmpl, char ** error_msg) +yyparse (mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner) { /* The lookahead symbol. */ int yychar; @@ -1309,7 +1311,7 @@ yybackup: if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (&yylval, &yylloc, mc); + yychar = yylex (&yylval, &yylloc, mc, scanner); } if (yychar <= YYEOF) @@ -1399,7 +1401,7 @@ yyreduce: tmpl->set(pattr); } -#line 1403 "template_syntax.cc" /* yacc.c:1646 */ +#line 1405 "template_syntax.cc" /* yacc.c:1646 */ break; case 7: @@ -1416,7 +1418,7 @@ yyreduce: delete amap; } -#line 1420 "template_syntax.cc" /* yacc.c:1646 */ +#line 1422 "template_syntax.cc" /* yacc.c:1646 */ break; case 8: @@ -1429,7 +1431,7 @@ yyreduce: tmpl->set(pattr); } -#line 1433 "template_syntax.cc" /* yacc.c:1646 */ +#line 1435 "template_syntax.cc" /* yacc.c:1646 */ break; case 9: @@ -1443,7 +1445,7 @@ yyreduce: tmpl->set(pattr); } -#line 1447 "template_syntax.cc" /* yacc.c:1646 */ +#line 1449 "template_syntax.cc" /* yacc.c:1646 */ break; case 10: @@ -1451,7 +1453,7 @@ yyreduce: { YYABORT; } -#line 1455 "template_syntax.cc" /* yacc.c:1646 */ +#line 1457 "template_syntax.cc" /* yacc.c:1646 */ break; case 11: @@ -1461,14 +1463,14 @@ yyreduce: string name((yyvsp[-2].val_str)); string value((yyvsp[0].val_str)); - TEMPLATE_TO_UPPER(name); + one_util::toupper(name); vattr = new map; vattr->insert(make_pair(name,unescape(value))); (yyval.val_attr) = static_cast(vattr); } -#line 1472 "template_syntax.cc" /* yacc.c:1646 */ +#line 1474 "template_syntax.cc" /* yacc.c:1646 */ break; case 12: @@ -1478,18 +1480,18 @@ yyreduce: string value((yyvsp[0].val_str)); map * attrmap; - TEMPLATE_TO_UPPER(name); + one_util::toupper(name); attrmap = static_cast *>((yyvsp[-4].val_attr)); attrmap->insert(make_pair(name,unescape(value))); (yyval.val_attr) = (yyvsp[-4].val_attr); } -#line 1489 "template_syntax.cc" /* yacc.c:1646 */ +#line 1491 "template_syntax.cc" /* yacc.c:1646 */ break; -#line 1493 "template_syntax.cc" /* yacc.c:1646 */ +#line 1495 "template_syntax.cc" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1540,7 +1542,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (&yylloc, mc, tmpl, error_msg, YY_("syntax error")); + yyerror (&yylloc, mc, tmpl, error_msg, scanner, YY_("syntax error")); #else # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ yyssp, yytoken) @@ -1567,7 +1569,7 @@ yyerrlab: yymsgp = yymsg; } } - yyerror (&yylloc, mc, tmpl, error_msg, yymsgp); + yyerror (&yylloc, mc, tmpl, error_msg, scanner, yymsgp); if (yysyntax_error_status == 2) goto yyexhaustedlab; } @@ -1591,7 +1593,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval, &yylloc, mc, tmpl, error_msg); + yytoken, &yylval, &yylloc, mc, tmpl, error_msg, scanner); yychar = YYEMPTY; } } @@ -1648,7 +1650,7 @@ yyerrlab1: yyerror_range[1] = *yylsp; yydestruct ("Error: popping", - yystos[yystate], yyvsp, yylsp, mc, tmpl, error_msg); + yystos[yystate], yyvsp, yylsp, mc, tmpl, error_msg, scanner); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1690,7 +1692,7 @@ yyabortlab: | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (&yylloc, mc, tmpl, error_msg, YY_("memory exhausted")); + yyerror (&yylloc, mc, tmpl, error_msg, scanner, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif @@ -1702,7 +1704,7 @@ yyreturn: user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, mc, tmpl, error_msg); + yytoken, &yylval, &yylloc, mc, tmpl, error_msg, scanner); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ @@ -1711,7 +1713,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yylsp, mc, tmpl, error_msg); + yystos[*yyssp], yyvsp, yylsp, mc, tmpl, error_msg, scanner); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1739,11 +1741,12 @@ string& unescape (string &str) return str; } -extern "C" void template__error( +void template_error( YYLTYPE * llocp, mem_collector * mc, Template * tmpl, char ** error_msg, + yyscan_t scanner, const char * str) { int length; diff --git a/src/template/template_syntax.h b/src/parsers/template_syntax.h similarity index 81% rename from src/template/template_syntax.h rename to src/parsers/template_syntax.h index dce3431d13..f77fa1871b 100644 --- a/src/template/template_syntax.h +++ b/src/parsers/template_syntax.h @@ -37,8 +37,29 @@ # define YYDEBUG 0 #endif #if YYDEBUG -extern int template__debug; +extern int template_debug; #endif +/* "%code requires" blocks. */ +#line 47 "template_syntax.y" /* yacc.c:1909 */ + +#include +#include +#include +#include + +#include +#include +#include + +#include "mem_collector.h" + +#include "Template.h" + +typedef void * yyscan_t; + +int template_parse(Template * tmpl, char ** errmsg, yyscan_t scanner); + +#line 63 "template_syntax.hh" /* yacc.c:1909 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -66,7 +87,7 @@ union YYSTYPE char * val_str; void * val_attr; -#line 70 "template_syntax.hh" /* yacc.c:1909 */ +#line 91 "template_syntax.hh" /* yacc.c:1909 */ }; typedef union YYSTYPE YYSTYPE; @@ -88,4 +109,8 @@ struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif + + +int template_parse (mem_collector * mc, Template * tmpl, char ** error_msg, yyscan_t scanner); + #endif /* !YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED */ diff --git a/src/template/template_syntax.y b/src/parsers/template_syntax.y similarity index 81% rename from src/template/template_syntax.y rename to src/parsers/template_syntax.y index 0cf5fec654..7ec3ff32e6 100644 --- a/src/template/template_syntax.y +++ b/src/parsers/template_syntax.y @@ -15,6 +15,36 @@ /* -------------------------------------------------------------------------- */ %{ +#include "template_syntax.h" +#include "template_parser.h" +#include "NebulaUtil.h" + +#define YYERROR_VERBOSE + +void template_error( YYLTYPE * llocp, mem_collector * mc, Template * tmpl, + char ** error_msg, yyscan_t scanner, const char * str); + +int template_lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc, + yyscan_t scanner); + +int template_parse(Template * tmpl, char ** errmsg, yyscan_t scanner) +{ + mem_collector mc; + int rc; + + mem_collector_init(&mc); + + rc = template_parse(&mc, tmpl, errmsg, scanner); + + mem_collector_cleanup(&mc); + + return rc; +} + +static string& unescape (string &str); +%} + +%code requires { #include #include #include @@ -23,53 +53,23 @@ #include #include #include -#include "template_syntax.h" + +#include "mem_collector.h" + #include "Template.h" -#define template__lex template_lex +typedef void * yyscan_t; -#define YYERROR_VERBOSE -#define TEMPLATE_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \ -(int(*)(int))toupper) -extern "C" -{ - #include "mem_collector.h" - - void template__error( - YYLTYPE * llocp, - mem_collector * mc, - Template * tmpl, - char ** error_msg, - const char * str); - - int template__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); - - int template__parse(mem_collector * mc, Template * tmpl, char ** errmsg); - - int template_parse(Template * tmpl, char ** errmsg) - { - mem_collector mc; - int rc; - - mem_collector_init(&mc); - - rc = template__parse(&mc, tmpl, errmsg); - - mem_collector_cleanup(&mc); - - return rc; - } - - static string& unescape (string &str); +int template_parse(Template * tmpl, char ** errmsg, yyscan_t scanner); } -%} - %parse-param {mem_collector * mc} -%parse-param {Template * tmpl} -%parse-param {char ** error_msg} +%parse-param {Template * tmpl} +%parse-param {char ** error_msg} +%parse-param {yyscan_t scanner} %lex-param {mem_collector * mc} +%lex-param {yyscan_t scanner} %union { char * val_str; @@ -79,7 +79,7 @@ extern "C" %defines %locations %pure-parser -%name-prefix "template__" +%name-prefix "template_" %output "template_syntax.cc" %token EQUAL COMMA OBRACKET CBRACKET EQUAL_EMPTY CCDATA @@ -153,7 +153,7 @@ array_val: VARIABLE EQUAL STRING string name($1); string value($3); - TEMPLATE_TO_UPPER(name); + one_util::toupper(name); vattr = new map; vattr->insert(make_pair(name,unescape(value))); @@ -166,7 +166,7 @@ array_val: VARIABLE EQUAL STRING string value($5); map * attrmap; - TEMPLATE_TO_UPPER(name); + one_util::toupper(name); attrmap = static_cast *>($1); @@ -188,11 +188,12 @@ string& unescape (string &str) return str; } -extern "C" void template__error( +void template_error( YYLTYPE * llocp, mem_collector * mc, Template * tmpl, char ** error_msg, + yyscan_t scanner, const char * str) { int length; diff --git a/src/vm/vm_file_var_syntax.cc b/src/parsers/vm_file_var_syntax.cc similarity index 94% rename from src/vm/vm_file_var_syntax.cc rename to src/parsers/vm_file_var_syntax.cc index 13724fa7d5..31e4fdc52c 100644 --- a/src/vm/vm_file_var_syntax.cc +++ b/src/parsers/vm_file_var_syntax.cc @@ -60,71 +60,41 @@ /* Substitute the variable and function names. */ -#define yyparse vm_file_var__parse -#define yylex vm_file_var__lex -#define yyerror vm_file_var__error -#define yydebug vm_file_var__debug -#define yynerrs vm_file_var__nerrs +#define yyparse vm_file_var_parse +#define yylex vm_file_var_lex +#define yyerror vm_file_var_error +#define yydebug vm_file_var_debug +#define yynerrs vm_file_var_nerrs /* Copy the first part of user declarations. */ -#line 17 "vm_file_var_syntax.y" /* yacc.c:339 */ - -#include -#include -#include -#include -#include - -#include -#include +#line 40 "vm_file_var_syntax.y" /* yacc.c:339 */ #include "vm_file_var_syntax.h" -#include "ImagePool.h" -#include "UserPool.h" -#include "VirtualMachine.h" -#include "Nebula.h" - -#define vm_file_var__lex vm_var_lex +#include "vm_var_parser.h" #define YYERROR_VERBOSE -#define VM_VAR_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \ -(int(*)(int))toupper) +#define vm_file_var_lex vm_var_lex -extern "C" +void vm_file_var_error(YYLTYPE * llocp, mem_collector * mc, VirtualMachine * vm, + vector * img_ids, char ** errmsg, yyscan_t scanner, const char * str); + +int vm_var_lex(YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc, + yyscan_t scanner); + +int vm_file_var_parse (VirtualMachine * vm, vector * img_ids, + char ** errmsg, yyscan_t scanner) { - #include "mem_collector.h" + mem_collector mc; + int rc; - void vm_file_var__error( - YYLTYPE * llocp, - mem_collector * mc, - VirtualMachine * vm, - vector * img_ids, - char ** errmsg, - const char * str); + mem_collector_init(&mc); - int vm_file_var__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + rc = vm_file_var_parse(&mc, vm, img_ids, errmsg, scanner); - int vm_file_var__parse (mem_collector * mc, - VirtualMachine * vm, - vector * img_ids, - char ** errmsg); + mem_collector_cleanup(&mc); - int vm_file_var_parse (VirtualMachine * vm, - vector * img_ids, - char ** errmsg) - { - mem_collector mc; - int rc; - - mem_collector_init(&mc); - - rc = vm_file_var__parse(&mc, vm, img_ids, errmsg); - - mem_collector_cleanup(&mc); - - return rc; - } + return rc; } /* -------------------------------------------------------------------------- */ @@ -175,7 +145,7 @@ int get_image_path(VirtualMachine * vm, delete vfile; } - img = ipool->get(val1, uid, true); + img = ipool->get(val1, uid); if ( img == 0 ) { @@ -196,7 +166,7 @@ int get_image_path(VirtualMachine * vm, if ( !is.fail() ) { - img = ipool->get(iid, true); + img = ipool->get(iid); } if ( img == 0 ) @@ -223,7 +193,7 @@ int get_image_path(VirtualMachine * vm, set gids; - user = upool->get(vm->get_uid(), true); + user = upool->get(vm->get_uid()); if (user != 0) { @@ -254,7 +224,7 @@ int get_image_path(VirtualMachine * vm, /* -------------------------------------------------------------------------- */ -#line 258 "vm_file_var_syntax.cc" /* yacc.c:339 */ +#line 228 "vm_file_var_syntax.cc" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -281,8 +251,33 @@ int get_image_path(VirtualMachine * vm, # define YYDEBUG 0 #endif #if YYDEBUG -extern int vm_file_var__debug; +extern int vm_file_var_debug; #endif +/* "%code requires" blocks. */ +#line 17 "vm_file_var_syntax.y" /* yacc.c:355 */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "ImagePool.h" +#include "UserPool.h" +#include "VirtualMachine.h" +#include "Nebula.h" + +#include "mem_collector.h" + +typedef void * yyscan_t; + +int vm_file_var_parse (VirtualMachine * vm, vector * img_ids, + char ** errmsg, yyscan_t scanner); + +#line 281 "vm_file_var_syntax.cc" /* yacc.c:355 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -306,13 +301,13 @@ extern int vm_file_var__debug; union YYSTYPE { -#line 210 "vm_file_var_syntax.y" /* yacc.c:355 */ +#line 205 "vm_file_var_syntax.y" /* yacc.c:355 */ char * val_str; int val_int; char val_char; -#line 316 "vm_file_var_syntax.cc" /* yacc.c:355 */ +#line 311 "vm_file_var_syntax.cc" /* yacc.c:355 */ }; typedef union YYSTYPE YYSTYPE; @@ -336,13 +331,13 @@ struct YYLTYPE -int vm_file_var__parse (mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg); +int vm_file_var_parse (mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg, yyscan_t scanner); #endif /* !YY_VM_FILE_VAR_VM_FILE_VAR_SYNTAX_HH_INCLUDED */ /* Copy the second part of user declarations. */ -#line 346 "vm_file_var_syntax.cc" /* yacc.c:358 */ +#line 341 "vm_file_var_syntax.cc" /* yacc.c:358 */ #ifdef short # undef short @@ -640,9 +635,9 @@ static const yytype_uint8 yytranslate[] = #if YYDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = +static const yytype_uint8 yyrline[] = { - 0, 234, 234, 235, 239, 257 + 0, 229, 229, 230, 234, 252 }; #endif @@ -766,7 +761,7 @@ do \ } \ else \ { \ - yyerror (&yylloc, mc, vm, img_ids, errmsg, YY_("syntax error: cannot back up")); \ + yyerror (&yylloc, mc, vm, img_ids, errmsg, scanner, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (0) @@ -868,7 +863,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, Location, mc, vm, img_ids, errmsg); \ + Type, Value, Location, mc, vm, img_ids, errmsg, scanner); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -879,7 +874,7 @@ do { \ `----------------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg, yyscan_t scanner) { FILE *yyo = yyoutput; YYUSE (yyo); @@ -888,6 +883,7 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue YYUSE (vm); YYUSE (img_ids); YYUSE (errmsg); + YYUSE (scanner); if (!yyvaluep) return; # ifdef YYPRINT @@ -903,14 +899,14 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue `--------------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg, yyscan_t scanner) { YYFPRINTF (yyoutput, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); YY_LOCATION_PRINT (yyoutput, *yylocationp); YYFPRINTF (yyoutput, ": "); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, vm, img_ids, errmsg); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, vm, img_ids, errmsg, scanner); YYFPRINTF (yyoutput, ")"); } @@ -943,7 +939,7 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg) +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg, yyscan_t scanner) { unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; @@ -957,7 +953,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule yy_symbol_print (stderr, yystos[yyssp[yyi + 1 - yynrhs]], &(yyvsp[(yyi + 1) - (yynrhs)]) - , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, vm, img_ids, errmsg); + , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, vm, img_ids, errmsg, scanner); YYFPRINTF (stderr, "\n"); } } @@ -965,7 +961,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, yylsp, Rule, mc, vm, img_ids, errmsg); \ + yy_reduce_print (yyssp, yyvsp, yylsp, Rule, mc, vm, img_ids, errmsg, scanner); \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that @@ -1223,7 +1219,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg, yyscan_t scanner) { YYUSE (yyvaluep); YYUSE (yylocationp); @@ -1231,6 +1227,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio YYUSE (vm); YYUSE (img_ids); YYUSE (errmsg); + YYUSE (scanner); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); @@ -1248,7 +1245,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio `----------*/ int -yyparse (mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg) +yyparse (mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg, yyscan_t scanner) { /* The lookahead symbol. */ int yychar; @@ -1442,7 +1439,7 @@ yybackup: if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (&yylval, &yylloc, mc); + yychar = yylex (&yylval, &yylloc, mc, scanner); } if (yychar <= YYEOF) @@ -1522,7 +1519,7 @@ yyreduce: switch (yyn) { case 4: -#line 240 "vm_file_var_syntax.y" /* yacc.c:1646 */ +#line 235 "vm_file_var_syntax.y" /* yacc.c:1646 */ { string file((yyvsp[-6].val_str)); string var1((yyvsp[-4].val_str)); @@ -1530,8 +1527,8 @@ yyreduce: string result; - VM_VAR_TO_UPPER(file); - VM_VAR_TO_UPPER(var1); + one_util::toupper(file); + one_util::toupper(var1); if (get_image_path(vm, file, var1, val1, "", "", img_ids, result) == -1) { @@ -1540,11 +1537,11 @@ yyreduce: YYABORT; } } -#line 1544 "vm_file_var_syntax.cc" /* yacc.c:1646 */ +#line 1541 "vm_file_var_syntax.cc" /* yacc.c:1646 */ break; case 5: -#line 258 "vm_file_var_syntax.y" /* yacc.c:1646 */ +#line 253 "vm_file_var_syntax.y" /* yacc.c:1646 */ { string file((yyvsp[-10].val_str)); string var1((yyvsp[-8].val_str)); @@ -1554,9 +1551,9 @@ yyreduce: string result; - VM_VAR_TO_UPPER(file); - VM_VAR_TO_UPPER(var1); - VM_VAR_TO_UPPER(var2); + one_util::toupper(file); + one_util::toupper(var1); + one_util::toupper(var2); if (get_image_path(vm, file, var1, val1, var2, val2, img_ids, result) == -1) { @@ -1565,11 +1562,11 @@ yyreduce: YYABORT; } } -#line 1569 "vm_file_var_syntax.cc" /* yacc.c:1646 */ +#line 1566 "vm_file_var_syntax.cc" /* yacc.c:1646 */ break; -#line 1573 "vm_file_var_syntax.cc" /* yacc.c:1646 */ +#line 1570 "vm_file_var_syntax.cc" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1620,7 +1617,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (&yylloc, mc, vm, img_ids, errmsg, YY_("syntax error")); + yyerror (&yylloc, mc, vm, img_ids, errmsg, scanner, YY_("syntax error")); #else # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ yyssp, yytoken) @@ -1647,7 +1644,7 @@ yyerrlab: yymsgp = yymsg; } } - yyerror (&yylloc, mc, vm, img_ids, errmsg, yymsgp); + yyerror (&yylloc, mc, vm, img_ids, errmsg, scanner, yymsgp); if (yysyntax_error_status == 2) goto yyexhaustedlab; } @@ -1671,7 +1668,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval, &yylloc, mc, vm, img_ids, errmsg); + yytoken, &yylval, &yylloc, mc, vm, img_ids, errmsg, scanner); yychar = YYEMPTY; } } @@ -1728,7 +1725,7 @@ yyerrlab1: yyerror_range[1] = *yylsp; yydestruct ("Error: popping", - yystos[yystate], yyvsp, yylsp, mc, vm, img_ids, errmsg); + yystos[yystate], yyvsp, yylsp, mc, vm, img_ids, errmsg, scanner); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1770,7 +1767,7 @@ yyabortlab: | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (&yylloc, mc, vm, img_ids, errmsg, YY_("memory exhausted")); + yyerror (&yylloc, mc, vm, img_ids, errmsg, scanner, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif @@ -1782,7 +1779,7 @@ yyreturn: user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, mc, vm, img_ids, errmsg); + yytoken, &yylval, &yylloc, mc, vm, img_ids, errmsg, scanner); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ @@ -1791,7 +1788,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yylsp, mc, vm, img_ids, errmsg); + yystos[*yyssp], yyvsp, yylsp, mc, vm, img_ids, errmsg, scanner); YYPOPSTACK (1); } #ifndef yyoverflow @@ -1804,15 +1801,16 @@ yyreturn: #endif return yyresult; } -#line 279 "vm_file_var_syntax.y" /* yacc.c:1906 */ +#line 274 "vm_file_var_syntax.y" /* yacc.c:1906 */ -extern "C" void vm_file_var__error( +void vm_file_var_error( YYLTYPE * llocp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** error_msg, + yyscan_t scanner, const char * str) { int length; diff --git a/src/vm/vm_file_var_syntax.h b/src/parsers/vm_file_var_syntax.h similarity index 76% rename from src/vm/vm_file_var_syntax.h rename to src/parsers/vm_file_var_syntax.h index 1f3060eed6..80ef43f7d2 100644 --- a/src/vm/vm_file_var_syntax.h +++ b/src/parsers/vm_file_var_syntax.h @@ -37,8 +37,33 @@ # define YYDEBUG 0 #endif #if YYDEBUG -extern int vm_file_var__debug; +extern int vm_file_var_debug; #endif +/* "%code requires" blocks. */ +#line 17 "vm_file_var_syntax.y" /* yacc.c:1909 */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "ImagePool.h" +#include "UserPool.h" +#include "VirtualMachine.h" +#include "Nebula.h" + +#include "mem_collector.h" + +typedef void * yyscan_t; + +int vm_file_var_parse (VirtualMachine * vm, vector * img_ids, + char ** errmsg, yyscan_t scanner); + +#line 67 "vm_file_var_syntax.hh" /* yacc.c:1909 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -62,13 +87,13 @@ extern int vm_file_var__debug; union YYSTYPE { -#line 210 "vm_file_var_syntax.y" /* yacc.c:1909 */ +#line 205 "vm_file_var_syntax.y" /* yacc.c:1909 */ char * val_str; int val_int; char val_char; -#line 72 "vm_file_var_syntax.hh" /* yacc.c:1909 */ +#line 97 "vm_file_var_syntax.hh" /* yacc.c:1909 */ }; typedef union YYSTYPE YYSTYPE; @@ -90,4 +115,8 @@ struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif + + +int vm_file_var_parse (mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg, yyscan_t scanner); + #endif /* !YY_VM_FILE_VAR_VM_FILE_VAR_SYNTAX_HH_INCLUDED */ diff --git a/src/vm/vm_file_var_syntax.y b/src/parsers/vm_file_var_syntax.y similarity index 81% rename from src/vm/vm_file_var_syntax.y rename to src/parsers/vm_file_var_syntax.y index b775d7cb56..1c3df8794c 100644 --- a/src/vm/vm_file_var_syntax.y +++ b/src/parsers/vm_file_var_syntax.y @@ -14,7 +14,7 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ -%{ +%code requires { #include #include #include @@ -24,52 +24,45 @@ #include #include -#include "vm_file_var_syntax.h" #include "ImagePool.h" #include "UserPool.h" #include "VirtualMachine.h" #include "Nebula.h" -#define vm_file_var__lex vm_var_lex +#include "mem_collector.h" + +typedef void * yyscan_t; + +int vm_file_var_parse (VirtualMachine * vm, vector * img_ids, + char ** errmsg, yyscan_t scanner); +} + +%{ +#include "vm_file_var_syntax.h" +#include "vm_var_parser.h" #define YYERROR_VERBOSE -#define VM_VAR_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \ -(int(*)(int))toupper) +#define vm_file_var_lex vm_var_lex -extern "C" +void vm_file_var_error(YYLTYPE * llocp, mem_collector * mc, VirtualMachine * vm, + vector * img_ids, char ** errmsg, yyscan_t scanner, const char * str); + +int vm_var_lex(YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc, + yyscan_t scanner); + +int vm_file_var_parse (VirtualMachine * vm, vector * img_ids, + char ** errmsg, yyscan_t scanner) { - #include "mem_collector.h" + mem_collector mc; + int rc; - void vm_file_var__error( - YYLTYPE * llocp, - mem_collector * mc, - VirtualMachine * vm, - vector * img_ids, - char ** errmsg, - const char * str); + mem_collector_init(&mc); - int vm_file_var__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + rc = vm_file_var_parse(&mc, vm, img_ids, errmsg, scanner); - int vm_file_var__parse (mem_collector * mc, - VirtualMachine * vm, - vector * img_ids, - char ** errmsg); + mem_collector_cleanup(&mc); - int vm_file_var_parse (VirtualMachine * vm, - vector * img_ids, - char ** errmsg) - { - mem_collector mc; - int rc; - - mem_collector_init(&mc); - - rc = vm_file_var__parse(&mc, vm, img_ids, errmsg); - - mem_collector_cleanup(&mc); - - return rc; - } + return rc; } /* -------------------------------------------------------------------------- */ @@ -120,7 +113,7 @@ int get_image_path(VirtualMachine * vm, delete vfile; } - img = ipool->get(val1, uid, true); + img = ipool->get(val1, uid); if ( img == 0 ) { @@ -141,7 +134,7 @@ int get_image_path(VirtualMachine * vm, if ( !is.fail() ) { - img = ipool->get(iid, true); + img = ipool->get(iid); } if ( img == 0 ) @@ -168,7 +161,7 @@ int get_image_path(VirtualMachine * vm, set gids; - user = upool->get(vm->get_uid(), true); + user = upool->get(vm->get_uid()); if (user != 0) { @@ -203,9 +196,11 @@ int get_image_path(VirtualMachine * vm, %parse-param {mem_collector * mc} %parse-param {VirtualMachine * vm} %parse-param {vector * img_ids} -%parse-param {char ** errmsg} +%parse-param {char ** errmsg} +%parse-param {yyscan_t scanner} %lex-param {mem_collector * mc} +%lex-param {yyscan_t scanner} %union { char * val_str; @@ -216,7 +211,7 @@ int get_image_path(VirtualMachine * vm, %defines %locations %pure-parser -%name-prefix "vm_file_var__" +%name-prefix "vm_file_var_" %output "vm_file_var_syntax.cc" %token EQUAL COMMA OBRACKET CBRACKET @@ -244,8 +239,8 @@ vm_variable: string result; - VM_VAR_TO_UPPER(file); - VM_VAR_TO_UPPER(var1); + one_util::toupper(file); + one_util::toupper(var1); if (get_image_path(vm, file, var1, val1, "", "", img_ids, result) == -1) { @@ -264,9 +259,9 @@ vm_variable: string result; - VM_VAR_TO_UPPER(file); - VM_VAR_TO_UPPER(var1); - VM_VAR_TO_UPPER(var2); + one_util::toupper(file); + one_util::toupper(var1); + one_util::toupper(var2); if (get_image_path(vm, file, var1, val1, var2, val2, img_ids, result) == -1) { @@ -278,12 +273,13 @@ vm_variable: ; %% -extern "C" void vm_file_var__error( +void vm_file_var_error( YYLTYPE * llocp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** error_msg, + yyscan_t scanner, const char * str) { int length; diff --git a/src/vm/vm_var_parser.c b/src/parsers/vm_var_parser.cc similarity index 64% rename from src/vm/vm_var_parser.c rename to src/parsers/vm_var_parser.cc index 52847abfaa..bc78613da1 100644 --- a/src/vm/vm_var_parser.c +++ b/src/parsers/vm_var_parser.cc @@ -1,36 +1,11 @@ -#line 1 "vm_var_parser.c" +#line 1 "vm_var_parser.cc" -#line 3 "vm_var_parser.c" +#line 3 "vm_var_parser.cc" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ -#define yy_create_buffer vm_var__create_buffer -#define yy_delete_buffer vm_var__delete_buffer -#define yy_scan_buffer vm_var__scan_buffer -#define yy_scan_string vm_var__scan_string -#define yy_scan_bytes vm_var__scan_bytes -#define yy_init_buffer vm_var__init_buffer -#define yy_flush_buffer vm_var__flush_buffer -#define yy_load_buffer_state vm_var__load_buffer_state -#define yy_switch_to_buffer vm_var__switch_to_buffer -#define yypush_buffer_state vm_var_push_buffer_state -#define yypop_buffer_state vm_var_pop_buffer_state -#define yyensure_buffer_stack vm_var_ensure_buffer_stack -#define yy_flex_debug vm_var__flex_debug -#define yyin vm_var_in -#define yyleng vm_var_leng -#define yylex vm_var_lex -#define yylineno vm_var_lineno -#define yyout vm_var_out -#define yyrestart vm_var_restart -#define yytext vm_var_text -#define yywrap vm_var_wrap -#define yyalloc vm_var_alloc -#define yyrealloc vm_var_realloc -#define yyfree vm_var_free - #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 6 @@ -213,12 +188,36 @@ #define yyset_lineno vm_var_set_lineno #endif +#ifdef yyget_column +#define vm_var_get_column_ALREADY_DEFINED +#else +#define yyget_column vm_var_get_column +#endif + +#ifdef yyset_column +#define vm_var_set_column_ALREADY_DEFINED +#else +#define yyset_column vm_var_set_column +#endif + #ifdef yywrap #define vm_var_wrap_ALREADY_DEFINED #else #define yywrap vm_var_wrap #endif +#ifdef yyget_lval +#define vm_var_get_lval_ALREADY_DEFINED +#else +#define yyget_lval vm_var_get_lval +#endif + +#ifdef yyset_lval +#define vm_var_set_lval_ALREADY_DEFINED +#else +#define yyset_lval vm_var_set_lval +#endif + #ifdef yyalloc #define vm_var_alloc_ALREADY_DEFINED #else @@ -237,42 +236,6 @@ #define yyfree vm_var_free #endif -#ifdef yytext -#define vm_var_text_ALREADY_DEFINED -#else -#define yytext vm_var_text -#endif - -#ifdef yyleng -#define vm_var_leng_ALREADY_DEFINED -#else -#define yyleng vm_var_leng -#endif - -#ifdef yyin -#define vm_var_in_ALREADY_DEFINED -#else -#define yyin vm_var_in -#endif - -#ifdef yyout -#define vm_var_out_ALREADY_DEFINED -#else -#define yyout vm_var_out -#endif - -#ifdef yy_flex_debug -#define vm_var__flex_debug_ALREADY_DEFINED -#else -#define yy_flex_debug vm_var__flex_debug -#endif - -#ifdef yylineno -#define vm_var_lineno_ALREADY_DEFINED -#else -#define yylineno vm_var_lineno -#endif - /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ @@ -370,21 +333,38 @@ typedef unsigned int flex_uint32_t; */ #define YY_SC_TO_UI(c) ((YY_CHAR) (c)) +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ -#define BEGIN (yy_start) = 1 + 2 * +#define BEGIN yyg->yy_start = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ -#define YY_START (((yy_start) - 1) / 2) +#define YY_START ((yyg->yy_start - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) +#define YY_NEW_FILE yyrestart( yyin , yyscanner ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ @@ -414,10 +394,6 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; typedef size_t yy_size_t; #endif -extern int yyleng; - -extern FILE *yyin, *yyout; - #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 @@ -451,13 +427,13 @@ extern FILE *yyin, *yyout; /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ + *yy_cp = yyg->yy_hold_char; \ YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) -#define unput(c) yyunput( c, (yytext_ptr) ) +#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE @@ -524,77 +500,57 @@ struct yy_buffer_state }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ - /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ +#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ + ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] +#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; +void yyrestart ( FILE *input_file , yyscan_t yyscanner ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner ); +void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +void yypop_buffer_state ( yyscan_t yyscanner ); -/* Points to current character in buffer. */ -static char *yy_c_buf_p = NULL; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ +static void yyensure_buffer_stack ( yyscan_t yyscanner ); +static void yy_load_buffer_state ( yyscan_t yyscanner ); +static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner ); +#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , yyscanner) -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner ); -void yyrestart ( FILE *input_file ); -void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size ); -void yy_delete_buffer ( YY_BUFFER_STATE b ); -void yy_flush_buffer ( YY_BUFFER_STATE b ); -void yypush_buffer_state ( YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state ( void ); - -static void yyensure_buffer_stack ( void ); -static void yy_load_buffer_state ( void ); -static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); -#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); -YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); - -void *yyalloc ( yy_size_t ); -void *yyrealloc ( void *, yy_size_t ); -void yyfree ( void * ); +void *yyalloc ( yy_size_t , yyscan_t yyscanner ); +void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner ); +void yyfree ( void * , yyscan_t yyscanner ); #define yy_new_buffer yy_create_buffer #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ + yyensure_buffer_stack (yyscanner); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ + yyensure_buffer_stack (yyscanner); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } @@ -603,33 +559,24 @@ void yyfree ( void * ); /* Begin user sect3 */ typedef flex_uint8_t YY_CHAR; -FILE *yyin = NULL, *yyout = NULL; - typedef int yy_state_type; -extern int yylineno; -int yylineno = 1; +#define yytext_ptr yytext_r -extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state ( void ); -static yy_state_type yy_try_NUL_trans ( yy_state_type current_state ); -static int yy_get_next_buffer ( void ); -static void yynoreturn yy_fatal_error ( const char* msg ); +static yy_state_type yy_get_previous_state ( yyscan_t yyscanner ); +static yy_state_type yy_try_NUL_trans ( yy_state_type current_state , yyscan_t yyscanner); +static int yy_get_next_buffer ( yyscan_t yyscanner ); +static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ + yyg->yytext_ptr = yy_bp; \ yyleng = (int) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ + yyg->yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; + yyg->yy_c_buf_p = yy_cp; #define YY_NUM_RULES 12 #define YY_END_OF_BUFFER 13 /* This struct is not used in this scanner, @@ -726,12 +673,6 @@ static const flex_int32_t yy_rule_can_match_eol[13] = { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, }; -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ @@ -739,7 +680,6 @@ int yy_flex_debug = 0; #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET -char *yytext; #line 1 "vm_var_parser.l" /* -------------------------------------------------------------------------- */ /* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */ @@ -763,19 +703,20 @@ char *yytext; #include #include "vm_var_syntax.h" +#include "vm_file_var_syntax.h" #include "mem_collector.h" #define YY_NO_INPUT -#define YY_DECL int vm_var_lex (YYSTYPE *lvalp, YYLTYPE *llocp, \ - mem_collector *mc) +#define YY_DECL int vm_var_lex (YYSTYPE *yylval_param, YYLTYPE *llocp, \ + mem_collector *mc, yyscan_t yyscanner) #define YY_USER_ACTION llocp->first_line = yylineno; \ llocp->first_column = llocp->last_column; \ llocp->last_column += yyleng; -#line 776 "vm_var_parser.c" +#line 717 "vm_var_parser.cc" -#line 778 "vm_var_parser.c" +#line 719 "vm_var_parser.cc" #define INITIAL 0 #define VAR 1 @@ -793,36 +734,88 @@ char *yytext; #define YY_EXTRA_TYPE void * #endif -static int yy_init_globals ( void ); +/* Holds the entire state of the reentrant scanner. */ +struct yyguts_t + { + + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; + + /* The rest are the same as the globals declared in the non-reentrant scanner. */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + int yylineno_r; + int yy_flex_debug_r; + + char *yytext_r; + int yy_more_flag; + int yy_more_len; + + YYSTYPE * yylval_r; + + }; /* end struct yyguts_t */ + +static int yy_init_globals ( yyscan_t yyscanner ); + + /* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ + # define yylval yyg->yylval_r + +int yylex_init (yyscan_t* scanner); + +int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy ( void ); +int yylex_destroy ( yyscan_t yyscanner ); -int yyget_debug ( void ); +int yyget_debug ( yyscan_t yyscanner ); -void yyset_debug ( int debug_flag ); +void yyset_debug ( int debug_flag , yyscan_t yyscanner ); -YY_EXTRA_TYPE yyget_extra ( void ); +YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner ); -void yyset_extra ( YY_EXTRA_TYPE user_defined ); +void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); -FILE *yyget_in ( void ); +FILE *yyget_in ( yyscan_t yyscanner ); -void yyset_in ( FILE * _in_str ); +void yyset_in ( FILE * _in_str , yyscan_t yyscanner ); -FILE *yyget_out ( void ); +FILE *yyget_out ( yyscan_t yyscanner ); -void yyset_out ( FILE * _out_str ); +void yyset_out ( FILE * _out_str , yyscan_t yyscanner ); - int yyget_leng ( void ); + int yyget_leng ( yyscan_t yyscanner ); -char *yyget_text ( void ); +char *yyget_text ( yyscan_t yyscanner ); -int yyget_lineno ( void ); +int yyget_lineno ( yyscan_t yyscanner ); -void yyset_lineno ( int _line_number ); +void yyset_lineno ( int _line_number , yyscan_t yyscanner ); + +int yyget_column ( yyscan_t yyscanner ); + +void yyset_column ( int _column_no , yyscan_t yyscanner ); + +YYSTYPE * yyget_lval ( yyscan_t yyscanner ); + +void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -830,9 +823,9 @@ void yyset_lineno ( int _line_number ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap ( void ); +extern "C" int yywrap ( yyscan_t yyscanner ); #else -extern int yywrap ( void ); +extern int yywrap ( yyscan_t yyscanner ); #endif #endif @@ -841,18 +834,18 @@ extern int yywrap ( void ); #endif #ifndef yytext_ptr -static void yy_flex_strncpy ( char *, const char *, int ); +static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen ( const char * ); +static int yy_flex_strlen ( const char * , yyscan_t yyscanner); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput ( void ); +static int yyinput ( yyscan_t yyscanner ); #else -static int input ( void ); +static int input ( yyscan_t yyscanner ); #endif #endif @@ -926,7 +919,7 @@ static int input ( void ); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) #endif /* end tables serialization structures and prototypes */ @@ -937,9 +930,11 @@ static int input ( void ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int yylex (void); +extern int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner); -#define YY_DECL int yylex (void) +#define YY_DECL int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -964,17 +959,20 @@ YY_DECL yy_state_type yy_current_state; char *yy_cp, *yy_bp; int yy_act; - - if ( !(yy_init) ) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yylval = yylval_param; + + if ( !yyg->yy_init ) { - (yy_init) = 1; + yyg->yy_init = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ + if ( ! yyg->yy_start ) + yyg->yy_start = 1; /* first start state */ if ( ! yyin ) yyin = stdin; @@ -983,19 +981,19 @@ YY_DECL yyout = stdout; if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); } - yy_load_buffer_state( ); + yy_load_buffer_state( yyscanner ); } { -#line 43 "vm_var_parser.l" +#line 47 "vm_var_parser.l" -#line 46 "vm_var_parser.l" +#line 50 "vm_var_parser.l" /* ------------------------------------------------------------------------- */ /* Parse variables in the form: */ /* $VARIABLE */ @@ -1004,29 +1002,29 @@ YY_DECL /* $NUM.CONTEXT_VARIABLE */ /* ------------------------------------------------------------------------- */ -#line 1007 "vm_var_parser.c" +#line 1005 "vm_var_parser.cc" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { - yy_cp = (yy_c_buf_p); + yy_cp = yyg->yy_c_buf_p; /* Support of yytext. */ - *yy_cp = (yy_hold_char); + *yy_cp = yyg->yy_hold_char; /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; - yy_current_state = (yy_start); + yy_current_state = yyg->yy_start; yy_match: do { YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1043,8 +1041,8 @@ yy_find_action: yy_act = yy_accept[yy_current_state]; if ( yy_act == 0 ) { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; yy_act = yy_accept[yy_current_state]; } @@ -1056,7 +1054,9 @@ yy_find_action: for ( yyl = 0; yyl < yyleng; ++yyl ) if ( yytext[yyl] == '\n' ) - yylineno++; + do{ yylineno++; + yycolumn=0; + }while(0) ; } @@ -1066,77 +1066,77 @@ do_action: /* This label is used only to access EOF actions. */ { /* beginning of action switch */ case 0: /* must back up */ /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; goto yy_find_action; case 1: YY_RULE_SETUP -#line 54 "vm_var_parser.l" +#line 58 "vm_var_parser.l" { BEGIN VAR;} YY_BREAK case 2: YY_RULE_SETUP -#line 56 "vm_var_parser.l" +#line 60 "vm_var_parser.l" { BEGIN VALUE; return EQUAL; } YY_BREAK case 3: YY_RULE_SETUP -#line 57 "vm_var_parser.l" +#line 61 "vm_var_parser.l" { return COMMA;} YY_BREAK case 4: YY_RULE_SETUP -#line 58 "vm_var_parser.l" +#line 62 "vm_var_parser.l" { return OBRACKET;} YY_BREAK case 5: YY_RULE_SETUP -#line 59 "vm_var_parser.l" +#line 63 "vm_var_parser.l" { return CBRACKET;} YY_BREAK case 6: YY_RULE_SETUP -#line 61 "vm_var_parser.l" -{ lvalp->val_str = +#line 65 "vm_var_parser.l" +{ yylval_param->val_str = mem_collector_strdup(mc,yytext); return VARIABLE;} YY_BREAK case 7: /* rule 7 can match eol */ YY_RULE_SETUP -#line 65 "vm_var_parser.l" -{ lvalp->val_str = +#line 69 "vm_var_parser.l" +{ yylval_param->val_str = mem_collector_strdup(mc,yytext+1); - lvalp->val_str[yyleng-2] = '\0'; + yylval_param->val_str[yyleng-2] = '\0'; BEGIN(VAR); return STRING;} YY_BREAK case 8: YY_RULE_SETUP -#line 71 "vm_var_parser.l" -{ lvalp->val_str = +#line 75 "vm_var_parser.l" +{ yylval_param->val_str = mem_collector_strdup(mc,yytext); BEGIN(VAR); return STRING;} YY_BREAK case 9: YY_RULE_SETUP -#line 76 "vm_var_parser.l" -{ lvalp->val_char = '\0'; +#line 80 "vm_var_parser.l" +{ yylval_param->val_char = '\0'; return EOA;} YY_BREAK case 10: YY_RULE_SETUP -#line 79 "vm_var_parser.l" -{ lvalp->val_char = *yytext; +#line 83 "vm_var_parser.l" +{ yylval_param->val_char = *yytext; BEGIN(INITIAL); return EOA;} YY_BREAK case YY_STATE_EOF(VAR): -#line 83 "vm_var_parser.l" -{ lvalp->val_char = '\0'; +#line 87 "vm_var_parser.l" +{ yylval_param->val_char = '\0'; BEGIN(INITIAL); return EOA;} YY_BREAK @@ -1146,15 +1146,15 @@ case YY_STATE_EOF(VAR): case 11: /* rule 11 can match eol */ YY_RULE_SETUP -#line 91 "vm_var_parser.l" -{ lvalp->val_str = mem_collector_strdup(mc,yytext); return RSTRING;} +#line 95 "vm_var_parser.l" +{ yylval_param->val_str = mem_collector_strdup(mc,yytext); return RSTRING;} YY_BREAK case 12: YY_RULE_SETUP -#line 93 "vm_var_parser.l" +#line 97 "vm_var_parser.l" ECHO; YY_BREAK -#line 1157 "vm_var_parser.c" +#line 1157 "vm_var_parser.cc" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(VALUE): yyterminate(); @@ -1162,10 +1162,10 @@ case YY_STATE_EOF(VALUE): case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); + *yy_cp = yyg->yy_hold_char; YY_RESTORE_YY_MORE_OFFSET if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) @@ -1179,7 +1179,7 @@ case YY_STATE_EOF(VALUE): * this is the first action (other than possibly a * back-up) that will match for the new input source. */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } @@ -1191,13 +1191,13 @@ case YY_STATE_EOF(VALUE): * end-of-buffer state). Contrast this with the test * in input(). */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) { /* This was really a NUL. */ yy_state_type yy_next_state; - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have @@ -1208,32 +1208,32 @@ case YY_STATE_EOF(VALUE): * will run more slowly). */ - yy_next_state = yy_try_NUL_trans( yy_current_state ); + yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); + yy_cp = ++yyg->yy_c_buf_p; yy_current_state = yy_next_state; goto yy_match; } else { - yy_cp = (yy_c_buf_p); + yy_cp = yyg->yy_c_buf_p; goto yy_find_action; } } - else switch ( yy_get_next_buffer( ) ) + else switch ( yy_get_next_buffer( yyscanner ) ) { case EOB_ACT_END_OF_FILE: { - (yy_did_buffer_switch_on_eof) = 0; + yyg->yy_did_buffer_switch_on_eof = 0; - if ( yywrap( ) ) + if ( yywrap( yyscanner ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up @@ -1244,7 +1244,7 @@ case YY_STATE_EOF(VALUE): * YY_NULL, it'll still work - another * YY_NULL will get returned. */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; @@ -1252,30 +1252,30 @@ case YY_STATE_EOF(VALUE): else { - if ( ! (yy_did_buffer_switch_on_eof) ) + if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; + yyg->yy_c_buf_p = + yyg->yytext_ptr + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; goto yy_find_action; } break; @@ -1296,20 +1296,21 @@ case YY_STATE_EOF(VALUE): * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer (void) +static int yy_get_next_buffer (yyscan_t yyscanner) { - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = yyg->yytext_ptr; int number_to_move, i; int ret_val; - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so * treat this as a final EOF. @@ -1329,7 +1330,7 @@ static int yy_get_next_buffer (void) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1); + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -1338,7 +1339,7 @@ static int yy_get_next_buffer (void) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; else { @@ -1352,7 +1353,7 @@ static int yy_get_next_buffer (void) YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); + (int) (yyg->yy_c_buf_p - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { @@ -1366,7 +1367,7 @@ static int yy_get_next_buffer (void) b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ yyrealloc( (void *) b->yy_ch_buf, - (yy_size_t) (b->yy_buf_size + 2) ); + (yy_size_t) (b->yy_buf_size + 2) , yyscanner ); } else /* Can't grow it, we don't own it. */ @@ -1376,7 +1377,7 @@ static int yy_get_next_buffer (void) YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; @@ -1388,17 +1389,17 @@ static int yy_get_next_buffer (void) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); + yyg->yy_n_chars, num_to_read ); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } - if ( (yy_n_chars) == 0 ) + if ( yyg->yy_n_chars == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); + yyrestart( yyin , yyscanner); } else @@ -1412,42 +1413,43 @@ static int yy_get_next_buffer (void) else ret_val = EOB_ACT_CONTINUE_SCAN; - if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( - (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); + (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); /* "- 2" to take care of EOB's */ YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2); } - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ - static yy_state_type yy_get_previous_state (void) + static yy_state_type yy_get_previous_state (yyscan_t yyscanner) { yy_state_type yy_current_state; char *yy_cp; - - yy_current_state = (yy_start); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + yy_current_state = yyg->yy_start; + + for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) { YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1466,16 +1468,17 @@ static int yy_get_next_buffer (void) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) { int yy_is_jam; - char *yy_cp = (yy_c_buf_p); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ + char *yy_cp = yyg->yy_c_buf_p; YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1486,7 +1489,8 @@ static int yy_get_next_buffer (void) yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; yy_is_jam = (yy_current_state == 33); - return yy_is_jam ? 0 : yy_current_state; + (void)yyg; + return yy_is_jam ? 0 : yy_current_state; } #ifndef YY_NO_UNPUT @@ -1495,32 +1499,33 @@ static int yy_get_next_buffer (void) #ifndef YY_NO_INPUT #ifdef __cplusplus - static int yyinput (void) + static int yyinput (yyscan_t yyscanner) #else - static int input (void) + static int input (yyscan_t yyscanner) #endif { int c; - - *(yy_c_buf_p) = (yy_hold_char); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + *yyg->yy_c_buf_p = yyg->yy_hold_char; + + if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; + *yyg->yy_c_buf_p = '\0'; else { /* need more input */ - int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); - ++(yy_c_buf_p); + int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr); + ++yyg->yy_c_buf_p; - switch ( yy_get_next_buffer( ) ) + switch ( yy_get_next_buffer( yyscanner ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() @@ -1534,38 +1539,40 @@ static int yy_get_next_buffer (void) */ /* Reset buffer status. */ - yyrestart( yyin ); + yyrestart( yyin , yyscanner); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { - if ( yywrap( ) ) + if ( yywrap( yyscanner ) ) return 0; - if ( ! (yy_did_buffer_switch_on_eof) ) + if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; #ifdef __cplusplus - return yyinput(); + return yyinput(yyscanner); #else - return input(); + return input(yyscanner); #endif } case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; break; } } } - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; if ( c == '\n' ) - yylineno++; + do{ yylineno++; + yycolumn=0; + }while(0) ; return c; @@ -1574,76 +1581,79 @@ static int yy_get_next_buffer (void) /** Immediately switch to a different input stream. * @param input_file A readable stream. - * + * @param yyscanner The scanner object. * @note This function does not reset the start condition to @c INITIAL . */ - void yyrestart (FILE * input_file ) + void yyrestart (FILE * input_file , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer( yyin, YY_BUF_SIZE ); + yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); } - yy_init_buffer( YY_CURRENT_BUFFER, input_file ); - yy_load_buffer_state( ); + yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner); + yy_load_buffer_state( yyscanner ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. - * + * @param yyscanner The scanner object. */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* TODO. We should be able to replace this entire function body * with * yypop_buffer_state(); * yypush_buffer_state(new_buffer); */ - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); if ( YY_CURRENT_BUFFER == new_buffer ) return; if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); + yy_load_buffer_state( yyscanner ); /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag * is looked at is after yywrap() is called, so it's safe * to go ahead and always set it. */ - (yy_did_buffer_switch_on_eof) = 1; + yyg->yy_did_buffer_switch_on_eof = 1; } -static void yy_load_buffer_state (void) +static void yy_load_buffer_state (yyscan_t yyscanner) { - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); + yyg->yy_hold_char = *yyg->yy_c_buf_p; } /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * + * @param yyscanner The scanner object. * @return the allocated buffer state. */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner) { YY_BUFFER_STATE b; - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -1652,24 +1662,25 @@ static void yy_load_buffer_state (void) /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) ); + b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; - yy_init_buffer( b, file ); + yy_init_buffer( b, file , yyscanner); return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() - * + * @param yyscanner The scanner object. */ - void yy_delete_buffer (YY_BUFFER_STATE b ) + void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) return; @@ -1677,21 +1688,22 @@ static void yy_load_buffer_state (void) YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) - yyfree( (void *) b->yy_ch_buf ); + yyfree( (void *) b->yy_ch_buf , yyscanner ); - yyfree( (void *) b ); + yyfree( (void *) b , yyscanner ); } /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) { int oerrno = errno; - - yy_flush_buffer( b ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yy_flush_buffer( b , yyscanner); b->yy_input_file = file; b->yy_fill_buffer = 1; @@ -1712,11 +1724,12 @@ static void yy_load_buffer_state (void) /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * + * @param yyscanner The scanner object. */ - void yy_flush_buffer (YY_BUFFER_STATE b ) + void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) { - if ( ! b ) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) return; b->yy_n_chars = 0; @@ -1734,114 +1747,117 @@ static void yy_load_buffer_state (void) b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); + yy_load_buffer_state( yyscanner ); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. - * + * @param yyscanner The scanner object. */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) { - if (new_buffer == NULL) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (new_buffer == NULL) return; - yyensure_buffer_stack(); + yyensure_buffer_stack(yyscanner); /* This block is copied from yy_switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; + yyg->yy_buffer_stack_top++; YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + yy_load_buffer_state( yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. - * + * @param yyscanner The scanner object. */ -void yypop_buffer_state (void) +void yypop_buffer_state (yyscan_t yyscanner) { - if (!YY_CURRENT_BUFFER) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (!YY_CURRENT_BUFFER) return; - yy_delete_buffer(YY_CURRENT_BUFFER ); + yy_delete_buffer(YY_CURRENT_BUFFER , yyscanner); YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + yy_load_buffer_state( yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void yyensure_buffer_stack (void) +static void yyensure_buffer_stack (yyscan_t yyscanner) { yy_size_t num_to_alloc; - - if (!(yy_buffer_stack)) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (!yyg->yy_buffer_stack) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; return; } - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ /* Increase the buffer to prepare for a possible push. */ yy_size_t grow_size = 8 /* arbitrary grow size */; - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc + (yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; + memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); + yyg->yy_buffer_stack_max = num_to_alloc; } } /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) { YY_BUFFER_STATE b; @@ -1851,7 +1867,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /* They forgot to leave room for the EOB's. */ return NULL; - b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); @@ -1865,7 +1881,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; - yy_switch_to_buffer( b ); + yy_switch_to_buffer( b , yyscanner ); return b; } @@ -1873,25 +1889,25 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /** Setup the input buffer state to scan a string. The next call to yylex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ -YY_BUFFER_STATE yy_scan_string (const char * yystr ) +YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner) { - return yy_scan_bytes( yystr, (int) strlen(yystr) ); + return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner); } /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner) { YY_BUFFER_STATE b; char *buf; @@ -1900,7 +1916,7 @@ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) /* Get memory for full buffer, including space for trailing EOB's. */ n = (yy_size_t) (_yybytes_len + 2); - buf = (char *) yyalloc( n ); + buf = (char *) yyalloc( n , yyscanner ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); @@ -1909,7 +1925,7 @@ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - b = yy_scan_buffer( buf, n ); + b = yy_scan_buffer( buf, n , yyscanner); if ( ! b ) YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); @@ -1925,9 +1941,11 @@ YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) #define YY_EXIT_FAILURE 2 #endif -static void yynoreturn yy_fatal_error (const char* msg ) +static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner) { - fprintf( stderr, "%s\n", msg ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } @@ -1940,109 +1958,249 @@ static void yynoreturn yy_fatal_error (const char* msg ) /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ yyleng = yyless_macro_arg; \ } \ while ( 0 ) /* Accessor methods (get/set functions) to struct members. */ -/** Get the current line number. - * +/** Get the user-defined data for this scanner. + * @param yyscanner The scanner object. */ -int yyget_lineno (void) +YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyextra; +} + +/** Get the current line number. + * @param yyscanner The scanner object. + */ +int yyget_lineno (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; return yylineno; } -/** Get the input stream. - * +/** Get the current column number. + * @param yyscanner The scanner object. */ -FILE *yyget_in (void) +int yyget_column (yyscan_t yyscanner) { - return yyin; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yycolumn; +} + +/** Get the input stream. + * @param yyscanner The scanner object. + */ +FILE *yyget_in (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyin; } /** Get the output stream. - * + * @param yyscanner The scanner object. */ -FILE *yyget_out (void) +FILE *yyget_out (yyscan_t yyscanner) { - return yyout; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyout; } /** Get the length of the current token. - * + * @param yyscanner The scanner object. */ -int yyget_leng (void) +int yyget_leng (yyscan_t yyscanner) { - return yyleng; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyleng; } /** Get the current token. - * + * @param yyscanner The scanner object. */ -char *yyget_text (void) +char *yyget_text (yyscan_t yyscanner) { - return yytext; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yytext; +} + +/** Set the user-defined data. This data is never touched by the scanner. + * @param user_defined The data to be associated with this scanner. + * @param yyscanner The scanner object. + */ +void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyextra = user_defined ; } /** Set the current line number. * @param _line_number line number - * + * @param yyscanner The scanner object. */ -void yyset_lineno (int _line_number ) +void yyset_lineno (int _line_number , yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* lineno is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + YY_FATAL_ERROR( "yyset_lineno called with no buffer" ); yylineno = _line_number; } +/** Set the current column. + * @param _column_no column number + * @param yyscanner The scanner object. + */ +void yyset_column (int _column_no , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* column is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + YY_FATAL_ERROR( "yyset_column called with no buffer" ); + + yycolumn = _column_no; +} + /** Set the input stream. This does not discard the current * input buffer. * @param _in_str A readable stream. - * + * @param yyscanner The scanner object. * @see yy_switch_to_buffer */ -void yyset_in (FILE * _in_str ) +void yyset_in (FILE * _in_str , yyscan_t yyscanner) { - yyin = _in_str ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyin = _in_str ; } -void yyset_out (FILE * _out_str ) +void yyset_out (FILE * _out_str , yyscan_t yyscanner) { - yyout = _out_str ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyout = _out_str ; } -int yyget_debug (void) +int yyget_debug (yyscan_t yyscanner) { - return yy_flex_debug; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yy_flex_debug; } -void yyset_debug (int _bdebug ) +void yyset_debug (int _bdebug , yyscan_t yyscanner) { - yy_flex_debug = _bdebug ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_flex_debug = _bdebug ; } -static int yy_init_globals (void) +/* Accessor methods for yylval and yylloc */ + +YYSTYPE * yyget_lval (yyscan_t yyscanner) { - /* Initialization is the same as for the non-reentrant scanner. + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yylval; +} + +void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yylval = yylval_param; +} + +/* User-visible API */ + +/* yylex_init is special because it creates the scanner itself, so it is + * the ONLY reentrant function that doesn't take the scanner as the last argument. + * That's why we explicitly handle the declaration, instead of using our macros. + */ +int yylex_init(yyscan_t* ptr_yy_globals) +{ + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + return yy_init_globals ( *ptr_yy_globals ); +} + +/* yylex_init_extra has the same functionality as yylex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to yyalloc in + * the yyextra field. + */ +int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals ) +{ + struct yyguts_t dummy_yyguts; + + yyset_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + yyset_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); +} + +static int yy_init_globals (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Initialization is the same as for the non-reentrant scanner. * This function is called from yylex_destroy(), so don't allocate here. */ - /* We do not touch yylineno unless the option is enabled. */ - yylineno = 1; - - (yy_buffer_stack) = NULL; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = NULL; - (yy_init) = 0; - (yy_start) = 0; + yyg->yy_buffer_stack = NULL; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = NULL; + yyg->yy_init = 0; + yyg->yy_start = 0; + + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; /* Defined in main.c */ #ifdef YY_STDINIT @@ -2060,24 +2218,32 @@ static int yy_init_globals (void) } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) +int yylex_destroy (yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ - yy_delete_buffer( YY_CURRENT_BUFFER ); + yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner ); YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); + yypop_buffer_state(yyscanner); } /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; + yyfree(yyg->yy_buffer_stack , yyscanner); + yyg->yy_buffer_stack = NULL; + + /* Destroy the start condition stack. */ + yyfree( yyg->yy_start_stack , yyscanner ); + yyg->yy_start_stack = NULL; /* Reset the globals. This is important in a non-reentrant scanner so the next time * yylex() is called, initialization will occur. */ - yy_init_globals( ); + yy_init_globals( yyscanner); + /* Destroy the main struct (reentrant only). */ + yyfree ( yyscanner , yyscanner ); + yyscanner = NULL; return 0; } @@ -2086,9 +2252,11 @@ int yylex_destroy (void) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, const char * s2, int n ) +static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; @@ -2096,7 +2264,7 @@ static void yy_flex_strncpy (char* s1, const char * s2, int n ) #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (const char * s ) +static int yy_flex_strlen (const char * s , yyscan_t yyscanner) { int n; for ( n = 0; s[n]; ++n ) @@ -2106,14 +2274,18 @@ static int yy_flex_strlen (const char * s ) } #endif -void *yyalloc (yy_size_t size ) +void *yyalloc (yy_size_t size , yyscan_t yyscanner) { - return malloc(size); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + return malloc(size); } -void *yyrealloc (void * ptr, yy_size_t size ) +void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter @@ -2124,17 +2296,19 @@ void *yyrealloc (void * ptr, yy_size_t size ) return realloc(ptr, size); } -void yyfree (void * ptr ) +void yyfree (void * ptr , yyscan_t yyscanner) { - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + (void)yyg; + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" -#line 93 "vm_var_parser.l" +#line 97 "vm_var_parser.l" -int vm_var_wrap() +int vm_var_wrap(yyscan_t scanner) { return 1; } diff --git a/src/parsers/vm_var_parser.h b/src/parsers/vm_var_parser.h new file mode 100644 index 0000000000..b0764e7569 --- /dev/null +++ b/src/parsers/vm_var_parser.h @@ -0,0 +1,719 @@ +#ifndef vm_var_HEADER_H +#define vm_var_HEADER_H 1 +#define vm_var_IN_HEADER 1 + +#line 5 "vm_var_parser.h" + +#line 7 "vm_var_parser.h" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 4 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +#ifdef yy_create_buffer +#define vm_var__create_buffer_ALREADY_DEFINED +#else +#define yy_create_buffer vm_var__create_buffer +#endif + +#ifdef yy_delete_buffer +#define vm_var__delete_buffer_ALREADY_DEFINED +#else +#define yy_delete_buffer vm_var__delete_buffer +#endif + +#ifdef yy_scan_buffer +#define vm_var__scan_buffer_ALREADY_DEFINED +#else +#define yy_scan_buffer vm_var__scan_buffer +#endif + +#ifdef yy_scan_string +#define vm_var__scan_string_ALREADY_DEFINED +#else +#define yy_scan_string vm_var__scan_string +#endif + +#ifdef yy_scan_bytes +#define vm_var__scan_bytes_ALREADY_DEFINED +#else +#define yy_scan_bytes vm_var__scan_bytes +#endif + +#ifdef yy_init_buffer +#define vm_var__init_buffer_ALREADY_DEFINED +#else +#define yy_init_buffer vm_var__init_buffer +#endif + +#ifdef yy_flush_buffer +#define vm_var__flush_buffer_ALREADY_DEFINED +#else +#define yy_flush_buffer vm_var__flush_buffer +#endif + +#ifdef yy_load_buffer_state +#define vm_var__load_buffer_state_ALREADY_DEFINED +#else +#define yy_load_buffer_state vm_var__load_buffer_state +#endif + +#ifdef yy_switch_to_buffer +#define vm_var__switch_to_buffer_ALREADY_DEFINED +#else +#define yy_switch_to_buffer vm_var__switch_to_buffer +#endif + +#ifdef yypush_buffer_state +#define vm_var_push_buffer_state_ALREADY_DEFINED +#else +#define yypush_buffer_state vm_var_push_buffer_state +#endif + +#ifdef yypop_buffer_state +#define vm_var_pop_buffer_state_ALREADY_DEFINED +#else +#define yypop_buffer_state vm_var_pop_buffer_state +#endif + +#ifdef yyensure_buffer_stack +#define vm_var_ensure_buffer_stack_ALREADY_DEFINED +#else +#define yyensure_buffer_stack vm_var_ensure_buffer_stack +#endif + +#ifdef yylex +#define vm_var_lex_ALREADY_DEFINED +#else +#define yylex vm_var_lex +#endif + +#ifdef yyrestart +#define vm_var_restart_ALREADY_DEFINED +#else +#define yyrestart vm_var_restart +#endif + +#ifdef yylex_init +#define vm_var_lex_init_ALREADY_DEFINED +#else +#define yylex_init vm_var_lex_init +#endif + +#ifdef yylex_init_extra +#define vm_var_lex_init_extra_ALREADY_DEFINED +#else +#define yylex_init_extra vm_var_lex_init_extra +#endif + +#ifdef yylex_destroy +#define vm_var_lex_destroy_ALREADY_DEFINED +#else +#define yylex_destroy vm_var_lex_destroy +#endif + +#ifdef yyget_debug +#define vm_var_get_debug_ALREADY_DEFINED +#else +#define yyget_debug vm_var_get_debug +#endif + +#ifdef yyset_debug +#define vm_var_set_debug_ALREADY_DEFINED +#else +#define yyset_debug vm_var_set_debug +#endif + +#ifdef yyget_extra +#define vm_var_get_extra_ALREADY_DEFINED +#else +#define yyget_extra vm_var_get_extra +#endif + +#ifdef yyset_extra +#define vm_var_set_extra_ALREADY_DEFINED +#else +#define yyset_extra vm_var_set_extra +#endif + +#ifdef yyget_in +#define vm_var_get_in_ALREADY_DEFINED +#else +#define yyget_in vm_var_get_in +#endif + +#ifdef yyset_in +#define vm_var_set_in_ALREADY_DEFINED +#else +#define yyset_in vm_var_set_in +#endif + +#ifdef yyget_out +#define vm_var_get_out_ALREADY_DEFINED +#else +#define yyget_out vm_var_get_out +#endif + +#ifdef yyset_out +#define vm_var_set_out_ALREADY_DEFINED +#else +#define yyset_out vm_var_set_out +#endif + +#ifdef yyget_leng +#define vm_var_get_leng_ALREADY_DEFINED +#else +#define yyget_leng vm_var_get_leng +#endif + +#ifdef yyget_text +#define vm_var_get_text_ALREADY_DEFINED +#else +#define yyget_text vm_var_get_text +#endif + +#ifdef yyget_lineno +#define vm_var_get_lineno_ALREADY_DEFINED +#else +#define yyget_lineno vm_var_get_lineno +#endif + +#ifdef yyset_lineno +#define vm_var_set_lineno_ALREADY_DEFINED +#else +#define yyset_lineno vm_var_set_lineno +#endif + +#ifdef yyget_column +#define vm_var_get_column_ALREADY_DEFINED +#else +#define yyget_column vm_var_get_column +#endif + +#ifdef yyset_column +#define vm_var_set_column_ALREADY_DEFINED +#else +#define yyset_column vm_var_set_column +#endif + +#ifdef yywrap +#define vm_var_wrap_ALREADY_DEFINED +#else +#define yywrap vm_var_wrap +#endif + +#ifdef yyget_lval +#define vm_var_get_lval_ALREADY_DEFINED +#else +#define yyget_lval vm_var_get_lval +#endif + +#ifdef yyset_lval +#define vm_var_set_lval_ALREADY_DEFINED +#else +#define yyset_lval vm_var_set_lval +#endif + +#ifdef yyalloc +#define vm_var_alloc_ALREADY_DEFINED +#else +#define yyalloc vm_var_alloc +#endif + +#ifdef yyrealloc +#define vm_var_realloc_ALREADY_DEFINED +#else +#define yyrealloc vm_var_realloc +#endif + +#ifdef yyfree +#define vm_var_free_ALREADY_DEFINED +#else +#define yyfree vm_var_free +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* begin standard C++ headers. */ + +/* TODO: this is always defined, so inline it */ +#define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) +#else +#define yynoreturn +#endif + +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +void yyrestart ( FILE *input_file , yyscan_t yyscanner ); +void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner ); +void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner ); +void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); +void yypop_buffer_state ( yyscan_t yyscanner ); + +YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner ); + +void *yyalloc ( yy_size_t , yyscan_t yyscanner ); +void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner ); +void yyfree ( void * , yyscan_t yyscanner ); + +/* Begin user sect3 */ + +#define yytext_ptr yytext_r + +#ifdef YY_HEADER_EXPORT_START_CONDITIONS +#define INITIAL 0 +#define VAR 1 +#define VALUE 2 + +#endif + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +int yylex_init (yyscan_t* scanner); + +int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy ( yyscan_t yyscanner ); + +int yyget_debug ( yyscan_t yyscanner ); + +void yyset_debug ( int debug_flag , yyscan_t yyscanner ); + +YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner ); + +void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); + +FILE *yyget_in ( yyscan_t yyscanner ); + +void yyset_in ( FILE * _in_str , yyscan_t yyscanner ); + +FILE *yyget_out ( yyscan_t yyscanner ); + +void yyset_out ( FILE * _out_str , yyscan_t yyscanner ); + + int yyget_leng ( yyscan_t yyscanner ); + +char *yyget_text ( yyscan_t yyscanner ); + +int yyget_lineno ( yyscan_t yyscanner ); + +void yyset_lineno ( int _line_number , yyscan_t yyscanner ); + +int yyget_column ( yyscan_t yyscanner ); + +void yyset_column ( int _column_no , yyscan_t yyscanner ); + +YYSTYPE * yyget_lval ( yyscan_t yyscanner ); + +void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap ( yyscan_t yyscanner ); +#else +extern int yywrap ( yyscan_t yyscanner ); +#endif +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen ( const char * , yyscan_t yyscanner); +#endif + +#ifndef YY_NO_INPUT + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner); + +#define YY_DECL int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner) +#endif /* !YY_DECL */ + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +#undef YY_NEW_FILE +#undef YY_FLUSH_BUFFER +#undef yy_set_bol +#undef yy_new_buffer +#undef yy_set_interactive +#undef YY_DO_BEFORE_ACTION + +#ifdef YY_DECL_IS_OURS +#undef YY_DECL_IS_OURS +#undef YY_DECL +#endif + +#ifndef vm_var__create_buffer_ALREADY_DEFINED +#undef yy_create_buffer +#endif +#ifndef vm_var__delete_buffer_ALREADY_DEFINED +#undef yy_delete_buffer +#endif +#ifndef vm_var__scan_buffer_ALREADY_DEFINED +#undef yy_scan_buffer +#endif +#ifndef vm_var__scan_string_ALREADY_DEFINED +#undef yy_scan_string +#endif +#ifndef vm_var__scan_bytes_ALREADY_DEFINED +#undef yy_scan_bytes +#endif +#ifndef vm_var__init_buffer_ALREADY_DEFINED +#undef yy_init_buffer +#endif +#ifndef vm_var__flush_buffer_ALREADY_DEFINED +#undef yy_flush_buffer +#endif +#ifndef vm_var__load_buffer_state_ALREADY_DEFINED +#undef yy_load_buffer_state +#endif +#ifndef vm_var__switch_to_buffer_ALREADY_DEFINED +#undef yy_switch_to_buffer +#endif +#ifndef vm_var_push_buffer_state_ALREADY_DEFINED +#undef yypush_buffer_state +#endif +#ifndef vm_var_pop_buffer_state_ALREADY_DEFINED +#undef yypop_buffer_state +#endif +#ifndef vm_var_ensure_buffer_stack_ALREADY_DEFINED +#undef yyensure_buffer_stack +#endif +#ifndef vm_var_lex_ALREADY_DEFINED +#undef yylex +#endif +#ifndef vm_var_restart_ALREADY_DEFINED +#undef yyrestart +#endif +#ifndef vm_var_lex_init_ALREADY_DEFINED +#undef yylex_init +#endif +#ifndef vm_var_lex_init_extra_ALREADY_DEFINED +#undef yylex_init_extra +#endif +#ifndef vm_var_lex_destroy_ALREADY_DEFINED +#undef yylex_destroy +#endif +#ifndef vm_var_get_debug_ALREADY_DEFINED +#undef yyget_debug +#endif +#ifndef vm_var_set_debug_ALREADY_DEFINED +#undef yyset_debug +#endif +#ifndef vm_var_get_extra_ALREADY_DEFINED +#undef yyget_extra +#endif +#ifndef vm_var_set_extra_ALREADY_DEFINED +#undef yyset_extra +#endif +#ifndef vm_var_get_in_ALREADY_DEFINED +#undef yyget_in +#endif +#ifndef vm_var_set_in_ALREADY_DEFINED +#undef yyset_in +#endif +#ifndef vm_var_get_out_ALREADY_DEFINED +#undef yyget_out +#endif +#ifndef vm_var_set_out_ALREADY_DEFINED +#undef yyset_out +#endif +#ifndef vm_var_get_leng_ALREADY_DEFINED +#undef yyget_leng +#endif +#ifndef vm_var_get_text_ALREADY_DEFINED +#undef yyget_text +#endif +#ifndef vm_var_get_lineno_ALREADY_DEFINED +#undef yyget_lineno +#endif +#ifndef vm_var_set_lineno_ALREADY_DEFINED +#undef yyset_lineno +#endif +#ifndef vm_var_get_column_ALREADY_DEFINED +#undef yyget_column +#endif +#ifndef vm_var_set_column_ALREADY_DEFINED +#undef yyset_column +#endif +#ifndef vm_var_wrap_ALREADY_DEFINED +#undef yywrap +#endif +#ifndef vm_var_get_lval_ALREADY_DEFINED +#undef yyget_lval +#endif +#ifndef vm_var_set_lval_ALREADY_DEFINED +#undef yyset_lval +#endif +#ifndef vm_var_get_lloc_ALREADY_DEFINED +#undef yyget_lloc +#endif +#ifndef vm_var_set_lloc_ALREADY_DEFINED +#undef yyset_lloc +#endif +#ifndef vm_var_alloc_ALREADY_DEFINED +#undef yyalloc +#endif +#ifndef vm_var_realloc_ALREADY_DEFINED +#undef yyrealloc +#endif +#ifndef vm_var_free_ALREADY_DEFINED +#undef yyfree +#endif +#ifndef vm_var_text_ALREADY_DEFINED +#undef yytext +#endif +#ifndef vm_var_leng_ALREADY_DEFINED +#undef yyleng +#endif +#ifndef vm_var_in_ALREADY_DEFINED +#undef yyin +#endif +#ifndef vm_var_out_ALREADY_DEFINED +#undef yyout +#endif +#ifndef vm_var__flex_debug_ALREADY_DEFINED +#undef yy_flex_debug +#endif +#ifndef vm_var_lineno_ALREADY_DEFINED +#undef yylineno +#endif +#ifndef vm_var_tables_fload_ALREADY_DEFINED +#undef yytables_fload +#endif +#ifndef vm_var_tables_destroy_ALREADY_DEFINED +#undef yytables_destroy +#endif +#ifndef vm_var_TABLES_NAME_ALREADY_DEFINED +#undef yyTABLES_NAME +#endif + +#line 97 "vm_var_parser.l" + + +#line 717 "vm_var_parser.h" +#undef vm_var_IN_HEADER +#endif /* vm_var_HEADER_H */ diff --git a/src/vm/vm_var_parser.l b/src/parsers/vm_var_parser.l similarity index 80% rename from src/vm/vm_var_parser.l rename to src/parsers/vm_var_parser.l index e463fe08bc..c70a15eece 100644 --- a/src/vm/vm_var_parser.l +++ b/src/parsers/vm_var_parser.l @@ -21,12 +21,13 @@ #include #include "vm_var_syntax.h" +#include "vm_file_var_syntax.h" #include "mem_collector.h" #define YY_NO_INPUT -#define YY_DECL int vm_var_lex (YYSTYPE *lvalp, YYLTYPE *llocp, \ - mem_collector *mc) +#define YY_DECL int vm_var_lex (YYSTYPE *yylval_param, YYLTYPE *llocp, \ + mem_collector *mc, yyscan_t yyscanner) #define YY_USER_ACTION llocp->first_line = yylineno; \ llocp->first_column = llocp->last_column; \ @@ -35,8 +36,11 @@ %option nounput %option prefix="vm_var_" -%option outfile="vm_var_parser.c" +%option outfile="vm_var_parser.cc" +%option header-file="vm_var_parser.h" %option yylineno +%option bison-bridge +%option reentrant %x VAR %x VALUE @@ -57,29 +61,29 @@ \[[[:blank:]]* { return OBRACKET;} [[:blank:]]*\] { return CBRACKET;} -[[:alnum:]_]+ { lvalp->val_str = +[[:alnum:]_]+ { yylval_param->val_str = mem_collector_strdup(mc,yytext); return VARIABLE;} -\"[^\"]*\" { lvalp->val_str = +\"[^\"]*\" { yylval_param->val_str = mem_collector_strdup(mc,yytext+1); - lvalp->val_str[yyleng-2] = '\0'; + yylval_param->val_str[yyleng-2] = '\0'; BEGIN(VAR); return STRING;} -[[:alnum:]]+ { lvalp->val_str = +[[:alnum:]]+ { yylval_param->val_str = mem_collector_strdup(mc,yytext); BEGIN(VAR); return STRING;} -\$ { lvalp->val_char = '\0'; +\$ { yylval_param->val_char = '\0'; return EOA;} -. { lvalp->val_char = *yytext; +. { yylval_param->val_char = *yytext; BEGIN(INITIAL); return EOA;} -<> { lvalp->val_char = '\0'; +<> { yylval_param->val_char = '\0'; BEGIN(INITIAL); return EOA;} @@ -87,11 +91,11 @@ /* Just copy the string verbatim till we find a variable (starts with $) */ /* ------------------------------------------------------------------------- */ -[^\$]+ { lvalp->val_str = mem_collector_strdup(mc,yytext); return RSTRING;} +[^\$]+ { yylval_param->val_str = mem_collector_strdup(mc,yytext); return RSTRING;} %% -int vm_var_wrap() +int vm_var_wrap(yyscan_t scanner) { return 1; } diff --git a/src/vm/vm_var_syntax.cc b/src/parsers/vm_var_syntax.cc similarity index 94% rename from src/vm/vm_var_syntax.cc rename to src/parsers/vm_var_syntax.cc index a3ce90aa40..75f8c5489a 100644 --- a/src/vm/vm_var_syntax.cc +++ b/src/parsers/vm_var_syntax.cc @@ -60,70 +60,42 @@ /* Substitute the variable and function names. */ -#define yyparse vm_var__parse -#define yylex vm_var__lex -#define yyerror vm_var__error -#define yydebug vm_var__debug -#define yynerrs vm_var__nerrs +#define yyparse vm_var_parse +#define yylex vm_var_lex +#define yyerror vm_var_error +#define yydebug vm_var_debug +#define yynerrs vm_var_nerrs /* Copy the first part of user declarations. */ -#line 17 "vm_var_syntax.y" /* yacc.c:339 */ - -#include -#include -#include -#include -#include - -#include -#include +#line 39 "vm_var_syntax.y" /* yacc.c:339 */ #include "vm_var_syntax.h" -#include "VirtualMachinePool.h" -#include "VirtualMachine.h" -#include "Nebula.h" +#include "vm_var_parser.h" -#define vm_var__lex vm_var_lex +#include "NebulaUtil.h" #define YYERROR_VERBOSE -#define VM_VAR_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \ -(int(*)(int))toupper) -extern "C" +void vm_var_error(YYLTYPE * llocp, mem_collector * mc, VirtualMachine * vm, + ostringstream * parsed, char ** errmsg, yyscan_t scanner, const char * str); + +int vm_var_lex(YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc, + yyscan_t scanner); + +int vm_var_parse (VirtualMachine * vm, ostringstream * parsed, char ** errmsg, + yyscan_t scanner) { - #include "mem_collector.h" + mem_collector mc; + int rc; - void vm_var__error( - YYLTYPE * llocp, - mem_collector * mc, - VirtualMachine * vm, - ostringstream * parsed, - char ** errmsg, - const char * str); + mem_collector_init(&mc); - int vm_var__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + rc = vm_var_parse(&mc, vm, parsed, errmsg, scanner); - int vm_var__parse (mem_collector * mc, - VirtualMachine * vm, - ostringstream * parsed, - char ** errmsg); + mem_collector_cleanup(&mc); - int vm_var_parse (VirtualMachine * vm, - ostringstream * parsed, - char ** errmsg) - { - mem_collector mc; - int rc; - - mem_collector_init(&mc); - - rc = vm_var__parse(&mc, vm, parsed, errmsg); - - mem_collector_cleanup(&mc); - - return rc; - } + return rc; } /* -------------------------------------------------------------------------- */ @@ -183,7 +155,7 @@ void get_image_attribute(VirtualMachine * vm, // ---------------------------------------------- // Get the attribute template from the image // ---------------------------------------------- - img = ipool->get(iid, true); + img = ipool->get(iid); if ( img == 0 ) { @@ -260,7 +232,7 @@ void get_network_attribute(VirtualMachine * vm, // ---------------------------------------------- // Get the attribute template from the image // ---------------------------------------------- - vn = vnpool->get(vnet_id, true); + vn = vnpool->get(vnet_id); if ( vn == 0 ) { @@ -293,7 +265,7 @@ void get_user_attribute(VirtualMachine * vm, attr_value.clear(); - user = upool->get(vm->get_uid(), true); + user = upool->get(vm->get_uid()); if ( user == 0 ) { @@ -452,7 +424,7 @@ void insert_vector(VirtualMachine * vm, /* -------------------------------------------------------------------------- */ -#line 456 "vm_var_syntax.cc" /* yacc.c:339 */ +#line 428 "vm_var_syntax.cc" /* yacc.c:339 */ # ifndef YY_NULLPTR # if defined __cplusplus && 201103L <= __cplusplus @@ -479,8 +451,32 @@ void insert_vector(VirtualMachine * vm, # define YYDEBUG 0 #endif #if YYDEBUG -extern int vm_var__debug; +extern int vm_var_debug; #endif +/* "%code requires" blocks. */ +#line 17 "vm_var_syntax.y" /* yacc.c:355 */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "VirtualMachinePool.h" +#include "VirtualMachine.h" +#include "Nebula.h" + +#include "mem_collector.h" + +typedef void * yyscan_t; + +int vm_var_parse (VirtualMachine * vm, ostringstream * parsed, char ** errmsg, + yyscan_t scanner); + +#line 480 "vm_var_syntax.cc" /* yacc.c:355 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -504,13 +500,13 @@ extern int vm_var__debug; union YYSTYPE { -#line 408 "vm_var_syntax.y" /* yacc.c:355 */ +#line 404 "vm_var_syntax.y" /* yacc.c:355 */ char * val_str; int val_int; char val_char; -#line 514 "vm_var_syntax.cc" /* yacc.c:355 */ +#line 510 "vm_var_syntax.cc" /* yacc.c:355 */ }; typedef union YYSTYPE YYSTYPE; @@ -534,13 +530,13 @@ struct YYLTYPE -int vm_var__parse (mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg); +int vm_var_parse (mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg, yyscan_t scanner); #endif /* !YY_VM_VAR_VM_VAR_SYNTAX_HH_INCLUDED */ /* Copy the second part of user declarations. */ -#line 544 "vm_var_syntax.cc" /* yacc.c:358 */ +#line 540 "vm_var_syntax.cc" /* yacc.c:358 */ #ifdef short # undef short @@ -840,7 +836,7 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 432, 432, 433, 436, 440, 453, 468 + 0, 428, 428, 429, 432, 436, 449, 464 }; #endif @@ -964,7 +960,7 @@ do \ } \ else \ { \ - yyerror (&yylloc, mc, vm, parsed, errmsg, YY_("syntax error: cannot back up")); \ + yyerror (&yylloc, mc, vm, parsed, errmsg, scanner, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (0) @@ -1066,7 +1062,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, Location, mc, vm, parsed, errmsg); \ + Type, Value, Location, mc, vm, parsed, errmsg, scanner); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -1077,7 +1073,7 @@ do { \ `----------------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg, yyscan_t scanner) { FILE *yyo = yyoutput; YYUSE (yyo); @@ -1086,6 +1082,7 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue YYUSE (vm); YYUSE (parsed); YYUSE (errmsg); + YYUSE (scanner); if (!yyvaluep) return; # ifdef YYPRINT @@ -1101,14 +1098,14 @@ yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvalue `--------------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg, yyscan_t scanner) { YYFPRINTF (yyoutput, "%s %s (", yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); YY_LOCATION_PRINT (yyoutput, *yylocationp); YYFPRINTF (yyoutput, ": "); - yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, vm, parsed, errmsg); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, vm, parsed, errmsg, scanner); YYFPRINTF (yyoutput, ")"); } @@ -1141,7 +1138,7 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg) +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg, yyscan_t scanner) { unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; @@ -1155,7 +1152,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule yy_symbol_print (stderr, yystos[yyssp[yyi + 1 - yynrhs]], &(yyvsp[(yyi + 1) - (yynrhs)]) - , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, vm, parsed, errmsg); + , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, vm, parsed, errmsg, scanner); YYFPRINTF (stderr, "\n"); } } @@ -1163,7 +1160,7 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyssp, yyvsp, yylsp, Rule, mc, vm, parsed, errmsg); \ + yy_reduce_print (yyssp, yyvsp, yylsp, Rule, mc, vm, parsed, errmsg, scanner); \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that @@ -1421,7 +1418,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg, yyscan_t scanner) { YYUSE (yyvaluep); YYUSE (yylocationp); @@ -1429,6 +1426,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio YYUSE (vm); YYUSE (parsed); YYUSE (errmsg); + YYUSE (scanner); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); @@ -1446,7 +1444,7 @@ yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocatio `----------*/ int -yyparse (mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg) +yyparse (mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg, yyscan_t scanner) { /* The lookahead symbol. */ int yychar; @@ -1640,7 +1638,7 @@ yybackup: if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); - yychar = yylex (&yylval, &yylloc, mc); + yychar = yylex (&yylval, &yylloc, mc, scanner); } if (yychar <= YYEOF) @@ -1720,19 +1718,19 @@ yyreduce: switch (yyn) { case 4: -#line 437 "vm_var_syntax.y" /* yacc.c:1646 */ +#line 433 "vm_var_syntax.y" /* yacc.c:1646 */ { (*parsed) << (yyvsp[0].val_str); } -#line 1728 "vm_var_syntax.cc" /* yacc.c:1646 */ +#line 1726 "vm_var_syntax.cc" /* yacc.c:1646 */ break; case 5: -#line 441 "vm_var_syntax.y" /* yacc.c:1646 */ +#line 437 "vm_var_syntax.y" /* yacc.c:1646 */ { string name((yyvsp[-1].val_str)); - VM_VAR_TO_UPPER(name); + one_util::toupper(name); insert_single(vm,*parsed,name); @@ -1741,17 +1739,17 @@ yyreduce: (*parsed) << (yyvsp[0].val_char); } } -#line 1745 "vm_var_syntax.cc" /* yacc.c:1646 */ +#line 1743 "vm_var_syntax.cc" /* yacc.c:1646 */ break; case 6: -#line 454 "vm_var_syntax.y" /* yacc.c:1646 */ +#line 450 "vm_var_syntax.y" /* yacc.c:1646 */ { string name((yyvsp[-4].val_str)); string vname((yyvsp[-2].val_str)); - VM_VAR_TO_UPPER(name); - VM_VAR_TO_UPPER(vname); + one_util::toupper(name); + one_util::toupper(vname); insert_vector(vm,*parsed,name,vname,"",""); @@ -1760,20 +1758,20 @@ yyreduce: (*parsed) << (yyvsp[0].val_char); } } -#line 1764 "vm_var_syntax.cc" /* yacc.c:1646 */ +#line 1762 "vm_var_syntax.cc" /* yacc.c:1646 */ break; case 7: -#line 469 "vm_var_syntax.y" /* yacc.c:1646 */ +#line 465 "vm_var_syntax.y" /* yacc.c:1646 */ { string name((yyvsp[-8].val_str)); string vname((yyvsp[-6].val_str)); string vvar((yyvsp[-4].val_str)); string vval((yyvsp[-2].val_str)); - VM_VAR_TO_UPPER(name); - VM_VAR_TO_UPPER(vname); - VM_VAR_TO_UPPER(vvar); + one_util::toupper(name); + one_util::toupper(vname); + one_util::toupper(vvar); insert_vector(vm,*parsed,name,vname,vvar,vval); @@ -1782,11 +1780,11 @@ yyreduce: (*parsed) << (yyvsp[0].val_char); } } -#line 1786 "vm_var_syntax.cc" /* yacc.c:1646 */ +#line 1784 "vm_var_syntax.cc" /* yacc.c:1646 */ break; -#line 1790 "vm_var_syntax.cc" /* yacc.c:1646 */ +#line 1788 "vm_var_syntax.cc" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1837,7 +1835,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (&yylloc, mc, vm, parsed, errmsg, YY_("syntax error")); + yyerror (&yylloc, mc, vm, parsed, errmsg, scanner, YY_("syntax error")); #else # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ yyssp, yytoken) @@ -1864,7 +1862,7 @@ yyerrlab: yymsgp = yymsg; } } - yyerror (&yylloc, mc, vm, parsed, errmsg, yymsgp); + yyerror (&yylloc, mc, vm, parsed, errmsg, scanner, yymsgp); if (yysyntax_error_status == 2) goto yyexhaustedlab; } @@ -1888,7 +1886,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval, &yylloc, mc, vm, parsed, errmsg); + yytoken, &yylval, &yylloc, mc, vm, parsed, errmsg, scanner); yychar = YYEMPTY; } } @@ -1945,7 +1943,7 @@ yyerrlab1: yyerror_range[1] = *yylsp; yydestruct ("Error: popping", - yystos[yystate], yyvsp, yylsp, mc, vm, parsed, errmsg); + yystos[yystate], yyvsp, yylsp, mc, vm, parsed, errmsg, scanner); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -1987,7 +1985,7 @@ yyabortlab: | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (&yylloc, mc, vm, parsed, errmsg, YY_("memory exhausted")); + yyerror (&yylloc, mc, vm, parsed, errmsg, scanner, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif @@ -1999,7 +1997,7 @@ yyreturn: user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, mc, vm, parsed, errmsg); + yytoken, &yylval, &yylloc, mc, vm, parsed, errmsg, scanner); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ @@ -2008,7 +2006,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yylsp, mc, vm, parsed, errmsg); + yystos[*yyssp], yyvsp, yylsp, mc, vm, parsed, errmsg, scanner); YYPOPSTACK (1); } #ifndef yyoverflow @@ -2021,15 +2019,16 @@ yyreturn: #endif return yyresult; } -#line 487 "vm_var_syntax.y" /* yacc.c:1906 */ +#line 483 "vm_var_syntax.y" /* yacc.c:1906 */ -extern "C" void vm_var__error( +void vm_var_error( YYLTYPE * llocp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** error_msg, + yyscan_t scanner, const char * str) { int length; diff --git a/src/vm/vm_var_syntax.h b/src/parsers/vm_var_syntax.h similarity index 77% rename from src/vm/vm_var_syntax.h rename to src/parsers/vm_var_syntax.h index 52def943b4..c1dc7710aa 100644 --- a/src/vm/vm_var_syntax.h +++ b/src/parsers/vm_var_syntax.h @@ -37,8 +37,32 @@ # define YYDEBUG 0 #endif #if YYDEBUG -extern int vm_var__debug; +extern int vm_var_debug; #endif +/* "%code requires" blocks. */ +#line 17 "vm_var_syntax.y" /* yacc.c:1909 */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "VirtualMachinePool.h" +#include "VirtualMachine.h" +#include "Nebula.h" + +#include "mem_collector.h" + +typedef void * yyscan_t; + +int vm_var_parse (VirtualMachine * vm, ostringstream * parsed, char ** errmsg, + yyscan_t scanner); + +#line 66 "vm_var_syntax.hh" /* yacc.c:1909 */ /* Token type. */ #ifndef YYTOKENTYPE @@ -62,13 +86,13 @@ extern int vm_var__debug; union YYSTYPE { -#line 408 "vm_var_syntax.y" /* yacc.c:1909 */ +#line 404 "vm_var_syntax.y" /* yacc.c:1909 */ char * val_str; int val_int; char val_char; -#line 72 "vm_var_syntax.hh" /* yacc.c:1909 */ +#line 96 "vm_var_syntax.hh" /* yacc.c:1909 */ }; typedef union YYSTYPE YYSTYPE; @@ -90,4 +114,8 @@ struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif + + +int vm_var_parse (mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** errmsg, yyscan_t scanner); + #endif /* !YY_VM_VAR_VM_VAR_SYNTAX_HH_INCLUDED */ diff --git a/src/vm/vm_var_syntax.y b/src/parsers/vm_var_syntax.y similarity index 88% rename from src/vm/vm_var_syntax.y rename to src/parsers/vm_var_syntax.y index 486287590b..e2ee359841 100644 --- a/src/vm/vm_var_syntax.y +++ b/src/parsers/vm_var_syntax.y @@ -14,7 +14,7 @@ /* limitations under the License. */ /* -------------------------------------------------------------------------- */ -%{ +%code requires { #include #include #include @@ -24,51 +24,45 @@ #include #include -#include "vm_var_syntax.h" #include "VirtualMachinePool.h" #include "VirtualMachine.h" #include "Nebula.h" -#define vm_var__lex vm_var_lex +#include "mem_collector.h" + +typedef void * yyscan_t; + +int vm_var_parse (VirtualMachine * vm, ostringstream * parsed, char ** errmsg, + yyscan_t scanner); +} + +%{ +#include "vm_var_syntax.h" +#include "vm_var_parser.h" + +#include "NebulaUtil.h" #define YYERROR_VERBOSE -#define VM_VAR_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \ -(int(*)(int))toupper) -extern "C" +void vm_var_error(YYLTYPE * llocp, mem_collector * mc, VirtualMachine * vm, + ostringstream * parsed, char ** errmsg, yyscan_t scanner, const char * str); + +int vm_var_lex(YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc, + yyscan_t scanner); + +int vm_var_parse (VirtualMachine * vm, ostringstream * parsed, char ** errmsg, + yyscan_t scanner) { - #include "mem_collector.h" + mem_collector mc; + int rc; - void vm_var__error( - YYLTYPE * llocp, - mem_collector * mc, - VirtualMachine * vm, - ostringstream * parsed, - char ** errmsg, - const char * str); + mem_collector_init(&mc); - int vm_var__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + rc = vm_var_parse(&mc, vm, parsed, errmsg, scanner); - int vm_var__parse (mem_collector * mc, - VirtualMachine * vm, - ostringstream * parsed, - char ** errmsg); + mem_collector_cleanup(&mc); - int vm_var_parse (VirtualMachine * vm, - ostringstream * parsed, - char ** errmsg) - { - mem_collector mc; - int rc; - - mem_collector_init(&mc); - - rc = vm_var__parse(&mc, vm, parsed, errmsg); - - mem_collector_cleanup(&mc); - - return rc; - } + return rc; } /* -------------------------------------------------------------------------- */ @@ -128,7 +122,7 @@ void get_image_attribute(VirtualMachine * vm, // ---------------------------------------------- // Get the attribute template from the image // ---------------------------------------------- - img = ipool->get(iid, true); + img = ipool->get(iid); if ( img == 0 ) { @@ -205,7 +199,7 @@ void get_network_attribute(VirtualMachine * vm, // ---------------------------------------------- // Get the attribute template from the image // ---------------------------------------------- - vn = vnpool->get(vnet_id, true); + vn = vnpool->get(vnet_id); if ( vn == 0 ) { @@ -238,7 +232,7 @@ void get_user_attribute(VirtualMachine * vm, attr_value.clear(); - user = upool->get(vm->get_uid(), true); + user = upool->get(vm->get_uid()); if ( user == 0 ) { @@ -400,10 +394,12 @@ void insert_vector(VirtualMachine * vm, %parse-param {mem_collector * mc} %parse-param {VirtualMachine * vm} -%parse-param {ostringstream * parsed} -%parse-param {char ** errmsg} +%parse-param {ostringstream * parsed} +%parse-param {char ** errmsg} +%parse-param {yyscan_t scanner} %lex-param {mem_collector * mc} +%lex-param {yyscan_t scanner} %union { char * val_str; @@ -414,7 +410,7 @@ void insert_vector(VirtualMachine * vm, %defines %locations %pure-parser -%name-prefix "vm_var__" +%name-prefix "vm_var_" %output "vm_var_syntax.cc" %token EQUAL COMMA OBRACKET CBRACKET @@ -441,7 +437,7 @@ vm_variable:RSTRING { string name($1); - VM_VAR_TO_UPPER(name); + one_util::toupper(name); insert_single(vm,*parsed,name); @@ -455,8 +451,8 @@ vm_variable:RSTRING string name($1); string vname($3); - VM_VAR_TO_UPPER(name); - VM_VAR_TO_UPPER(vname); + one_util::toupper(name); + one_util::toupper(vname); insert_vector(vm,*parsed,name,vname,"",""); @@ -472,9 +468,9 @@ vm_variable:RSTRING string vvar($5); string vval($7); - VM_VAR_TO_UPPER(name); - VM_VAR_TO_UPPER(vname); - VM_VAR_TO_UPPER(vvar); + one_util::toupper(name); + one_util::toupper(vname); + one_util::toupper(vvar); insert_vector(vm,*parsed,name,vname,vvar,vval); @@ -486,12 +482,13 @@ vm_variable:RSTRING ; %% -extern "C" void vm_var__error( +void vm_var_error( YYLTYPE * llocp, mem_collector * mc, VirtualMachine * vm, ostringstream * parsed, char ** error_msg, + yyscan_t scanner, const char * str) { int length; diff --git a/src/pool/PoolObjectSQL.cc b/src/pool/PoolObjectSQL.cc index d53a099eb2..100950b8e6 100644 --- a/src/pool/PoolObjectSQL.cc +++ b/src/pool/PoolObjectSQL.cc @@ -82,6 +82,80 @@ int PoolObjectSQL::select(SqlDB *db) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int PoolObjectSQL::select_oid(SqlDB *db, const char * _table, + const string& _name, int _uid) +{ + char * sql_name = db->escape_str(_name.c_str()); + + if ( sql_name == 0 ) + { + return -1; + } + + ostringstream oss; + + oss << "SELECT oid FROM " << _table << " WHERE name = '" << sql_name << "'"; + + if ( _uid != -1 ) + { + oss << " AND uid = " << _uid; + } + + int bd_oid = -1; + + single_cb oid_cb; + + oid_cb.set_callback(&bd_oid); + + int rc = db->exec_rd(oss, &oid_cb); + + oid_cb.unset_callback(); + + db->free_str(sql_name); + + if (rc != 0) + { + return -1; + } + + return bd_oid; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int PoolObjectSQL::exist(SqlDB *db, const char * _table, int _oid) +{ + if ( _oid < 0 ) + { + return -1; + } + + ostringstream oss; + + oss << "SELECT oid FROM " << _table << " WHERE oid = '" << _oid << "'"; + + int bd_oid = -1; + + single_cb oid_cb; + + oid_cb.set_callback(&bd_oid); + + int rc = db->exec_rd(oss, &oid_cb); + + oid_cb.unset_callback(); + + if (rc != 0) + { + return -1; + } + + return bd_oid; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + int PoolObjectSQL::select(SqlDB *db, const string& _name, int _uid) { ostringstream oss; @@ -135,11 +209,6 @@ int PoolObjectSQL::drop(SqlDB *db) rc = db->exec_wr(oss); - if ( rc == 0 ) - { - set_valid(false); - } - return rc; } diff --git a/src/pool/PoolSQL.cc b/src/pool/PoolSQL.cc index 1d3db5a229..93d82021c1 100644 --- a/src/pool/PoolSQL.cc +++ b/src/pool/PoolSQL.cc @@ -87,8 +87,7 @@ void PoolSQL::set_lastOID(int _last_oid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -PoolSQL::PoolSQL(SqlDB * _db, const char * _table): - db(_db), table(_table) +PoolSQL::PoolSQL(SqlDB * _db, const char * _table):db(_db), table(_table) { pthread_mutex_init(&mutex,0); }; @@ -102,15 +101,6 @@ PoolSQL::~PoolSQL() pthread_mutex_lock(&mutex); - for ( it = pool.begin(); it != pool.end(); ++it) - { - (*it)->lock(); - - delete *it; - } - - pthread_mutex_unlock(&mutex); - pthread_mutex_destroy(&mutex); } @@ -171,18 +161,18 @@ int PoolSQL::allocate(PoolObjectSQL *objsql, string& error_str) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -PoolObjectSQL * PoolSQL::get(int oid, bool olock) +PoolObjectSQL * PoolSQL::get(int oid) { if ( oid < 0 ) { return 0; } - lock(); + PoolObjectSQL * objectsql; - flush_cache(oid); + cache.lock_line(oid); - PoolObjectSQL * objectsql = create(); + objectsql = create(); objectsql->oid = oid; @@ -190,23 +180,16 @@ PoolObjectSQL * PoolSQL::get(int oid, bool olock) if ( rc != 0 ) { - objectsql->lock(); - delete objectsql; - unlock(); + cache.set_line(oid, 0); return 0; } - pool.push_back(objectsql); + objectsql->lock(); - if ( olock == true ) - { - objectsql->lock(); - } - - unlock(); + cache.set_line(oid, objectsql); return objectsql; } @@ -214,144 +197,22 @@ PoolObjectSQL * PoolSQL::get(int oid, bool olock) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -PoolObjectSQL * PoolSQL::get(const string& name, int ouid, bool olock) +PoolObjectSQL * PoolSQL::get(const string& name, int ouid) { - lock(); - string name_key = key(name, ouid); + int oid = PoolObjectSQL::select_oid(db, table.c_str(), name, ouid); - flush_cache(name_key); - - PoolObjectSQL * objectsql = create(); - - int rc = objectsql->select(db, name, ouid); - - if ( rc != 0 ) + if ( oid == -1 ) { - objectsql->lock(); - - delete objectsql; - - unlock(); - return 0; } - pool.push_back(objectsql); - - if ( olock == true ) - { - objectsql->lock(); - } - - unlock(); - - return objectsql; + return get(oid); } /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void PoolSQL::flush_cache(int oid) -{ - for (vector::iterator it = pool.begin(); it != pool.end();) - { - // The object we are looking for in ::get(). Wait until it is unlocked() - if ((*it)->oid == oid) - { - (*it)->lock(); - } - else - { - // Any other locked object is just ignored - int rc = pthread_mutex_trylock(&((*it)->mutex)); - - if ( rc == EBUSY ) // In use by other thread - { - it++; - continue; - } - } - - delete *it; - - it = pool.erase(it); - } -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void PoolSQL::flush_cache(const string& name_key) -{ - for (vector::iterator it = pool.begin(); it != pool.end();) - { - string okey = key((*it)->name, (*it)->uid); - - // The object we are looking for in ::get(). Wait until it is unlocked() - if ( name_key == okey) - { - (*it)->lock(); - } - else - { - // Any other locked object is just ignored - int rc = pthread_mutex_trylock(&((*it)->mutex)); - - if ( rc == EBUSY ) // In use by other thread - { - it++; - continue; - } - } - - delete *it; - - it = pool.erase(it); - } -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void PoolSQL::clean() -{ - vector::iterator it; - - lock(); - - for (it = pool.begin(); it != pool.end(); ++it) - { - (*it)->lock(); - - delete *it; - } - - pool.clear(); - - unlock(); -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -int PoolSQL::dump_cb(void * _oss, int num, char **values, char **names) -{ - ostringstream * oss; - - oss = static_cast(_oss); - - if ( (!values[0]) || (num != 1) ) - { - return -1; - } - - *oss << values[0]; - return 0; -} - -/* -------------------------------------------------------------------------- */ - int PoolSQL::dump(ostringstream& oss, const string& elem_name, const char* table, const string& where, const string& limit) { @@ -382,18 +243,19 @@ int PoolSQL::dump(ostringstream& oss, const string& root_elem_name, { int rc; + stream_cb cb(1); + oss << "<" << root_elem_name << ">"; - set_callback(static_cast(&PoolSQL::dump_cb), - static_cast(&oss)); + cb.set_callback(&oss); - rc = db->exec_rd(sql_query, this); + rc = db->exec_rd(sql_query, &cb); add_extra_xml(oss); oss << ""; - unset_callback(); + cb.unset_callback(); return rc; } @@ -401,24 +263,6 @@ int PoolSQL::dump(ostringstream& oss, const string& root_elem_name, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int PoolSQL:: search_cb(void * _oids, int num, char **values, char **names) -{ - vector * oids; - - oids = static_cast *>(_oids); - - if ( num == 0 || values == 0 || values[0] == 0 ) - { - return -1; - } - - oids->push_back(atoi(values[0])); - - return 0; -} - -/* -------------------------------------------------------------------------- */ - int PoolSQL::search( vector& oids, const char * table, @@ -427,8 +271,9 @@ int PoolSQL::search( ostringstream sql; int rc; - set_callback(static_cast(&PoolSQL::search_cb), - static_cast(&oids)); + vector_cb cb; + + cb.set_callback(&oids); sql << "SELECT oid FROM " << table; @@ -437,9 +282,9 @@ int PoolSQL::search( sql << " WHERE " << where; } - rc = db->exec_rd(sql, this); + rc = db->exec_rd(sql, &cb); - unset_callback(); + cb.unset_callback(); return rc; } @@ -668,3 +513,7 @@ void PoolSQL::register_hooks(vector hook_mads, } } } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + diff --git a/src/pool/PoolSQLCache.cc b/src/pool/PoolSQLCache.cc new file mode 100644 index 0000000000..a91d986bc3 --- /dev/null +++ b/src/pool/PoolSQLCache.cc @@ -0,0 +1,152 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +#include "PoolSQLCache.h" +#include "Nebula.h" + +unsigned int PoolSQLCache::MAX_ELEMENTS = 10000; + +PoolSQLCache::PoolSQLCache() +{ + pthread_mutex_init(&mutex, 0); +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void PoolSQLCache::lock_line(int oid) +{ + std::map::iterator it; + + CacheLine * cl; + + lock(); + + it = cache.find(oid); + + if ( it == cache.end() ) + { + cl = new CacheLine(0); + + cl->active++; + + cache.insert(make_pair(oid, cl)); + + unlock(); + + cl->lock(); + + return; + } + + cl = it->second; + + cl->active++; + + unlock(); + + cl->lock(); + + if ( cl->object != 0 ) + { + cl->object->lock(); + + delete cl->object; + } + + cl->object = 0; + + return; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int PoolSQLCache::set_line(int oid, PoolObjectSQL * object) +{ + std::map::iterator it; + + lock(); + + it = cache.find(oid); + + if ( it == cache.end() ) + { + unlock(); + + return -1; + } + + it->second->active--; + + it->second->object = object; + + it->second->unlock(); + + if ( cache.size() > MAX_ELEMENTS ) + { + flush_cache_lines(); + } + + unlock(); + + return 0; +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void PoolSQLCache::flush_cache_lines() +{ + for (std::map::iterator it=cache.begin(); it!=cache.end();) + { + CacheLine * cl = it->second; + + int rc = cl->trylock(); + + if ( rc == EBUSY ) // cache line locked + { + ++it; + continue; + } + + if ( cl->active > 0 ) // cache line being set + { + cl->unlock(); + + ++it; + continue; + } + + if ( cl->object != 0 ) + { + rc = cl->object->trylock(); + + if ( rc == EBUSY ) //object int use + { + cl->unlock(); + + ++it; + continue; + } + } + + delete it->second; // cache line & pool object locked & active == 0 + + it = cache.erase(it); + } +}; + diff --git a/src/pool/SConstruct b/src/pool/SConstruct index b1a1aef093..df61f729a9 100644 --- a/src/pool/SConstruct +++ b/src/pool/SConstruct @@ -24,6 +24,7 @@ lib_name='nebula_pool' source_files=[ 'PoolSQL.cc', 'PoolObjectSQL.cc', + 'PoolSQLCache.cc', 'ObjectCollection.cc', 'PoolObjectAuth.cc' ] diff --git a/src/raft/FedReplicaManager.cc b/src/raft/FedReplicaManager.cc index d347b5cc8b..1d9a8c8b64 100644 --- a/src/raft/FedReplicaManager.cc +++ b/src/raft/FedReplicaManager.cc @@ -166,7 +166,7 @@ void FedReplicaManager::update_zones(std::vector& zone_ids) } else { - Zone * zone = zpool->get(*it, true); + Zone * zone = zpool->get(*it); if ( zone == 0 ) { @@ -204,7 +204,7 @@ void FedReplicaManager::add_zone(int zone_id) Nebula& nd = Nebula::instance(); ZonePool * zpool = nd.get_zonepool(); - Zone * zone = zpool->get(zone_id, true); + Zone * zone = zpool->get(zone_id); if ( zone == 0 ) { diff --git a/src/rm/Request.cc b/src/rm/Request.cc index 0685cfce17..ab4fa2a0af 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -380,7 +380,7 @@ Request::ErrorCode Request::basic_authorization( if ( oid >= 0 ) { - object = pool->get(oid,true); + object = pool->get(oid); if ( object == 0 ) { @@ -437,7 +437,7 @@ bool Request::user_quota_authorization (Template * tmpl, bool rc = false; - user = upool->get(att.uid, true); + user = upool->get(att.uid); if ( user == 0 ) { @@ -481,7 +481,7 @@ bool Request::group_quota_authorization (Template * tmpl, bool rc = false; - group = gpool->get(att.gid, true); + group = gpool->get(att.gid); if ( group == 0 ) { @@ -523,7 +523,7 @@ void Request::user_quota_rollback(Template * tmpl, User * user; - user = upool->get(att.uid, true); + user = upool->get(att.uid); if ( user == 0 ) { @@ -548,7 +548,7 @@ void Request::group_quota_rollback(Template * tmpl, Group * group; - group = gpool->get(att.gid, true); + group = gpool->get(att.gid); if ( group == 0 ) { @@ -806,7 +806,7 @@ int Request::get_info( { PoolObjectSQL * ob; - if ((ob = pool->get(id,true)) == 0 ) + if ((ob = pool->get(id)) == 0 ) { if (throw_error) { diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 6d74c36c7d..68613c5ea7 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -207,7 +207,7 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params, if ( cluster_id != ClusterPool::NONE_CLUSTER_ID ) { - cluster = clpool->get(cluster_id, true); + cluster = clpool->get(cluster_id); if ( cluster == 0 ) { @@ -226,7 +226,7 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params, cluster->unlock(); - obj = pool->get(id, true); + obj = pool->get(id); if ( obj != 0 ) { @@ -384,7 +384,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, // ------------------------- Check Datastore exists ------------------------ - if ((ds = dspool->get(ds_id,true)) == 0 ) + if ((ds = dspool->get(ds_id)) == 0 ) { att.resp_id = ds_id; att.resp_obj = PoolObjectSQL::DATASTORE; @@ -426,7 +426,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, { // This image comes from a MarketPlaceApp. Get the Market info and // the size. - app = apppool->get(app_id, true); + app = apppool->get(app_id); if ( app == 0 ) { @@ -444,7 +444,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, app->unlock(); - market = marketpool->get(market_id, true); + market = marketpool->get(market_id); if ( market == 0 ) { @@ -591,7 +591,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, return; } - ds = dspool->get(ds_id, true); + ds = dspool->get(ds_id); if ( ds != 0 ) // TODO: error otherwise or leave image in ERROR? { @@ -720,7 +720,7 @@ bool UserAllocate::allocate_authorization( { int tmp_gid = xmlrpc_c::value_int(*it); - Group* group = gpool->get(tmp_gid, true); + Group* group = gpool->get(tmp_gid); if (group == 0) { @@ -847,7 +847,7 @@ Request::ErrorCode GroupAllocate::pool_allocate( return Request::INTERNAL; } - Vdc* vdc = vdcpool->get(VdcPool::DEFAULT_ID, true); + Vdc* vdc = vdcpool->get(VdcPool::DEFAULT_ID); if (vdc != 0) { @@ -1137,7 +1137,7 @@ Request::ErrorCode MarketPlaceAppAllocate::pool_allocate( // ---------------------------------------------------------------------- // // Get Marketplace information for this app // // ---------------------------------------------------------------------- // - MarketPlace * mp = mppool->get(mp_id, true); + MarketPlace * mp = mppool->get(mp_id); if ( mp == 0 ) { @@ -1178,13 +1178,13 @@ Request::ErrorCode MarketPlaceAppAllocate::pool_allocate( return Request::INTERNAL; } - mp = mppool->get(mp_id, true); + mp = mppool->get(mp_id); if ( mp == 0 ) { att.resp_msg = "Marketplace no longer exists"; - MarketPlaceApp * app = appool->get(id, true); + MarketPlaceApp * app = appool->get(id); if ( app != 0 ) { diff --git a/src/rm/RequestManagerChmod.cc b/src/rm/RequestManagerChmod.cc index fd1dfc4c06..e4106aa6cd 100644 --- a/src/rm/RequestManagerChmod.cc +++ b/src/rm/RequestManagerChmod.cc @@ -86,7 +86,7 @@ Request::ErrorCode RequestManagerChmod::chmod( AuthRequest::Operation op = AuthRequest::MANAGE; PoolObjectAuth perms; - object = pool->get(oid,true); + object = pool->get(oid); if ( object == 0 ) { @@ -155,7 +155,7 @@ Request::ErrorCode RequestManagerChmod::chmod( // ------------- Update the object --------------------- - object = pool->get(oid,true); + object = pool->get(oid); if ( object == 0 ) { @@ -213,7 +213,7 @@ Request::ErrorCode TemplateChmod::chmod( return SUCCESS; } - VMTemplate* tmpl = static_cast(pool)->get(oid, true); + VMTemplate* tmpl = static_cast(pool)->get(oid); vector vdisks; vector::iterator i; diff --git a/src/rm/RequestManagerChown.cc b/src/rm/RequestManagerChown.cc index 0920a8d490..fbe7b5d725 100644 --- a/src/rm/RequestManagerChown.cc +++ b/src/rm/RequestManagerChown.cc @@ -39,7 +39,7 @@ PoolObjectSQL * RequestManagerChown::get_and_quota( PoolObjectSQL * object; - object = pool->get(oid,true); + object = pool->get(oid); if ( object == 0 ) { @@ -170,7 +170,7 @@ PoolObjectSQL * RequestManagerChown::get_and_quota( quota_rollback(it->second, it->first, att_old); } - object = pool->get(oid,true); + object = pool->get(oid); } // ------------------------------------------------------------------------- @@ -228,7 +228,7 @@ int RequestManagerChown::check_name_unique(int oid, int noid, RequestAttributes& int obj_oid; ostringstream oss; - object = pool->get(oid, true); + object = pool->get(oid); if ( object == 0 ) { @@ -241,13 +241,10 @@ int RequestManagerChown::check_name_unique(int oid, int noid, RequestAttributes& object->unlock(); - object = get(name, noid, true); + obj_oid = pool->exist(name, noid); - if ( object != 0 ) + if ( obj_oid != -1 ) { - obj_oid = object->get_oid(); - object->unlock(); - oss << object_name(PoolObjectSQL::USER) << " ["<get(oid,true); + object = pool->get(oid); if ( object == 0 ) { @@ -425,7 +422,7 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList, return; } - if ((user = upool->get(oid,true)) == 0 ) + if ((user = upool->get(oid)) == 0 ) { att.resp_obj = PoolObjectSQL::USER; att.resp_id = oid; @@ -499,7 +496,7 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList, // ------------- Change users primary group --------------------- - user = upool->get(oid,true); + user = upool->get(oid); if ( user == 0 ) { @@ -537,7 +534,7 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList, // ------------- Updates new group with this new user --------------------- - group = gpool->get(ngid, true); + group = gpool->get(ngid); if( group == 0 ) { @@ -559,7 +556,7 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList, if (remove_old_group) { - group = gpool->get(old_gid, true); + group = gpool->get(old_gid); if( group != 0 ) { diff --git a/src/rm/RequestManagerClone.cc b/src/rm/RequestManagerClone.cc index bcab974633..d3f3d03fbd 100644 --- a/src/rm/RequestManagerClone.cc +++ b/src/rm/RequestManagerClone.cc @@ -60,7 +60,7 @@ Request::ErrorCode RequestManagerClone::clone(int source_id, const string &name, int rc; PoolObjectAuth perms; - PoolObjectSQL * source_obj = pool->get(source_id, true); + PoolObjectSQL * source_obj = pool->get(source_id); if ( source_obj == 0 ) { @@ -161,7 +161,7 @@ Request::ErrorCode VMTemplateClone::clone(int source_id, const string &name, RequestAttributes img_att(att); img_att.resp_obj = PoolObjectSQL::IMAGE; - VMTemplate * vmtmpl = tpool->get(new_id, true); + VMTemplate * vmtmpl = tpool->get(new_id); if (vmtmpl == 0) { @@ -226,7 +226,7 @@ Request::ErrorCode VMTemplateClone::clone(int source_id, const string &name, ndisk++; } - vmtmpl = tpool->get(new_id, true); + vmtmpl = tpool->get(new_id); if (vmtmpl == 0) { diff --git a/src/rm/RequestManagerCluster.cc b/src/rm/RequestManagerCluster.cc index 9bd90842f3..4ddaa7f992 100644 --- a/src/rm/RequestManagerCluster.cc +++ b/src/rm/RequestManagerCluster.cc @@ -74,7 +74,7 @@ void RequestManagerCluster::action_generic( } // ------------- Set new cluster id in object --------------------- - get(object_id, true, &object, &cluster_obj); + get(object_id, &object, &cluster_obj); if ( object == 0 ) { @@ -105,7 +105,7 @@ void RequestManagerCluster::action_generic( object->unlock(); // ------------- Add/del object to new cluster --------------------- - cluster = clpool->get(cluster_id, true); + cluster = clpool->get(cluster_id); if ( cluster == 0 ) { @@ -114,7 +114,7 @@ void RequestManagerCluster::action_generic( failure_response(NO_EXISTS, att); // Rollback - get(object_id, true, &object, &cluster_obj); + get(object_id, &object, &cluster_obj); if ( object != 0 ) { @@ -151,7 +151,7 @@ void RequestManagerCluster::action_generic( failure_response(ACTION, att); // Rollback - get(object_id, true, &object, &cluster_obj); + get(object_id, &object, &cluster_obj); if ( object != 0 ) { @@ -236,7 +236,7 @@ void RequestManagerClusterHost::add_generic( } // ------------- Set new cluster id in object --------------------- - host = hpool->get(host_id, true); + host = hpool->get(host_id); if ( host == 0 ) { @@ -263,7 +263,7 @@ void RequestManagerClusterHost::add_generic( host->unlock(); // ------------- Add object to new cluster --------------------- - cluster = clpool->get(cluster_id, true); + cluster = clpool->get(cluster_id); if ( cluster == 0 ) { @@ -272,7 +272,7 @@ void RequestManagerClusterHost::add_generic( failure_response(NO_EXISTS, att); // Rollback - host = hpool->get(host_id, true); + host = hpool->get(host_id); if ( host != 0 ) { @@ -293,7 +293,7 @@ void RequestManagerClusterHost::add_generic( failure_response(INTERNAL, att); // Rollback - host = hpool->get(host_id, true); + host = hpool->get(host_id); if ( host != 0 ) { @@ -313,7 +313,7 @@ void RequestManagerClusterHost::add_generic( // ------------- Remove host from old cluster --------------------- - cluster = clpool->get(old_cluster_id, true); + cluster = clpool->get(old_cluster_id); if ( cluster == 0 ) { diff --git a/src/rm/RequestManagerDatastore.cc b/src/rm/RequestManagerDatastore.cc index 019bbaa84d..c9e28b8e3f 100644 --- a/src/rm/RequestManagerDatastore.cc +++ b/src/rm/RequestManagerDatastore.cc @@ -35,7 +35,7 @@ void DatastoreEnable::request_execute(xmlrpc_c::paramList const& paramList, return; } - ds = static_cast(pool->get(id,true)); + ds = static_cast(pool->get(id)); if ( ds == 0 ) { diff --git a/src/rm/RequestManagerDelete.cc b/src/rm/RequestManagerDelete.cc index e636deddf0..f1408d31b4 100644 --- a/src/rm/RequestManagerDelete.cc +++ b/src/rm/RequestManagerDelete.cc @@ -32,7 +32,7 @@ static Request::ErrorCode delete_authorization(PoolSQL* pool, return Request::SUCCESS; } - PoolObjectSQL * object = pool->get(oid, true); + PoolObjectSQL * object = pool->get(oid); if ( object == 0 ) { @@ -98,7 +98,7 @@ Request::ErrorCode RequestManagerDelete::delete_object(int oid, return ec; } - PoolObjectSQL * object = pool->get(oid, true); + PoolObjectSQL * object = pool->get(oid); if ( object == 0 ) { @@ -144,7 +144,7 @@ int RequestManagerDelete::drop(PoolObjectSQL * object, bool recursive, for(it = cluster_ids.begin(); it != cluster_ids.end(); it++) { - Cluster * cluster = clpool->get(*it, true); + Cluster * cluster = clpool->get(*it); if( cluster != 0 ) { @@ -296,7 +296,7 @@ int GroupDelete::drop(PoolObjectSQL * object, bool recursive, for (it = vdcs.begin() ; it != vdcs.end() ; ++it) { - Vdc * vdc = vdcpool->get(*it, true); + Vdc * vdc = vdcpool->get(*it); if ( vdc == 0 ) { @@ -362,7 +362,7 @@ int UserDelete::drop(PoolObjectSQL * object, bool recursive, for ( it = group_set.begin(); it != group_set.end(); it++ ) { - group = gpool->get(*it, true); + group = gpool->get(*it); if( group == 0 ) { @@ -426,7 +426,7 @@ int VirtualNetworkDelete::drop(PoolObjectSQL * object, bool recursive, if (pvid != -1) { - vnet = (static_cast(pool))->get(pvid, true); + vnet = (static_cast(pool))->get(pvid); if (vnet == 0) { @@ -536,7 +536,7 @@ int MarketPlaceAppDelete::drop(PoolObjectSQL * object, bool recursive, return -1; } - MarketPlace * mp = marketpool->get(mp_id, true); + MarketPlace * mp = marketpool->get(mp_id); if ( mp == 0 ) { @@ -601,7 +601,7 @@ int MarketPlaceDelete::drop(PoolObjectSQL * object, bool recursive, for ( set::iterator i = apps.begin(); i != apps.end(); ++i ) { - app = apppool->get(*i, true); + app = apppool->get(*i); if ( app == 0 ) { @@ -625,7 +625,7 @@ int MarketPlaceDelete::drop(PoolObjectSQL * object, bool recursive, MarketPlacePool* mppool = static_cast(pool); - mp = mppool->get(mp_id, true); + mp = mppool->get(mp_id); if (mp == 0) { diff --git a/src/rm/RequestManagerGroup.cc b/src/rm/RequestManagerGroup.cc index 8860911c75..71cda76d58 100644 --- a/src/rm/RequestManagerGroup.cc +++ b/src/rm/RequestManagerGroup.cc @@ -50,7 +50,7 @@ void GroupSetQuota:: return; } - group = static_cast(pool->get(id,true)); + group = static_cast(pool->get(id)); if ( group == 0 ) { @@ -136,7 +136,7 @@ void GroupEditAdmin::request_execute( } } - group = static_cast(pool)->get(group_id, true); + group = static_cast(pool)->get(group_id); if ( group == 0 ) { diff --git a/src/rm/RequestManagerHost.cc b/src/rm/RequestManagerHost.cc index 6b17bb90bc..8b31dd473f 100644 --- a/src/rm/RequestManagerHost.cc +++ b/src/rm/RequestManagerHost.cc @@ -33,7 +33,7 @@ void HostStatus::request_execute(xmlrpc_c::paramList const& paramList, return; } - Host * host = hpool->get(id,true); + Host * host = hpool->get(id); if ( host == 0 ) { diff --git a/src/rm/RequestManagerImage.cc b/src/rm/RequestManagerImage.cc index 8eb4f63bb3..5657735cf8 100644 --- a/src/rm/RequestManagerImage.cc +++ b/src/rm/RequestManagerImage.cc @@ -107,7 +107,7 @@ Request::ErrorCode ImagePersistent::request_execute( return ec; } - image = ipool->get(id,true); + image = ipool->get(id); if ( image == 0 ) { @@ -129,7 +129,7 @@ Request::ErrorCode ImagePersistent::request_execute( image->unlock(); - ds = dspool->get(ds_id, true); + ds = dspool->get(ds_id); if ( ds == 0 ) { @@ -142,7 +142,7 @@ Request::ErrorCode ImagePersistent::request_execute( ds->unlock(); - image = ipool->get(id,true); + image = ipool->get(id); if ( image == 0 ) { @@ -221,7 +221,7 @@ void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList, return; } - image = static_cast(pool->get(id,true)); + image = static_cast(pool->get(id)); if ( image == 0 ) { @@ -344,7 +344,7 @@ Request::ErrorCode ImageClone::request_execute( // ------------------------- Get source Image info ------------------------- - img = ipool->get(clone_id, true); + img = ipool->get(clone_id); if ( img == 0 ) { @@ -396,7 +396,7 @@ Request::ErrorCode ImageClone::request_execute( // ----------------------- Get target Datastore info ----------------------- - ds = dspool->get(ds_id, true); + ds = dspool->get(ds_id); if ( ds == 0 ) { @@ -432,7 +432,7 @@ Request::ErrorCode ImageClone::request_execute( if (ds_id != ds_id_orig) //check same DS_MAD { - ds = dspool->get(ds_id_orig, true); + ds = dspool->get(ds_id_orig); if (ds == 0) { @@ -547,7 +547,7 @@ Request::ErrorCode ImageClone::request_execute( return ALLOCATE; } - ds = dspool->get(ds_id, true); + ds = dspool->get(ds_id); if ( ds != 0 ) // TODO: error otherwise or leave image in ERROR? { diff --git a/src/rm/RequestManagerInfo.cc b/src/rm/RequestManagerInfo.cc index b77cc963fc..7ef86c4c8f 100644 --- a/src/rm/RequestManagerInfo.cc +++ b/src/rm/RequestManagerInfo.cc @@ -47,7 +47,7 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList, return; } - object = pool->get(oid,true); + object = pool->get(oid); if ( object == 0 ) { @@ -86,7 +86,7 @@ void TemplateInfo::request_execute(xmlrpc_c::paramList const& paramList, extended = xmlrpc_c::value_boolean(paramList.getBoolean(2)); } - vm_tmpl = tpool->get(oid,true); + vm_tmpl = tpool->get(oid); if ( vm_tmpl == 0 ) { @@ -127,7 +127,7 @@ void TemplateInfo::request_execute(xmlrpc_c::paramList const& paramList, } } - vm_tmpl = tpool->get(oid,true); + vm_tmpl = tpool->get(oid); if ( vm_tmpl == 0 ) { diff --git a/src/rm/RequestManagerLock.cc b/src/rm/RequestManagerLock.cc index 64e7092755..1b2cef146f 100644 --- a/src/rm/RequestManagerLock.cc +++ b/src/rm/RequestManagerLock.cc @@ -36,7 +36,7 @@ void RequestManagerLock::request_execute(xmlrpc_c::paramList const& paramList, return; } - object = pool->get(oid,true); + object = pool->get(oid); if ( object == 0 ) { @@ -83,7 +83,7 @@ void RequestManagerUnlock::request_execute(xmlrpc_c::paramList const& paramList, return; } - object = pool->get(oid,true); + object = pool->get(oid); if ( object == 0 ) { diff --git a/src/rm/RequestManagerMarketPlaceApp.cc b/src/rm/RequestManagerMarketPlaceApp.cc index 2188d37e74..5c88c11d49 100644 --- a/src/rm/RequestManagerMarketPlaceApp.cc +++ b/src/rm/RequestManagerMarketPlaceApp.cc @@ -33,7 +33,7 @@ void MarketPlaceAppEnable::request_execute(xmlrpc_c::paramList const& paramList, return; } - app = static_cast(pool->get(id, true)); + app = static_cast(pool->get(id)); if ( app == 0 ) { diff --git a/src/rm/RequestManagerRename.cc b/src/rm/RequestManagerRename.cc index a22f753e03..77bc33c5bd 100644 --- a/src/rm/RequestManagerRename.cc +++ b/src/rm/RequestManagerRename.cc @@ -78,18 +78,15 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, // ----------------------- Check name uniqueness --------------------------- - object = get(new_name, operms.uid, true); + int db_id = exist(new_name, operms.uid); - if ( object != 0 ) + if ( db_id !=-1 ) { ostringstream oss; - int id = object->get_oid(); - - object->unlock(); oss << object_name(auth_object) << " cannot be renamed to " << new_name << " because it collides with " << object_name(auth_object) << " " - << id; + << db_id; att.resp_msg = oss.str(); @@ -101,7 +98,7 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, // -------------------------- Update the object ---------------------------- - object = pool->get(oid, true); + object = pool->get(oid); if ( object == 0 ) { @@ -140,7 +137,7 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList, void ClusterRename::batch_rename(int oid) { - Cluster * cluster = static_cast(pool)->get(oid, true); + Cluster * cluster = static_cast(pool)->get(oid); if (cluster == 0) { @@ -158,7 +155,7 @@ void ClusterRename::batch_rename(int oid) for (set::iterator it = hosts.begin(); it != hosts.end(); it++) { - host = hpool->get(*it, true); + host = hpool->get(*it); if (host != 0) { @@ -178,7 +175,7 @@ void ClusterRename::batch_rename(int oid) void DatastoreRename::batch_rename(int oid) { - Datastore * datastore = static_cast(pool)->get(oid, true); + Datastore * datastore = static_cast(pool)->get(oid); if (datastore == 0) { @@ -198,7 +195,7 @@ void DatastoreRename::batch_rename(int oid) for (it = images.begin(); it != images.end(); it++) { - image = ipool->get(*it, true); + image = ipool->get(*it); if (image != 0) { @@ -218,7 +215,7 @@ void DatastoreRename::batch_rename(int oid) void HostRename::batch_rename(int oid) { - Host * host = static_cast(pool)->get(oid, true); + Host * host = static_cast(pool)->get(oid); if (host == 0) { @@ -238,7 +235,7 @@ void HostRename::batch_rename(int oid) for (it = vms.begin(); it != vms.end(); it++) { - vm = vmpool->get(*it, true); + vm = vmpool->get(*it); if (vm != 0) { @@ -258,7 +255,7 @@ void HostRename::batch_rename(int oid) void MarketPlaceRename::batch_rename(int oid) { - MarketPlace * market = static_cast(pool)->get(oid, true); + MarketPlace * market = static_cast(pool)->get(oid); if (market == 0) { @@ -278,7 +275,7 @@ void MarketPlaceRename::batch_rename(int oid) for (it = apps.begin(); it != apps.end(); it++) { - app = apppool->get(*it, true); + app = apppool->get(*it); if (app != 0) { diff --git a/src/rm/RequestManagerSecurityGroup.cc b/src/rm/RequestManagerSecurityGroup.cc index 53961b9c78..e51e517f54 100644 --- a/src/rm/RequestManagerSecurityGroup.cc +++ b/src/rm/RequestManagerSecurityGroup.cc @@ -35,7 +35,7 @@ void SecurityGroupCommit::request_execute(xmlrpc_c::paramList const& paramList, return; } - sg = static_cast(pool)->get(oid,true); + sg = static_cast(pool)->get(oid); if ( sg == 0 ) { diff --git a/src/rm/RequestManagerUpdateTemplate.cc b/src/rm/RequestManagerUpdateTemplate.cc index 566790b09d..e9111f4914 100644 --- a/src/rm/RequestManagerUpdateTemplate.cc +++ b/src/rm/RequestManagerUpdateTemplate.cc @@ -90,7 +90,7 @@ void RequestManagerUpdateTemplate::request_execute( } - object = pool->get(oid,true); + object = pool->get(oid); if ( object == 0 ) { diff --git a/src/rm/RequestManagerUser.cc b/src/rm/RequestManagerUser.cc index 562e06d4e7..7fab72a9bb 100644 --- a/src/rm/RequestManagerUser.cc +++ b/src/rm/RequestManagerUser.cc @@ -23,7 +23,6 @@ void RequestManagerUser:: RequestAttributes& att) { int id = xmlrpc_c::value_int(paramList.getInt(1)); - User * user; string error_str; if ( basic_authorization(id, att) == false ) @@ -31,9 +30,7 @@ void RequestManagerUser:: return; } - user = (static_cast(pool))->get(id,false); - - if ( user == 0 ) + if ( pool->exist(id) == -1 ) { att.resp_id = id; failure_response(NO_EXISTS, att); @@ -60,7 +57,7 @@ int UserChangePassword::user_action(int user_id, string new_pass = xmlrpc_c::value_string(paramList.getString(2)); - User * user = (static_cast(pool))->get(user_id,true); + User * user = (static_cast(pool))->get(user_id); if ( user == 0 ) { @@ -112,7 +109,7 @@ int UserChangeAuth::user_action(int user_id, User * user; - user = (static_cast(pool))->get(user_id,true); + user = (static_cast(pool))->get(user_id); if ( user == 0 ) { @@ -173,7 +170,7 @@ int UserSetQuota::user_action(int user_id, return -1; } - user = (static_cast(pool))->get(user_id,true); + user = (static_cast(pool))->get(user_id); if ( user == 0 ) { @@ -210,7 +207,7 @@ void UserEditGroup:: PoolObjectAuth uperms; PoolObjectAuth gperms; - User* user = upool->get(user_id,true); + User* user = upool->get(user_id); if ( user == 0 ) { @@ -290,7 +287,7 @@ int UserAddGroup::secondary_group_action( int rc; - user = upool->get(user_id,true); + user = upool->get(user_id); if ( user == 0 ) { @@ -311,11 +308,11 @@ int UserAddGroup::secondary_group_action( user->unlock(); - group = gpool->get(group_id, true); + group = gpool->get(group_id); if( group == 0 ) { - user = upool->get(user_id,true); + user = upool->get(user_id); if ( user != 0 ) { @@ -353,7 +350,7 @@ int UserDelGroup::secondary_group_action( int rc; - user = upool->get(user_id,true); + user = upool->get(user_id); rc = user->del_group(group_id); @@ -381,7 +378,7 @@ int UserDelGroup::secondary_group_action( user->unlock(); - group = gpool->get(group_id, true); + group = gpool->get(group_id); if( group == 0 ) { @@ -425,7 +422,7 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList, { PoolObjectAuth perms; - user = static_cast(pool)->get(uname, true); + user = static_cast(pool)->get(uname); if ( user == 0 ) { @@ -449,7 +446,7 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList, } } - user = static_cast(pool)->get(uname, true); + user = static_cast(pool)->get(uname); if ( user == 0 ) { diff --git a/src/rm/RequestManagerVMTemplate.cc b/src/rm/RequestManagerVMTemplate.cc index 77034d10e5..739b04f22d 100644 --- a/src/rm/RequestManagerVMTemplate.cc +++ b/src/rm/RequestManagerVMTemplate.cc @@ -43,7 +43,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList clone_template = xmlrpc_c::value_boolean(paramList.getBoolean(5)); } - VMTemplate * tmpl = static_cast (pool)->get(id,true); + VMTemplate * tmpl = static_cast (pool)->get(id); if ( tmpl == 0 ) { @@ -141,7 +141,7 @@ Request::ErrorCode VMTemplateInstantiate::request_execute(int id, string name, /* ---------------------------------------------------------------------- */ /* Get, check and clone the template */ /* ---------------------------------------------------------------------- */ - rtmpl = tpool->get(id,true); + rtmpl = tpool->get(id); if ( rtmpl == 0 ) { diff --git a/src/rm/RequestManagerVdc.cc b/src/rm/RequestManagerVdc.cc index 960d4b23b0..96c27c7ac2 100644 --- a/src/rm/RequestManagerVdc.cc +++ b/src/rm/RequestManagerVdc.cc @@ -73,7 +73,7 @@ void VdcEditGroup::request_execute( } } - vdc = static_cast(pool)->get(vdc_id, true); + vdc = static_cast(pool)->get(vdc_id); if ( vdc == 0 ) { @@ -207,7 +207,7 @@ void VdcEditResource::request_execute( } } - vdc = static_cast(pool)->get(vdc_id, true); + vdc = static_cast(pool)->get(vdc_id); if ( vdc == 0 ) { diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 1880c8d303..ee6f27ea9d 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -36,7 +36,7 @@ bool RequestManagerVirtualMachine::vm_authorization( PoolObjectSQL * object; PoolObjectAuth vm_perms; - object = pool->get(oid,true); + object = pool->get(oid); if ( object == 0 ) { @@ -108,7 +108,7 @@ bool RequestManagerVirtualMachine::quota_resize_authorization( RequestAttributes& att) { PoolObjectAuth vm_perms; - VirtualMachine * vm = Nebula::instance().get_vmpool()->get(oid, true); + VirtualMachine * vm = Nebula::instance().get_vmpool()->get(oid); if (vm == 0) { @@ -144,7 +144,7 @@ bool RequestManagerVirtualMachine::quota_resize_authorization( if (vm_perms.uid != UserPool::ONEADMIN_ID) { - User * user = upool->get(vm_perms.uid, true); + User * user = upool->get(vm_perms.uid); if ( user != 0 ) { @@ -174,7 +174,7 @@ bool RequestManagerVirtualMachine::quota_resize_authorization( if (vm_perms.gid != GroupPool::ONEADMIN_ID) { - Group * group = gpool->get(vm_perms.gid, true); + Group * group = gpool->get(vm_perms.gid); if ( group != 0 ) { @@ -226,7 +226,7 @@ int RequestManagerVirtualMachine::get_default_ds_information( ds_id = -1; - cluster = clpool->get(cluster_id, true); + cluster = clpool->get(cluster_id); if (cluster == 0) { @@ -275,7 +275,7 @@ int RequestManagerVirtualMachine::get_ds_information(int ds_id, { Nebula& nd = Nebula::instance(); - Datastore * ds = nd.get_dspool()->get(ds_id, true); + Datastore * ds = nd.get_dspool()->get(ds_id); ds_cluster_ids.clear(); @@ -333,7 +333,7 @@ int RequestManagerVirtualMachine::get_host_information( Nebula& nd = Nebula::instance(); HostPool * hpool = nd.get_hpool(); - Host * host = hpool->get(hid,true); + Host * host = hpool->get(hid); if ( host == 0 ) { @@ -385,7 +385,7 @@ bool RequestManagerVirtualMachine::check_host( vm->get_requirements(cpu, mem, disk, pci); - host = hpool->get(hid, true); + host = hpool->get(hid); if (host == 0) { @@ -426,7 +426,7 @@ VirtualMachine * RequestManagerVirtualMachine::get_vm(int id, { VirtualMachine * vm; - vm = static_cast(pool->get(id,true)); + vm = static_cast(pool->get(id)); if ( vm == 0 ) { @@ -836,7 +836,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, } else { - Datastore * ds = dspool->get(ds_id, true); + Datastore * ds = dspool->get(ds_id); if (ds == 0 ) { @@ -1018,7 +1018,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList } else { - Datastore * ds = dspool->get(ds_id, true); + Datastore * ds = dspool->get(ds_id); if (ds == 0 ) { @@ -1149,7 +1149,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList vm->unlock(); // Check we are migrating to a compatible cluster - Host * host = nd.get_hpool()->get(c_hid, true); + Host * host = nd.get_hpool()->get(c_hid); if (host == 0) { @@ -1360,7 +1360,7 @@ void VirtualMachineDiskSaveas::request_execute( // ------------------------------------------------------------------------- // Get the data of the Image to be saved // ------------------------------------------------------------------------- - img = ipool->get(iid_orig, true); + img = ipool->get(iid_orig); if ( img == 0 ) { @@ -1397,7 +1397,7 @@ void VirtualMachineDiskSaveas::request_execute( // ------------------------------------------------------------------------- // Get the data of the DataStore for the new image & size // ------------------------------------------------------------------------- - if ((ds = dspool->get(ds_id, true)) == 0 ) + if ((ds = dspool->get(ds_id)) == 0 ) { goto error_ds; } @@ -1499,7 +1499,7 @@ void VirtualMachineDiskSaveas::request_execute( goto error_allocate; } - ds = dspool->get(ds_id, true); + ds = dspool->get(ds_id); if (ds == 0) { @@ -1567,7 +1567,7 @@ error_allocate: goto error_common; error_common: - if ((vm = vmpool->get(id, true)) != 0) + if ((vm = vmpool->get(id)) != 0) { vm->clear_saveas_state(); @@ -1858,7 +1858,7 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, tmpl.get("VCPU", nvcpu); tmpl.get("MEMORY", nmemory); - vm = vmpool->get(id, true); + vm = vmpool->get(id); if (vm == 0) { @@ -1957,7 +1957,7 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, vector empty_pci; - host = hpool->get(hid, true); + host = hpool->get(hid); if (host == 0) { @@ -1999,7 +1999,7 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, /* Resize the VM */ /* ---------------------------------------------------------------------- */ - vm = vmpool->get(id, true); + vm = vmpool->get(id); if (vm == 0) { @@ -2010,7 +2010,7 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, if (hid != -1) { - host = hpool->get(hid, true); + host = hpool->get(hid); if (host != 0) { @@ -2061,7 +2061,7 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, if (hid != -1) { - host = hpool->get(hid, true); + host = hpool->get(hid); if (host != 0) { @@ -2274,7 +2274,7 @@ Request::ErrorCode VirtualMachineAttachNic::request_execute(int id, // ------------------------------------------------------------------------- // Authorize the operation, restricted attributes & check quotas // ------------------------------------------------------------------------- - vm = vmpool->get(id, true); + vm = vmpool->get(id); if ( vm == 0 ) { @@ -2399,7 +2399,7 @@ Request::ErrorCode VirtualMachineDetachNic::request_execute(int id, int nic_id, // ------------------------------------------------------------------------- // Authorize the operation // ------------------------------------------------------------------------- - vm = vmpool->get(id, true); + vm = vmpool->get(id); if ( vm == 0 ) { @@ -2478,7 +2478,7 @@ void VirtualMachineRecover::request_execute( return; } - VirtualMachine * vm=(static_cast(pool))->get(id,true); + VirtualMachine * vm=(static_cast(pool))->get(id); if (vm == 0) { @@ -2644,7 +2644,7 @@ void VirtualMachineDiskSnapshotCreate::request_execute( { PoolObjectAuth img_perms; - Image* img = ipool->get(img_id, true); + Image* img = ipool->get(img_id); if (img == 0) { @@ -2825,7 +2825,7 @@ void VirtualMachineDiskSnapshotDelete::request_execute( { PoolObjectAuth img_perms; - Image* img = ipool->get(img_id, true); + Image* img = ipool->get(img_id); if (img == 0) { @@ -2912,7 +2912,7 @@ void VirtualMachineUpdateConf::request_execute( /* Update VirtualMachine Configuration */ /* ---------------------------------------------------------------------- */ - vm = static_cast(pool)->get(id, true); + vm = static_cast(pool)->get(id); if (vm == 0) { @@ -3036,7 +3036,7 @@ void VirtualMachineDiskResize::request_execute( if ( img_id != -1 ) { - Image* img = ipool->get(img_id, true); + Image* img = ipool->get(img_id); if (img == 0) { diff --git a/src/rm/RequestManagerVirtualNetwork.cc b/src/rm/RequestManagerVirtualNetwork.cc index 27fe7112b9..4368179ee3 100644 --- a/src/rm/RequestManagerVirtualNetwork.cc +++ b/src/rm/RequestManagerVirtualNetwork.cc @@ -47,7 +47,7 @@ void RequestManagerVirtualNetwork:: return; } - vn = static_cast(pool->get(id,true)); + vn = static_cast(pool->get(id)); if ( vn == 0 ) { @@ -96,7 +96,7 @@ void VirtualNetworkRmAddressRange:: // ------------------------------------------------------------------------- // Get VNET and data for reservations // ------------------------------------------------------------------------- - vn = static_cast(pool->get(id,true)); + vn = static_cast(pool->get(id)); if ( vn == 0 ) { @@ -137,7 +137,7 @@ void VirtualNetworkRmAddressRange:: if (parent != -1 && parent_ar != -1 && !mac.empty() && rc == 0) { - vn = static_cast(pool->get(parent, true)); + vn = static_cast(pool->get(parent)); if ( vn != 0 ) { @@ -235,7 +235,7 @@ void VirtualNetworkReserve::request_execute( return; } - rvn = vnpool->get(rid,true); + rvn = vnpool->get(rid); if (rvn == 0) { @@ -319,7 +319,7 @@ void VirtualNetworkReserve::request_execute( // ------------------------------------------------------------------------- // Authorize the operation Parent:USE Reservation:MANAGE // ------------------------------------------------------------------------- - vn = vnpool->get(id,true); + vn = vnpool->get(id); if ( vn == 0 ) { @@ -381,7 +381,7 @@ void VirtualNetworkReserve::request_execute( } } - rvn = vnpool->get(rid, true); + rvn = vnpool->get(rid); if (rvn == 0) { @@ -415,7 +415,7 @@ void VirtualNetworkReserve::request_execute( { if (!on_exisiting) { - rvn = vnpool->get(rid, true); + rvn = vnpool->get(rid); if (rvn != 0) { @@ -465,7 +465,7 @@ void VirtualNetworkReserve::request_execute( if (!on_exisiting) { - rvn = vnpool->get(rid, true); + rvn = vnpool->get(rid); if (rvn != 0) { @@ -489,7 +489,7 @@ void VirtualNetworkReserve::request_execute( for (set::iterator i=cluster_ids.begin(); i!= cluster_ids.end(); i++) { - Cluster * cluster = clpool->get(*i, true); + Cluster * cluster = clpool->get(*i); if ( cluster != 0 ) { diff --git a/src/rm/RequestManagerVirtualRouter.cc b/src/rm/RequestManagerVirtualRouter.cc index 9d9b72bace..c764190cd2 100644 --- a/src/rm/RequestManagerVirtualRouter.cc +++ b/src/rm/RequestManagerVirtualRouter.cc @@ -54,7 +54,7 @@ void VirtualRouterInstantiate::request_execute( /* ---------------------------------------------------------------------- */ /* Get the Virtual Router NICs */ /* ---------------------------------------------------------------------- */ - vr = vrpool->get(vrid, true); + vr = vrpool->get(vrid); if (vr == 0) { @@ -97,7 +97,7 @@ void VirtualRouterInstantiate::request_execute( } } - VMTemplate * tmpl = tpool->get(tmpl_id,true); + VMTemplate * tmpl = tpool->get(tmpl_id); if ( tmpl == 0 ) { @@ -149,7 +149,7 @@ void VirtualRouterInstantiate::request_execute( vms.push_back(vid); } - vr = vrpool->get(vrid, true); + vr = vrpool->get(vrid); if (vr != 0) { @@ -210,7 +210,7 @@ void VirtualRouterAttachNic::request_execute( // ------------------------------------------------------------------------- // Authorize the operation & check quotas // ------------------------------------------------------------------------- - vr = vrpool->get(vrid, true); + vr = vrpool->get(vrid); if (vr == 0) { @@ -249,7 +249,7 @@ void VirtualRouterAttachNic::request_execute( // ------------------------------------------------------------------------- // Attach NIC to the Virtual Router // ------------------------------------------------------------------------- - vr = vrpool->get(vrid, true); + vr = vrpool->get(vrid); if (vr == 0) { @@ -318,7 +318,7 @@ void VirtualRouterDetachNic::request_execute( // ------------------------------------------------------------------------- // Authorize the operation // ------------------------------------------------------------------------- - vr = vrpool->get(vrid, true); + vr = vrpool->get(vrid); if (vr == 0) { @@ -348,7 +348,7 @@ void VirtualRouterDetachNic::request_execute( // ------------------------------------------------------------------------- // Detach the NIC from the Virtual Router // ------------------------------------------------------------------------- - vr = vrpool->get(vrid, true); + vr = vrpool->get(vrid); if (vr == 0) { diff --git a/src/rm/RequestManagerZone.cc b/src/rm/RequestManagerZone.cc index 819a69b882..5a50ed1c2a 100644 --- a/src/rm/RequestManagerZone.cc +++ b/src/rm/RequestManagerZone.cc @@ -98,7 +98,7 @@ void ZoneAddServer::request_execute(xmlrpc_c::paramList const& paramList, return; } - Zone * zone = (static_cast(pool))->get(id, true); + Zone * zone = (static_cast(pool))->get(id); if ( zone == 0 ) { @@ -153,7 +153,7 @@ void ZoneAddServer::request_execute(xmlrpc_c::paramList const& paramList, while (!updated) { - Zone * zone = (static_cast(pool))->get(id, true); + Zone * zone = (static_cast(pool))->get(id); if ( zone != 0 ) { @@ -202,7 +202,7 @@ void ZoneDeleteServer::request_execute(xmlrpc_c::paramList const& paramList, return; } - Zone * zone = (static_cast(pool))->get(id, true); + Zone * zone = (static_cast(pool))->get(id); if ( zone == 0 ) { diff --git a/src/scheduler/src/sched/SConstruct b/src/scheduler/src/sched/SConstruct index 7da4bdd5b8..c381550b32 100644 --- a/src/scheduler/src/sched/SConstruct +++ b/src/scheduler/src/sched/SConstruct @@ -41,6 +41,7 @@ sched_env.Prepend(LIBS=[ 'nebula_template', 'nebula_vm', 'nebula_host', + 'nebula_parsers', 'crypto', 'xml2' ]) diff --git a/src/secgroup/SecurityGroupPool.cc b/src/secgroup/SecurityGroupPool.cc index d685ea3d17..77ff343a5f 100644 --- a/src/secgroup/SecurityGroupPool.cc +++ b/src/secgroup/SecurityGroupPool.cc @@ -38,7 +38,7 @@ SecurityGroupPool::SecurityGroupPool(SqlDB * db):PoolSQL(db,SecurityGroup::table Nebula& nd = Nebula::instance(); UserPool * upool = nd.get_upool(); - User * oneadmin = upool->get(0, false); + User * oneadmin = upool->get(0); string error; @@ -55,6 +55,8 @@ SecurityGroupPool::SecurityGroupPool(SqlDB * db):PoolSQL(db,SecurityGroup::table oneadmin->get_umask(), default_tmpl); + oneadmin->unlock(); + secgroup->set_permissions(1,1,1,1,0,0,1,0,0,error); if (PoolSQL::allocate(secgroup, error) < 0) @@ -88,8 +90,8 @@ int SecurityGroupPool::allocate( string& error_str) { SecurityGroup * secgroup; - SecurityGroup * secgroup_aux = 0; + int db_oid; string name; ostringstream oss; @@ -107,9 +109,9 @@ int SecurityGroupPool::allocate( goto error_name; } - secgroup_aux = get(name,uid,false); + db_oid = exist(name, uid); - if( secgroup_aux != 0 ) + if( db_oid != -1 ) { goto error_duplicated; } @@ -119,7 +121,7 @@ int SecurityGroupPool::allocate( return *oid; error_duplicated: - oss << "NAME is already taken by SecurityGroup " << secgroup_aux->get_oid() << "."; + oss << "NAME is already taken by SecurityGroup " << db_oid << "."; error_str = oss.str(); error_name: @@ -141,7 +143,7 @@ void SecurityGroupPool::get_security_group_rules(int vmid, int sgid, int vnet_id; VirtualNetworkPool* vnet_pool = Nebula::instance().get_vnpool(); - SecurityGroup* sg = get(sgid, true); + SecurityGroup* sg = get(sgid); if (sg == 0) { @@ -167,7 +169,7 @@ void SecurityGroupPool::get_security_group_rules(int vmid, int sgid, VectorAttribute* rule = *rule_it; - VirtualNetwork* vnet = vnet_pool->get(vnet_id, true); + VirtualNetwork* vnet = vnet_pool->get(vnet_id); if (vnet == 0) { @@ -200,7 +202,7 @@ void SecurityGroupPool::release_security_groups(int id, set& sgs) for (it = sgs.begin(); it != sgs.end(); it++) { - sg = get(*it, true); + sg = get(*it); if (sg == 0) { diff --git a/src/sql/MySqlDB.cc b/src/sql/MySqlDB.cc index 90ec3bb05f..c5dbc824b9 100644 --- a/src/sql/MySqlDB.cc +++ b/src/sql/MySqlDB.cc @@ -21,8 +21,6 @@ * Doc: http://dev.mysql.com/doc/refman/5.5/en/c-api-function-overview.html ********/ -const int MySqlDB::DB_CONNECT_SIZE = 10; - /* -------------------------------------------------------------------------- */ MySqlDB::MySqlDB( @@ -30,9 +28,10 @@ MySqlDB::MySqlDB( int _port, const string& _user, const string& _password, - const string& _database) + const string& _database, + int _max_connections) { - vector connections(DB_CONNECT_SIZE); + vector connections(_max_connections); MYSQL * rc; ostringstream oss; @@ -43,11 +42,13 @@ MySqlDB::MySqlDB( password = _password; database = _database; + max_connections = _max_connections; + // Initialize the MySQL library mysql_library_init(0, NULL, NULL); // Create connection pool to the server - for (int i=0 ; i < DB_CONNECT_SIZE ; i++) + for (int i=0 ; i < max_connections ; i++) { connections[i] = mysql_init(NULL); @@ -61,7 +62,12 @@ MySqlDB::MySqlDB( 0); if ( rc == NULL) { - throw runtime_error("Could not open connect to database server."); + ostringstream oss; + + oss << "Could not open connect to database server: " + << mysql_error(connections[i]); + + throw runtime_error(oss.str()); } } @@ -78,7 +84,12 @@ MySqlDB::MySqlDB( if ( rc == NULL) { - throw runtime_error("Could not open connect to database server."); + ostringstream oss; + + oss << "Could not open connect to database server: " + << mysql_error(db_escape_connect); + + throw runtime_error(oss.str()); } //Connect to the database & initialize connection pool @@ -92,11 +103,16 @@ MySqlDB::MySqlDB( oss.str(""); oss << "USE " << database; - for (int i=0 ; i < DB_CONNECT_SIZE ; i++) + for (int i=0 ; i < max_connections ; i++) { if ( mysql_query(connections[i], oss.str().c_str()) != 0 ) { - throw runtime_error("Could not connect to the database."); + ostringstream oss; + + oss << "Could not connect to database server: " + << mysql_error(connections[i]); + + throw runtime_error(oss.str()); } db_connect.push(connections[i]); diff --git a/src/template/SConstruct b/src/template/SConstruct index fb420fa264..6edef38105 100644 --- a/src/template/SConstruct +++ b/src/template/SConstruct @@ -20,25 +20,9 @@ Import('env') lib_name='nebula_template' -if env['parsers']=='yes': - # LEX - parser=env.Lex( - source='template_parser.l' - ) - env.NoClean(parser) - - # BISON - parser=env.Bison( - source='template_syntax.y' - ) - env.NoClean(parser) - - # Sources to generate the library source_files=[ - 'Template.cc', - 'template_parser.c', - 'template_syntax.cc' + 'Template.cc' ] # Build library diff --git a/src/template/Template.cc b/src/template/Template.cc index e1a8ffb699..b0f3459c4f 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -16,6 +16,7 @@ #include "Template.h" #include "template_syntax.h" +#include "template_parser.h" #include "NebulaUtil.h" #include @@ -39,57 +40,40 @@ Template::~Template() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -pthread_mutex_t Template::mutex = PTHREAD_MUTEX_INITIALIZER; - -extern "C" -{ - typedef struct yy_buffer_state * YY_BUFFER_STATE; - - extern FILE *template_in, *template_out; - - int template_parse(Template * tmpl, char ** errmsg); - - int template_lex_destroy(); - - YY_BUFFER_STATE template__scan_string(const char * str); - - void template__delete_buffer(YY_BUFFER_STATE); -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - int Template::parse(const char * filename, char **error_msg) { - int rc; + int rc; - pthread_mutex_lock(&mutex); + yyscan_t scanner = 0; + + YY_BUFFER_STATE file_buffer = 0; + + template_lex_init(&scanner); *error_msg = 0; - template_in = fopen (filename, "r"); + FILE * template_in = fopen (filename, "r"); if ( template_in == 0 ) { - goto error_open; + *error_msg = strdup("Error opening template file"); + + return -1; } - rc = template_parse(this,error_msg); + file_buffer = template__create_buffer(template_in, YY_BUF_SIZE, scanner); + + template__switch_to_buffer(file_buffer, scanner); + + rc = template_parse(this, error_msg, scanner); fclose(template_in); - template_lex_destroy(); + template__delete_buffer(file_buffer, scanner); - pthread_mutex_unlock(&mutex); + template_lex_destroy(scanner); return rc; - -error_open: - *error_msg = strdup("Error opening template file"); - - pthread_mutex_unlock(&mutex); - - return -1; } /* -------------------------------------------------------------------------- */ @@ -97,40 +81,34 @@ error_open: int Template::parse(const string &parse_str, char **error_msg) { - YY_BUFFER_STATE str_buffer = 0; - const char * str; - int rc; + const char * str; + int rc; - pthread_mutex_lock(&mutex); + YY_BUFFER_STATE str_buffer = 0; + yyscan_t scanner = 0; *error_msg = 0; + template_lex_init(&scanner); + str = parse_str.c_str(); - str_buffer = template__scan_string(str); + str_buffer = template__scan_string(str, scanner); if (str_buffer == 0) { - goto error_yy; + *error_msg=strdup("Error setting scan buffer"); + + return -1; } - rc = template_parse(this,error_msg); + rc = template_parse(this, error_msg, scanner); - template__delete_buffer(str_buffer); + template__delete_buffer(str_buffer, scanner); - template_lex_destroy(); - - pthread_mutex_unlock(&mutex); + template_lex_destroy(scanner); return rc; - -error_yy: - - *error_msg=strdup("Error setting scan buffer"); - - pthread_mutex_unlock(&mutex); - - return -1; } /* -------------------------------------------------------------------------- */ diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 699a364759..ed46ccbaec 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -86,7 +86,7 @@ void TransferManager::user_action(const ActionRequest& ar) Nebula& nd = Nebula::instance(); - VirtualMachine * vm = vmpool->get(vid,true); + VirtualMachine * vm = vmpool->get(vid); if (vm == 0) { @@ -574,7 +574,7 @@ void TransferManager::prolog_action(int vid) // ------------------------------------------------------------------------- // Setup & Transfer script // ------------------------------------------------------------------------- - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -587,7 +587,7 @@ void TransferManager::prolog_action(int vid) token_password = Nebula::instance().get_upool()->get_token_password(uid, owner_id); - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -737,7 +737,7 @@ void TransferManager::prolog_migr_action(int vid) // ------------------------------------------------------------------------- // Setup & Transfer script // ------------------------------------------------------------------------- - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -868,7 +868,7 @@ void TransferManager::prolog_resume_action(int vid) // ------------------------------------------------------------------------- // Setup & Transfer script // ------------------------------------------------------------------------- - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -881,7 +881,7 @@ void TransferManager::prolog_resume_action(int vid) token_password = Nebula::instance().get_upool()->get_token_password(uid, owner_id); - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -1010,7 +1010,7 @@ void TransferManager::prolog_attach_action(int vid) // Setup & Transfer script // ------------------------------------------------------------------------- - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -1192,7 +1192,7 @@ void TransferManager::epilog_action(bool local, int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -1301,7 +1301,7 @@ void TransferManager::epilog_stop_action(int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -1550,7 +1550,7 @@ void TransferManager::epilog_delete_action(bool local, int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -1623,7 +1623,7 @@ void TransferManager::epilog_delete_previous_action(int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -1696,7 +1696,7 @@ void TransferManager::epilog_delete_both_action(int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -1771,7 +1771,7 @@ void TransferManager::epilog_detach_action(int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -1870,7 +1870,7 @@ void TransferManager::driver_cancel_action(int vid) return; } - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -1920,7 +1920,7 @@ void TransferManager::saveas_hot_action(int vid) // ------------------------------------------------------------------------ // Setup & Transfer script // ------------------------------------------------------------------------ - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -2071,7 +2071,7 @@ void TransferManager::do_snapshot_action(int vid, const char * snap_action) goto error_driver; } - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { @@ -2195,7 +2195,7 @@ void TransferManager::resize_action(int vid) goto error_driver; } - vm = vmpool->get(vid,true); + vm = vmpool->get(vid); if (vm == 0) { diff --git a/src/tm/TransferManagerDriver.cc b/src/tm/TransferManagerDriver.cc index 6855910ef8..e13825c663 100644 --- a/src/tm/TransferManagerDriver.cc +++ b/src/tm/TransferManagerDriver.cc @@ -88,7 +88,7 @@ void TransferManagerDriver::protocol(const string& message) const return; // Get the VM from the pool - vm = vmpool->get(id,true); + vm = vmpool->get(id); if ( vm == 0 ) { diff --git a/src/um/Quotas.cc b/src/um/Quotas.cc index b68a81ecac..c88312af38 100644 --- a/src/um/Quotas.cc +++ b/src/um/Quotas.cc @@ -265,7 +265,7 @@ void Quotas::quota_del(QuotaType type, int uid, int gid, Template * tmpl) if ( uid != UserPool::ONEADMIN_ID ) { - user = upool->get(uid, true); + user = upool->get(uid); if ( user != 0 ) { @@ -279,7 +279,7 @@ void Quotas::quota_del(QuotaType type, int uid, int gid, Template * tmpl) if ( gid != GroupPool::ONEADMIN_ID ) { - group = gpool->get(gid, true); + group = gpool->get(gid); if ( group != 0 ) { @@ -315,7 +315,7 @@ void Quotas::ds_del_recreate(int uid, int gid, vector