/* Dialect - Code Output Formatter
 * Copyright (C) 2001-2002  Jay Freeman (saurik)
*/

/*
 *        Redistribution and use in source and binary
 * forms, with or without modification, are permitted
 * provided that the following conditions are met:
 * 
 * 1. Redistributions of source code must retain the
 *    above copyright notice, this list of conditions
 *    and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the
 *    above copyright notice, this list of conditions
 *    and the following disclaimer in the documentation
 *    and/or other materials provided with the
 *    distribution.
 * 3. The name of the author may not be used to endorse
 *    or promote products derived from this software
 *    without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "stdafx.h"
#include "CSharpDialect.h"

void Dialect::CSharpDialect::Render(const Metallurgy::Value *value, std::wstring &builder) {
	wchar_t buff[16];

	switch (value->getFlag()) {
		case Chordata::Element::Boolean:
			builder += (* (bool *) value->getBlob()) ? L"true" : L"false";
		break;

		case Chordata::Element::Char:
			builder += L":-P";
		break;
		case Chordata::Element::I1:
			builder += L":-P";
		break;
		case Chordata::Element::U1:
			builder += L":-P";
		break;
		case Chordata::Element::I2:
			builder += L":-P";
		break;
		case Chordata::Element::U2:
			builder += L":-P";
		break;

		case Chordata::Element::I4:
			wsprintf(buff, L"0x%x", * (int32_t *) value->getBlob());
			builder += buff;
		break;

		case Chordata::Element::U4:
			wsprintf(buff, L"0x%x", * (uint32_t *) value->getBlob());
			builder += buff;
		break;

		case Chordata::Element::I8:
			builder += L":-P";
		break;
		case Chordata::Element::U8:
			builder += L":-P";
		break;
		case Chordata::Element::R4:
			builder += L":-P";
		break;
		case Chordata::Element::R8:
			builder += L":-P";
		break;

		case Chordata::Element::String: {
			/*uint32_t width(value->getLength() + 1);
			char *wicked = new char[width];

			memmove(wicked, value->getBlob(), width - 1);
			wicked[width - 1] = '\0';

			wchar_t *area = new wchar_t[width];
			wsprintf(area, L"%S", wicked);

			builder += L"\"";
			builder += area;
			builder += L"\"";

			delete wicked;
			delete area;*/

			builder += L"\"";
			builder.append((wcstr_t) value->getBlob(), value->getLength());
			builder += L"\"";
		} break;

		case Chordata::Element::Class:
			builder += L":-P";
		break;
	}
}