/* valaccodegenerator.vala
 *
 * Copyright (C) 2006-2008  Jürg Billeter, Raffaele Sandrini
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 *	Raffaele Sandrini <raffaele@sandrini.ch>
 */

#ifndef __GOBJECT_VALACCODEGENERATOR_H__
#define __GOBJECT_VALACCODEGENERATOR_H__

#include <glib.h>
#include <glib-object.h>
#include <vala/valacodegenerator.h>
#include <vala/valacodecontext.h>
#include <vala/valasymbol.h>
#include <vala/valatypesymbol.h>
#include <vala/valaclass.h>
#include <vala/valamethod.h>
#include <vala/valadatatype.h>
#include <vala/valatrystatement.h>
#include <vala/valapropertyaccessor.h>
#include <ccode/valaccodefragment.h>
#include <ccode/valaccodestruct.h>
#include <ccode/valaccodeenum.h>
#include <ccode/valaccodefunction.h>
#include <ccode/valaccodeblock.h>
#include <gee/arraylist.h>
#include <gee/set.h>
#include <vala/valaerrortype.h>
#include <vala/valastruct.h>
#include <vala/valainterface.h>
#include <stdlib.h>
#include <string.h>
#include <vala/valaenum.h>
#include <vala/valaenumvalue.h>
#include <vala/valaerrordomain.h>
#include <vala/valaerrorcode.h>
#include <vala/valadelegate.h>
#include <vala/valamember.h>
#include <vala/valaconstant.h>
#include <vala/valafield.h>
#include <ccode/valaccodeexpression.h>
#include <vala/valacreationmethod.h>
#include <vala/valaformalparameter.h>
#include <vala/valaproperty.h>
#include <vala/valaconstructor.h>
#include <vala/valadestructor.h>
#include <vala/valablock.h>
#include <vala/valaemptystatement.h>
#include <vala/valadeclarationstatement.h>
#include <vala/valalocalvariable.h>
#include <vala/valainitializerlist.h>
#include <vala/valacodenode.h>
#include <vala/valasourcereference.h>
#include <vala/valaexpression.h>
#include <vala/valaexpressionstatement.h>
#include <vala/valaifstatement.h>
#include <vala/valaswitchstatement.h>
#include <vala/valaswitchsection.h>
#include <vala/valawhilestatement.h>
#include <vala/valadostatement.h>
#include <vala/valaforstatement.h>
#include <vala/valaforeachstatement.h>
#include <vala/valabreakstatement.h>
#include <vala/valacontinuestatement.h>
#include <vala/valareturnstatement.h>
#include <vala/valathrowstatement.h>
#include <vala/valacatchclause.h>
#include <vala/valalockstatement.h>
#include <vala/valadeletestatement.h>
#include <vala/valaarraycreationexpression.h>
#include <vala/valabooleanliteral.h>
#include <vala/valacharacterliteral.h>
#include <vala/valaintegerliteral.h>
#include <vala/valarealliteral.h>
#include <vala/valastringliteral.h>
#include <vala/valanullliteral.h>
#include <vala/valaparenthesizedexpression.h>
#include <vala/valamemberaccess.h>
#include <vala/valainvocationexpression.h>
#include <vala/valaelementaccess.h>
#include <vala/valabaseaccess.h>
#include <vala/valapostfixexpression.h>
#include <vala/valaobjectcreationexpression.h>
#include <vala/valasizeofexpression.h>
#include <vala/valatypeofexpression.h>
#include <vala/valaunaryexpression.h>
#include <vala/valacastexpression.h>
#include <vala/valapointerindirection.h>
#include <vala/valaaddressofexpression.h>
#include <vala/valareferencetransferexpression.h>
#include <vala/valabinaryexpression.h>
#include <vala/valatypecheck.h>
#include <vala/valaconditionalexpression.h>
#include <vala/valalambdaexpression.h>
#include <vala/valaassignment.h>
#include <ccode/valaccodefunctioncall.h>
#include <ccode/valaccodestatement.h>
#include <float.h>
#include <math.h>
#include <vala/valaarraytype.h>
#include <vala/valacodebinding.h>
#include <vala/valanamespace.h>
#include <vala/valadynamicmethod.h>
#include <vala/valadynamicproperty.h>
#include <vala/valasignal.h>
#include <vala/valadynamicsignal.h>
#include <vala/valatypeparameter.h>
#include <vala/valaswitchlabel.h>
#include <gee/list.h>
#include <vala/valasourcefile.h>
#include <gobject/valaccodebinding.h>

G_BEGIN_DECLS


#define VALA_TYPE_CCODE_GENERATOR (vala_ccode_generator_get_type ())
#define VALA_CCODE_GENERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALA_TYPE_CCODE_GENERATOR, ValaCCodeGenerator))
#define VALA_CCODE_GENERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALA_TYPE_CCODE_GENERATOR, ValaCCodeGeneratorClass))
#define VALA_IS_CCODE_GENERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALA_TYPE_CCODE_GENERATOR))
#define VALA_IS_CCODE_GENERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALA_TYPE_CCODE_GENERATOR))
#define VALA_CCODE_GENERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALA_TYPE_CCODE_GENERATOR, ValaCCodeGeneratorClass))

typedef struct _ValaCCodeGeneratorPrivate ValaCCodeGeneratorPrivate;

/**
 * Code visitor generating C Code.
 */
struct _ValaCCodeGenerator {
	ValaCodeGenerator parent_instance;
	ValaCCodeGeneratorPrivate * priv;
	ValaCodeContext* context;
	ValaSymbol* root_symbol;
	ValaSymbol* current_symbol;
	ValaTypeSymbol* current_type_symbol;
	ValaClass* current_class;
	ValaMethod* current_method;
	ValaDataType* current_return_type;
	ValaTryStatement* current_try;
	ValaPropertyAccessor* current_property_accessor;
	ValaCCodeFragment* header_begin;
	ValaCCodeFragment* header_type_declaration;
	ValaCCodeFragment* header_type_definition;
	ValaCCodeFragment* header_type_member_declaration;
	ValaCCodeFragment* header_constant_declaration;
	ValaCCodeFragment* source_begin;
	ValaCCodeFragment* source_include_directives;
	ValaCCodeFragment* source_type_declaration;
	ValaCCodeFragment* source_type_definition;
	ValaCCodeFragment* source_type_member_declaration;
	ValaCCodeFragment* source_constant_declaration;
	ValaCCodeFragment* source_signal_marshaller_declaration;
	ValaCCodeFragment* source_type_member_definition;
	ValaCCodeFragment* class_init_fragment;
	ValaCCodeFragment* instance_init_fragment;
	ValaCCodeFragment* instance_dispose_fragment;
	ValaCCodeFragment* source_signal_marshaller_definition;
	ValaCCodeFragment* module_init_fragment;
	ValaCCodeStruct* instance_struct;
	ValaCCodeStruct* type_struct;
	ValaCCodeStruct* instance_priv_struct;
	ValaCCodeEnum* prop_enum;
	ValaCCodeEnum* cenum;
	ValaCCodeFunction* function;
	ValaCCodeBlock* block;
	GeeArrayList* temp_vars;
	GeeArrayList* temp_ref_vars;
	GeeSet* user_marshal_set;
	GeeSet* predefined_marshal_set;
	GeeSet* c_keywords;
	gint next_temp_var_id;
	gboolean in_creation_method;
	gboolean in_static_or_class_ctor;
	gboolean current_method_inner_error;
	ValaDataType* bool_type;
	ValaDataType* char_type;
	ValaDataType* uchar_type;
	ValaDataType* unichar_type;
	ValaDataType* short_type;
	ValaDataType* ushort_type;
	ValaDataType* int_type;
	ValaDataType* uint_type;
	ValaDataType* long_type;
	ValaDataType* ulong_type;
	ValaDataType* int8_type;
	ValaDataType* uint8_type;
	ValaDataType* int32_type;
	ValaDataType* uint32_type;
	ValaDataType* int64_type;
	ValaDataType* uint64_type;
	ValaDataType* string_type;
	ValaDataType* float_type;
	ValaDataType* double_type;
	ValaTypeSymbol* gtype_type;
	ValaTypeSymbol* gobject_type;
	ValaErrorType* gerror_type;
	ValaClass* glist_type;
	ValaClass* gslist_type;
	ValaTypeSymbol* gstringbuilder_type;
	ValaTypeSymbol* garray_type;
	ValaDataType* gquark_type;
	ValaStruct* mutex_type;
	ValaTypeSymbol* type_module_type;
	ValaInterface* iterable_type;
	ValaInterface* iterator_type;
	ValaInterface* collection_type;
	ValaInterface* list_type;
	ValaInterface* map_type;
	ValaTypeSymbol* dbus_object_type;
	ValaMethod* substring_method;
	gboolean in_plugin;
	char* module_init_param_name;
	gboolean string_h_needed;
	gboolean requires_array_move;
	gboolean dbus_glib_h_needed;
};

struct _ValaCCodeGeneratorClass {
	ValaCodeGeneratorClass parent_class;
};


ValaCCodeGenerator* vala_ccode_generator_new (void);
gboolean vala_ccode_generator_is_pure_ccode_expression (ValaCCodeGenerator* self, ValaCCodeExpression* cexpr);
char* vala_ccode_generator_get_variable_cname (ValaCCodeGenerator* self, const char* name);
ValaLocalVariable* vala_ccode_generator_get_temp_variable (ValaCCodeGenerator* self, ValaDataType* type, gboolean value_owned, ValaCodeNode* node_reference);
ValaCCodeExpression* vala_ccode_generator_get_dup_func_expression (ValaCCodeGenerator* self, ValaDataType* type, ValaSourceReference* source_reference);
ValaCCodeExpression* vala_ccode_generator_get_destroy_func_expression (ValaCCodeGenerator* self, ValaDataType* type);
ValaCCodeExpression* vala_ccode_generator_get_unref_expression (ValaCCodeGenerator* self, ValaCCodeExpression* cvar, ValaDataType* type, ValaExpression* expr);
char* vala_ccode_generator_get_array_length_cname (ValaCCodeGenerator* self, const char* array_cname, gint dim);
ValaCCodeExpression* vala_ccode_generator_get_array_length_cexpression (ValaCCodeGenerator* self, ValaExpression* array_expr, gint dim);
char* vala_ccode_generator_get_delegate_target_cname (ValaCCodeGenerator* self, const char* delegate_cname);
ValaCCodeExpression* vala_ccode_generator_get_delegate_target_cexpression (ValaCCodeGenerator* self, ValaExpression* delegate_expr);
char* vala_ccode_generator_get_delegate_target_destroy_notify_cname (ValaCCodeGenerator* self, const char* delegate_cname);
gboolean vala_ccode_generator_requires_copy (ValaCCodeGenerator* self, ValaDataType* type);
gboolean vala_ccode_generator_requires_destroy (ValaCCodeGenerator* self, ValaDataType* type);
ValaCCodeExpression* vala_ccode_generator_convert_from_generic_pointer (ValaCCodeGenerator* self, ValaCCodeExpression* cexpr, ValaDataType* actual_type);
ValaCCodeExpression* vala_ccode_generator_convert_to_generic_pointer (ValaCCodeGenerator* self, ValaCCodeExpression* cexpr, ValaDataType* actual_type);
ValaCCodeExpression* vala_ccode_generator_transform_expression (ValaCCodeGenerator* self, ValaCCodeExpression* source_cexpr, ValaDataType* expression_type, ValaDataType* target_type, ValaExpression* expr);
ValaCCodeFunctionCall* vala_ccode_generator_get_property_set_call (ValaCCodeGenerator* self, ValaProperty* prop, ValaMemberAccess* ma, ValaCCodeExpression* cexpr);
gboolean vala_ccode_generator_is_address_of_possible (ValaCCodeGenerator* self, ValaExpression* e);
ValaCCodeExpression* vala_ccode_generator_get_address_of_expression (ValaCCodeGenerator* self, ValaExpression* e, ValaCCodeExpression* ce);
gboolean vala_ccode_generator_add_wrapper (ValaCCodeGenerator* self, const char* wrapper_name);
ValaDataType* vala_ccode_generator_get_data_type_for_symbol (ValaTypeSymbol* sym);
ValaCCodeExpression* vala_ccode_generator_default_value_for_type (ValaCCodeGenerator* self, ValaDataType* type, gboolean initializer_expression);
ValaCCodeStatement* vala_ccode_generator_create_type_check_statement (ValaCCodeGenerator* self, ValaCodeNode* method_node, ValaDataType* ret_type, ValaTypeSymbol* t, gboolean non_null, const char* var_name);
gint vala_ccode_generator_get_param_pos (ValaCCodeGenerator* self, double param_pos, gboolean ellipsis);
gboolean vala_ccode_generator_dbus_use_ptr_array (ValaCCodeGenerator* self, ValaArrayType* array_type);
ValaCCodeBinding* vala_ccode_generator_code_binding (ValaCCodeGenerator* self, ValaCodeNode* node);
ValaCCodeMethodBinding* vala_ccode_generator_method_binding (ValaCCodeGenerator* self, ValaMethod* node);
ValaCCodeDynamicMethodBinding* vala_ccode_generator_dynamic_method_binding (ValaCCodeGenerator* self, ValaDynamicMethod* node);
ValaCCodeDynamicPropertyBinding* vala_ccode_generator_dynamic_property_binding (ValaCCodeGenerator* self, ValaDynamicProperty* node);
ValaCCodeDynamicSignalBinding* vala_ccode_generator_dynamic_signal_binding (ValaCCodeGenerator* self, ValaDynamicSignal* node);
ValaCCodeArrayCreationExpressionBinding* vala_ccode_generator_array_creation_expression_binding (ValaCCodeGenerator* self, ValaArrayCreationExpression* node);
ValaCCodeElementAccessBinding* vala_ccode_generator_element_access_binding (ValaCCodeGenerator* self, ValaElementAccess* node);
ValaCCodeAssignmentBinding* vala_ccode_generator_assignment_binding (ValaCCodeGenerator* self, ValaAssignment* node);
char* vala_ccode_generator_get_marshaller_function (ValaCCodeGenerator* self, GeeList* params, ValaDataType* return_type, const char* prefix, gboolean dbus);
void vala_ccode_generator_generate_marshaller (ValaCCodeGenerator* self, GeeList* params, ValaDataType* return_type, gboolean dbus);
GType vala_ccode_generator_get_type (void);


G_END_DECLS

#endif
