<commit_before>// FuncDeclCodegen.cpp
// Copyright (c) 2014 - 2015, <EMAIL>
// Licensed under the Apache License Version 2.0.


#include "ast.h"
#include "codegen.h"

using namespace Ast;
using namespace Codegen;

static fir::LinkageType getFunctionDeclLinkage(FuncDecl* fd)
{
	fir::LinkageType linkageType;

	if(fd->isFFI)
	{
		linkageType = fir::LinkageType::External;
	}
	else if((fd->attribs & Attr_VisPrivate) || (fd->attribs & Attr_VisInternal))
	{
		linkageType = fir::LinkageType::Internal;
	}
	else if(fd->attribs & Attr_VisPublic)
	{
		linkageType = fir::LinkageType::External;
	}
	else if(fd->parentClass && (fd->attribs & (Attr_VisPublic | Attr_VisInternal | Attr_VisPrivate)) == 0)
	{
		// default.
		linkageType = fd->attribs & Attr_VisPrivate ? fir::LinkageType::Internal : fir::LinkageType::Internal;
	}
	else
	{
		linkageType = fir::LinkageType::Internal;
	}


	return linkageType;
}


static Result_t generateActualFuncDecl(CodegenInstance* cgi, FuncDecl* fd, std::deque<fir::Type*> argtypes, fir::Type* rettype,
	std::string genericMangling)
{
	fir::FunctionType* ft = 0;

	if(fd->isCStyleVarArg)
	{
		ft = fir::FunctionType::getCVariadicFunc(argtypes, rettype);
	}
	else
	{
		ft = fir::FunctionType::get(argtypes, rettype, fd->isVariadic);
	}


	auto linkageType = getFunctionDeclLinkage(fd);

	// check for redef
	fir::Function* func = nullptr;
	if(false /*cgi->getType(fd->mangledName) != nullptr*/)
	{
		GenError::duplicateSymbol(cgi, fd, fd->ident.str() + " (symbol previously declared as a type)", SymbolType::Generic);
	}
	else if(fd->genericTypes.size() == 0 && cgi->module->getFunction(fd->ident) != 0)
	{
		if(!fd->isFFI)
		{
			GenError::duplicateSymbol(cgi, fd, fd->ident.str(), SymbolType::Function);
		}
	}
	else
	{
		if(genericMangling.empty())
		{
			iceAssert(!(fd->attribs & Attr_NoMangle) && !fd->isFFI);
			func = cgi->module->getOrCreateFunction(fd->ident, ft, linkageType);
		}
		else
		{
			func = cgi->module->getOrCreateFunction(genericMangling, ft, linkageType);
		}<commit_msg>cleanup, prep for moving types into ident system<commit_after>// FuncDeclCodegen.cpp
// Copyright (c) 2014 - 2015, <EMAIL>
// Licensed under the Apache License Version 2.0.


#include "ast.h"
#include "codegen.h"

using namespace Ast;
using namespace Codegen;

static fir::LinkageType getFunctionDeclLinkage(FuncDecl* fd)
{
	fir::LinkageType linkageType;

	if(fd->isFFI)
	{
		linkageType = fir::LinkageType::External;
	}
	else if((fd->attribs & Attr_VisPrivate) || (fd->attribs & Attr_VisInternal))
	{
		linkageType = fir::LinkageType::Internal;
	}
	else if(fd->attribs & Attr_VisPublic)
	{
		linkageType = fir::LinkageType::External;
	}
	else if(fd->parentClass && (fd->attribs & (Attr_VisPublic | Attr_VisInternal | Attr_VisPrivate)) == 0)
	{
		// default.
		linkageType = fd->attribs & Attr_VisPrivate ? fir::LinkageType::Internal : fir::LinkageType::Internal;
	}
	else
	{
		linkageType = fir::LinkageType::Internal;
	}


	return linkageType;
}


static Result_t generateActualFuncDecl(CodegenInstance* cgi, FuncDecl* fd, std::deque<fir::Type*> argtypes, fir::Type* rettype,
	std::string genericMangling)
{
	fir::FunctionType* ft = 0;

	if(fd->isCStyleVarArg)
	{
		ft = fir::FunctionType::getCVariadicFunc(argtypes, rettype);
	}
	else
	{
		ft = fir::FunctionType::get(argtypes, rettype, fd->isVariadic);
	}


	auto linkageType = getFunctionDeclLinkage(fd);

	// check for redef
	fir::Function* func = nullptr;
	if(fd->genericTypes.size() == 0 && cgi->module->getFunction(fd->ident) != 0)
	{
		if(!fd->isFFI)
		{
			GenError::duplicateSymbol(cgi, fd, fd->ident.str(), SymbolType::Function);
		}
	}
	else
	{
		if(genericMangling.empty())
		{
			iceAssert(!(fd->attribs & Attr_NoMangle) && !fd->isFFI);
			func = cgi->module->getOrCreateFunction(fd->ident, ft, linkageType);
		}
		else
		{
			func = cgi->module->getOrCreateFunction(genericMangling, ft, linkageType);
		}
{'fraction_non_alphanumeric': 0.1574216743708269, 'fraction_numerical': 0.007190549563430919, 'mean_word_length': 4.88368580060423, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4429641', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1441, 'n_words': 259}