file is now attribute of ast location
This commit is contained in:
parent
560e24950e
commit
b23ce945ea
|
@ -152,6 +152,10 @@ void AST_push_node(struct AST_Node_t *owner, struct AST_Node_t *child) {
|
||||||
owner->location.col_start = min(owner->location.col_start, child->location.col_start);
|
owner->location.col_start = min(owner->location.col_start, child->location.col_start);
|
||||||
owner->location.line_start = min(owner->location.line_start, child->location.line_start);
|
owner->location.line_start = min(owner->location.line_start, child->location.line_start);
|
||||||
|
|
||||||
|
if (owner->location.file == NULL) {
|
||||||
|
owner->location.file = child->location.file;
|
||||||
|
}
|
||||||
|
|
||||||
assert(owner->children != NULL);
|
assert(owner->children != NULL);
|
||||||
|
|
||||||
owner->children[owner->child_count++] = child;
|
owner->children[owner->child_count++] = child;
|
||||||
|
|
|
@ -192,8 +192,7 @@ const char* get_absolute_import_path(const TargetConfig* config, const char* imp
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AST_NODE_PTR compile_module_with_dependencies(ModuleFileStack *unit, ModuleFile* file, const TargetConfig *target) {
|
static int compile_module_with_dependencies(ModuleFileStack *unit, ModuleFile* file, const TargetConfig *target, AST_NODE_PTR root_module) {
|
||||||
AST_NODE_PTR root_module = AST_new_node(empty_location(), AST_Module, NULL);
|
|
||||||
|
|
||||||
if (compile_file_to_ast(root_module, file) == EXIT_SUCCESS) {
|
if (compile_file_to_ast(root_module, file) == EXIT_SUCCESS) {
|
||||||
|
|
||||||
|
@ -205,19 +204,23 @@ static AST_NODE_PTR compile_module_with_dependencies(ModuleFileStack *unit, Modu
|
||||||
|
|
||||||
const char* path = get_absolute_import_path(target, child->value);
|
const char* path = get_absolute_import_path(target, child->value);
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
return NULL;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleFile *imported_file = push_file(unit, path);
|
ModuleFile *imported_file = push_file(unit, path);
|
||||||
|
|
||||||
if (compile_file_to_ast(imported_module, imported_file) == EXIT_SUCCESS) {
|
if (compile_file_to_ast(imported_module, imported_file) == EXIT_SUCCESS) {
|
||||||
AST_merge_modules(root_module, i + 1, imported_module);
|
AST_merge_modules(root_module, i + 1, imported_module);
|
||||||
|
} else {
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return root_module;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,20 +232,22 @@ static void build_target(ModuleFileStack *unit, const TargetConfig *target) {
|
||||||
print_message(Info, "Building target: %s", target->name);
|
print_message(Info, "Building target: %s", target->name);
|
||||||
|
|
||||||
ModuleFile *file = push_file(unit, target->root_module);
|
ModuleFile *file = push_file(unit, target->root_module);
|
||||||
AST_NODE_PTR ast = compile_module_with_dependencies(unit, file, target);
|
AST_NODE_PTR root_module = AST_new_node(empty_location(), AST_Module, NULL);
|
||||||
|
|
||||||
if (ast != NULL) {
|
if (compile_module_with_dependencies(unit, file, target, root_module) == EXIT_SUCCESS) {
|
||||||
|
if (root_module != NULL) {
|
||||||
if (setup_target_environment(target) == 0) {
|
if (setup_target_environment(target) == 0) {
|
||||||
|
|
||||||
print_ast_to_file(ast, target);
|
print_ast_to_file(root_module, target);
|
||||||
Module *module = create_set(ast);
|
Module *module = create_set(root_module);
|
||||||
|
|
||||||
if (module != NULL) {
|
if (module != NULL) {
|
||||||
run_backend_codegen(module, target);
|
run_backend_codegen(module, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_delete_node(ast);
|
AST_delete_node(root_module);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mem_purge_namespace(MemoryNamespaceLex);
|
mem_purge_namespace(MemoryNamespaceLex);
|
||||||
|
|
|
@ -84,19 +84,20 @@ static void custom_fgets(char *buffer, size_t n, FILE *stream) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, const char *message, ...) {
|
void print_diagnostic(TokenLocation *location, Message kind, const char *message, ...) {
|
||||||
assert(file->handle != NULL);
|
assert(location->file != NULL);
|
||||||
|
assert(location->file->handle != NULL);
|
||||||
assert(location != NULL);
|
assert(location != NULL);
|
||||||
assert(message != NULL);
|
assert(message != NULL);
|
||||||
|
|
||||||
// reset to start
|
// reset to start
|
||||||
rewind(file->handle);
|
rewind(location->file->handle);
|
||||||
|
|
||||||
char *buffer = alloca(SEEK_BUF_BYTES);
|
char *buffer = alloca(SEEK_BUF_BYTES);
|
||||||
unsigned long int line_count = 1;
|
unsigned long int line_count = 1;
|
||||||
|
|
||||||
// seek to first line
|
// seek to first line
|
||||||
while (line_count < location->line_start && fgets(buffer, SEEK_BUF_BYTES, file->handle) != NULL) {
|
while (line_count < location->line_start && fgets(buffer, SEEK_BUF_BYTES, location->file->handle) != NULL) {
|
||||||
line_count += strchr(buffer, '\n') != NULL;
|
line_count += strchr(buffer, '\n') != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,21 +107,21 @@ void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, c
|
||||||
case Info:
|
case Info:
|
||||||
kind_text = "info";
|
kind_text = "info";
|
||||||
accent_color = CYAN;
|
accent_color = CYAN;
|
||||||
file->statistics.info_count++;
|
location->file->statistics.info_count++;
|
||||||
break;
|
break;
|
||||||
case Warning:
|
case Warning:
|
||||||
kind_text = "warning";
|
kind_text = "warning";
|
||||||
accent_color = YELLOW;
|
accent_color = YELLOW;
|
||||||
file->statistics.warning_count++;
|
location->file->statistics.warning_count++;
|
||||||
break;
|
break;
|
||||||
case Error:
|
case Error:
|
||||||
kind_text = "error";
|
kind_text = "error";
|
||||||
accent_color = RED;
|
accent_color = RED;
|
||||||
file->statistics.error_count++;
|
location->file->statistics.error_count++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *absolute_path = get_absolute_path(file->path);
|
const char *absolute_path = get_absolute_path(location->file->path);
|
||||||
|
|
||||||
printf("%s%s:%ld:%s %s%s:%s ", BOLD, absolute_path, location->line_start, RESET, accent_color, kind_text, RESET);
|
printf("%s%s:%ld:%s %s%s:%s ", BOLD, absolute_path, location->line_start, RESET, accent_color, kind_text, RESET);
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, c
|
||||||
// print line before token group start
|
// print line before token group start
|
||||||
unsigned long int limit = min(location->col_start, SEEK_BUF_BYTES);
|
unsigned long int limit = min(location->col_start, SEEK_BUF_BYTES);
|
||||||
while (limit > 1) {
|
while (limit > 1) {
|
||||||
custom_fgets(buffer, (int) limit, file->handle);
|
custom_fgets(buffer, (int) limit, location->file->handle);
|
||||||
chars += printf("%s", buffer);
|
chars += printf("%s", buffer);
|
||||||
limit = min(location->col_start - chars, SEEK_BUF_BYTES);
|
limit = min(location->col_start - chars, SEEK_BUF_BYTES);
|
||||||
|
|
||||||
|
@ -159,7 +160,7 @@ void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, c
|
||||||
chars = 0;
|
chars = 0;
|
||||||
limit = min(location->col_end - location->col_start + 1, SEEK_BUF_BYTES);
|
limit = min(location->col_end - location->col_start + 1, SEEK_BUF_BYTES);
|
||||||
while (limit > 0) {
|
while (limit > 0) {
|
||||||
custom_fgets(buffer, (int) limit, file->handle);
|
custom_fgets(buffer, (int) limit, location->file->handle);
|
||||||
chars += printf("%s", buffer);
|
chars += printf("%s", buffer);
|
||||||
limit = min(location->col_end - location->col_start + 1 - chars, SEEK_BUF_BYTES);
|
limit = min(location->col_end - location->col_start + 1 - chars, SEEK_BUF_BYTES);
|
||||||
|
|
||||||
|
@ -172,7 +173,7 @@ void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, c
|
||||||
|
|
||||||
// print rest of the line
|
// print rest of the line
|
||||||
do {
|
do {
|
||||||
custom_fgets(buffer, SEEK_BUF_BYTES, file->handle);
|
custom_fgets(buffer, SEEK_BUF_BYTES, location->file->handle);
|
||||||
printf("%s", buffer);
|
printf("%s", buffer);
|
||||||
} while (strchr(buffer, '\n') == NULL);
|
} while (strchr(buffer, '\n') == NULL);
|
||||||
|
|
||||||
|
@ -195,13 +196,14 @@ void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, c
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenLocation new_location(unsigned long int line_start, unsigned long int col_start, unsigned long int line_end,
|
TokenLocation new_location(unsigned long int line_start, unsigned long int col_start, unsigned long int line_end,
|
||||||
unsigned long int col_end) {
|
unsigned long int col_end, ModuleFile* file) {
|
||||||
TokenLocation location;
|
TokenLocation location;
|
||||||
|
|
||||||
location.line_start = line_start;
|
location.line_start = line_start;
|
||||||
location.line_end = line_end;
|
location.line_end = line_end;
|
||||||
location.col_start = col_start;
|
location.col_start = col_start;
|
||||||
location.col_end = col_end;
|
location.col_end = col_end;
|
||||||
|
location.file = file;
|
||||||
|
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
@ -213,6 +215,7 @@ TokenLocation empty_location(void) {
|
||||||
location.line_end = 0;
|
location.line_end = 0;
|
||||||
location.col_start = 0;
|
location.col_start = 0;
|
||||||
location.col_end = 0;
|
location.col_end = 0;
|
||||||
|
location.file = NULL;
|
||||||
|
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ typedef struct TokenLocation_t {
|
||||||
unsigned long int col_start;
|
unsigned long int col_start;
|
||||||
unsigned long int line_end;
|
unsigned long int line_end;
|
||||||
unsigned long int col_end;
|
unsigned long int col_end;
|
||||||
|
ModuleFile* file;
|
||||||
} TokenLocation;
|
} TokenLocation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,7 +76,7 @@ void delete_files(ModuleFileStack *stack);
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
TokenLocation new_location(unsigned long int line_start, unsigned long int col_start, unsigned long int line_end,
|
TokenLocation new_location(unsigned long int line_start, unsigned long int col_start, unsigned long int line_end,
|
||||||
unsigned long int col_end);
|
unsigned long int col_end, ModuleFile* file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new empty location with all of its contents set to zero
|
* @brief Create a new empty location with all of its contents set to zero
|
||||||
|
@ -86,13 +87,12 @@ TokenLocation empty_location(void);
|
||||||
/**
|
/**
|
||||||
* @brief Prints some diagnostic message to stdout.
|
* @brief Prints some diagnostic message to stdout.
|
||||||
* This also print the token group and the attached source as context.
|
* This also print the token group and the attached source as context.
|
||||||
* @param file
|
|
||||||
* @param location
|
* @param location
|
||||||
* @param kind
|
* @param kind
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
[[gnu::nonnull(1), gnu::nonnull(2)]]
|
[[gnu::nonnull(1)]]
|
||||||
void print_diagnostic(ModuleFile *file, TokenLocation *location, Message kind, const char *message, ...);
|
void print_diagnostic(TokenLocation *location, Message kind, const char *message, ...);
|
||||||
|
|
||||||
[[gnu::nonnull(2)]]
|
[[gnu::nonnull(2)]]
|
||||||
/**
|
/**
|
||||||
|
|
115
src/set/set.c
115
src/set/set.c
|
@ -9,7 +9,6 @@
|
||||||
#include <set/set.h>
|
#include <set/set.h>
|
||||||
#include <mem/cache.h>
|
#include <mem/cache.h>
|
||||||
|
|
||||||
extern ModuleFile *current_file;
|
|
||||||
static GHashTable *declaredComposites = NULL;//pointer to composites with names
|
static GHashTable *declaredComposites = NULL;//pointer to composites with names
|
||||||
static GHashTable *declaredBoxes = NULL;//pointer to type
|
static GHashTable *declaredBoxes = NULL;//pointer to type
|
||||||
static GHashTable *functionParameter = NULL;
|
static GHashTable *functionParameter = NULL;
|
||||||
|
@ -103,12 +102,12 @@ int check_scale_factor(AST_NODE_PTR node, Scale scale) {
|
||||||
assert(node != NULL);
|
assert(node != NULL);
|
||||||
|
|
||||||
if (8 < scale) {
|
if (8 < scale) {
|
||||||
print_diagnostic(current_file, &node->location, Error, "Composite scale overflow");
|
print_diagnostic(&node->location, Error, "Composite scale overflow");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0.25 > scale) {
|
if (0.25 > scale) {
|
||||||
print_diagnostic(current_file, &node->location, Error, "Composite scale underflow");
|
print_diagnostic(&node->location, Error, "Composite scale underflow");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +197,7 @@ int set_impl_composite_type(AST_NODE_PTR ast_type, CompositeType *composite) {
|
||||||
Type *nested_type = NULL;
|
Type *nested_type = NULL;
|
||||||
status = get_type_decl(typeKind->value, &nested_type);
|
status = get_type_decl(typeKind->value, &nested_type);
|
||||||
if (status == SEMANTIC_ERROR) {
|
if (status == SEMANTIC_ERROR) {
|
||||||
print_diagnostic(current_file, &typeKind->location, Error, "Unknown composite type in declaration");
|
print_diagnostic(&typeKind->location, Error, "Unknown composite type in declaration");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,13 +214,13 @@ int set_impl_composite_type(AST_NODE_PTR ast_type, CompositeType *composite) {
|
||||||
composite->scale = composite->scale * nested_type->impl.composite.scale;
|
composite->scale = composite->scale * nested_type->impl.composite.scale;
|
||||||
|
|
||||||
if (composite->scale > 8 || composite->scale < 0.25) {
|
if (composite->scale > 8 || composite->scale < 0.25) {
|
||||||
print_diagnostic(current_file, &typeKind->location, Error, "Invalid type scale of composite type: %lf",
|
print_diagnostic(&typeKind->location, Error, "Invalid type scale of composite type: %lf",
|
||||||
composite->scale);
|
composite->scale);
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
print_diagnostic(current_file, &typeKind->location, Error, "Type must be either composite or primitive");
|
print_diagnostic(&typeKind->location, Error, "Type must be either composite or primitive");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,7 +273,7 @@ int set_get_type_impl(AST_NODE_PTR currentNode, Type **type) {
|
||||||
*type = g_hash_table_lookup(declaredBoxes, typekind);
|
*type = g_hash_table_lookup(declaredBoxes, typekind);
|
||||||
|
|
||||||
if (currentNode->child_count > 1) {
|
if (currentNode->child_count > 1) {
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Box type cannot modified");
|
print_diagnostic(¤tNode->location, Error, "Box type cannot modified");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
return SEMANTIC_OK;
|
return SEMANTIC_OK;
|
||||||
|
@ -299,7 +298,7 @@ int set_get_type_impl(AST_NODE_PTR currentNode, Type **type) {
|
||||||
return SEMANTIC_OK;
|
return SEMANTIC_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
print_diagnostic(current_file, ¤tNode->children[currentNode->child_count - 1]->location, Error,
|
print_diagnostic(¤tNode->children[currentNode->child_count - 1]->location, Error,
|
||||||
"Expected either primitive or composite type");
|
"Expected either primitive or composite type");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -503,7 +502,7 @@ int getVariableFromScope(const char *name, Variable **variable) {
|
||||||
DEBUG("Found var");
|
DEBUG("Found var");
|
||||||
return SEMANTIC_OK;
|
return SEMANTIC_OK;
|
||||||
} else if (found > 1) {
|
} else if (found > 1) {
|
||||||
print_diagnostic(current_file, &(*variable)->nodePtr->location, Warning,
|
print_diagnostic(&(*variable)->nodePtr->location, Warning,
|
||||||
"Parameter shadows variable of same name: %s", name);
|
"Parameter shadows variable of same name: %s", name);
|
||||||
return SEMANTIC_OK;
|
return SEMANTIC_OK;
|
||||||
}
|
}
|
||||||
|
@ -514,7 +513,7 @@ int getVariableFromScope(const char *name, Variable **variable) {
|
||||||
int addVarToScope(Variable *variable) {
|
int addVarToScope(Variable *variable) {
|
||||||
Variable *tmp = NULL;
|
Variable *tmp = NULL;
|
||||||
if (getVariableFromScope(variable->name, &tmp) == SEMANTIC_OK) {
|
if (getVariableFromScope(variable->name, &tmp) == SEMANTIC_OK) {
|
||||||
print_diagnostic(current_file, &variable->nodePtr->location, Error, "Variable already exist: ", variable->name);
|
print_diagnostic(&variable->nodePtr->location, Error, "Variable already exist: ", variable->name);
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
GHashTable *currentScope = g_array_index(Scope, GHashTable*, Scope->len - 1);
|
GHashTable *currentScope = g_array_index(Scope, GHashTable*, Scope->len - 1);
|
||||||
|
@ -532,7 +531,7 @@ int fillTablesWithVars(GHashTable *variableTable, const GArray *variables) {
|
||||||
|
|
||||||
// this variable is discarded, only need status code
|
// this variable is discarded, only need status code
|
||||||
if (g_hash_table_contains(variableTable, (gpointer) var->name)) {
|
if (g_hash_table_contains(variableTable, (gpointer) var->name)) {
|
||||||
print_diagnostic(current_file, &var->nodePtr->location, Error, "Variable already exists");
|
print_diagnostic(&var->nodePtr->location, Error, "Variable already exists");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,7 +622,7 @@ Type *createTypeFromOperands(Type *LeftOperandType, Type *RightOperandType, AST_
|
||||||
result->impl.composite.nodePtr = currentNode;
|
result->impl.composite.nodePtr = currentNode;
|
||||||
} else {
|
} else {
|
||||||
mem_free(result);
|
mem_free(result);
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Incompatible types in expression");
|
print_diagnostic(¤tNode->location, Error, "Incompatible types in expression");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
DEBUG("Succsessfully created type");
|
DEBUG("Succsessfully created type");
|
||||||
|
@ -645,7 +644,7 @@ int createTypeCastFromExpression(Expression *expression, Type *resultType, Expre
|
||||||
|
|
||||||
if (expression->result->kind != TypeKindComposite
|
if (expression->result->kind != TypeKindComposite
|
||||||
&& expression->result->kind != TypeKindPrimitive) {
|
&& expression->result->kind != TypeKindPrimitive) {
|
||||||
print_diagnostic(current_file, &expression->nodePtr->location, Error,
|
print_diagnostic(&expression->nodePtr->location, Error,
|
||||||
"Expected either primitive or composite type");
|
"Expected either primitive or composite type");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -699,7 +698,7 @@ int createArithOperation(Expression *ParentExpression, AST_NODE_PTR currentNode,
|
||||||
result->nodePtr = currentNode;
|
result->nodePtr = currentNode;
|
||||||
|
|
||||||
if (result->kind == TypeKindReference || result->kind == TypeKindBox) {
|
if (result->kind == TypeKindReference || result->kind == TypeKindBox) {
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Invalid type for arithmetic operation");
|
print_diagnostic(¤tNode->location, Error, "Invalid type for arithmetic operation");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
} else if (result->kind == TypeKindComposite) {
|
} else if (result->kind == TypeKindComposite) {
|
||||||
result->impl.composite.sign = Signed;
|
result->impl.composite.sign = Signed;
|
||||||
|
@ -829,32 +828,32 @@ int createBoolOperation(Expression *ParentExpression, AST_NODE_PTR currentNode)
|
||||||
|
|
||||||
// should not be a box or a reference
|
// should not be a box or a reference
|
||||||
if (LeftOperandType->kind != TypeKindPrimitive && LeftOperandType->kind != TypeKindComposite) {
|
if (LeftOperandType->kind != TypeKindPrimitive && LeftOperandType->kind != TypeKindComposite) {
|
||||||
print_diagnostic(current_file, &lhs->nodePtr->location, Error, "invalid type for boolean operation");
|
print_diagnostic(&lhs->nodePtr->location, Error, "invalid type for boolean operation");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
if (RightOperandType->kind != TypeKindPrimitive && RightOperandType->kind != TypeKindComposite) {
|
if (RightOperandType->kind != TypeKindPrimitive && RightOperandType->kind != TypeKindComposite) {
|
||||||
print_diagnostic(current_file, &rhs->nodePtr->location, Error, "invalid type for boolean operation");
|
print_diagnostic(&rhs->nodePtr->location, Error, "invalid type for boolean operation");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
// should not be a float
|
// should not be a float
|
||||||
if (LeftOperandType->kind == TypeKindComposite) {
|
if (LeftOperandType->kind == TypeKindComposite) {
|
||||||
if (LeftOperandType->impl.composite.primitive == Float) {
|
if (LeftOperandType->impl.composite.primitive == Float) {
|
||||||
print_diagnostic(current_file, &lhs->nodePtr->location, Error, "operand must not be a float");
|
print_diagnostic(&lhs->nodePtr->location, Error, "operand must not be a float");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
} else if (LeftOperandType->kind == TypeKindPrimitive) {
|
} else if (LeftOperandType->kind == TypeKindPrimitive) {
|
||||||
if (LeftOperandType->impl.primitive == Float) {
|
if (LeftOperandType->impl.primitive == Float) {
|
||||||
print_diagnostic(current_file, &lhs->nodePtr->location, Error, "operand must not be a float");
|
print_diagnostic(&lhs->nodePtr->location, Error, "operand must not be a float");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
} else if (RightOperandType->kind == TypeKindComposite) {
|
} else if (RightOperandType->kind == TypeKindComposite) {
|
||||||
if (RightOperandType->impl.composite.primitive == Float) {
|
if (RightOperandType->impl.composite.primitive == Float) {
|
||||||
print_diagnostic(current_file, &rhs->nodePtr->location, Error, "operand must not be a float");
|
print_diagnostic(&rhs->nodePtr->location, Error, "operand must not be a float");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
} else if (RightOperandType->kind == TypeKindPrimitive) {
|
} else if (RightOperandType->kind == TypeKindPrimitive) {
|
||||||
if (RightOperandType->impl.primitive == Float) {
|
if (RightOperandType->impl.primitive == Float) {
|
||||||
print_diagnostic(current_file, &rhs->nodePtr->location, Error, "operand must not be a float");
|
print_diagnostic(&rhs->nodePtr->location, Error, "operand must not be a float");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -896,14 +895,14 @@ int createBoolNotOperation(Expression *ParentExpression, AST_NODE_PTR currentNod
|
||||||
result->nodePtr = currentNode;
|
result->nodePtr = currentNode;
|
||||||
|
|
||||||
if (Operand->kind == TypeKindBox || Operand->kind == TypeKindReference) {
|
if (Operand->kind == TypeKindBox || Operand->kind == TypeKindReference) {
|
||||||
print_diagnostic(current_file, &Operand->nodePtr->location, Error,
|
print_diagnostic(&Operand->nodePtr->location, Error,
|
||||||
"Operand must be a variant of primitive type int");
|
"Operand must be a variant of primitive type int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Operand->kind == TypeKindPrimitive) {
|
if (Operand->kind == TypeKindPrimitive) {
|
||||||
if (Operand->impl.primitive == Float) {
|
if (Operand->impl.primitive == Float) {
|
||||||
print_diagnostic(current_file, &Operand->nodePtr->location, Error,
|
print_diagnostic(&Operand->nodePtr->location, Error,
|
||||||
"Operand must be a variant of primitive type int");
|
"Operand must be a variant of primitive type int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -912,7 +911,7 @@ int createBoolNotOperation(Expression *ParentExpression, AST_NODE_PTR currentNod
|
||||||
|
|
||||||
} else if (Operand->kind == TypeKindComposite) {
|
} else if (Operand->kind == TypeKindComposite) {
|
||||||
if (Operand->impl.composite.primitive == Float) {
|
if (Operand->impl.composite.primitive == Float) {
|
||||||
print_diagnostic(current_file, &Operand->nodePtr->location, Error,
|
print_diagnostic(&Operand->nodePtr->location, Error,
|
||||||
"Operand must be a variant of primitive type int");
|
"Operand must be a variant of primitive type int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -986,24 +985,24 @@ int createBitOperation(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
|
|
||||||
//should not be a box or a reference
|
//should not be a box or a reference
|
||||||
if (LeftOperandType->kind != TypeKindPrimitive && LeftOperandType->kind != TypeKindComposite) {
|
if (LeftOperandType->kind != TypeKindPrimitive && LeftOperandType->kind != TypeKindComposite) {
|
||||||
print_diagnostic(current_file, &lhs->nodePtr->location, Error, "Must be a type variant of int");
|
print_diagnostic(&lhs->nodePtr->location, Error, "Must be a type variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RightOperandType->kind != TypeKindPrimitive && RightOperandType->kind != TypeKindComposite) {
|
if (RightOperandType->kind != TypeKindPrimitive && RightOperandType->kind != TypeKindComposite) {
|
||||||
print_diagnostic(current_file, &rhs->nodePtr->location, Error, "Must be a type variant of int");
|
print_diagnostic(&rhs->nodePtr->location, Error, "Must be a type variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LeftOperandType->kind == TypeKindPrimitive && RightOperandType->kind == TypeKindPrimitive) {
|
if (LeftOperandType->kind == TypeKindPrimitive && RightOperandType->kind == TypeKindPrimitive) {
|
||||||
|
|
||||||
if (LeftOperandType->impl.primitive == Float) {
|
if (LeftOperandType->impl.primitive == Float) {
|
||||||
print_diagnostic(current_file, &lhs->nodePtr->location, Error, "Must be a type variant of int");
|
print_diagnostic(&lhs->nodePtr->location, Error, "Must be a type variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RightOperandType->impl.primitive == Float) {
|
if (RightOperandType->impl.primitive == Float) {
|
||||||
print_diagnostic(current_file, &rhs->nodePtr->location, Error, "Must be a type variant of int");
|
print_diagnostic(&rhs->nodePtr->location, Error, "Must be a type variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1013,12 +1012,12 @@ int createBitOperation(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
} else if (LeftOperandType->kind == TypeKindPrimitive && RightOperandType->kind == TypeKindComposite) {
|
} else if (LeftOperandType->kind == TypeKindPrimitive && RightOperandType->kind == TypeKindComposite) {
|
||||||
|
|
||||||
if (LeftOperandType->impl.primitive == Float) {
|
if (LeftOperandType->impl.primitive == Float) {
|
||||||
print_diagnostic(current_file, &lhs->nodePtr->location, Error, "Must be a type variant of int");
|
print_diagnostic(&lhs->nodePtr->location, Error, "Must be a type variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RightOperandType->impl.composite.primitive == Float) {
|
if (RightOperandType->impl.composite.primitive == Float) {
|
||||||
print_diagnostic(current_file, &rhs->nodePtr->location, Error, "Must be a type variant of int");
|
print_diagnostic(&rhs->nodePtr->location, Error, "Must be a type variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1028,12 +1027,12 @@ int createBitOperation(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
} else if (LeftOperandType->kind == TypeKindComposite && RightOperandType->kind == TypeKindPrimitive) {
|
} else if (LeftOperandType->kind == TypeKindComposite && RightOperandType->kind == TypeKindPrimitive) {
|
||||||
|
|
||||||
if (LeftOperandType->impl.composite.primitive == Float) {
|
if (LeftOperandType->impl.composite.primitive == Float) {
|
||||||
print_diagnostic(current_file, &lhs->nodePtr->location, Error, "Must be a type variant of int");
|
print_diagnostic(&lhs->nodePtr->location, Error, "Must be a type variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RightOperandType->impl.primitive == Float) {
|
if (RightOperandType->impl.primitive == Float) {
|
||||||
print_diagnostic(current_file, &rhs->nodePtr->location, Error, "Must be a type variant of int");
|
print_diagnostic(&rhs->nodePtr->location, Error, "Must be a type variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1042,17 +1041,17 @@ int createBitOperation(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (RightOperandType->impl.composite.primitive == Float) {
|
if (RightOperandType->impl.composite.primitive == Float) {
|
||||||
print_diagnostic(current_file, &rhs->nodePtr->location, Error, "Must be a type variant of int");
|
print_diagnostic(&rhs->nodePtr->location, Error, "Must be a type variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LeftOperandType->impl.composite.primitive == Float) {
|
if (LeftOperandType->impl.composite.primitive == Float) {
|
||||||
print_diagnostic(current_file, &lhs->nodePtr->location, Error, "Must be a type variant of int");
|
print_diagnostic(&lhs->nodePtr->location, Error, "Must be a type variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isScaleEqual(LeftOperandType->impl.composite.scale, RightOperandType->impl.composite.scale)) {
|
if (!isScaleEqual(LeftOperandType->impl.composite.scale, RightOperandType->impl.composite.scale)) {
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Operands must be of equal size");
|
print_diagnostic(¤tNode->location, Error, "Operands must be of equal size");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1103,7 +1102,7 @@ int createBitNotOperation(Expression *ParentExpression, AST_NODE_PTR currentNode
|
||||||
if (Operand->kind == TypeKindPrimitive) {
|
if (Operand->kind == TypeKindPrimitive) {
|
||||||
|
|
||||||
if (Operand->impl.primitive == Float) {
|
if (Operand->impl.primitive == Float) {
|
||||||
print_diagnostic(current_file, &Operand->nodePtr->location, Error, "Operand type must be a variant of int");
|
print_diagnostic(&Operand->nodePtr->location, Error, "Operand type must be a variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1112,7 +1111,7 @@ int createBitNotOperation(Expression *ParentExpression, AST_NODE_PTR currentNode
|
||||||
} else if (Operand->kind == TypeKindComposite) {
|
} else if (Operand->kind == TypeKindComposite) {
|
||||||
|
|
||||||
if (Operand->impl.composite.primitive == Float) {
|
if (Operand->impl.composite.primitive == Float) {
|
||||||
print_diagnostic(current_file, &Operand->nodePtr->location, Error, "Operand type must be a variant of int");
|
print_diagnostic(&Operand->nodePtr->location, Error, "Operand type must be a variant of int");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1192,7 +1191,7 @@ int createBoxAccess(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
int status = getVariableFromScope(boxname, &boxVariable);
|
int status = getVariableFromScope(boxname, &boxVariable);
|
||||||
|
|
||||||
if (status == SEMANTIC_ERROR) {
|
if (status == SEMANTIC_ERROR) {
|
||||||
print_diagnostic(current_file, ¤tNode->children[0]->location, Error,
|
print_diagnostic(¤tNode->children[0]->location, Error,
|
||||||
"Variable of name `%s` does not exist");
|
"Variable of name `%s` does not exist");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -1258,7 +1257,7 @@ int createTypeCast(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
Type *target = mem_alloc(MemoryNamespaceSet, sizeof(Type));
|
Type *target = mem_alloc(MemoryNamespaceSet, sizeof(Type));
|
||||||
int status = set_get_type_impl(currentNode->children[1], &target);
|
int status = set_get_type_impl(currentNode->children[1], &target);
|
||||||
if (status) {
|
if (status) {
|
||||||
print_diagnostic(current_file, ¤tNode->children[1]->location, Error, "Unknown type");
|
print_diagnostic(¤tNode->children[1]->location, Error, "Unknown type");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
ParentExpression->impl.typecast.targetType = target;
|
ParentExpression->impl.typecast.targetType = target;
|
||||||
|
@ -1277,7 +1276,7 @@ int createTransmute(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
Type *target = mem_alloc(MemoryNamespaceSet, sizeof(Type));
|
Type *target = mem_alloc(MemoryNamespaceSet, sizeof(Type));
|
||||||
int status = set_get_type_impl(currentNode->children[1], &target);
|
int status = set_get_type_impl(currentNode->children[1], &target);
|
||||||
if (status) {
|
if (status) {
|
||||||
print_diagnostic(current_file, ¤tNode->children[1]->location, Error, "Unknown type");
|
print_diagnostic(¤tNode->children[1]->location, Error, "Unknown type");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1302,7 +1301,7 @@ int createDeref(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
Type *indexType = deref.index->result;
|
Type *indexType = deref.index->result;
|
||||||
//indexType can only be a composite or a primitive
|
//indexType can only be a composite or a primitive
|
||||||
if (indexType->kind != TypeKindComposite && indexType->kind != TypeKindPrimitive) {
|
if (indexType->kind != TypeKindComposite && indexType->kind != TypeKindPrimitive) {
|
||||||
print_diagnostic(current_file, &AST_get_node(currentNode, 1)->location, Error,
|
print_diagnostic(&AST_get_node(currentNode, 1)->location, Error,
|
||||||
"Index must a primitive int or composite variation");
|
"Index must a primitive int or composite variation");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -1310,7 +1309,7 @@ int createDeref(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
//indexType can only be int
|
//indexType can only be int
|
||||||
if (indexType->kind == TypeKindPrimitive) {
|
if (indexType->kind == TypeKindPrimitive) {
|
||||||
if (indexType->impl.primitive != Int) {
|
if (indexType->impl.primitive != Int) {
|
||||||
print_diagnostic(current_file, &AST_get_node(currentNode, 1)->location, Error,
|
print_diagnostic(&AST_get_node(currentNode, 1)->location, Error,
|
||||||
"Index must a primitive int or composite variation");
|
"Index must a primitive int or composite variation");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -1318,7 +1317,7 @@ int createDeref(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
|
|
||||||
if (indexType->kind == TypeKindComposite) {
|
if (indexType->kind == TypeKindComposite) {
|
||||||
if (indexType->impl.composite.primitive != Int) {
|
if (indexType->impl.composite.primitive != Int) {
|
||||||
print_diagnostic(current_file, &AST_get_node(currentNode, 1)->location, Error,
|
print_diagnostic(&AST_get_node(currentNode, 1)->location, Error,
|
||||||
"Index must a primitive int or composite variation");
|
"Index must a primitive int or composite variation");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -1328,13 +1327,13 @@ int createDeref(Expression *ParentExpression, AST_NODE_PTR currentNode) {
|
||||||
|
|
||||||
//variable has to be made
|
//variable has to be made
|
||||||
if (deref.index == NULL) {
|
if (deref.index == NULL) {
|
||||||
print_diagnostic(current_file, &AST_get_node(currentNode, 0)->location, Error, "Invalid index");
|
print_diagnostic(&AST_get_node(currentNode, 0)->location, Error, "Invalid index");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
//variable can only be a reference
|
//variable can only be a reference
|
||||||
if (deref.variable->result->kind != TypeKindReference) {
|
if (deref.variable->result->kind != TypeKindReference) {
|
||||||
print_diagnostic(current_file, &AST_get_node(currentNode, 0)->location, Error,
|
print_diagnostic(&AST_get_node(currentNode, 0)->location, Error,
|
||||||
"Only references can be dereferenced");
|
"Only references can be dereferenced");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -1389,7 +1388,7 @@ Expression *createExpression(AST_NODE_PTR currentNode) {
|
||||||
int status = getVariableFromScope(currentNode->value, &(expression->impl.variable));
|
int status = getVariableFromScope(currentNode->value, &(expression->impl.variable));
|
||||||
if (status == SEMANTIC_ERROR) {
|
if (status == SEMANTIC_ERROR) {
|
||||||
DEBUG("Identifier is not in current scope");
|
DEBUG("Identifier is not in current scope");
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Variable not found");
|
print_diagnostic(¤tNode->location, Error, "Variable not found");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
switch (expression->impl.variable->kind) {
|
switch (expression->impl.variable->kind) {
|
||||||
|
@ -1563,7 +1562,7 @@ int createAssign(Statement *ParentStatement, AST_NODE_PTR currentNode) {
|
||||||
|
|
||||||
bool result = compareTypes(varType, assign.value->result);
|
bool result = compareTypes(varType, assign.value->result);
|
||||||
if (result == FALSE) {
|
if (result == FALSE) {
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Assignment expression has incompatible type");
|
print_diagnostic(¤tNode->location, Error, "Assignment expression has incompatible type");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1719,7 +1718,7 @@ int createfuncall(Statement *parentStatement, AST_NODE_PTR currentNode) {
|
||||||
if (nameNode->kind == AST_Ident) {
|
if (nameNode->kind == AST_Ident) {
|
||||||
int result = getFunction(nameNode->value, &fun);
|
int result = getFunction(nameNode->value, &fun);
|
||||||
if (result == SEMANTIC_ERROR) {
|
if (result == SEMANTIC_ERROR) {
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Unknown function: `%s`", nameNode);
|
print_diagnostic(¤tNode->location, Error, "Unknown function: `%s`", nameNode);
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1735,7 +1734,7 @@ int createfuncall(Statement *parentStatement, AST_NODE_PTR currentNode) {
|
||||||
|
|
||||||
int result = getFunction(name, &fun);
|
int result = getFunction(name, &fun);
|
||||||
if (result) {
|
if (result) {
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Unknown function: `%s`", nameNode);
|
print_diagnostic(¤tNode->location, Error, "Unknown function: `%s`", nameNode);
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1756,7 +1755,7 @@ int createfuncall(Statement *parentStatement, AST_NODE_PTR currentNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count != paramCount) {
|
if (count != paramCount) {
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Expected %d arguments instead of %d", paramCount,
|
print_diagnostic(¤tNode->location, Error, "Expected %d arguments instead of %d", paramCount,
|
||||||
count);
|
count);
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -1920,7 +1919,7 @@ int createParam(GArray *Paramlist, AST_NODE_PTR currentNode) {
|
||||||
paramvar->impl.declaration.type = param.impl.declaration.type;
|
paramvar->impl.declaration.type = param.impl.declaration.type;
|
||||||
|
|
||||||
if (g_hash_table_contains(functionParameter, param.name)) {
|
if (g_hash_table_contains(functionParameter, param.name)) {
|
||||||
print_diagnostic(current_file, ¶m.nodePtr->location, Error, "Names of function parameters must be unique");
|
print_diagnostic(¶m.nodePtr->location, Error, "Names of function parameters must be unique");
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
g_hash_table_insert(functionParameter, (gpointer) param.name, paramvar);
|
g_hash_table_insert(functionParameter, (gpointer) param.name, paramvar);
|
||||||
|
@ -2003,7 +2002,7 @@ bool compareParameter(GArray *leftParameter, GArray *rightParameter) {
|
||||||
int addFunction(const char *name, Function *function) {
|
int addFunction(const char *name, Function *function) {
|
||||||
if (function->kind == FunctionDefinitionKind) {
|
if (function->kind == FunctionDefinitionKind) {
|
||||||
if (g_hash_table_contains(definedFunctions, name)) {
|
if (g_hash_table_contains(definedFunctions, name)) {
|
||||||
print_diagnostic(current_file, &function->nodePtr->location, Error, "Multiple definition of function: `%s`", function->name);
|
print_diagnostic(&function->nodePtr->location, Error, "Multiple definition of function: `%s`", function->name);
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
g_hash_table_insert(declaredFunctions, (gpointer) name, function);
|
g_hash_table_insert(declaredFunctions, (gpointer) name, function);
|
||||||
|
@ -2014,7 +2013,7 @@ int addFunction(const char *name, Function *function) {
|
||||||
function->impl.declaration.parameter);
|
function->impl.declaration.parameter);
|
||||||
// a function can have multiple declartations but all have to be identical
|
// a function can have multiple declartations but all have to be identical
|
||||||
if (result == FALSE) {
|
if (result == FALSE) {
|
||||||
print_diagnostic(current_file, &function->nodePtr->location, Error, "Divergent declaration of function: `%s`", function->name);
|
print_diagnostic(&function->nodePtr->location, Error, "Divergent declaration of function: `%s`", function->name);
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2133,7 +2132,7 @@ int createDefMember(BoxType *ParentBox, AST_NODE_PTR currentNode) {
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression *init = createExpression(expressionNode);;
|
Expression *init = createExpression(expressionNode);
|
||||||
if (init == NULL) {
|
if (init == NULL) {
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -2195,10 +2194,6 @@ int createBox(GHashTable *boxes, AST_NODE_PTR currentNode) {
|
||||||
for (size_t i = 0; boxMemberList->child_count; i++) {
|
for (size_t i = 0; boxMemberList->child_count; i++) {
|
||||||
switch (boxMemberList->children[i]->kind) {
|
switch (boxMemberList->children[i]->kind) {
|
||||||
case AST_Decl:
|
case AST_Decl:
|
||||||
if (createDeclMember(box, boxMemberList->children[i])) {
|
|
||||||
return SEMANTIC_ERROR;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case AST_Def:
|
case AST_Def:
|
||||||
if (createDeclMember(box, boxMemberList->children[i])) {
|
if (createDeclMember(box, boxMemberList->children[i])) {
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
|
@ -2240,14 +2235,14 @@ int createTypeDef(GHashTable *types, AST_NODE_PTR currentNode) {
|
||||||
def->type = type;
|
def->type = type;
|
||||||
|
|
||||||
if (g_hash_table_contains(types, (gpointer) def->name)) {
|
if (g_hash_table_contains(types, (gpointer) def->name)) {
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Multiple definition of type: `%s`",
|
print_diagnostic(¤tNode->location, Error, "Multiple definition of type: `%s`",
|
||||||
nameNode->value);
|
nameNode->value);
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
g_hash_table_insert(types, (gpointer) def->name, def);
|
g_hash_table_insert(types, (gpointer) def->name, def);
|
||||||
|
|
||||||
if (g_hash_table_contains(declaredComposites, (gpointer) def->name)) {
|
if (g_hash_table_contains(declaredComposites, (gpointer) def->name)) {
|
||||||
print_diagnostic(current_file, ¤tNode->location, Error, "Multiple definition of type: `%s`",
|
print_diagnostic(¤tNode->location, Error, "Multiple definition of type: `%s`",
|
||||||
nameNode->value);
|
nameNode->value);
|
||||||
return SEMANTIC_ERROR;
|
return SEMANTIC_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -2334,7 +2329,7 @@ Module *create_set(AST_NODE_PTR currentNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_hash_table_contains(functions, function->name)) {
|
if (g_hash_table_contains(functions, function->name)) {
|
||||||
print_diagnostic(current_file, &function->impl.definition.nodePtr->location, Error,
|
print_diagnostic(&function->impl.definition.nodePtr->location, Error,
|
||||||
"Multiple definition of function: `%s`", function->name);
|
"Multiple definition of function: `%s`", function->name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
extern int yylex();
|
extern int yylex();
|
||||||
extern AST_NODE_PTR root;
|
extern AST_NODE_PTR root;
|
||||||
|
|
||||||
#define new_loc() new_location(yylloc.first_line, yylloc.first_column, yylloc.last_line, yylloc.last_column)
|
#define new_loc() new_location(yylloc.first_line, yylloc.first_column, yylloc.last_line, yylloc.last_column, current_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
%union {
|
%union {
|
||||||
|
@ -544,6 +544,6 @@ opbit: expr OpBitand expr {AST_NODE_PTR and = AST_new_node(new_loc(), AST_BitAnd
|
||||||
|
|
||||||
int yyerror(const char *s) {
|
int yyerror(const char *s) {
|
||||||
TokenLocation location = new_loc();
|
TokenLocation location = new_loc();
|
||||||
print_diagnostic(current_file, &location, Error, s);
|
print_diagnostic(&location, Error, s);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue