-
Notifications
You must be signed in to change notification settings - Fork 2
Enum Types #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Enum Types #49
Conversation
case ExprKind_TypeEnum: { | ||
symbol->state = SymbolState_Resolving; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to do additional work to support circular enum references ... for example:
StmtKind :: enum (u8) {
Invalid
Start
// ...
End
ExprStart :: Start + 100
// ...
ExprEnd
DeclStart :: Start + 200
// ...
DeclEnd
}
will work fine with a naïve solution should work fine in this case because Start
is processed before DeclStart
. Do we limit Enums to forbid forward references? Saves us handling the circular checking case
src/llvm.cpp
Outdated
@@ -1852,4 +1896,8 @@ void printIR(llvm::Type *value) { | |||
puts("\n"); | |||
} | |||
|
|||
void printModule(llvm::Module *module) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/kai-language/kai-c/pull/49/files#diff-cf87bdfd88530e0c5c46f9b95cf006beR1885
There is already and overload for this called printIR let's just use it for now
@@ -0,0 +1,4 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn this came back. I was trying to make it a blank file that git would keep in the repo but ignore changes. The Xcode build system fails if the file isn't there because other xcconfig files #include
it and it doesn't run the script to generate this xcconfig file if any of the xcconfig files have any errors. I made my git ignore changes to it but that only works locally for myself. Not sure what would work for any contributors. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I am running 6.0.1 and planning on trying out 7.0.0rc2 soon so it will change lots if we can't just ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>.>
src/checker.c
Outdated
@@ -932,7 +928,8 @@ Type *checkExprTypeEnum(Expr *expr, CheckerContext *ctx, Package *pkg) { | |||
} | |||
|
|||
if (hasMinMax && currentValue > maxValue) { | |||
printf("oops!\n"); | |||
ReportError(pkg, IntOverflowError, item.init->start, | |||
"Enum case is will overflow backing type"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReportError(pkg, IntOverflowError, item.init->start,
"Value for enum case exceeds the max value for the enum backing type (%s)",
DescribeType(backingType));
ReportNote(pkg, item.init->start,
"You can force the overflow by explicitly casting the value '%s(%s)"
DescribeType(backingType), DescribeExpr(item.init));
@@ -945,6 +942,10 @@ Type *checkExprTypeEnum(Expr *expr, CheckerContext *ctx, Package *pkg) { | |||
storeInfoBasicExpr(pkg, expr, type, ctx); | |||
ctx->mode = ExprMode_Type; | |||
return type; | |||
|
|||
unresolved: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the prior leak of fields
with:
if (fields) ArrayFree(fields);
@@ -909,20 +910,15 @@ Type *checkExprTypeEnum(Expr *expr, CheckerContext *ctx, Package *pkg) { | |||
if (item.init) { | |||
CheckerContext itemCtx = {.scope = ctx->scope, .desiredType = backingType}; | |||
Type *type = checkExpr(item.init, &itemCtx, pkg); | |||
if (itemCtx.mode == ExprMode_Unresolved) goto unresolved; // TODO: @Leak this will leak the 'fields' array | |||
|
|||
if (!IsConstant(&itemCtx)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a b32 expectType(Package *pkg, Type *type, CheckerContext *ctx, Position pos) do you think we should have a b32 expectConstant(Package *pkg, CheckerContext *ctx, Position pos)? This would mean we would get a more consistent error message. What do you think?
case SelectorKind_Enum: { | ||
llvm::Type *type = canonicalize(ctx, info.type); | ||
if (ctx->returnAddress) { | ||
UNIMPLEMENTED(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The frontend should report errors if a user tries to address an enum. This should be an ASSERT(false)
No description provided.