/****************************************************************************
 * KONOHA COPYRIGHT, LICENSE NOTICE, AND DISCRIMER  
 * 
 * Copyright (c) 2005-2008, Kimio Kuramitsu <kimio at ynu.ac.jp>
 *           (c) 2008-      Konoha Software Foundation  
 * All rights reserved.
 * 
 * You may choose one of the following two licenses when you use konoha. 
 * See www.konohaware.org/license.html for further information.
 * 
 * (1) GNU General Public License 2.0      (with    KONOHA_UNDER_GPL2)
 * (2) Konoha Software Foundation License 1.0
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "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 COPYRIGHT OWNER 
 * OR CONTRIBUTORS 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"commons.h"

/* ************************************************************************ */

#ifdef __cplusplus 
extern "C" {
#endif

/* ------------------------------------------------------------------------ */
/* [declc] */

///* ------------------------------------------------------------------------ */
//
//char *
//knh_os_npath(knh_bytes_t orig, char *buf, size_t bufsiz)
//{
//	TODO();
//	knh_snprintf(buf, bufsiz, "%s", orig.buf);
//	return buf;
//}
//
///* ------------------------------------------------------------------------ */
//
//void knh_stmtvisit_declc__include(Ctx *ctx, Stmt *stmt, Object *v, int level, int step)
//{
//	//DEBUG_STMT(ctx, stmt);
//	/* ['include', 'ANY'] */
//	Compiler *b = (Compiler*)v;
//	KNH_ASSERT(stmt->size == 2);
//	char npath[FILENAME_BUFSIZ];
//	knh_os_npath(knh_String_tobytes(knh_Term_getString(stmt->terms[1])), npath, sizeof(npath));
//	DEBUG("including '%s'...", npath);
//	FILE *fp = fopen(npath, "r");
//	if(fp == NULL) {
//		MC_EPRINT(ctx, (Token*)stmt->terms[0], MC_ERROR, "cannot open: '%s'", npath);
//		knh_Stmt_done(ctx, stmt);
//		return;
//	}
//
//	InputStream *in = new_InputStream__FILE(ctx, fp);
//	in->filen = knh_tfilen_forname(ctx, B(npath));
//	knh_konohac_eval(ctx, b->nsn, in);
//	knh_Stmt_done(ctx, stmt);
//}

/* ------------------------------------------------------------------------ */

void knh_StmtUIMPORT_decl(Ctx *ctx, Stmt *stmt, Compiler *cpr, NameSpace *ns, int level)
{
	DBG2_DUMP(ctx, stmt, KNH_NULL, "decl");
	TODO();
//	//DEBUG_STMT(ctx, stmt);
//	//Compiler *mc = (Compiler*)v;
//	/* ['CLASS, NSNAME'] */
//	Token *ctk = (Token*)stmt->terms[0];
//	Token *ntk = (Token*)stmt->terms[1];
////	DEBUG("using %s %s", knh_Token_tochar(ctk), knh_Token_tochar(ntk));
//	NameSpace *ns = knh_Compiler_getNameSpace(ctx, (Compiler*)v);
//
//	knh_bytes_t cname = knh_Token_tobytes(ctk);
//	knh_bytes_t lname = knh_Token_tobytes(ntk);
//	
//	if(ctk->tt == TT_ASIS) {
//		knh_index_t idx = knh_bytes_rindex(lname, '.');
//		if(idx == -1) {
//			MC_EPRINT(ctx, ntk, MC_IGNORED, "wrong class name: %s", lname.buf);
//		}
//
//		knh_tclass_load(ctx, knh_bytes_first(lname, idx));
//		if(lname.buf[lname.len - 1] == '*') {
//			knh_NameSpace_import(ctx, ns, lname);
//			return;
//		}
//		cname = knh_bytes_last(lname, idx+1);
//	}
//
//	/* single */
//	if(lname.buf[lname.len - 1] == '*') {
//		MC_EPRINT(ctx, ntk, MC_IGNORED, "ambigious name: %s", lname.buf);
//		return;
//	}
//	knh_class_t newcid = knh_NameSpace_getClass(ctx, ns, lname);
//	if(newcid == CLASS_unknown) {
//		MC_EPRINT(ctx, ntk, MC_WARNING, "unknown class: %s", lname.buf);
//		return;
//	}
//	knh_class_t oldcid = knh_NameSpace_getClass(ctx, ns, cname);
//	if(oldcid != CLASS_unknown && newcid != oldcid) {
//		MC_EPRINT(ctx, ntk, MC_INFO, "renaming class: %s => %s", CLASSN(oldcid), CLASSN(newcid));
//	}
//	knh_NameSpace_setLocalName(ctx, ns, new_StringX__fast(ctx, CLASS_String, cname), newcid);
	knh_Stmt_done(ctx, stmt);
}

/* ------------------------------------------------------------------------ */

void knh_StmtUALIAS_decl(Ctx *ctx, Stmt *stmt, Compiler *cpr, NameSpace *ns, int level)
{
	DBG2_DUMP(ctx, stmt, KNH_NULL, "decl");
	TODO();
	knh_Stmt_done(ctx, stmt);
}

/* ------------------------------------------------------------------------ */

void knh_StmtUVOCAB_decl(Ctx *ctx, Stmt *stmt, Compiler *cpr, NameSpace *ns, int level)
{
	DBG2_DUMP(ctx, stmt, KNH_NULL, "decl");
	TODO();
//	//DEBUG_STMT(ctx, stmt);
//	//Compiler *mc = (Compiler*)v;
//	/* ['CLASSTN', 'CURN'] */
//
//	Compiler *b = (Compiler*)v;
//	Token *tkc = (Token*)stmt->terms[0];
//	Token *tku = (Token*)stmt->terms[1];
//	KNH_ASSERT(IS_Token(tkc)); KNH_ASSERT(IS_Token(tku));
//	NameSpace *ns = knh_Compiler_getNameSpace(ctx, b);
//	
//	knh_class_t cid = knh_tclass_classURN(ctx, CLASS_String, knh_Token_tobytes(tku));
//	if(cid == CLASS_String) {
//		MC_EPRINT(ctx, tkc, MC_ERRATA, "undefined '%s': %s => %s", 
//			knh_Token_tochar(tku), knh_Token_tochar(tkc), CLASSN(cid));
//		return;	
//	}
//	
//	knh_class_t oldcid = knh_NameSpace_getClass(ctx, ns, knh_Token_tobytes(tkc));
//	if(oldcid != CLASS_unknown && cid != oldcid) {
//		MC_EPRINT(ctx, tkc, MC_INFO, "renaming class: %s => %s", CLASSN(oldcid), CLASSN(cid));
//	}
//
//	KNH_ASSERT(IS_String(tkc->data));
//	knh_NameSpace_setLocalName(ctx, ns, tkc->data, cid);
//	
	knh_Stmt_done(ctx, stmt);
}

/* ------------------------------------------------------------------------ */

void knh_StmtUENUM_decl(Ctx *ctx, Stmt *stmt, Compiler *cpr, NameSpace *ns, int level)
{
	DBG2_DUMP(ctx, stmt, KNH_NULL, "decl");
	TODO();
//	//DEBUG_STMT(ctx, stmt);
//	//Compiler *mc = (Compiler*)v;
//	/* ['CLASSTN', 'CURN'] */
//
//	Compiler *b = (Compiler*)v;
//	Token *tkc = (Token*)stmt->terms[0];
//	Token *tku = (Token*)stmt->terms[1];
//	KNH_ASSERT(IS_Token(tkc)); KNH_ASSERT(IS_Token(tku));
//	NameSpace *ns = knh_Compiler_getNameSpace(ctx, b);
//	
//	knh_class_t cid = knh_tclass_classURN(ctx, CLASS_Int, knh_Token_tobytes(tku));
//	if(cid == CLASS_Int) {
//		MC_EPRINT(ctx, tkc, MC_ERRATA, "undefined '%s': %s => %s", 
//			knh_Token_tochar(tku), knh_Token_tochar(tkc), CLASSN(cid));
//		return;	
//	}
//	
//	knh_class_t oldcid = knh_NameSpace_getClass(ctx, ns, knh_Token_tobytes(tkc));
//	if(oldcid != CLASS_unknown && cid != oldcid) {
//		MC_EPRINT(ctx, tkc, MC_INFO, "renaming class: %s => %s", CLASSN(oldcid), CLASSN(cid));
//	}
//
//	KNH_ASSERT(IS_String(tkc->data));
//	knh_NameSpace_setLocalName(ctx, ns, tkc->data, cid);
	
	knh_Stmt_done(ctx, stmt);
}

/* ------------------------------------------------------------------------ */

void knh_StmtUUNIT_decl(Ctx *ctx, Stmt *stmt, Compiler *cpr, NameSpace *ns, int level)
{
	DBG2_DUMP(ctx, stmt, KNH_NULL, "decl");
	TODO();
//	//DEBUG_STMT(ctx, stmt);
//	/* ['CLASSTN', 'CURN'] */
//	Compiler *b = (Compiler*)v;
//	Token *tkc = (Token*)stmt->terms[0];
//	Token *tku = (Token*)stmt->terms[1];
//	KNH_ASSERT(IS_Token(tkc)); KNH_ASSERT(IS_Token(tku));
//	NameSpace *ns = knh_Compiler_getNameSpace(ctx, b);
//	
//	knh_class_t cid = knh_tclass_classURN(ctx, CLASS_Float, knh_Token_tobytes(tku));
//	if(cid == CLASS_Float) {
//		MC_EPRINT(ctx, tkc, MC_ERRATA, "undefined '%s': %s => %s", 
//			knh_Token_tochar(tku), knh_Token_tochar(tkc), CLASSN(cid));
//		return;	
//	}
//	
//	knh_class_t oldcid = knh_NameSpace_getClass(ctx, ns, knh_Token_tobytes(tkc));
//	if(oldcid != CLASS_unknown && cid != oldcid) {
//		MC_EPRINT(ctx, tkc, MC_INFO, "renaming class: %s => %s", CLASSN(oldcid), CLASSN(cid));
//	}
//
//	KNH_ASSERT(IS_String(tkc->data));
//	knh_NameSpace_setLocalName(ctx, ns, tkc->data, cid);
	
	knh_Stmt_done(ctx, stmt);
}

/* ------------------------------------------------------------------------ */

void knh_StmtUFUNC_decl(Ctx *ctx, Stmt *stmt, Compiler *cpr, NameSpace *ns, int level)
{
	DBG2_DUMP(ctx, stmt, KNH_NULL, "decl");
	TODO();
	knh_Stmt_done(ctx, stmt);
}

/* ------------------------------------------------------------------------ */

void knh_StmtUMAPMAP_decl(Ctx *ctx, Stmt *stmt, Compiler *cpr, NameSpace *ns, int level)
{
	DBG2_DUMP(ctx, stmt, KNH_NULL, "decl");
	TODO();
	knh_Stmt_done(ctx, stmt);
}

/* ------------------------------------------------------------------------ */

void knh_StmtUALIAS(Ctx *ctx, Stmt *stmt, Compiler *cpr, NameSpace *ns, int level)
{
	DBG2_DUMP(ctx, stmt, KNH_NULL, "decl");
	TODO();
	knh_Stmt_done(ctx, stmt);
}

///* ------------------------------------------------------------------------ */
//
//void knh_stmtvisit_declc__weave(Ctx *ctx, Stmt *stmt, Compiler *cpr, NameSpace *ns, int level)
//{
//	//DEBUG_STMT(ctx, stmt);
//	//Compiler *mc = (Compiler*)v;
//	/* ['weave', 'ANY', 'METHODFN'] */
//	fprintf(stdout, "weaving %s into %s..\n", knh_Token_tochar((Token*)stmt->terms[1]), knh_Token_tochar((Token*)stmt->terms[2]));
//	Method *mtd = knh_Class_getMethod(ctx, CLASS_Amazon, METHODN_placeOrder);
//	if(IS_Method(mtd)) {
//		String *aspect = ((Token*)stmt->terms[1])->data;
//		if(IS_NULL(aspect)) {
//			knh_weave(ctx, NULL, mtd);
//		}
//		else if(knh_String_equals(aspect, STEXT("null"))) {
//			knh_weave(ctx, NULL, mtd);
//		}	
//		else if(knh_String_equals(aspect, STEXT("RBAC"))) {
//			knh_weave(ctx, knh_security_RBAC, mtd);
//		}
//		else if(knh_String_equals(aspect, STEXT("Audit"))) {	
//			knh_weave(ctx, knh_security_Audit, mtd);
//		}
//		else {
//			KNH_THROWf(ctx, "NoSuchAspect!!: %s", knh_String_tochar(aspect));
//		}
//	}
//	else{
//		DEBUG("what?");
//	}
//	knh_Stmt_done(ctx, stmt);
//}

/* ------------------------------------------------------------------------ */


/* ------------------------------------------------------------------------ */


#ifdef __cplusplus
}
#endif
