<commit_before>#ifndef __OBJECT_HPP_INCLUDED
#define __OBJECT_HPP_INCLUDED

#include "shader.hpp"
#include "species.hpp"
#include "glyph.hpp"
#include "render_templates.hpp"
#include "cpp/ylikuutio/hierarchy/hierarchy_templates.hpp"

// Include GLEW
#ifndef __GL_GLEW_H_INCLUDED
#define __GL_GLEW_H_INCLUDED
#include <GL/glew.h> // GLfloat, GLuint etc.
#endif

// Include GLM
#ifndef __GLM_GLM_HPP_INCLUDED
#define __GLM_GLM_HPP_INCLUDED
#include <glm/glm.hpp> // glm
#endif

#ifndef __GLM_GTC_MATRIX_TRANSFORM_HPP_INCLUDED
#define __GLM_GTC_MATRIX_TRANSFORM_HPP_INCLUDED
#include <glm/gtc/matrix_transform.hpp>
#endif

#ifndef __GLM_GTC_QUATERNION_HPP_INCLUDED
#define __GLM_GTC_QUATERNION_HPP_INCLUDED
#include <glm/gtc/quaternion.hpp> // glm::quat
#endif

#ifndef __GLM_GTX_QUATERNION_HPP_INCLUDED
#define __GLM_GTX_QUATERNION_HPP_INCLUDED
#include <glm/gtx/quaternion.hpp> // glm::toMat4
#endif

// Include standard headers
#include <queue>    // std::queue
#include <stdint.h> // uint32_t etc.
#include <vector>   // std::vector

namespace ontology
{
    class Species;
    class Glyph;

    class Object
    {
        public:
            // constructor.
            Object(ObjectStruct object_struct);

            // destructor.
            ~Object();

            // this method sets pointer to this object to nullptr, sets `parent_pointer` according to the input, and requests a new `childID` from the new species.
            void bind_to_new_parent(void* new_parent_pointer);
            template<class T1>
                friend void hierarchy::bind_child_to_parent(T1 child_pointer, std::vector<T1> &child_pointer_vector, std::queue<uint32_t> &free_childID_queue);
            template<class T1, class T2>
                friend void hierarchy::bind_child_to_new_parent(T1 child_pointer, T2 new_parent_pointer, std::vector<T1> &old_child_pointer_vector, std::queue<uint32_t> &old_free_childID_queue);
            template<class T1>
                friend void render_children(std::vector<T1> &child_pointer_vector);
            template<class T1>
                friend void render_this_object(ontology::Object* object_pointer, ontology::Shader* shader_pointer);

            // this method renders this object.
            void render();

        private:
            void bind_to_parent();

            ontology::Species* species_parent_pointer; // pointer to `Species`.
            ontology::Glyph* glyph_parent_pointer;     // pointer to `Glyph`.
            ontology::Text3D* text3D_parent_pointer;   // pointer to `Text3D`.
            bool is_character;

            uint32_t childID;                      // object ID, returned by `ontology::Species->get_objectID()`.
            bool has_entered;

            glm::vec3 coordinate_vector;           // coordinate vector.
            glm::vec3 original_scale_vector;       // original scale vector.
            GLfloat rotate_angle;                  // rotate angle.
            glm::vec3 rotate_vector;               // rotate vector.
            glm::vec3 translate_vector;            // translate vector.

            // The rest fields are created in the constructor.
            glm::mat4 model_matrix;                // model matrix.
            glm::mat4 MVP_matrix;                  // model view projection matrix.
    };

    template<class T1>
        void render_this_object(ontology::Object* object_pointer, ontology::Shader* shader_pointer)
        {
            if (!object_pointer->has_entered)
            {
                object_pointer->model_matrix = glm::translate(glm::mat4(1.0f), object_pointer->coordinate_vector);
                object_pointer->model_matrix = glm::scale(object_pointer->model_matrix, object_pointer->original_scale_vector);

                // store the new coordinates to be used in the next update.
                object_pointer->coordinate_vector = glm::vec3(object_pointer->model_matrix[0][0], object_pointer->model_matrix[1][1], object_pointer->model_matrix[2][2]);
                object_pointer->has_entered = true;
            }
            else
            {
                // create `rotation_matrix` using quaternions.
                glm::quat my_quaternion;
                my_quaternion = glm::quat(DEGREES_TO_RADIANS(object_pointer->rotate_vector));
                glm::mat4 rotation_matrix = glm::toMat4(my_quaternion);

                // rotate.
                // this->model_matrix = rotation_matrix * this->model_matrix;
                if (object_pointer->rotate_vector != glm::vec3(0.0f, 0.0f, 0.0f))
                {
                    object_pointer->model_matrix = glm::rotate(object_pointer->model_matrix, object_pointer->rotate_angle, object_pointer->rotate_vector);
                }

                object_pointer->model_matrix = glm::translate(object_pointer->model_matrix, object_pointer->translate_vector);
                object_pointer->coordinate_vector = glm::vec3(object_pointer->model_matrix[0][0], object_pointer->model_matrix[1][1], object_pointer->model_matrix[2][2]);
            }

            object_pointer->MVP_matrix = ProjectionMatrix * ViewMatrix * object_pointer->model_matrix;

            // Send our transformation to the currently bound shader,
            // in the "MVP" uniform.
            // glUniformMatrix4fv(this->parent_pointer->parent_pointer->parent_pointer->MatrixID, 1, GL_FALSE, &this->MVP_matrix[0][0]);
            glUniformMatrix4fv(shader_pointer->MatrixID, 1, GL_FALSE, &object_pointer->MVP_matrix[0][0]);
            // glUniformMatrix4fv(this->parent_pointer->parent_pointer->parent_pointer->ModelMatrixID, 1, GL_FALSE, &this->model_matrix[0][0]);
            glUniformMatrix4fv(shader_pointer->ModelMatrixID, 1, GL_FALSE, &object_pointer->model_matrix[0][0]);

            GLuint vertexbuffer;
            GLuint vertexPosition_modelspaceID;
            GLuint uvbuffer;
            GLuint vertexUVID;
            GLuint normalbuffer;
            GLuint vertexNormal_modelspaceID;
            GLuint elementbuffer;
            GLuint indices_size;

            if (object_pointer->is_character)
            {
                ontology::Glyph* parent_glyph = object_pointer->glyph_parent_pointer;
                vertexbuffer = parent_glyph->vertexbuffer;
                vertexPosition_modelspaceID = parent_glyph->vertexPosition_modelspaceID;
                uvbuffer = parent_glyph->uvbuffer;
                vertexUVID = parent_glyph->vertexUVID;
                normalbuffer = parent_glyph->normalbuffer;
                vertexNormal_modelspaceID = parent_glyph->vertexNormal_modelspaceID;
                elementbuffer = parent_glyph->elementbuffer;
                indices_size = parent_glyph->indices.size();
            }
            else
            {
                ontology::Species* parent_species = object_pointer->species_parent_pointer;
                vertexbuffer = parent_species->vertexbuffer;
                vertexPosition_modelspaceID = parent_species->vertexPosition_modelspaceID;
                uvbuffer = parent_species->uvbuffer;
                vertexUVID = parent_species->vertexUVID;
                normalbuffer = parent_species->normalbuffer;
                vertexNormal_modelspaceID = parent_species->vertexNormal_modelspaceID;
                elementbuffer = parent_species->elementbuffer;
                indices_size = parent_species->indices.size();
            }

            // 1st attribute buffer : vertices.
            glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
            glVertexAttribPointer(
                    vertexPosition_modelspaceID, // The attribute we want to configure
                    3,                           // size
                    GL_FLOAT,                    // type
                    GL_FALSE,                    // normalized?
                    0,                           // stride
                    (void*) 0                    // array buffer offset
                    );

            // 2nd attribute buffer : UVs.
            glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
            glVertexAttribPointer(
                    vertexUVID, // The attribute we want to configure
                    2,          // size : U+V => 2
                    GL_FLOAT,   // type
                    GL_FALSE,   // normalized?
                    0,          // stride
                    (void*) 0   // array buffer offset
                    );

            // 3rd attribute buffer : normals.
            glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
            glVertexAttribPointer(
                    vertexNormal_modelspaceID, // The attribute we want to configure
                    3,                         // size
                    GL_FLOAT,                  // type
                    GL_FALSE,                  // normalized?
                    0,                         // stride
                    (void*) 0                  // array buffer offset
                    );

            // Index buffer.
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);

            // Draw the triangles!
            glDrawElements(
                    GL_TRIANGLES,    // mode
                    indices_size,    // count
                    GL_UNSIGNED_INT, // type
                    (void*) 0        // element array buffer offset
                    );
        }
}

#endif
<commit_msg>`void Object::render()` is `private` again.<commit_after>#ifndef __OBJECT_HPP_INCLUDED
#define __OBJECT_HPP_INCLUDED

#include "shader.hpp"
#include "species.hpp"
#include "glyph.hpp"
#include "render_templates.hpp"
#include "cpp/ylikuutio/hierarchy/hierarchy_templates.hpp"

// Include GLEW
#ifndef __GL_GLEW_H_INCLUDED
#define __GL_GLEW_H_INCLUDED
#include <GL/glew.h> // GLfloat, GLuint etc.
#endif

// Include GLM
#ifndef __GLM_GLM_HPP_INCLUDED
#define __GLM_GLM_HPP_INCLUDED
#include <glm/glm.hpp> // glm
#endif

#ifndef __GLM_GTC_MATRIX_TRANSFORM_HPP_INCLUDED
#define __GLM_GTC_MATRIX_TRANSFORM_HPP_INCLUDED
#include <glm/gtc/matrix_transform.hpp>
#endif

#ifndef __GLM_GTC_QUATERNION_HPP_INCLUDED
#define __GLM_GTC_QUATERNION_HPP_INCLUDED
#include <glm/gtc/quaternion.hpp> // glm::quat
#endif

#ifndef __GLM_GTX_QUATERNION_HPP_INCLUDED
#define __GLM_GTX_QUATERNION_HPP_INCLUDED
#include <glm/gtx/quaternion.hpp> // glm::toMat4
#endif

// Include standard headers
#include <queue>    // std::queue
#include <stdint.h> // uint32_t etc.
#include <vector>   // std::vector

namespace ontology
{
    class Species;
    class Glyph;

    class Object
    {
        public:
            // constructor.
            Object(ObjectStruct object_struct);

            // destructor.
            ~Object();

            // this method sets pointer to this object to nullptr, sets `parent_pointer` according to the input, and requests a new `childID` from the new species.
            void bind_to_new_parent(void* new_parent_pointer);
            template<class T1>
                friend void hierarchy::bind_child_to_parent(T1 child_pointer, std::vector<T1> &child_pointer_vector, std::queue<uint32_t> &free_childID_queue);
            template<class T1, class T2>
                friend void hierarchy::bind_child_to_new_parent(T1 child_pointer, T2 new_parent_pointer, std::vector<T1> &old_child_pointer_vector, std::queue<uint32_t> &old_free_childID_queue);
            template<class T1>
                friend void render_children(std::vector<T1> &child_pointer_vector);
            template<class T1>
                friend void render_this_object(ontology::Object* object_pointer, ontology::Shader* shader_pointer);

        private:
            void bind_to_parent();

            // this method renders this object.
            void render();

            ontology::Species* species_parent_pointer; // pointer to `Species`.
            ontology::Glyph* glyph_parent_pointer;     // pointer to `Glyph`.
            ontology::Text3D* text3D_parent_pointer;   // pointer to `Text3D`.
            bool is_character;

            uint32_t childID;                      // object ID, returned by `ontology::Species->get_objectID()`.
            bool has_entered;

            glm::vec3 coordinate_vector;           // coordinate vector.
            glm::vec3 original_scale_vector;       // original scale vector.
            GLfloat rotate_angle;                  // rotate angle.
            glm::vec3 rotate_vector;               // rotate vector.
            glm::vec3 translate_vector;            // translate vector.

            // The rest fields are created in the constructor.
            glm::mat4 model_matrix;                // model matrix.
            glm::mat4 MVP_matrix;                  // model view projection matrix.
    };

    template<class T1>
        void render_this_object(ontology::Object* object_pointer, ontology::Shader* shader_pointer)
        {
            if (!object_pointer->has_entered)
            {
                object_pointer->model_matrix = glm::translate(glm::mat4(1.0f), object_pointer->coordinate_vector);
                object_pointer->model_matrix = glm::scale(object_pointer->model_matrix, object_pointer->original_scale_vector);

                // store the new coordinates to be used in the next update.
                object_pointer->coordinate_vector = glm::vec3(object_pointer->model_matrix[0][0], object_pointer->model_matrix[1][1], object_pointer->model_matrix[2][2]);
                object_pointer->has_entered = true;
            }
            else
            {
                // create `rotation_matrix` using quaternions.
                glm::quat my_quaternion;
                my_quaternion = glm::quat(DEGREES_TO_RADIANS(object_pointer->rotate_vector));
                glm::mat4 rotation_matrix = glm::toMat4(my_quaternion);

                // rotate.
                // this->model_matrix = rotation_matrix * this->model_matrix;
                if (object_pointer->rotate_vector != glm::vec3(0.0f, 0.0f, 0.0f))
                {
                    object_pointer->model_matrix = glm::rotate(object_pointer->model_matrix, object_pointer->rotate_angle, object_pointer->rotate_vector);
                }

                object_pointer->model_matrix = glm::translate(object_pointer->model_matrix, object_pointer->translate_vector);
                object_pointer->coordinate_vector = glm::vec3(object_pointer->model_matrix[0][0], object_pointer->model_matrix[1][1], object_pointer->model_matrix[2][2]);
            }

            object_pointer->MVP_matrix = ProjectionMatrix * ViewMatrix * object_pointer->model_matrix;

            // Send our transformation to the currently bound shader,
            // in the "MVP" uniform.
            // glUniformMatrix4fv(this->parent_pointer->parent_pointer->parent_pointer->MatrixID, 1, GL_FALSE, &this->MVP_matrix[0][0]);
            glUniformMatrix4fv(shader_pointer->MatrixID, 1, GL_FALSE, &object_pointer->MVP_matrix[0][0]);
            // glUniformMatrix4fv(this->parent_pointer->parent_pointer->parent_pointer->ModelMatrixID, 1, GL_FALSE, &this->model_matrix[0][0]);
            glUniformMatrix4fv(shader_pointer->ModelMatrixID, 1, GL_FALSE, &object_pointer->model_matrix[0][0]);

            GLuint vertexbuffer;
            GLuint vertexPosition_modelspaceID;
            GLuint uvbuffer;
            GLuint vertexUVID;
            GLuint normalbuffer;
            GLuint vertexNormal_modelspaceID;
            GLuint elementbuffer;
            GLuint indices_size;

            if (object_pointer->is_character)
            {
                ontology::Glyph* parent_glyph = object_pointer->glyph_parent_pointer;
                vertexbuffer = parent_glyph->vertexbuffer;
                vertexPosition_modelspaceID = parent_glyph->vertexPosition_modelspaceID;
                uvbuffer = parent_glyph->uvbuffer;
                vertexUVID = parent_glyph->vertexUVID;
                normalbuffer = parent_glyph->normalbuffer;
                vertexNormal_modelspaceID = parent_glyph->vertexNormal_modelspaceID;
                elementbuffer = parent_glyph->elementbuffer;
                indices_size = parent_glyph->indices.size();
            }
            else
            {
                ontology::Species* parent_species = object_pointer->species_parent_pointer;
                vertexbuffer = parent_species->vertexbuffer;
                vertexPosition_modelspaceID = parent_species->vertexPosition_modelspaceID;
                uvbuffer = parent_species->uvbuffer;
                vertexUVID = parent_species->vertexUVID;
                normalbuffer = parent_species->normalbuffer;
                vertexNormal_modelspaceID = parent_species->vertexNormal_modelspaceID;
                elementbuffer = parent_species->elementbuffer;
                indices_size = parent_species->indices.size();
            }

            // 1st attribute buffer : vertices.
            glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
            glVertexAttribPointer(
                    vertexPosition_modelspaceID, // The attribute we want to configure
                    3,                           // size
                    GL_FLOAT,                    // type
                    GL_FALSE,                    // normalized?
                    0,                           // stride
                    (void*) 0                    // array buffer offset
                    );

            // 2nd attribute buffer : UVs.
            glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
            glVertexAttribPointer(
                    vertexUVID, // The attribute we want to configure
                    2,          // size : U+V => 2
                    GL_FLOAT,   // type
                    GL_FALSE,   // normalized?
                    0,          // stride
                    (void*) 0   // array buffer offset
                    );

            // 3rd attribute buffer : normals.
            glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);
            glVertexAttribPointer(
                    vertexNormal_modelspaceID, // The attribute we want to configure
                    3,                         // size
                    GL_FLOAT,                  // type
                    GL_FALSE,                  // normalized?
                    0,                         // stride
                    (void*) 0                  // array buffer offset
                    );

            // Index buffer.
            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);

            // Draw the triangles!
            glDrawElements(
                    GL_TRIANGLES,    // mode
                    indices_size,    // count
                    GL_UNSIGNED_INT, // type
                    (void*) 0        // element array buffer offset
                    );
        }
}

#endif
<|endoftext|>


<commit_before>// $Id$
# ifndef CPPAD_LOCAL_OPTIMIZE_MATCH_OP_HPP
# define CPPAD_LOCAL_OPTIMIZE_MATCH_OP_HPP
/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell

CppAD is distributed under multiple licenses. This distribution is under
the terms of the
                    Eclipse Public License Version 1.0.

A copy of this license is included in the COPYING file of this distribution.
Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
-------------------------------------------------------------------------- */
# include <cppad/local/optimize/hash_code.hpp>
/*!
\file match_op.hpp
Check if current operator matches a previous operator.
*/
// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE
namespace CppAD { namespace local { namespace optimize  {
/*!
Search for a previous operator that matches the current one.

\param var2op
mapping from variable index to operator index.

\param op_info
mapping from operator index to operator information

\param current
is the index of the current operator.

\li
This must be a unary or binary
operator; hence, NumArg( op_info[current].op ) is one or two.
There is one exception, NumRes( ErfOp ) == 3, but arg[0]
is the only true arguments (the others are always the same).

\li
This must not be a VecAD load or store operation; i.e.,
LtpvOp, LtvpOp, LtvvOp, StppOp, StpvOp, StvpOp, StvvOp.
It also must not be an independent variable operator InvOp.

\param hash_table_op
is a vector with size CPPAD_HASH_TABLE_SIZE
that maps a hash code to the corresponding
variable index in the operation sequence.
All the values in this table are less than current.

\param code [out]
The input value of code does not matter.
The output value of code is the hash code corresponding to
the current operation in the new operation sequence.

\return
We refer to the return value as pevious.
If pevious == 0, no match was found.
If previous != 0,
it is a pevious operator that can be used in place of current.
In addition op_info[previous].previous == 0.
*/

inline size_t match_op(
	const vector<size_t>&                              var2op         ,
	const vector<struct_op_info>&                      op_info        ,
	size_t                                             current        ,
	const vector<size_t>&                              hash_table_op  ,
	unsigned short&                                    code           )
{	// current operator
	OpCode        op         = op_info[current].op;
	const addr_t* arg        = op_info[current].arg;
	//
	// which arguments are variable
	size_t num_arg = NumArg(op);
	//
	bool   variable[2];
	variable[0] = false;
	variable[1] = false;
	//
	// If i-th argument to current operator has a previous operator,
	// this is the i-th argument for previous operator.
	// Otherwise, it is the i-th argument for the current operator
	// (if a previous variable exists)
	addr_t arg_match[2];
	switch(op)
	{	//
		case ErfOp:
		case AbsOp:
		case AcosOp:
		case AcoshOp:
		case AsinOp:
		case AsinhOp:
		case AtanOp:
		case AtanhOp:
		case CosOp:
		case CoshOp:
		case ExpOp:
		case Expm1Op:
		case LogOp:
		case Log1pOp:
		case SignOp:
		case SinOp:
		case SinhOp:
		case SqrtOp:
		case TanOp:
		case TanhOp:
		{	arg_match[0] = arg[0];
			size_t previous = op_info[ var2op[arg[0]] ].previous;
			if( previous != 0 )
			{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
				arg_match[0] = op_info[previous].i_var;
			}
			num_arg = 1;
			code = optimize_hash_code(op, num_arg, arg_match);
			//
			// candidate previous for current operator
			size_t candidate  = hash_table_op[code];
			CPPAD_ASSERT_UNKNOWN( candidate < current );
			CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 );
			//
			if( (candidate == 0) | (op != op_info[candidate].op) )
				return 0;
			//
			// check for a match
			bool match;
			previous = op_info[ var2op[op_info[candidate].arg[0]] ].previous;
			if( previous == 0 )
				match = arg_match[0] == op_info[candidate].arg[0];
			else
			{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
				match = arg_match[0] == addr_t( op_info[previous].i_var );
			}
			if( match )
				return candidate;
			return 0;
		}
		break;

		case AddpvOp:
		case DisOp:
		case DivpvOp:
		case EqpvOp:
		case LepvOp:
		case LtpvOp:
		case MulpvOp:
		case NepvOp:
		case PowpvOp:
		case SubpvOp:
		case ZmulpvOp:
		CPPAD_ASSERT_UNKNOWN( num_arg == 2 );
		variable[1] = true;
		break;

		case DivvpOp:
		case LevpOp:
		case LtvpOp:
		case PowvpOp:
		case SubvpOp:
		case ZmulvpOp:
		CPPAD_ASSERT_UNKNOWN( num_arg == 2 );
		variable[0] = true;
		break;

		case AddvvOp:
		case DivvvOp:
		case EqvvOp:
		case LevvOp:
		case LtvvOp:
		case MulvvOp:
		case NevvOp:
		case PowvvOp:
		case SubvvOp:
		case ZmulvvOp:
		CPPAD_ASSERT_UNKNOWN( num_arg == 2 );
		variable[0] = true;
		variable[1] = true;
		break;

		default:
		CPPAD_ASSERT_UNKNOWN(false);
	}
	for(size_t j = 0; j < num_arg; ++j)
	{	arg_match[j] = arg[j];
		if( variable[j] )
		{	size_t previous = op_info[ var2op[arg[j]] ].previous;
			if( previous != 0 )
			{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
				//
				arg_match[j] = op_info[previous].i_var;
			}
		}
	}
	code = optimize_hash_code(op, num_arg, arg_match);
	//
	// candidate previous for current operator
	size_t  candidate  = hash_table_op[code];
	CPPAD_ASSERT_UNKNOWN( candidate < current );
	CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 );
	//
	// check for a match
	bool match = candidate != 0;
	match     &= op == op_info[candidate].op;
	if( match )
	{	for(size_t j = 0; j < num_arg; j++)
		{	if( variable[j] )
			{	size_t previous =
					op_info[ var2op[op_info[candidate].arg[j]] ].previous;
				if( previous != 0 )
				{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
					//
					match &= arg_match[j] == addr_t( op_info[previous].i_var );
				}
				else
					match &= arg_match[j] == op_info[candidate].arg[j];
			}
		}
		if( match )
			return candidate;
	}

	// special case where operator is commutative
	if( (op == AddvvOp) | (op == MulvvOp ) )
	{	CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 );
		std::swap( arg_match[0], arg_match[1] );
		//
		code      = optimize_hash_code(op, num_arg, arg_match);
		candidate  = hash_table_op[code];
		CPPAD_ASSERT_UNKNOWN( candidate < current );
		CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 );
		//
		match  = candidate != 0;
		match &= op == op_info[candidate].op;
		if( match )
		{	for(size_t j = 0; j < num_arg; j++)
			{	CPPAD_ASSERT_UNKNOWN( variable[j] )
				size_t previous =
					op_info[ var2op[op_info[candidate].arg[j]] ].previous;
				if( previous != 0 )
				{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
					//
					match &= arg_match[j] == addr_t( op_info[previous].i_var );
				}
				else
					match &= arg_match[j] == op_info[candidate].arg[j];
			}
			if( match )
				return candidate;
		}
	}
	// special op code used for no match
	return 0;
}

} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE

# endif
<commit_msg>optimize branch: match_op.hpp: Convert more operators to special cases.<commit_after>// $Id$
# ifndef CPPAD_LOCAL_OPTIMIZE_MATCH_OP_HPP
# define CPPAD_LOCAL_OPTIMIZE_MATCH_OP_HPP
/* --------------------------------------------------------------------------
CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell

CppAD is distributed under multiple licenses. This distribution is under
the terms of the
                    Eclipse Public License Version 1.0.

A copy of this license is included in the COPYING file of this distribution.
Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
-------------------------------------------------------------------------- */
# include <cppad/local/optimize/hash_code.hpp>
/*!
\file match_op.hpp
Check if current operator matches a previous operator.
*/
// BEGIN_CPPAD_LOCAL_OPTIMIZE_NAMESPACE
namespace CppAD { namespace local { namespace optimize  {
/*!
Search for a previous operator that matches the current one.

\param var2op
mapping from variable index to operator index.

\param op_info
mapping from operator index to operator information

\param current
is the index of the current operator.

\li
This must be a unary or binary
operator; hence, NumArg( op_info[current].op ) is one or two.
There is one exception, NumRes( ErfOp ) == 3, but arg[0]
is the only true arguments (the others are always the same).

\li
This must not be a VecAD load or store operation; i.e.,
LtpvOp, LtvpOp, LtvvOp, StppOp, StpvOp, StvpOp, StvvOp.
It also must not be an independent variable operator InvOp.

\param hash_table_op
is a vector with size CPPAD_HASH_TABLE_SIZE
that maps a hash code to the corresponding
variable index in the operation sequence.
All the values in this table are less than current.

\param code [out]
The input value of code does not matter.
The output value of code is the hash code corresponding to
the current operation in the new operation sequence.

\return
We refer to the return value as pevious.
If pevious == 0, no match was found.
If previous != 0,
it is a pevious operator that can be used in place of current.
In addition op_info[previous].previous == 0.
*/

inline size_t match_op(
	const vector<size_t>&                              var2op         ,
	const vector<struct_op_info>&                      op_info        ,
	size_t                                             current        ,
	const vector<size_t>&                              hash_table_op  ,
	unsigned short&                                    code           )
{	// current operator
	OpCode        op         = op_info[current].op;
	const addr_t* arg        = op_info[current].arg;
	//
	// which arguments are variable
	size_t num_arg = NumArg(op);
	//
	bool   variable[2];
	variable[0] = false;
	variable[1] = false;
	//
	// If i-th argument to current operator has a previous operator,
	// this is the i-th argument for previous operator.
	// Otherwise, it is the i-th argument for the current operator
	// (if a previous variable exists)
	addr_t arg_match[2];
	switch(op)
	{	//
		case ErfOp:
		case AbsOp:
		case AcosOp:
		case AcoshOp:
		case AsinOp:
		case AsinhOp:
		case AtanOp:
		case AtanhOp:
		case CosOp:
		case CoshOp:
		case ExpOp:
		case Expm1Op:
		case LogOp:
		case Log1pOp:
		case SignOp:
		case SinOp:
		case SinhOp:
		case SqrtOp:
		case TanOp:
		case TanhOp:
		{	// arg[0] is a variable index
			arg_match[0] = arg[0];
			size_t previous = op_info[ var2op[arg[0]] ].previous;
			if( previous != 0 )
			{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
				arg_match[0] = op_info[previous].i_var;
			}
			num_arg = 1;
			code = optimize_hash_code(op, num_arg, arg_match);
			//
			// candidate previous for current operator
			size_t candidate  = hash_table_op[code];
			CPPAD_ASSERT_UNKNOWN( candidate < current );
			CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 );
			//
			if( (candidate == 0) | (op != op_info[candidate].op) )
				return 0;
			//
			// check for a match
			bool match;
			previous = op_info[ var2op[op_info[candidate].arg[0]] ].previous;
			if( previous == 0 )
				match = arg_match[0] == op_info[candidate].arg[0];
			else
			{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
				match = arg_match[0] == addr_t( op_info[previous].i_var );
			}
			if( match )
				return candidate;
			return 0;
		}
		break;

		case AddpvOp:
		case DisOp:
		case DivpvOp:
		case EqpvOp:
		case LepvOp:
		case LtpvOp:
		case MulpvOp:
		case NepvOp:
		case PowpvOp:
		case SubpvOp:
		case ZmulpvOp:
		{	// arg[0] is a parameter index, arg[1] is a variable index
			arg_match[0] = arg[0];
			arg_match[1] = arg[1];
			size_t previous = op_info[ var2op[arg[1]] ].previous;
			if( previous != 0 )
			{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
				arg_match[1] = op_info[previous].i_var;
			}
			num_arg = 2;
			code = optimize_hash_code(op, num_arg, arg_match);
			//
			// candidate previous for current operator
			size_t candidate  = hash_table_op[code];
			CPPAD_ASSERT_UNKNOWN( candidate < current );
			CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 );
			//
			// check for a match
			bool match = candidate != 0;
			match     &= op == op_info[candidate].op;
			match     &= arg[0] == op_info[candidate].arg[0];
			if( ! match )
				return 0;
			//
			previous = op_info[ var2op[op_info[candidate].arg[1]] ].previous;
			if( previous == 0 )
				match = arg_match[1] == op_info[candidate].arg[1];
			else
			{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
				match = arg_match[1] == addr_t( op_info[previous].i_var );
			}
			if( match )
				return candidate;
			return 0;
		}
		break;

		case DivvpOp:
		case LevpOp:
		case LtvpOp:
		case PowvpOp:
		case SubvpOp:
		case ZmulvpOp:
		{	// arg[0] is a variable index, arg[1] is a parameter index
			arg_match[0] = arg[0];
			arg_match[1] = arg[1];
			size_t previous = op_info[ var2op[arg[0]] ].previous;
			if( previous != 0 )
			{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
				arg_match[0] = op_info[previous].i_var;
			}
			num_arg = 2;
			code = optimize_hash_code(op, num_arg, arg_match);
			//
			// candidate previous for current operator
			size_t candidate  = hash_table_op[code];
			CPPAD_ASSERT_UNKNOWN( candidate < current );
			CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 );
			//
			// check for a match
			bool match = candidate != 0;
			match     &= op == op_info[candidate].op;
			match     &= arg[1] == op_info[candidate].arg[1];
			if( ! match )
				return 0;
			//
			previous = op_info[ var2op[op_info[candidate].arg[0]] ].previous;
			if( previous == 0 )
				match = arg_match[0] == op_info[candidate].arg[0];
			else
			{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
				match = arg_match[0] == addr_t( op_info[previous].i_var );
			}
			if( match )
				return candidate;
			return 0;
		}
		break;

		case DivvvOp:
		case EqvvOp:
		case LevvOp:
		case LtvvOp:
		case NevvOp:
		case PowvvOp:
		case SubvvOp:
		case ZmulvvOp:
		{	// arg[0] is a variable index, arg[1] is a variable index
			arg_match[0] = arg[0];
			arg_match[1] = arg[1];
			size_t previous;
			for(size_t j = 0; j < 2; j++)
			{	previous = op_info[ var2op[arg[j]] ].previous;
				if( previous != 0 )
				{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
					arg_match[j] = op_info[previous].i_var;
				}
			}
			num_arg = 2;
			code = optimize_hash_code(op, num_arg, arg_match);
			//
			// candidate previous for current operator
			size_t candidate  = hash_table_op[code];
			CPPAD_ASSERT_UNKNOWN( candidate < current );
			CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 );
			//
			// check for a match
			bool match = candidate != 0;
			match     &= op == op_info[candidate].op;
			if( ! match )
				return 0;
			for(size_t j = 0; j < 2; j++)
			{	previous =
					op_info[ var2op[op_info[candidate].arg[j]] ].previous;
				if( previous == 0 )
					match &= arg_match[j] == op_info[candidate].arg[j];
				else
				{	CPPAD_ASSERT_UNKNOWN(op_info[previous].previous == 0);
					match &= arg_match[j] == addr_t( op_info[previous].i_var );
				}
			}
			if( match )
				return candidate;
			return 0;
		}
		break;

		case AddvvOp:
		case MulvvOp:
		num_arg = 2;
		variable[0] = true;
		variable[1] = true;
		break;

		default:
		CPPAD_ASSERT_UNKNOWN(false);
	}
	for(size_t j = 0; j < num_arg; ++j)
	{	arg_match[j] = arg[j];
		if( variable[j] )
		{	size_t previous = op_info[ var2op[arg[j]] ].previous;
			if( previous != 0 )
			{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
				//
				arg_match[j] = op_info[previous].i_var;
			}
		}
	}
	code = optimize_hash_code(op, num_arg, arg_match);
	//
	// candidate previous for current operator
	size_t  candidate  = hash_table_op[code];
	CPPAD_ASSERT_UNKNOWN( candidate < current );
	CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 );
	//
	// check for a match
	bool match = candidate != 0;
	match     &= op == op_info[candidate].op;
	if( match )
	{	for(size_t j = 0; j < num_arg; j++)
		{	if( variable[j] )
			{	size_t previous =
					op_info[ var2op[op_info[candidate].arg[j]] ].previous;
				if( previous != 0 )
				{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
					//
					match &= arg_match[j] == addr_t( op_info[previous].i_var );
				}
				else
					match &= arg_match[j] == op_info[candidate].arg[j];
			}
		}
		if( match )
			return candidate;
	}

	// special case where operator is commutative
	if( (op == AddvvOp) | (op == MulvvOp ) )
	{	CPPAD_ASSERT_UNKNOWN( NumArg(op) == 2 );
		std::swap( arg_match[0], arg_match[1] );
		//
		code      = optimize_hash_code(op, num_arg, arg_match);
		candidate  = hash_table_op[code];
		CPPAD_ASSERT_UNKNOWN( candidate < current );
		CPPAD_ASSERT_UNKNOWN( op_info[candidate].previous == 0 );
		//
		match  = candidate != 0;
		match &= op == op_info[candidate].op;
		if( match )
		{	for(size_t j = 0; j < num_arg; j++)
			{	CPPAD_ASSERT_UNKNOWN( variable[j] )
				size_t previous =
					op_info[ var2op[op_info[candidate].arg[j]] ].previous;
				if( previous != 0 )
				{	CPPAD_ASSERT_UNKNOWN( op_info[previous].previous == 0 );
					//
					match &= arg_match[j] == addr_t( op_info[previous].i_var );
				}
				else
					match &= arg_match[j] == op_info[candidate].arg[j];
			}
			if( match )
				return candidate;
		}
	}
	// special op code used for no match
	return 0;
}

} } } // END_CPPAD_LOCAL_OPTIMIZE_NAMESPACE

# endif
<|endoftext|>


<commit_before><commit_msg>INTEGRATION: CWS locales201 (1.8.80); FILE MERGED 2005/10/08 08:55:23 er 1.8.80.2: RESYNC: (1.8-1.9); FILE MERGED 2005/08/23 15:41:00 er 1.8.80.1: #i46908# parseText: during rewind from value switch state if ignoring leading whitespace, don't loop forever<commit_after><|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you 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 .
 */

#include <rtl/instance.hxx>
#include <osl/diagnose.h>
#include <osl/doublecheckedlocking.h>
#include <osl/mutex.hxx>
#include <uno/dispatcher.hxx>
#include <uno/lbnames.h>
#include <uno/mapping.hxx>
#include <cppuhelper/detail/XExceptionThrower.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>

#include <cppuhelper/exc_hlp.hxx>

using namespace ::osl;
using namespace ::cppu;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;

namespace
{

using cppuhelper::detail::XExceptionThrower;

struct ExceptionThrower : public uno_Interface, XExceptionThrower
{
    inline ExceptionThrower();

    virtual ~ExceptionThrower() {}

    static inline Type const & getCppuType()
    {
        return ::getCppuType(
            reinterpret_cast< Reference< XExceptionThrower > const * >(0) );
    }

    // XInterface
    virtual Any SAL_CALL queryInterface( Type const & type )
        throw (RuntimeException, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL acquire() throw () SAL_OVERRIDE;
    virtual void SAL_CALL release() throw () SAL_OVERRIDE;

    // XExceptionThrower
    virtual void SAL_CALL throwException( Any const & exc ) throw (Exception, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL rethrowException() throw (Exception, std::exception) SAL_OVERRIDE;
};

extern "C"
{

static void SAL_CALL ExceptionThrower_acquire_release_nop(
    SAL_UNUSED_PARAMETER uno_Interface * )
{}

static void SAL_CALL ExceptionThrower_dispatch(
    uno_Interface * pUnoI, typelib_TypeDescription const * pMemberType,
    void * pReturn, void * pArgs [], uno_Any ** ppException )
{
    OSL_ASSERT( pMemberType->eTypeClass == typelib_TypeClass_INTERFACE_METHOD );

    switch (reinterpret_cast< typelib_InterfaceMemberTypeDescription * >(
                const_cast< typelib_TypeDescription * >( pMemberType ) )->
            nPosition)
    {
    case 0: // queryInterace()
    {
        Type const & rType_demanded =
            *reinterpret_cast< Type const * >( pArgs[ 0 ] );
        if (rType_demanded.equals(
                ::getCppuType( reinterpret_cast<
                               Reference< XInterface > const * >(0) ) ) ||
            rType_demanded.equals( ExceptionThrower::getCppuType() ))
        {
            typelib_TypeDescription * pTD = 0;
            TYPELIB_DANGER_GET( &pTD, rType_demanded.getTypeLibType() );
            uno_any_construct(
                reinterpret_cast< uno_Any * >( pReturn ), &pUnoI, pTD, 0 );
            TYPELIB_DANGER_RELEASE( pTD );
        }
        else
        {
            uno_any_construct(
                reinterpret_cast< uno_Any * >( pReturn ), 0, 0, 0 );
        }
        *ppException = 0;
        break;
    }
    case 1: // acquire()
    case 2: // release()
        *ppException = 0;
        break;
    case 3: // throwException()
    {
        uno_Any * pAny = reinterpret_cast< uno_Any * >( pArgs[ 0 ] );
        OSL_ASSERT( pAny->pType->eTypeClass == typelib_TypeClass_EXCEPTION );
        uno_type_any_construct( *ppException, pAny->pData, pAny->pType, 0 );
        break;
    }
    default:
    {
        OSL_ASSERT( false );
        RuntimeException exc( "not implemented!" );
        uno_type_any_construct(
            *ppException, &exc, ::getCppuType( &exc ).getTypeLibType(), 0 );
        break;
    }
    }
}

} // extern "C"

Any ExceptionThrower::queryInterface( Type const & type )
    throw (RuntimeException, std::exception)
{
    if (type.equals( ::getCppuType( reinterpret_cast<
                                    Reference< XInterface > const * >(0) ) ) ||
        type.equals( ExceptionThrower::getCppuType() ))
    {
        XExceptionThrower * that = static_cast< XExceptionThrower * >( this );
        return Any( &that, type );
    }
    return Any();
}

void ExceptionThrower::acquire() throw ()
{
}

void ExceptionThrower::release() throw ()
{
}

void ExceptionThrower::throwException( Any const & exc ) throw (Exception, std::exception)
{
    OSL_FAIL( "unexpected!" );
    throwException( exc );
}

void ExceptionThrower::rethrowException() throw (Exception, std::exception)
{
    throw;
}

inline ExceptionThrower::ExceptionThrower()
{
    uno_Interface::acquire = ExceptionThrower_acquire_release_nop;
    uno_Interface::release = ExceptionThrower_acquire_release_nop;
    uno_Interface::pDispatcher = ExceptionThrower_dispatch;
}

class theExceptionThrower : public rtl::Static<ExceptionThrower, theExceptionThrower> {};

} // anonymous namespace

namespace cppu
{

void SAL_CALL throwException( Any const & exc )
{
    if (exc.getValueTypeClass() != TypeClass_EXCEPTION)
    {
        throw RuntimeException(
            "no UNO exception given "
            "(must be derived from com::sun::star::uno::Exception)!" );
    }

    Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent());
    if (! uno2cpp.is())
    {
        throw RuntimeException(
            "cannot get binary UNO to C++ mapping!" );
    }

    Reference< XExceptionThrower > xThrower;
    uno2cpp.mapInterface(
        reinterpret_cast< void ** >( &xThrower ),
        static_cast< uno_Interface * >( &theExceptionThrower::get() ),
        ExceptionThrower::getCppuType() );
    OSL_ASSERT( xThrower.is() );
    xThrower->throwException( exc );
}

Any SAL_CALL getCaughtException()
{
    Mapping cpp2uno(Environment::getCurrent(), Environment(UNO_LB_UNO));
    if (! cpp2uno.is())
    {
        throw RuntimeException(
            "cannot get C++ to binary UNO mapping!" );
    }
    Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent());
    if (! uno2cpp.is())
    {
        throw RuntimeException(
            "cannot get binary UNO to C++ mapping!" );
    }

    typelib_TypeDescription * pTD = 0;
    TYPELIB_DANGER_GET(
        &pTD, ExceptionThrower::getCppuType().getTypeLibType() );

    UnoInterfaceReference unoI;
    cpp2uno.mapInterface(
        reinterpret_cast< void ** >( &unoI.m_pUnoI ),
        static_cast< XExceptionThrower * >( &theExceptionThrower::get() ), pTD );
    OSL_ASSERT( unoI.is() );

    typelib_TypeDescription * pMemberTD = 0;
    TYPELIB_DANGER_GET(
        &pMemberTD,
        reinterpret_cast< typelib_InterfaceTypeDescription * >( pTD )->
        ppMembers[ 1 ] /* rethrowException() */ );

    uno_Any exc_mem;
    uno_Any * exc = &exc_mem;
    unoI.dispatch( pMemberTD, 0, 0, &exc );

    TYPELIB_DANGER_RELEASE( pMemberTD );
    TYPELIB_DANGER_RELEASE( pTD );

    if (exc == 0)
    {
        throw RuntimeException( "rethrowing C++ exception failed!" );
    }

    Any ret;
    uno_any_destruct( &ret, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
    uno_type_any_constructAndConvert(
        &ret, exc->pData, exc->pType, uno2cpp.get() );
    uno_any_destruct( exc, 0 );
    return ret;
}

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>-Werror,-Winfinite-recursion<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you 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 .
 */

#include <rtl/instance.hxx>
#include <osl/diagnose.h>
#include <osl/doublecheckedlocking.h>
#include <osl/mutex.hxx>
#include <uno/dispatcher.hxx>
#include <uno/lbnames.h>
#include <uno/mapping.hxx>
#include <cppuhelper/detail/XExceptionThrower.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>

#include <cppuhelper/exc_hlp.hxx>

using namespace ::osl;
using namespace ::cppu;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;

namespace
{

using cppuhelper::detail::XExceptionThrower;

struct ExceptionThrower : public uno_Interface, XExceptionThrower
{
    inline ExceptionThrower();

    virtual ~ExceptionThrower() {}

    static inline Type const & getCppuType()
    {
        return ::getCppuType(
            reinterpret_cast< Reference< XExceptionThrower > const * >(0) );
    }

    // XInterface
    virtual Any SAL_CALL queryInterface( Type const & type )
        throw (RuntimeException, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL acquire() throw () SAL_OVERRIDE;
    virtual void SAL_CALL release() throw () SAL_OVERRIDE;

    // XExceptionThrower
    virtual void SAL_CALL throwException( Any const & exc ) throw (Exception, std::exception) SAL_OVERRIDE;
    virtual void SAL_CALL rethrowException() throw (Exception, std::exception) SAL_OVERRIDE;
};

extern "C"
{

static void SAL_CALL ExceptionThrower_acquire_release_nop(
    SAL_UNUSED_PARAMETER uno_Interface * )
{}

static void SAL_CALL ExceptionThrower_dispatch(
    uno_Interface * pUnoI, typelib_TypeDescription const * pMemberType,
    void * pReturn, void * pArgs [], uno_Any ** ppException )
{
    OSL_ASSERT( pMemberType->eTypeClass == typelib_TypeClass_INTERFACE_METHOD );

    switch (reinterpret_cast< typelib_InterfaceMemberTypeDescription * >(
                const_cast< typelib_TypeDescription * >( pMemberType ) )->
            nPosition)
    {
    case 0: // queryInterace()
    {
        Type const & rType_demanded =
            *reinterpret_cast< Type const * >( pArgs[ 0 ] );
        if (rType_demanded.equals(
                ::getCppuType( reinterpret_cast<
                               Reference< XInterface > const * >(0) ) ) ||
            rType_demanded.equals( ExceptionThrower::getCppuType() ))
        {
            typelib_TypeDescription * pTD = 0;
            TYPELIB_DANGER_GET( &pTD, rType_demanded.getTypeLibType() );
            uno_any_construct(
                reinterpret_cast< uno_Any * >( pReturn ), &pUnoI, pTD, 0 );
            TYPELIB_DANGER_RELEASE( pTD );
        }
        else
        {
            uno_any_construct(
                reinterpret_cast< uno_Any * >( pReturn ), 0, 0, 0 );
        }
        *ppException = 0;
        break;
    }
    case 1: // acquire()
    case 2: // release()
        *ppException = 0;
        break;
    case 3: // throwException()
    {
        uno_Any * pAny = reinterpret_cast< uno_Any * >( pArgs[ 0 ] );
        OSL_ASSERT( pAny->pType->eTypeClass == typelib_TypeClass_EXCEPTION );
        uno_type_any_construct( *ppException, pAny->pData, pAny->pType, 0 );
        break;
    }
    default:
    {
        OSL_ASSERT( false );
        RuntimeException exc( "not implemented!" );
        uno_type_any_construct(
            *ppException, &exc, ::getCppuType( &exc ).getTypeLibType(), 0 );
        break;
    }
    }
}

} // extern "C"

Any ExceptionThrower::queryInterface( Type const & type )
    throw (RuntimeException, std::exception)
{
    if (type.equals( ::getCppuType( reinterpret_cast<
                                    Reference< XInterface > const * >(0) ) ) ||
        type.equals( ExceptionThrower::getCppuType() ))
    {
        XExceptionThrower * that = static_cast< XExceptionThrower * >( this );
        return Any( &that, type );
    }
    return Any();
}

void ExceptionThrower::acquire() throw ()
{
}

void ExceptionThrower::release() throw ()
{
}

void ExceptionThrower::throwException( Any const & exc ) throw (Exception, std::exception)
{
    OSL_FAIL( "unexpected!" );
    cppu::throwException( exc );
}

void ExceptionThrower::rethrowException() throw (Exception, std::exception)
{
    throw;
}

inline ExceptionThrower::ExceptionThrower()
{
    uno_Interface::acquire = ExceptionThrower_acquire_release_nop;
    uno_Interface::release = ExceptionThrower_acquire_release_nop;
    uno_Interface::pDispatcher = ExceptionThrower_dispatch;
}

class theExceptionThrower : public rtl::Static<ExceptionThrower, theExceptionThrower> {};

} // anonymous namespace

namespace cppu
{

void SAL_CALL throwException( Any const & exc )
{
    if (exc.getValueTypeClass() != TypeClass_EXCEPTION)
    {
        throw RuntimeException(
            "no UNO exception given "
            "(must be derived from com::sun::star::uno::Exception)!" );
    }

    Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent());
    if (! uno2cpp.is())
    {
        throw RuntimeException(
            "cannot get binary UNO to C++ mapping!" );
    }

    Reference< XExceptionThrower > xThrower;
    uno2cpp.mapInterface(
        reinterpret_cast< void ** >( &xThrower ),
        static_cast< uno_Interface * >( &theExceptionThrower::get() ),
        ExceptionThrower::getCppuType() );
    OSL_ASSERT( xThrower.is() );
    xThrower->throwException( exc );
}

Any SAL_CALL getCaughtException()
{
    Mapping cpp2uno(Environment::getCurrent(), Environment(UNO_LB_UNO));
    if (! cpp2uno.is())
    {
        throw RuntimeException(
            "cannot get C++ to binary UNO mapping!" );
    }
    Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent());
    if (! uno2cpp.is())
    {
        throw RuntimeException(
            "cannot get binary UNO to C++ mapping!" );
    }

    typelib_TypeDescription * pTD = 0;
    TYPELIB_DANGER_GET(
        &pTD, ExceptionThrower::getCppuType().getTypeLibType() );

    UnoInterfaceReference unoI;
    cpp2uno.mapInterface(
        reinterpret_cast< void ** >( &unoI.m_pUnoI ),
        static_cast< XExceptionThrower * >( &theExceptionThrower::get() ), pTD );
    OSL_ASSERT( unoI.is() );

    typelib_TypeDescription * pMemberTD = 0;
    TYPELIB_DANGER_GET(
        &pMemberTD,
        reinterpret_cast< typelib_InterfaceTypeDescription * >( pTD )->
        ppMembers[ 1 ] /* rethrowException() */ );

    uno_Any exc_mem;
    uno_Any * exc = &exc_mem;
    unoI.dispatch( pMemberTD, 0, 0, &exc );

    TYPELIB_DANGER_RELEASE( pMemberTD );
    TYPELIB_DANGER_RELEASE( pTD );

    if (exc == 0)
    {
        throw RuntimeException( "rethrowing C++ exception failed!" );
    }

    Any ret;
    uno_any_destruct( &ret, reinterpret_cast< uno_ReleaseFunc >(cpp_release) );
    uno_type_any_constructAndConvert(
        &ret, exc->pData, exc->pType, uno2cpp.get() );
    uno_any_destruct( exc, 0 );
    return ret;
}

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>


<commit_before><commit_msg>Fixing an oopsie (1)<commit_after><|endoftext|>


<commit_before>#ifndef OCCA_PARSER_STATEMENT_HEADER
#define OCCA_PARSER_STATEMENT_HEADER

#include "occaParserDefines.hpp"
#include "occaParserMacro.hpp"
#include "occaParserTools.hpp"
#include "occaParserNodes.hpp"
#include "occaParserTypes.hpp"

namespace occa {
  namespace parserNamespace {
    class statement;

    //---[ Exp Node ]-------------------------------
    namespace expType {
      static const int root            = (1 << 0);

      static const int LCR             = (7 << 1);
      static const int L               = (1 << 1);
      static const int C               = (1 << 2);
      static const int R               = (1 << 3);

      static const int qualifier       = (1 <<  4);
      static const int type            = (1 <<  5);
      static const int presetValue     = (1 <<  6);
      static const int operator_       = (1 <<  7);
      static const int unknown         = (1 <<  8);
      static const int variable        = (1 <<  9);
      static const int function        = (1 << 11);
      static const int functionPointer = (1 << 12);
      static const int typedef_        = (1 << 13);
      static const int prototype       = (1 << 14);
      static const int declaration     = (1 << 15);
      static const int struct_         = (1 << 16);
      static const int namespace_      = (1 << 17);
      static const int cast_           = (1 << 18);
      static const int macro_          = (1 << 19);
      static const int goto_           = (1 << 20);
      static const int gotoLabel_      = (1 << 21);
      static const int case_           = (1 << 22);
      static const int return_         = (1 << 23);
      static const int occaFor         = (1 << 24);
      static const int checkSInfo      = (1 << 25);

      static const int printValue      = (1 << 26);
      static const int printLeaves     = (1 << 27);
      static const int maxBit          = 27;
    };

    class _varInfo;

    class expNode {
    public:
      statement *sInfo;

      std::string value;
      int info;

      expNode *up;

      int leafCount;

      union {
        expNode **leaves;
        _varInfo **varLeaves;
      };

      expNode();
      expNode(statement &s);
      expNode(expNode &up_);

      //---[ Find Statement ]-----------
      void labelStatement(strNode *&nodeRoot);

      int loadMacroStatement(strNode *&nodeRoot);
      int loadOccaForStatement(strNode *&nodeRoot);
      int loadTypedefStatement(strNode *&nodeRoot);
      int loadStructStatement(strNode *&nodeRoot);
      int loadUpdateStatement(strNode *&nodeRoot);
      int loadDescriptorStatement(strNode *&nodeRoot);
      int loadGotoStatement(strNode *&nodeRoot);
      int loadFlowStatement(strNode *&nodeRoot);
      int loadSpecialStatement(strNode *&nodeRoot);
      int loadBlockStatement(strNode *&nodeRoot);
      //================================

      void loadFromNode(strNode *&nodePos);

      void splitAndOrganizeNode(strNode *nodeRoot);
      void organize();

      void addNewVariables(strNode *nodePos);

      void splitDeclareStatement();
      void splitForStatement();
      void splitFunctionStatement();
      void splitStructStatement();
      void splitStructStatements();
      void splitTypedefStatement();

      void initLoadFromNode(strNode *nodeRoot,
                            const int initPos = 0);

      int initDownsFromNode(strNode *nodeRoot,
                            int leafPos = 0);

      void initOrganization();

      void organizeLeaves();
      void organizeLeaves(const int level);

      int mergeRange(const int newLeafType,
                     const int leafPosStart,
                     const int leafPosEnd);

      // [a][::][b]
      void mergeNamespaces();

      // [(class)]
      void labelCasts();

      // const int [*] x
      void labelReferenceQualifiers();

      // [const] int x
      void mergeQualifiers();

      // [[const] [int] [*]] x
      void mergeTypes();

      // [[[const] [int] [*]] [x]]
      void mergeVariables();

      // 1 [type]                           2 [(]       3 [(]
      // [[qualifiers] [type] [qualifiers]] [(*[name])] [([args])]
      void mergeFunctionPointers();

      // class(...), class{1,2,3}
      void mergeClassConstructs();

      // static_cast<>()
      void mergeCasts();

      // [max(a,b)]
      void mergeFunctionCalls();

      void mergeArguments();

      // a[3]
      void mergeArrays();

      // (class) x
      void mergeClassCasts();

      // sizeof x
      void mergeSizeOf();

      // new, new [], delete, delete []
      void mergeNewsAndDeletes();

      // throw x
      void mergeThrows();

      // [++]i
      int mergeLeftUnary(const int leafPos);

      // i[++]
      int mergeRightUnary(const int leafPos);

      // a [+] b
      int mergeBinary(const int leafPos);

      // a [?] b : c
      int mergeTernary(const int leafPos);

      //---[ Custom Functions ]---------
      void labelNewVariables();
      //================================

      //---[ Custom Type Info ]---------
      bool qualifierEndsWithStar() const;

      bool typeEndsWithStar() const;

      bool hasAnArrayQualifier(const int pos = 0) const;
      //================================

      static void swap(expNode &a, expNode &b);

      expNode* clone(statement &s);
      expNode* clone(expNode *original);

      void cloneTo(expNode &newRoot);

      expNode* lastLeaf();

      //---[ Exp Info ]-----------------
      int depth();
      int whichLeafAmI();
      int nestedLeafCount();

      expNode* makeFlatHandle();
      void makeFlatHandle(int &offset,
                          expNode **flatLeaves);

      void addNode(const int info_, const int pos = 0);
      void removeNode(const int pos = 0);

      void convertTo(const int info_ = 0);

      bool hasQualifier(const std::string &qualifier) const;

      void addQualifier(const std::string &qualifier, const int pos = 0);
      void addPostQualifier(const std::string &qualifier, const int pos = 0);

      void removeQualifier(const std::string &qualifier);

      void changeType(const std::string &newType);

      std::string getVariableName() const;

      void setVarInfo(varInfo &var);
      //================================

      void freeLeaf(const int leafPos);

      void free();

      void print(const std::string &tab = "");
      void printOn(std::ostream &out, const std::string &tab = "");

      std::string getString(const std::string &tab = "");
      operator std::string ();

      friend std::ostream& operator << (std::ostream &out, expNode &n);
    };

    struct statementExp {
      int sType;
      expNode exp;
    };
    //==============================================

    //---[ Statement ]------------------------------
    class statement {
    public:
      scopeTypeMap_t scopeTypeMap;
      scopeVarMap_t scopeVarMap;

      varOriginMap_t &varOriginMap;
      varUsedMap_t   &varUsedMap;

      strNode *nodeStart, *nodeEnd;

      int depth;
      statement *up;

      int type;

      expNode expRoot;

      int statementCount;
      statementNode *statementStart, *statementEnd;

      statement(parserBase &pb);

      statement(const int depth_, statement *up_);

      statement(const int depth_,
                const int type_,
                statement *up_);

      ~statement();

      statement* makeSubStatement();

      std::string getTab() const;

      int statementType(strNode *&nodeRoot);

      int checkMacroStatementType(strNode *&nodeRoot);
      int checkOccaForStatementType(strNode *&nodeRoot);
      int checkStructStatementType(strNode *&nodeRoot);
      int checkUpdateStatementType(strNode *&nodeRoot);
      int checkDescriptorStatementType(strNode *&nodeRoot);
      int checkGotoStatementType(strNode *&nodeRoot);
      int checkFlowStatementType(strNode *&nodeRoot);
      int checkSpecialStatementType(strNode *&nodeRoot);
      int checkBlockStatementType(strNode *&nodeRoot);

      void addTypeDef(const std::string &typeDefName);

      bool nodeHasQualifier(strNode *n) const;
      bool nodeHasSpecifier(strNode *n) const;
      bool nodeHasDescriptor(strNode *n) const;

      varInfo loadVarInfo(strNode *&nodePos);

      typeDef* hasTypeInScope(const std::string &typeName) const;

      varInfo* hasVariableInScope(const std::string &varName) const;

      bool hasDescriptorVariable(const std::string descriptor) const;
      bool hasDescriptorVariableInScope(const std::string descriptor) const;

      void loadAllFromNode(strNode *nodeRoot);
      strNode* loadFromNode(strNode *nodeRoot);

      void setExpNodeFromStrNode(expNode &exp,
                                 strNode *nodePos);

      expNode* createExpNodeFrom(strNode *nodePos);
      expNode* createExpNodeFrom(const std::string &source);

      void loadBlocksFromLastNode(strNode *end,
                                  const int startBlockPos = 0);

      strNode* loadSimpleFromNode(const int st,
                                  strNode *nodeRoot,
                                  strNode *nodeRootEnd);

      strNode* loadForFromNode(const int st,
                               strNode *nodeRoot,
                               strNode *nodeRootEnd);

      strNode* loadWhileFromNode(const int st,
                                 strNode *nodeRoot,
                                 strNode *nodeRootEnd);

      strNode* loadIfFromNode(const int st,
                              strNode *nodeRoot,
                              strNode *nodeRootEnd);

      // [-] Missing
      strNode* loadSwitchFromNode(const int st,
                                  strNode *nodeRoot,
                                  strNode *nodeRootEnd);

      strNode* loadGotoFromNode(const int st,
                                strNode *nodeRoot,
                                strNode *nodeRootEnd);

      strNode* loadFunctionDefinitionFromNode(const int st,
                                              strNode *nodeRoot,
                                              strNode *nodeRootEnd);

      strNode* loadFunctionPrototypeFromNode(const int st,
                                             strNode *nodeRoot,
                                             strNode *nodeRootEnd);

      strNode* loadBlockFromNode(const int st,
                                 strNode *nodeRoot,
                                 strNode *nodeRootEnd);

      // [-] Missing
      strNode* loadStructFromNode(const int st,
                                  strNode *nodeRoot,
                                  strNode *nodeRootEnd);

      // [-] Missing
      strNode* loadBlankFromNode(const int st,
                                 strNode *nodeRoot,
                                 strNode *nodeRootEnd);

      // [-] Missing
      strNode* loadMacroFromNode(const int st,
                                 strNode *nodeRoot,
                                 strNode *nodeRootEnd);

      statementNode* getStatementNode();

      varInfo* addVariable(const varInfo &info,
                           statement *origin = NULL);

      void addStatement(statement *newStatement);

      statement* clone();

      void printVariablesInStatement();

      void printVariablesInScope();

      void printTypesInScope();
      void printTypesInStatement();
      void printTypeDefsInStatement();

      //---[ Statement Info ]-----------
      void swapExpWith(statement &s);

      bool hasQualifier(const std::string &qualifier) const;

      void addQualifier(const std::string &qualifier, const int pos = 0);
      void removeQualifier(const std::string &qualifier);

      expNode* getDeclarationTypeNode();
      expNode* getDeclarationVarNode(const int pos);
      std::string getDeclarationVarName(const int pos) const;
      int getDeclarationVarCount() const;

      std::string getFunctionName() const;
      void setFunctionName(const std::string &newName);
      expNode* getFunctionArgsNode();
      expNode* getFunctionArgNode(const int pos);
      std::string getFunctionArgType(const int pos);
      std::string getFunctionArgName(const int pos);
      varInfo* getFunctionArgVar(const int pos);
      int getFunctionArgCount() const;

      int getForStatementCount() const;
      //================================

      // autoMode: Handles newlines and tabs
      std::string prettyString(strNode *nodeRoot,
                               const std::string &tab_ = "",
                               const bool autoMode = true) const;

      operator std::string();
    };

    std::ostream& operator << (std::ostream &out, statement &s);
  };
};

#endif
<commit_msg>[Parser] Going to start typeInfo<commit_after>#ifndef OCCA_PARSER_STATEMENT_HEADER
#define OCCA_PARSER_STATEMENT_HEADER

#include "occaParserDefines.hpp"
#include "occaParserMacro.hpp"
#include "occaParserTools.hpp"
#include "occaParserNodes.hpp"
#include "occaParserTypes.hpp"

namespace occa {
  namespace parserNamespace {
    class statement;

    //---[ Exp Node ]-------------------------------
    namespace expType {
      static const int root            = (1 << 0);

      static const int LCR             = (7 << 1);
      static const int L               = (1 << 1);
      static const int C               = (1 << 2);
      static const int R               = (1 << 3);

      static const int qualifier       = (1 <<  4);
      static const int type            = (1 <<  5);
      static const int presetValue     = (1 <<  6);
      static const int operator_       = (1 <<  7);
      static const int unknown         = (1 <<  8);
      static const int variable        = (1 <<  9);
      static const int function        = (1 << 11);
      static const int functionPointer = (1 << 12);
      static const int typedef_        = (1 << 13);
      static const int prototype       = (1 << 14);
      static const int declaration     = (1 << 15);
      static const int struct_         = (1 << 16);
      static const int namespace_      = (1 << 17);
      static const int cast_           = (1 << 18);
      static const int macro_          = (1 << 19);
      static const int goto_           = (1 << 20);
      static const int gotoLabel_      = (1 << 21);
      static const int case_           = (1 << 22);
      static const int return_         = (1 << 23);
      static const int occaFor         = (1 << 24);
      static const int checkSInfo      = (1 << 25);

      static const int printValue      = (1 << 26);
      static const int printLeaves     = (1 << 27);
      static const int maxBit          = 27;
    };

    class _varInfo;
    class _typeInfo;

    class expNode {
    public:
      statement *sInfo;

      std::string value;
      int info;

      expNode *up;

      int leafCount;

      union {
        expNode **leaves;
        _varInfo **varLeaves;
        _typeInfo **typeLeaves;
      };

      expNode();
      expNode(statement &s);
      expNode(expNode &up_);

      //---[ Find Statement ]-----------
      void labelStatement(strNode *&nodeRoot);

      int loadMacroStatement(strNode *&nodeRoot);
      int loadOccaForStatement(strNode *&nodeRoot);
      int loadTypedefStatement(strNode *&nodeRoot);
      int loadStructStatement(strNode *&nodeRoot);
      int loadUpdateStatement(strNode *&nodeRoot);
      int loadDescriptorStatement(strNode *&nodeRoot);
      int loadGotoStatement(strNode *&nodeRoot);
      int loadFlowStatement(strNode *&nodeRoot);
      int loadSpecialStatement(strNode *&nodeRoot);
      int loadBlockStatement(strNode *&nodeRoot);
      //================================

      void loadFromNode(strNode *&nodePos);

      void splitAndOrganizeNode(strNode *nodeRoot);
      void organize();

      void addNewVariables(strNode *nodePos);

      void splitDeclareStatement();
      void splitForStatement();
      void splitFunctionStatement();
      void splitStructStatement();
      void splitStructStatements();
      void splitTypedefStatement();

      void initLoadFromNode(strNode *nodeRoot,
                            const int initPos = 0);

      int initDownsFromNode(strNode *nodeRoot,
                            int leafPos = 0);

      void initOrganization();

      void organizeLeaves();
      void organizeLeaves(const int level);

      int mergeRange(const int newLeafType,
                     const int leafPosStart,
                     const int leafPosEnd);

      // [a][::][b]
      void mergeNamespaces();

      // [(class)]
      void labelCasts();

      // const int [*] x
      void labelReferenceQualifiers();

      // [const] int x
      void mergeQualifiers();

      // [[const] [int] [*]] x
      void mergeTypes();

      // [[[const] [int] [*]] [x]]
      void mergeVariables();

      // 1 [type]                           2 [(]       3 [(]
      // [[qualifiers] [type] [qualifiers]] [(*[name])] [([args])]
      void mergeFunctionPointers();

      // class(...), class{1,2,3}
      void mergeClassConstructs();

      // static_cast<>()
      void mergeCasts();

      // [max(a,b)]
      void mergeFunctionCalls();

      void mergeArguments();

      // a[3]
      void mergeArrays();

      // (class) x
      void mergeClassCasts();

      // sizeof x
      void mergeSizeOf();

      // new, new [], delete, delete []
      void mergeNewsAndDeletes();

      // throw x
      void mergeThrows();

      // [++]i
      int mergeLeftUnary(const int leafPos);

      // i[++]
      int mergeRightUnary(const int leafPos);

      // a [+] b
      int mergeBinary(const int leafPos);

      // a [?] b : c
      int mergeTernary(const int leafPos);

      //---[ Custom Functions ]---------
      void labelNewVariables();
      //================================

      //---[ Custom Type Info ]---------
      bool qualifierEndsWithStar() const;

      bool typeEndsWithStar() const;

      bool hasAnArrayQualifier(const int pos = 0) const;
      //================================

      static void swap(expNode &a, expNode &b);

      expNode* clone(statement &s);
      expNode* clone(expNode *original);

      void cloneTo(expNode &newRoot);

      expNode* lastLeaf();

      //---[ Exp Info ]-----------------
      int depth();
      int whichLeafAmI();
      int nestedLeafCount();

      expNode* makeFlatHandle();
      void makeFlatHandle(int &offset,
                          expNode **flatLeaves);

      void addNode(const int info_, const int pos = 0);
      void removeNode(const int pos = 0);

      void convertTo(const int info_ = 0);

      bool hasQualifier(const std::string &qualifier) const;

      void addQualifier(const std::string &qualifier, const int pos = 0);
      void addPostQualifier(const std::string &qualifier, const int pos = 0);

      void removeQualifier(const std::string &qualifier);

      void changeType(const std::string &newType);

      std::string getVariableName() const;

      void setVarInfo(varInfo &var);
      //================================

      void freeLeaf(const int leafPos);

      void free();

      void print(const std::string &tab = "");
      void printOn(std::ostream &out, const std::string &tab = "");

      std::string getString(const std::string &tab = "");
      operator std::string ();

      friend std::ostream& operator << (std::ostream &out, expNode &n);
    };

    struct statementExp {
      int sType;
      expNode exp;
    };
    //==============================================

    //---[ Statement ]------------------------------
    class statement {
    public:
      scopeTypeMap_t scopeTypeMap;
      scopeVarMap_t scopeVarMap;

      varOriginMap_t &varOriginMap;
      varUsedMap_t   &varUsedMap;

      strNode *nodeStart, *nodeEnd;

      int depth;
      statement *up;

      int type;

      expNode expRoot;

      int statementCount;
      statementNode *statementStart, *statementEnd;

      statement(parserBase &pb);

      statement(const int depth_, statement *up_);

      statement(const int depth_,
                const int type_,
                statement *up_);

      ~statement();

      statement* makeSubStatement();

      std::string getTab() const;

      int statementType(strNode *&nodeRoot);

      int checkMacroStatementType(strNode *&nodeRoot);
      int checkOccaForStatementType(strNode *&nodeRoot);
      int checkStructStatementType(strNode *&nodeRoot);
      int checkUpdateStatementType(strNode *&nodeRoot);
      int checkDescriptorStatementType(strNode *&nodeRoot);
      int checkGotoStatementType(strNode *&nodeRoot);
      int checkFlowStatementType(strNode *&nodeRoot);
      int checkSpecialStatementType(strNode *&nodeRoot);
      int checkBlockStatementType(strNode *&nodeRoot);

      void addTypeDef(const std::string &typeDefName);

      bool nodeHasQualifier(strNode *n) const;
      bool nodeHasSpecifier(strNode *n) const;
      bool nodeHasDescriptor(strNode *n) const;

      varInfo loadVarInfo(strNode *&nodePos);

      typeDef* hasTypeInScope(const std::string &typeName) const;

      varInfo* hasVariableInScope(const std::string &varName) const;

      bool hasDescriptorVariable(const std::string descriptor) const;
      bool hasDescriptorVariableInScope(const std::string descriptor) const;

      void loadAllFromNode(strNode *nodeRoot);
      strNode* loadFromNode(strNode *nodeRoot);

      void setExpNodeFromStrNode(expNode &exp,
                                 strNode *nodePos);

      expNode* createExpNodeFrom(strNode *nodePos);
      expNode* createExpNodeFrom(const std::string &source);

      void loadBlocksFromLastNode(strNode *end,
                                  const int startBlockPos = 0);

      strNode* loadSimpleFromNode(const int st,
                                  strNode *nodeRoot,
                                  strNode *nodeRootEnd);

      strNode* loadForFromNode(const int st,
                               strNode *nodeRoot,
                               strNode *nodeRootEnd);

      strNode* loadWhileFromNode(const int st,
                                 strNode *nodeRoot,
                                 strNode *nodeRootEnd);

      strNode* loadIfFromNode(const int st,
                              strNode *nodeRoot,
                              strNode *nodeRootEnd);

      // [-] Missing
      strNode* loadSwitchFromNode(const int st,
                                  strNode *nodeRoot,
                                  strNode *nodeRootEnd);

      strNode* loadGotoFromNode(const int st,
                                strNode *nodeRoot,
                                strNode *nodeRootEnd);

      strNode* loadFunctionDefinitionFromNode(const int st,
                                              strNode *nodeRoot,
                                              strNode *nodeRootEnd);

      strNode* loadFunctionPrototypeFromNode(const int st,
                                             strNode *nodeRoot,
                                             strNode *nodeRootEnd);

      strNode* loadBlockFromNode(const int st,
                                 strNode *nodeRoot,
                                 strNode *nodeRootEnd);

      // [-] Missing
      strNode* loadStructFromNode(const int st,
                                  strNode *nodeRoot,
                                  strNode *nodeRootEnd);

      // [-] Missing
      strNode* loadBlankFromNode(const int st,
                                 strNode *nodeRoot,
                                 strNode *nodeRootEnd);

      // [-] Missing
      strNode* loadMacroFromNode(const int st,
                                 strNode *nodeRoot,
                                 strNode *nodeRootEnd);

      statementNode* getStatementNode();

      varInfo* addVariable(const varInfo &info,
                           statement *origin = NULL);

      void addStatement(statement *newStatement);

      statement* clone();

      void printVariablesInStatement();

      void printVariablesInScope();

      void printTypesInScope();
      void printTypesInStatement();
      void printTypeDefsInStatement();

      //---[ Statement Info ]-----------
      void swapExpWith(statement &s);

      bool hasQualifier(const std::string &qualifier) const;

      void addQualifier(const std::string &qualifier, const int pos = 0);
      void removeQualifier(const std::string &qualifier);

      expNode* getDeclarationTypeNode();
      expNode* getDeclarationVarNode(const int pos);
      std::string getDeclarationVarName(const int pos) const;
      int getDeclarationVarCount() const;

      std::string getFunctionName() const;
      void setFunctionName(const std::string &newName);
      expNode* getFunctionArgsNode();
      expNode* getFunctionArgNode(const int pos);
      std::string getFunctionArgType(const int pos);
      std::string getFunctionArgName(const int pos);
      varInfo* getFunctionArgVar(const int pos);
      int getFunctionArgCount() const;

      int getForStatementCount() const;
      //================================

      // autoMode: Handles newlines and tabs
      std::string prettyString(strNode *nodeRoot,
                               const std::string &tab_ = "",
                               const bool autoMode = true) const;

      operator std::string();
    };

    std::ostream& operator << (std::ostream &out, statement &s);
  };
};

#endif
<|endoftext|>


<commit_before><commit_msg>fix stdtbb<commit_after><|endoftext|>