summaryrefslogtreecommitdiff
path: root/scope.c
diff options
context:
space:
mode:
authorCarson Fleming <cflems@cflems.net>2026-07-17 18:09:04 -0700
committerCarson Fleming <cflems@cflems.net>2026-07-17 18:09:04 -0700
commitb43aebd9d3c2e072ee2acc50d4381dcb0f01ec98 (patch)
tree26727e2abac02f19a557171fbd8f08ae1d21a68e /scope.c
parentbfb8020c1a64f505537163caa465bd7f06e43f18 (diff)
downloadccc-b43aebd9d3c2e072ee2acc50d4381dcb0f01ec98.tar.gz
type shortcuts for literals
Diffstat (limited to 'scope.c')
-rw-r--r--scope.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/scope.c b/scope.c
index db5c240..1d15ff2 100644
--- a/scope.c
+++ b/scope.c
@@ -1,4 +1,5 @@
#include "scope.h"
+#include "ast.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -159,9 +160,9 @@ void scope_pop(struct scope** p_scope) {
*p_scope = (*p_scope)->next_out;
}
-void scope_install_default_types(struct scope* scope) {
+void scope_install_default_types(struct ast* ast) {
/* TODO: don't let people make void variables */
- scope_define_type(scope, (struct type_def) {
+ ast->void_type = scope_define_type(ast->root_scope, (struct type_def) {
.key = {
.name = strdup("void"),
.how_long = 0,
@@ -173,7 +174,7 @@ void scope_install_default_types(struct scope* scope) {
.sz = 0,
});
- scope_define_type(scope, (struct type_def) {
+ ast->char_type = scope_define_type(ast->root_scope, (struct type_def) {
.key = {
.name = strdup("char"),
.how_long = 0,
@@ -185,7 +186,7 @@ void scope_install_default_types(struct scope* scope) {
.is_floating = false,
});
- scope_define_type(scope, (struct type_def) {
+ scope_define_type(ast->root_scope, (struct type_def) {
.key = {
.name = strdup("short"),
.how_long = 0,
@@ -197,7 +198,7 @@ void scope_install_default_types(struct scope* scope) {
.is_floating = false,
});
- scope_define_type(scope, (struct type_def) {
+ scope_define_type(ast->root_scope, (struct type_def) {
.key = {
.name = strdup("int"),
.how_long = 0,
@@ -209,7 +210,7 @@ void scope_install_default_types(struct scope* scope) {
.is_floating = false,
});
- scope_define_type(scope, (struct type_def) {
+ ast->integral_type = scope_define_type(ast->root_scope, (struct type_def) {
.key = {
.name = strdup("int"),
.how_long = 1,
@@ -220,8 +221,9 @@ void scope_install_default_types(struct scope* scope) {
.is_signed = true,
.is_floating = false,
});
+ ast->string_type = ast->integral_type; /* TODO: support pointers */
- scope_define_type(scope, (struct type_def) {
+ scope_define_type(ast->root_scope, (struct type_def) {
.key = {
.name = strdup("float"),
.how_long = 0,
@@ -233,7 +235,7 @@ void scope_install_default_types(struct scope* scope) {
.is_floating = true,
});
- scope_define_type(scope, (struct type_def) {
+ ast->decimal_type = scope_define_type(ast->root_scope, (struct type_def) {
.key = {
.name = strdup("double"),
.how_long = 0,