Typechecking fixes, moved some printing behind debug flag
This commit is contained in:
5
ctx.cpp
5
ctx.cpp
@@ -1927,6 +1927,11 @@ FunctionEmitContext::BinaryOperator(llvm::Instruction::BinaryOps inst,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (v0->getType() != v1->getType()) {
|
||||
v0->dump();
|
||||
printf("\n\n");
|
||||
v1->dump();
|
||||
}
|
||||
AssertPos(currentPos, v0->getType() == v1->getType());
|
||||
llvm::Type *type = v0->getType();
|
||||
int arraySize = lArrayVectorWidth(type);
|
||||
|
||||
8
expr.cpp
8
expr.cpp
@@ -561,6 +561,7 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr,
|
||||
"\"%s\" for %s", fromType->GetString().c_str(),
|
||||
toPolyType->GetString().c_str(), errorMsgBase);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7148,8 +7149,11 @@ TypeCastExpr::GetValue(FunctionEmitContext *ctx) const {
|
||||
return NULL;
|
||||
|
||||
return ctx->IntToPtrInst(exprVal, llvmToType, "int_to_ptr");
|
||||
}
|
||||
else {
|
||||
} else if (CastType<PolyType>(toType)) {
|
||||
Error(pos, "Unexpected polymorphic type cast to \"%s\"",
|
||||
toType->GetString().c_str());
|
||||
return NULL;
|
||||
} else {
|
||||
const AtomicType *toAtomic = CastType<AtomicType>(toType);
|
||||
// typechecking should ensure this is the case
|
||||
if (!toAtomic) {
|
||||
|
||||
18
func.cpp
18
func.cpp
@@ -651,8 +651,10 @@ Function::ExpandPolyArguments(SymbolTable *symbolTable) const {
|
||||
|
||||
const FunctionType *func = CastType<FunctionType>(sym->type);
|
||||
|
||||
printf("%s before replacing anything:\n", sym->name.c_str());
|
||||
code->Print(0);
|
||||
if (g->debugPrint) {
|
||||
printf("%s before replacing anything:\n", sym->name.c_str());
|
||||
code->Print(0);
|
||||
}
|
||||
|
||||
for (size_t i=0; i<versions.size(); i++) {
|
||||
const FunctionType *ft = CastType<FunctionType>(versions[i]->type);
|
||||
@@ -665,13 +667,15 @@ Function::ExpandPolyArguments(SymbolTable *symbolTable) const {
|
||||
|
||||
ncode = (Stmt*)TranslatePoly(ncode, from,
|
||||
ft->GetParameterType(j)->GetBaseType());
|
||||
printf("%s after replacing %s with %s:\n\n",
|
||||
sym->name.c_str(), from->GetString().c_str(),
|
||||
ft->GetParameterType(j)->GetBaseType()->GetString().c_str());
|
||||
if (g->debugPrint) {
|
||||
printf("%s after replacing %s with %s:\n\n",
|
||||
sym->name.c_str(), from->GetString().c_str(),
|
||||
ft->GetParameterType(j)->GetBaseType()->GetString().c_str());
|
||||
|
||||
ncode->Print(0);
|
||||
ncode->Print(0);
|
||||
|
||||
printf("------------------------------------------\n\n");
|
||||
printf("------------------------------------------\n\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
module.cpp
17
module.cpp
@@ -1032,8 +1032,7 @@ Module::AddFunctionDeclaration(const std::string &name,
|
||||
}
|
||||
|
||||
std::vector<const FunctionType *> nextExpanded;
|
||||
std::set<const Type*>::iterator iter;
|
||||
for (iter = toExpand.begin(); iter != toExpand.end(); iter++) {
|
||||
for (auto iter = toExpand.begin(); iter != toExpand.end(); iter++) {
|
||||
for (size_t j=0; j<expanded.size(); j++) {
|
||||
const FunctionType *eft = expanded[j];
|
||||
|
||||
@@ -1060,7 +1059,14 @@ Module::AddFunctionDeclaration(const std::string &name,
|
||||
nargsp.push_back(eft->GetParameterSourcePos(k));
|
||||
}
|
||||
|
||||
nextExpanded.push_back(new FunctionType(eft->GetReturnType(),
|
||||
const Type *ret = eft->GetReturnType();
|
||||
if (Type::EqualForReplacement(ret, pt)) {
|
||||
printf("Replaced return type %s\n",
|
||||
ret->GetString().c_str());
|
||||
ret = PolyType::ReplaceType(ret, *te);
|
||||
}
|
||||
|
||||
nextExpanded.push_back(new FunctionType(ret,
|
||||
nargs,
|
||||
nargsn,
|
||||
nargsd,
|
||||
@@ -1078,6 +1084,11 @@ Module::AddFunctionDeclaration(const std::string &name,
|
||||
|
||||
if (expanded.size() > 1) {
|
||||
for (size_t i=0; i<expanded.size(); i++) {
|
||||
if (expanded[i]->GetReturnType()->IsPolymorphicType()) {
|
||||
Error(pos, "Unexpected polymorphic return type \"%s\"",
|
||||
expanded[i]->GetReturnType()->GetString().c_str());
|
||||
return;
|
||||
}
|
||||
std::string nname = name;
|
||||
if (functionType->isExported || functionType->isExternC) {
|
||||
for (int j=0; j<expanded[i]->GetNumParameters(); j++) {
|
||||
|
||||
7
sym.cpp
7
sym.cpp
@@ -147,7 +147,7 @@ bool
|
||||
SymbolTable::AddFunction(Symbol *symbol) {
|
||||
const FunctionType *ft = CastType<FunctionType>(symbol->type);
|
||||
Assert(ft != NULL);
|
||||
if (LookupFunction(symbol->name.c_str(), ft) != NULL)
|
||||
if (LookupFunction(symbol->name.c_str(), ft, true) != NULL)
|
||||
// A function of the same name and type has already been added to
|
||||
// the symbol table
|
||||
return false;
|
||||
@@ -183,7 +183,8 @@ SymbolTable::LookupFunction(const char *name, std::vector<Symbol *> *matches) {
|
||||
|
||||
|
||||
Symbol *
|
||||
SymbolTable::LookupFunction(const char *name, const FunctionType *type) {
|
||||
SymbolTable::LookupFunction(const char *name, const FunctionType *type,
|
||||
bool ignorePoly) {
|
||||
FunctionMapType::iterator iter = functions.find(name);
|
||||
if (iter != functions.end()) {
|
||||
std::vector<Symbol *> funcs = iter->second;
|
||||
@@ -193,7 +194,7 @@ SymbolTable::LookupFunction(const char *name, const FunctionType *type) {
|
||||
}
|
||||
}
|
||||
// Try looking for a polymorphic function
|
||||
if (polyFunctions[name].size() > 0) {
|
||||
if (!ignorePoly && polyFunctions[name].size() > 0) {
|
||||
std::string n = name;
|
||||
return new Symbol(name, polyFunctions[name][0]->pos, type);
|
||||
}
|
||||
|
||||
3
sym.h
3
sym.h
@@ -181,7 +181,8 @@ public:
|
||||
in the symbol table.
|
||||
|
||||
@return pointer to matching Symbol; NULL if none is found. */
|
||||
Symbol *LookupFunction(const char *name, const FunctionType *type);
|
||||
Symbol *LookupFunction(const char *name, const FunctionType *type,
|
||||
bool ignorePoly = false);
|
||||
|
||||
std::vector<Symbol *>& LookupPolyFunction(const char *name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user