Ejemplo n.º 1
0
void CppCodeGenerator::GenIncludes( shared_ptr<ObjectBase> project, set<wxString>* includes)
{
	// Call GenIncludes on all children as well
	for ( unsigned int i = 0; i < project->GetChildCount(); i++ )
	{
		GenIncludes( project->GetChild(i), includes );
	}

	// Fill the set
	shared_ptr<CodeInfo> code_info = project->GetObjectInfo()->GetCodeInfo( wxT("C++") );
	if (code_info)
	{
		CppTemplateParser parser(project,code_info->GetTemplate( wxT("include") ) );
		wxString include = parser.ParseTemplate();
		if ( !include.empty() )
		{
			includes->insert( include );
		}
	}
}
Ejemplo n.º 2
0
bool CppCodeGenerator::GenerateCode(PObjectBase project)
{
  m_header->Clear();
  m_source->Clear();
  string date(__DATE__);
  string time(__TIME__);
  string code_header (
   "///////////////////////////////////////////////////////////////////////////\n"
   "// C++ code generated with wxFormBuilder (version " __DATE__ ")\n" 
   "// http://wxformbuilder.software-libre.org/\n"
   "//\n"
   "// PLEASE DO \"NOT\" EDIT THIS FILE!\n"
   "///////////////////////////////////////////////////////////////////////////\n");
   
  m_header->WriteLn(code_header);
  m_source->WriteLn(code_header);
  
  string file = project->GetProperty("file")->GetValue();
  
  m_header->WriteLn("#ifndef __" + file + "__");
  m_header->WriteLn("#define __" + file + "__");

  m_source->WriteLn("#include \""+file+".h\"");
  
  
  GenIncludes(project);
  GenDefines(project);
  
  for (unsigned int i=0; i<project->GetChildCount(); i++)
  {
    GenClassDeclaration(project->GetChild(i));
    GenConstructor(project->GetChild(i));
  }
  
  m_header->WriteLn("#endif //__" + file + "__");
  m_header->WriteLn("");
  
  return true;
}
Ejemplo n.º 3
0
bool CppCodeGenerator::GenerateCode( shared_ptr<ObjectBase> project )
{
	if (!project)
	{
		wxLogError(wxT("There is no project to generate code"));
		return false;
	}

	bool useEnum = false;

	shared_ptr< Property > useEnumProperty = project->GetProperty( wxT("use_enum") );
	if (useEnumProperty && useEnumProperty->GetValueAsInteger())
		useEnum = true;

	m_i18n = false;
	shared_ptr< Property > i18nProperty = project->GetProperty( wxT("internationalize") );
	if (i18nProperty && i18nProperty->GetValueAsInteger())
		m_i18n = true;

	m_header->Clear();
	m_source->Clear();
	wxString code (
		wxT("///////////////////////////////////////////////////////////////////////////\n")
		wxT("// C++ code generated with wxFormBuilder (version ") wxT(__DATE__) wxT(")\n")
		wxT("// http://wxformbuilder.sourceforge.net/\n")
		wxT("//\n")
		wxT("// PLEASE DO \"NOT\" EDIT THIS FILE!\n")
		wxT("///////////////////////////////////////////////////////////////////////////\n") );

	m_header->WriteLn( code );
	m_source->WriteLn( code );

	shared_ptr<Property> propFile = project->GetProperty( wxT("file") );
	if (!propFile)
	{
		wxLogError( wxT("Missing \"file\" property on Project Object") );
		return false;
	}

	wxString file = propFile->GetValue();
	if ( file.empty() )
	{
		file = wxT("noname");
	}

	m_header->WriteLn( wxT("#ifndef __") + file + wxT("__") );
	m_header->WriteLn( wxT("#define __") + file + wxT("__") );
	m_header->WriteLn( wxT("") );

	code = GetCode( project, wxT("header_preamble") );
	m_header->WriteLn( code );

	// Generate the libraries
	set< wxString > libraries;
	GenLibraries( project, &libraries );

	// Write the library lines
	WriteLibrariesBlock( libraries );

	// generamos en el h los includes de las dependencias de los componentes.
	set<wxString> includes;
	GenIncludes(project, &includes);

	// Write the include lines
	set<wxString>::iterator include_it;
	for ( include_it = includes.begin(); include_it != includes.end(); ++include_it )
	{
		m_header->WriteLn( *include_it );
	}
	if ( !includes.empty() )
	{
		m_header->WriteLn( wxT("") );
	}

	code = GetCode( project, wxT("header_epilogue") );
	m_header->WriteLn( code );
	m_header->WriteLn( wxT("") );

	// en el cpp generamos el include del .h generado y los xpm
	code = GetCode( project, wxT("cpp_preamble") );
	m_source->WriteLn( code );
	m_source->WriteLn( wxT("") );

	m_source->WriteLn( wxT("#include \"") + file + wxT(".h\""));
	m_source->WriteLn( wxT("") );
	GenXpmIncludes( project );

	code = GetCode( project, wxT("cpp_epilogue") );
	m_source->WriteLn( code );

	// generamos los defines de las macros
	if ( !useEnum )
	{
		GenDefines( project );
	}

	for ( unsigned int i = 0; i < project->GetChildCount(); i++ )
	{
		GenClassDeclaration( project->GetChild( i ), useEnum );
		GenConstructor( project->GetChild( i ) );
	}

	m_header->WriteLn( wxT("#endif //__") + file + wxT("__") );

	return true;
}
Ejemplo n.º 4
0
bool PHPCodeGenerator::GenerateCode( PObjectBase project )
{
	if (!project)
	{
		wxLogError(wxT("There is no project to generate code"));
		return false;
	}

	m_i18n = false;
	PProperty i18nProperty = project->GetProperty( wxT("internationalize") );
	if (i18nProperty && i18nProperty->GetValueAsInteger())
		m_i18n = true;

	m_disconnectEvents = ( project->GetPropertyAsInteger( wxT("disconnect_php_events") ) != 0 );

	m_source->Clear();

	// Insert php preamble

	wxString code = GetCode( project, wxT("php_preamble") );
	if ( !code.empty() )
	{
		m_source->WriteLn( code );
		m_source->WriteLn( wxEmptyString );
	}

	code = (
		wxT("/*\n")
		wxT(" * PHP code generated with wxFormBuilder (version ") wxT(__DATE__) wxT(")\n")
		wxT(" * http://www.wxformbuilder.org/\n")
		wxT(" *\n")
		wxT(" * PLEASE DO *NOT* EDIT THIS FILE!\n")
		wxT(" */\n") );

	m_source->WriteLn( code );


	PProperty propFile = project->GetProperty( wxT("file") );
	if (!propFile)
	{
		wxLogError( wxT("Missing \"file\" property on Project Object") );
		return false;
	}

	wxString file = propFile->GetValue();
	if ( file.empty() )
	{
		file = wxT("noname");
	}

	// Generate the subclass sets
	std::set< wxString > subclasses;
	std::vector< wxString > headerIncludes;

	GenSubclassSets( project, &subclasses, &headerIncludes );

	// Generating in the .h header file those include from components dependencies.
	std::set< wxString > templates;
	GenIncludes(project, &headerIncludes, &templates );

	// Write the include lines
	std::vector<wxString>::iterator include_it;
	for ( include_it = headerIncludes.begin(); include_it != headerIncludes.end(); ++include_it )
	{
		m_source->WriteLn( *include_it );
	}
	if ( !headerIncludes.empty() )
	{
		m_source->WriteLn( wxT("") );
	}

	// Write internationalization support
	if( m_i18n )
	{
		//PHP gettext already implements this function
		//m_source->WriteLn( wxT("function _(){ /*TODO: Implement this function on wxPHP*/ }") );
		//m_source->WriteLn( wxT("") );
	}

	// Generating "defines" for macros
	GenDefines( project );

	wxString eventHandlerPostfix;
	PProperty eventKindProp = project->GetProperty( wxT("skip_php_events") );
	if( eventKindProp->GetValueAsInteger() )
	{
		 eventHandlerPostfix = wxT("$event->Skip();");
	}
	else
		eventHandlerPostfix = wxT("");

	PProperty disconnectMode = project->GetProperty( wxT("disconnect_mode") );
	m_disconnecMode = disconnectMode->GetValueAsString();

	for ( unsigned int i = 0; i < project->GetChildCount(); i++ )
	{
		PObjectBase child = project->GetChild( i );

		EventVector events;
		FindEventHandlers( child, events );
		//GenClassDeclaration( child, useEnum, classDecoration, events, eventHandlerPrefix, eventHandlerPostfix );
		GenClassDeclaration( child, false, wxT(""), events, eventHandlerPostfix );
	}

	code = GetCode( project, wxT("php_epilogue") );
	if( !code.empty() ) m_source->WriteLn( code );

	return true;
}