[WIP] add check for polymorphic functions

This commit is contained in:
2017-05-02 14:59:04 -04:00
parent 0887760de1
commit b3b02df569
5 changed files with 30 additions and 1 deletions

View File

@@ -58,7 +58,14 @@ void
AST::AddFunction(Symbol *sym, Stmt *code) {
if (sym == NULL)
return;
functions.push_back(new Function(sym, code));
Function *f = new Function(sym, code);
if (f->IsPolyFunction()) {
FATAL("This is a good start, but implement me!");
} else {
functions.push_back(f);
}
}

View File

@@ -627,3 +627,14 @@ Function::GenerateIR() {
}
}
}
const bool
Function::IsPolyFunction() const {
for (size_t i = 0; i < args.size(); i++) {
if (args[i]->type->IsPolymorphicType()) {
return true;
}
}
return false;
}

3
func.h
View File

@@ -51,6 +51,9 @@ public:
/** Generate LLVM IR for the function into the current module. */
void GenerateIR();
/** Checks if the function has polymorphic parameters */
const bool IsPolyFunction() const;
private:
void emitCode(FunctionEmitContext *ctx, llvm::Function *function,
SourcePos firstStmtPos);

View File

@@ -247,6 +247,11 @@ Type::IsVoidType() const {
return EqualIgnoringConst(this, AtomicType::Void);
}
bool
Type::IsPolymorphicType() const {
return (CastType<PolyType>(GetBaseType()) != NULL);
}
bool
AtomicType::IsFloatType() const {
return (basicType == TYPE_FLOAT || basicType == TYPE_DOUBLE);

3
type.h
View File

@@ -133,6 +133,9 @@ public:
/** Returns true if the underlying type is either a pointer or an array */
bool IsVoidType() const;
/** Returns true if the underlying type is polymorphic */
bool IsPolymorphicType() const;
/** Returns true if this type is 'const'-qualified. */
virtual bool IsConstType() const = 0;