diff --git a/ast.cpp b/ast.cpp index d858c371..097439bd 100644 --- a/ast.cpp +++ b/ast.cpp @@ -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); + } } diff --git a/func.cpp b/func.cpp index 925bbc2b..0d68fb5e 100644 --- a/func.cpp +++ b/func.cpp @@ -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; +} diff --git a/func.h b/func.h index 3019eeb1..94f012a7 100644 --- a/func.h +++ b/func.h @@ -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); diff --git a/type.cpp b/type.cpp index 9078b1fb..8450ee23 100644 --- a/type.cpp +++ b/type.cpp @@ -247,6 +247,11 @@ Type::IsVoidType() const { return EqualIgnoringConst(this, AtomicType::Void); } +bool +Type::IsPolymorphicType() const { + return (CastType(GetBaseType()) != NULL); +} + bool AtomicType::IsFloatType() const { return (basicType == TYPE_FLOAT || basicType == TYPE_DOUBLE); diff --git a/type.h b/type.h index 7f2fc9bd..07831e01 100644 --- a/type.h +++ b/type.h @@ -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;