[WIP] add check for polymorphic functions
This commit is contained in:
9
ast.cpp
9
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
11
func.cpp
11
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;
|
||||
}
|
||||
|
||||
3
func.h
3
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);
|
||||
|
||||
5
type.cpp
5
type.cpp
@@ -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
3
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user