F diff --git a/.denoted.h.swp b/.denoted.h.swp
deleted file mode 100644
B Binary files a/.denoted.h.swp and /dev/null differ
F diff --git a/.exrc b/.exrc
deleted file mode 100644
--- a/.exrc
+++ /dev/null
- if &cp | set nocp | endif
- let s:cpo_save=&cpo
- set cpo&vim
- vmap gx <Plug>NetrwBrowseXVis
- nmap gx <Plug>NetrwBrowseX
- vnoremap <silent> <Plug>NetrwBrowseXVis :call netrw#BrowseXVis()
- nnoremap <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>')),netrw#CheckIfRemote())
- map <F4> :r !timestamp<NL>
- map <F6> :set keymap=<NL>
- map <F5> :set keymap=bulgarian-phonetic<NL>
- imap l <F6>
- imap ; <F5>
- let &cpo=s:cpo_save
- unlet s:cpo_save
- set background=dark
- set backspace=indent,eol,start
- set cindent
- set fileencodings=ucs-bom,utf-8,default,latin1
- set helplang=en
- set nomodeline
- set printoptions=paper:letter
- set ruler
- set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim81,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
- set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc
- " vim: set ft=vim :
F diff --git a/.parse_declaration.c.swp b/.parse_declaration.c.swp
deleted file mode 100644
B Binary files a/.parse_declaration.c.swp and /dev/null differ
F diff --git a/all.h b/all.h
--- a/all.h
+++ b/all.h
#include "lexer.h"
#include "program.h"
#include "scope.h"
+ #include "denoted.h"
#include "type.h"
#include "parse_declaration.h"
- #include "ast.h"
#include "parse_expression.h"
#include "parse_statement.h"
#include "parse_translation_unit.h"
+ #include "ast.h"
#include "semantics.h"
+ #include "lexer.c"
+ #include "program.c"
+ #include "scope.c"
+ #include "denoted.c"
+ #include "type.c"
+ #include "parse_declaration.c"
#include "parse_expression.c"
#include "parse_statement.c"
- #include "parse_declaration.c"
#include "parse_translation_unit.c"
#include "ast.c"
- #include "scope.c"
- #include "lexer.c"
- #include "print.c"
- #include "type.c"
#include "semantics.c"
- #include "program.c"
-
-
-
-
-
-
#endif
F diff --git a/denoted.c b/denoted.c
--- a/denoted.c
+++ b/denoted.c
ret->denotation=DT_Error;
ret->error=error;
- return error;
+ return (struct Denoted*)ret;
}
struct Denoted_Function* get_denoted_function(struct Type *type)
{
ret->type=type;
ret->body=NULL;
- return ret;
+ return (struct Denoted*)ret;
}
struct Denoted_Object* get_denoted_object(struct Type *type)
{
ret->type=type;
ret->location=NULL;
- return ret;
+ return (struct Denoted*)ret;
}
struct Denoted_Typedef* get_denoted_typedef(struct token* id,struct Type *typedefed)
ret->type=typedefed;
ret->id=id;
- return ret;
+ return (struct Denoted*)ret;
}
struct Denoted_Enum_Const* get_denoted_enum_const(struct token *id,struct Type_Enum *parent,int value)
ret->parent=parent;
ret->value=value;
- return ret;
+ return (struct Denoted*)ret;
}
struct Denoted_Struct_Union_Member* get_denoted_struct_union_member(struct token *id,struct Type *type,size_t offset)
ret->type=type;
ret->offset=offset;
- return ret;
+ return (struct Denoted*)ret;
}
+ struct Denoted* get_denoted_struct_union(struct token *id,struct Struct_Union *struct_union)
+ {
+ struct Denoted_Struct_Union *ret;
+ ret=malloc(sizeof(struct Denoted_Struct_Union));
+ ret->denotation=DT_Struct_Union_Tag;
+ ret->id=id;
+ ret->struct_union=struct_union;
+ return (struct Denoted*)ret;
+ }
#endif
F diff --git a/denoted.h b/denoted.h
--- a/denoted.h
+++ b/denoted.h
DT_Function,
DT_Enum_Constant,
DT_Struct_Union_Member,
+ DT_Struct_Union_Tag,
DT_Error
};
+ enum Function_Specifier
+ {
+ TFS_Inline,
+ TFS_None
+ };
+ enum Storage_Class
+ {
+ TSC_EXTERN,
+ TSC_STATIC,
+ TSC_NONE
+ };
struct Denoted
{
enum Denotation_Type denotation;
};
- struct Declarator
- {
- struct Denoted *thing;
- struct token *id;
- };
struct Denoted_Error
{
enum Denotation_Type denotation;
struct Denoted *error;
- }
+ };
struct Denoted_Function
{
enum Denotation_Type denotation;
+ enum Function_Specifier function_specifier;
struct Type *type;
struct AST_Compound_Statement *body;
struct Denoted_Object
{
enum Denotation_Type denotation;
-
- enum Type_Storage_Class storage_class;
- struct Type *type;
- struct Location *location;
+ struct token *id;
+ struct Object *object;
};
struct Denoted_Typedef
{
size_t offset;
struct token *id;
};
+ struct Denoted_Struct_Union
+ {
+ enum Denotation_Type denotation;
+ struct token *id;
+ struct Struct_Union *struct_union;
+ };
+
+ struct Denotation_Prototype
+ {
+ enum Storage_Class storage_class;
+ enum Type_Constraint constraint;
+ enum Type_Signedness sign;
+ size_t size;
+ char is_const:1;
+ char is_volatile:1;
+ };
+ struct Object
+ {
+ struct Type *type;
+ struct Location *location;
+ enum Storage_Class storage_class;
+ };
+
+ struct Denoted* get_denoted_error(struct Denoted *error);
+ struct Denoted* get_denoted_function(struct Type *type);
+ struct Denoted* get_denoted_object(struct Type *type);
+ struct Denoted* get_denoted_typedef(struct token* id,struct Type *typedefed);
+ struct Denoted* get_denoted_enum_const(struct token *id,struct Type_Enum *parent,int value);
+ struct Denoted* get_denoted_struct_union_member(struct token *id,struct Type *type,size_t offset);
+ struct Denoted* get_denoted_struct_union(struct token *id,struct Struct_Union *struct_union);
+ struct Object_Prototype* get_denotation_prototype();
#endif
F diff --git a/parse_declaration.c b/parse_declaration.c
--- a/parse_declaration.c
+++ b/parse_declaration.c
alignment-specifier [ declaration-specifiers ]
*/
- struct Type_Node* parse_declaration_specifiers(struct Queue *tokens,struct Scope *scope)
+ struct Denoted* parse_declaration_specifiers(struct Queue *tokens,struct Scope *scope)
{
- struct Type_Prototype *hold;
+ struct Object_Prototype *hold;
enum KEYWORDS kw;
- hold=get_type_prototype();
+ hold=(struct Object_Prototype*)get_object_prototype();
for(kw=kw_get(tokens);tokens->size>0;chomp(tokens),kw=kw_get(tokens))
{
switch(kw)
{
case KW_CONST:
- base->is_const=1;
+ hold->is_const=1;
break;
case KW_VOLATILE:
- base->is_volatile=1;
+ hold->is_volatile=1;
break;
case KW_STATIC:
- base->is_static=1;
+ if(hold->storage_class==TSC_NONE)
+ {
+ hold->storage_class=TSC_STATIC;
+ }else
+ {
+ return get_denoted_error(get_denoted_object((struct Type*)hold));
+ }
break;
case KW_EXTERN:
- base->is_extern=1;
+ if(hold->storage_class==TSC_NONE)
+ {
+ hold->storage_class=TSC_EXTERN;
+ }else
+ {
+ return get_denoted_error(get_denoted_object((struct Type*)hold));
+ }
break;
case KW_INT:
- if(base->type_specifier!=TS_NONE)
+ if(hold->specifier!=TS_NONE)
{
- base->error=1;
- return base;
+ return get_denoted_error(get_denoted_object((struct Type*)hold));
}
- base->type_specifier=TS_INT;
+ hold->specifier=TS_INT;
break;
case KW_CHAR:
- if(base->type_specifier!=TS_NONE)
+ if(hold->specifier!=TS_NONE)
{
- base->error=1;
- return base;
+ return get_denoted_error(get_denoted_object((struct Type*)hold));
}
- base->type_specifier=TS_CHAR;
+ hold->specifier=TS_CHAR;
break;
case KW_VOID:
- if(base->type_specifier!=TS_NONE)
+ if(hold->specifier!=TS_NONE)
{
- base->error=1;
- return base;
+ return get_denoted_error(get_denoted_object((struct Type*)hold));
}
- base->type_specifier=TS_VOID;
+ hold->specifier=TS_VOID;
break;
case KW_DOUBLE:
- if(base->type_specifier!=TS_NONE)
+ if(hold->specifier!=TS_NONE)
{
- base->error=1;
- return base;
+ return get_denoted_error(get_denoted_object((struct Type*)hold));
}
- base->type_specifier=TS_DOUBLE;
+ hold->specifier=TS_DOUBLE;
break;
case KW_FLOAT:
- if(base->type_specifier!=TS_NONE)
+ if(hold->specifier!=TS_NONE)
{
- base->error=1;
- return base;
+ return get_denoted_error(get_denoted_object((struct Type*)hold));
}
- base->type_specifier=TS_FLOAT;
+ hold->specifier=TS_FLOAT;
break;
case KW_UNION:
case KW_STRUCT:
if(check(tokens,KW_ID,1) )
{
/*this struct might already have been defined*/
+ struct Denoted_Struct_Union *hold_su;
+ struct token *tag=tokens->first->prev->data;
+ hold_su=check_tag(scope,tag);
- hold_type=check_tag(scope,tokens->first->prev->data);
- if(hold_type!=NULL)
+ if(hold_su==NULL)
{
- return check_first_type_component(hold_type);
+ /*this tag isn't taken*/
+ /*denote an incomplete struct/union type*/
+ hold_su=get_denoted_struct_union(tag,get_struct_union());
+
}
- hold=parse_struct_union_specifier(tokens,scope);
- merge_type_nodes(base,hold);
- return base;
+ /*consume struct/union tag*/
+ chomp(tokens);
+ return get_denoted_object(get_struct_union_type(hold,hold_su->struct_union));
}else if(check(tokens,KW_OPEN_CURLY,1))
{
- /*this is a definition of an anonymous struct*/
- hold=parse_struct_union_specifier(tokens,scope);
- merge_type_nodes(base,hold);
- return base;
+ /*this is a definition of an anonymous struct/union*/
+ return get_denoted_struct_union(NULL,parse_struct_union_specifier(tokens,scope))
}else
{
- base->error=1;
- return base;
+ return get_denoted_error(get_denoted_object((struct Type*)hold));
}
case KW_TYPEDEF:
- base->is_typedef=1;
+ hold->is_typedef=1;
break;
case KW_ID:
- if(base->type_specifier==TS_NONE && check_if_typedefed(scope,tokens->first->data))
+ if(hold->specifier==TS_NONE && check_if_typedefed(scope,tokens->first->data))
{
- base->type_def=check_ordinary(scope,tokens->first->data);
- merge_type_nodes(base,check_base_type_component(base->type_def));
+ hold->type_def=check_ordinary(scope,tokens->first->data);
+ merge_type_nodes(base,check_base_type_component(hold->type_def));
break;
}else
{
F diff --git a/parse_declaration.h b/parse_declaration.h
--- a/parse_declaration.h
+++ b/parse_declaration.h
#include "ast.h"
#include "parse_expression.h"
#include "type.h"
+ #include "denoted.h"
#include "scope.h"
#include "queue.c"
#include "map.c"
#include "lexer.h"
#include <assert.h>
+ struct Denoted;
+ struct AST;
+ struct Scope;
struct AST* parse_declaration(struct Queue *tokens,struct Scope *scope);
- void parse_declarator(struct Queue *tokens,struct Declarator *base,struct Scope *scope);
- void parse_direct_declarator(struct Queue *tokens,struct Declarator *upper,struct Scope *scope);
- void parse_abstract_declarator(struct Queue *tokens,struct Declarator *base,struct Scope *scope);
- void parse_direct_abstract_declarator(struct Queue *tokens,struct Declarator *upper,struct Scope *scope);
- void parse_pointer(struct Queue *tokens,struct Declarator *upper,struct Scope *scope);
- struct Declarator* parse_init_declarator(struct Queue *tokens,struct Type_Node *base,struct Scope *scope);
+ void parse_declarator(struct Queue *tokens,struct Denoted *base,struct Scope *scope);
+ void parse_direct_declarator(struct Queue *tokens,struct Denoted *upper,struct Scope *scope);
+ void parse_abstract_declarator(struct Queue *tokens,struct Denoted *base,struct Scope *scope);
+ void parse_direct_abstract_declarator(struct Queue *tokens,struct Denoted *upper,struct Scope *scope);
+ void parse_pointer(struct Queue *tokens,struct Denoted *upper,struct Scope *scope);
+ struct Denoted* parse_init_declarator(struct Queue *tokens,struct Type_Node *base,struct Scope *scope);
struct AST* parse_initialiser(struct Queue *tokens,struct Scope *scope);
- struct Type_Node* parse_declaration_specifiers(struct Queue *tokens,struct Scope *scope);
+ struct Denoted* parse_declaration_specifiers(struct Queue *tokens,struct Scope *scope);
struct Type_Node* parse_specifier_qualifier_list(struct Queue *tokens,struct Scope *scope);
void parse_parameter_type_list(struct Queue *tokens,struct Type_Node *function_base,struct Scope *scope);
void parse_parameter_list(struct Queue *tokens,struct Type_Node *function_base,struct Scope *scope);
struct Type* parse_type_name(struct Queue *tokens,struct Scope *scope);
- void parse_struct_declarator(struct Queue *tokens,struct Declarator *base,struct Scope *scope);
+ void parse_struct_declarator(struct Queue *tokens,struct Denoted *base,struct Scope *scope);
void parse_struct_declarator_list(struct Queue *tokens,struct Queue *declarators,struct Type_Node *base_type,struct Scope *scope);
void parse_struct_declaration(struct Queue *tokens,struct Type_Node *struct_union_base,struct Scope *scope);
void parse_struct_declaration_list(struct Queue *tokens,struct Type_Node *struct_union_base,struct Scope *scope);
- struct Type_Node* parse_struct_union_specifier(struct Queue *tokens,struct Scope *scope);
+ struct Struct_Union* parse_struct_union_specifier(struct Queue *tokens,struct Scope *scope);
char is_type(struct Queue *tokens,struct Scope *scope);
struct Type_Node* get_node();
struct Type* get_type();
- struct Declarator* get_declarator(struct Type_Node *base_type);
+ struct Denoted* get_declarator(struct Type_Node *base_type);
#endif
F diff --git a/scope.c b/scope.c
--- a/scope.c
+++ b/scope.c
return hold;
}
- void* check_tag(struct Scope *current,struct token *id)
+ struct Denoted_Struct_Union* check_tag(struct Scope *current,struct token *id)
{
void *hold;
hold=NULL;
hold=Map_Check(¤t->tags,id->data,id->data_size);
current=current->parent;
}
- return hold;
+ return (struct Denoted_Struct_Union*)hold;
}
void* check_ordinary(struct Scope *current,struct token *id)
{
F diff --git a/scope.h b/scope.h
--- a/scope.h
+++ b/scope.h
#ifndef GCC_SCOPE_H
#define GCC_SCOPE_H GCC_SCOPE_H
#include "map.c"
- #include "parse_declaration.h"
+ #include "denoted.h"
struct Scope
{
Map labels;
+
Map tags;
+ /*In go denoted*/
Map ordinary;
+
struct Scope *parent;
};
void* check_label(struct Scope *current,struct token *id);
void* check_tag(struct Scope *current,struct token *id);
void* check_ordinary(struct Scope *current,struct token *id);
- char Scope_Push(struct Scope *scope,struct Declarator *declarator);
+ char Scope_Push(struct Scope *scope,struct Denoted* denoted);
char check_if_typedefed(struct Scope* scope,struct token *id);
#endif
F diff --git a/type.c b/type.c
--- a/type.c
+++ b/type.c
return ret;
}
- struct Type_Prototype* get_type_prototype()
+ struct Object_Prototype* get_object_prototype()
{
struct Type_Prototype *ret;
ret=malloc(sizeof(struct Type_Prototype));
- ret->type_specifier=TS_NONE;
+ ret->specifier=TS_NONE;
ret->size=0;
ret->is_const=ret->is_volatile=0;
ret->storage_class=TSC_NONE;
return ret;
}
/*could return error */
- struct Type* get_struct_union(struct Type_Prototype *prototype,struct token *id,enum Type_Specifier ts)
+ struct Type* get_struct_union_type(struct Denotation_Prototype *prototype,struct Struct_Union *base)
{
struct Type_Struct_Union *ret;
ret->specifier=ts;
ret->size=prototype->size;
- ret->number_of_members=0;
- ret->members=NULL;
+ ret->struct_union=base;
ret->inner_namespace=get_scope(NULL);
ret->id=id;
return (struct Type*)ret;
}
}
+ struct Struct_Union* get_struct_union_base()
+ {
+ struct Struct_Union *ret;
+ ret=malloc(sizeof(struct Struct_Union));
+ ret->number_of_members=0;
+ ret->members=NULL;
+ ret->inner_namespace=NULL;
+
+ return ret;
+ }
/*could return error*/
- struct Type* get_basic_type(struct Type_Prototype *prototype)
+ struct Type* get_basic_type(struct Denotation_Prototype *prototype)
{
struct Type_Basic *ret;
ret=malloc(sizeof(struct Type_Basic));
F diff --git a/type.h b/type.h
--- a/type.h
+++ b/type.h
#ifndef GCC_TYPE_H
#define GCC_TYPE_H GCC_TYPE_H
- #include "queue.c"
- #include "map.c"
+ #include "denoted.h"
#include "scope.h"
#include <limits.h>
+ struct Denotation_Prototype;
enum Type_Specifier
{
TC_SHORT,
TC_NONE
};
- enum Type_Storage_Class
- {
- TSC_EXTERN,
- TSC_STATIC,
- TSC_NONE
- };
enum Type_Signedness
{
TSIGN_SIGNED,
enum Type_Specifier specifier;
struct Type *error;
};
- struct Type_Prototype
+
+ struct Type_Struct_Union
{
enum Type_Specifier specifier;
- enum Type_Storage_Class storage_class;
- enum Type_Constraint constraint;
- enum Type_Signedness sign;
- size_t size;
+ struct Struct_Union *struct_union;
+
char is_const:1;
char is_volatile:1;
- struct Type *points_to;
};
- struct Type_Struct_Union
+ struct Struct_Union
{
- enum Type_Specifier specifier;
size_t size;
-
size_t number_of_members;
struct Denoted_Struct_Union_Member **members;
struct Scope *inner_namespace;
- struct token *id;
- char is_const:1;
- char is_volatile:1;
};
struct Type_Basic
{
enum Type_Specifier specifier;
- enum Type_Storage_Class storage_class;
enum Type_Constraint constraint;
enum Type_Signedness sign;
size_t size;
struct Type_Pointer
{
enum Type_Specifier specifier;
- enum Type_Storage_Class storage_class;
size_t size;
struct Type *points_to;
char is_const:1;
struct Type_Array
{
enum Type_Specifier specifier;
- enum Type_Storage_Class storage_class;
size_t size;
size_t number_of_elements;
struct Type *is_array_of;
enum Type_Specifier specifier;
struct Type *return_type;
- struct Declarator **parameters;
+ struct Denoted_Object **parameters;
size_t number_of_parameters;
};
struct Type_Enum
struct Denoted_Enum_Const **consts;
struct token *id;
};
- struct Type_Error* get_type_error(struct Type* error);
- struct Type_Prototype* get_type_prototype();
- struct Type* get_struct_union(struct Type_Prototype *prototype,struct token *id,enum Type_Specifier ts);
- struct Type* get_basic_type(struct Type_Prototype *prototype);
+
+ struct Type* get_type_error(struct Type* error);
+ struct Type* get_struct_union_type(struct Denotation_Prototype *prototype,struct Struct_Union *base);
+ struct Struct_Union* get_struct_union_base();
+ struct Type* get_basic_type(struct Denotation_Prototype *prototype);
struct Type* get_pointer_type(struct Type* points_to);
struct Type* get_array_type(struct Type *is_array_of);
struct Type* get_enum_type(struct token *id);