Skip to content
Snippets Groups Projects
Commit da6f3c31 authored by zhaochaoyi's avatar zhaochaoyi
Browse files

Lab2-tey remove VarList and fix bug:FunDec varlist type

parent 8b5f23f7
No related branches found
No related tags found
No related merge requests found
......@@ -2,11 +2,7 @@
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="true">
<option name="clangTidyCheckOptions">
<list>
<ClangTidyCheckOption />
</list>
</option>
<option name="clangTidyChecks" value="-*,bugprone-argument-comment,bugprone-assert-side-effect,bugprone-bad-signal-to-kill-thread,bugprone-branch-clone,bugprone-copy-constructor-init,bugprone-dangling-handle,bugprone-dynamic-static-initializers,bugprone-fold-init-type,bugprone-forward-declaration-namespace,bugprone-forwarding-reference-overload,bugprone-inaccurate-erase,bugprone-incorrect-roundings,bugprone-integer-division,bugprone-lambda-function-name,bugprone-macro-parentheses,bugprone-macro-repeated-side-effects,bugprone-misplaced-operator-in-strlen-in-alloc,bugprone-misplaced-pointer-arithmetic-in-alloc,bugprone-misplaced-widening-cast,bugprone-move-forwarding-reference,bugprone-multiple-statement-macro,bugprone-no-escape,bugprone-not-null-terminated-result,bugprone-parent-virtual-call,bugprone-posix-return,bugprone-reserved-identifier,bugprone-sizeof-container,bugprone-sizeof-expression,bugprone-spuriously-wake-up-functions,bugprone-string-constructor,bugprone-string-integer-assignment,bugprone-string-literal-with-embedded-nul,bugprone-suspicious-enum-usage,bugprone-suspicious-include,bugprone-suspicious-memory-comparison,bugprone-suspicious-memset-usage,bugprone-suspicious-missing-comma,bugprone-suspicious-semicolon,bugprone-suspicious-string-compare,bugprone-swapped-arguments,bugprone-terminating-continue,bugprone-throw-keyword-missing,bugprone-too-small-loop-variable,bugprone-undefined-memory-manipulation,bugprone-undelegated-constructor,bugprone-unhandled-self-assignment,bugprone-unused-raii,bugprone-unused-return-value,bugprone-use-after-move,bugprone-virtual-near-miss,cert-dcl21-cpp,cert-dcl58-cpp,cert-err34-c,cert-err52-cpp,cert-err58-cpp,cert-err60-cpp,cert-flp30-c,cert-msc50-cpp,cert-msc51-cpp,cert-str34-c,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-slicing,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,misc-misplaced-const,misc-new-delete-overloads,misc-non-copyable-objects,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,modernize-avoid-bind,modernize-concat-nested-namespaces,modernize-deprecated-headers,modernize-deprecated-ios-base-aliases,modernize-loop-convert,modernize-make-shared,modernize-make-unique,modernize-pass-by-value,modernize-raw-string-literal,modernize-redundant-void-arg,modernize-replace-auto-ptr,modernize-replace-disallow-copy-and-assign-macro,modernize-replace-random-shuffle,modernize-return-braced-init-list,modernize-shrink-to-fit,modernize-unary-static-assert,modernize-use-auto,modernize-use-bool-literals,modernize-use-emplace,modernize-use-equals-default,modernize-use-equals-delete,modernize-use-nodiscard,modernize-use-noexcept,modernize-use-nullptr,modernize-use-override,modernize-use-transparent-functors,modernize-use-uncaught-exceptions,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-string-concatenation,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,portability-simd-intrinsics,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-inconsistent-declaration-parameter-name,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-subscript-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,readability-use-anyofallof" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
Error type 1 at Line 4: Undefined variable "j"
Error type 5 at Line 4: Type mismatched for assignment "="
Error type 2 at Line 4: Undefined function "inc"
Error type 3 at Line 4: Redefined variable "i"
Error type 4 at Line 6: Redefined function "func"
Error type 5 at Line 4: Type mismatched for assignment "="
Error type 6 at Line 4: The left-hand side of an assignment must be a variable "="
Error type 7 at Line 4: Type mismatched for operands ""
Error type 8 at Line 4: Type mismatched for return "return"
Error type 9 at Line 8: Function is not applicable for arguments ","
Error type 10 at Line 4: Variable is not an array "["
Error type 11 at Line 4: Not a function "i"
Error type 12 at Line 4: Not an integer "["
Error type 13 at Line 9: Illegal use of "."
Error type 14 at Line 9: Non-existent field "."
Error type 7 at Line 9: Type mismatched for operands "=="
Error type 7 at Line 9: Type mismatched for operands "=="
Error type 15 at Line 4: Struct redefined field "x"
Error type 16 at Line 6: Duplicated name struct "Position"
Error type 17 at Line 3: None Defined Struct "Position"
Error type 19 at Line 8: Inconsistent declaration of function "func"
Error type 18 at Line 6: Undefined function "func"
Error type 3 at Line 10: Redefined variable "i"
Error type 5 at Line 16: Type mismatched for assignment "="
Error type 2 at Line 52: Undefined function "nonexist_func"
Error type 1 at Line 58: Undefined variable "true"
Error type 5 at Line 58: Type mismatched for assignment "="
Error type 1 at Line 59: Undefined variable "false"
Error type 1 at Line 59: Undefined variable "true"
Error type 7 at Line 59: Type mismatched for operands ""
Error type 7 at Line 59: Type mismatched for operands ""
Error type 1 at Line 60: Undefined variable "true"
Error type 7 at Line 60: Type mismatched for operands ""
Error type 1 at Line 61: Undefined variable "false"
Error type 8 at Line 61: Type mismatched for return "return"
Error type 1 at Line 65: Undefined variable "true"
Error type 7 at Line 65: Type mismatched for operands "&&"
Error type 1 at Line 66: Undefined variable "false"
Error type 7 at Line 66: Type mismatched for operands "&&"
Error type 1 at Line 67: Undefined variable "true"
Error type 8 at Line 67: Type mismatched for return "return"
Error type 1 at Line 69: Undefined variable "which_if"
Error type 8 at Line 69: Type mismatched for return "return"
Error type 2 at Line 73: Undefined function "some_condition"
Error type 7 at Line 73: Type mismatched for operands ""
Error type 2 at Line 74: Undefined function "do_nothing"
Error type 2 at Line 83: Undefined function "some_func"
Error type 12 at Line 83: Not an integer "["
Error type 1 at Line 86: Undefined variable "non_exist_bool"
Error type 1 at Line 86: Undefined variable "true"
Error type 1 at Line 86: Undefined variable "false"
Error type 7 at Line 86: Type mismatched for operands "&&"
Error type 7 at Line 87: Type mismatched for operands ">"
Error type 6 at Line 87: The left-hand side of an assignment must be a variable "="
Error type 5 at Line 86: Type mismatched for assignment "="
Error type 1 at Line 90: Undefined variable "b"
Error type 5 at Line 90: Type mismatched for assignment "="
Error type 1 at Line 91: Undefined variable "b"
Error type 7 at Line 91: Type mismatched for operands "!"
Error type 1 at Line 92: Undefined variable "b"
Error type 7 at Line 92: Type mismatched for operands ""
Error type 7 at Line 92: Type mismatched for operands ""
Error type 1 at Line 92: Undefined variable "d"
Error type 7 at Line 92: Type mismatched for operands ""
Error type 5 at Line 92: Type mismatched for assignment "="
Error type 1 at Line 93: Undefined variable "b"
Error type 7 at Line 93: Type mismatched for operands ""
Error type 7 at Line 93: Type mismatched for operands ""
Error type 1 at Line 93: Undefined variable "d"
Error type 7 at Line 93: Type mismatched for operands ""
Error type 5 at Line 93: Type mismatched for assignment "="
Error type 1 at Line 94: Undefined variable "b"
Error type 7 at Line 94: Type mismatched for operands ""
Error type 7 at Line 94: Type mismatched for operands ""
Error type 1 at Line 94: Undefined variable "d"
Error type 7 at Line 94: Type mismatched for operands ""
Error type 5 at Line 94: Type mismatched for assignment "="
Error type 1 at Line 95: Undefined variable "b"
Error type 7 at Line 95: Type mismatched for operands ""
Error type 7 at Line 95: Type mismatched for operands ""
Error type 1 at Line 95: Undefined variable "d"
Error type 7 at Line 95: Type mismatched for operands ""
Error type 5 at Line 95: Type mismatched for assignment "="
Error type 1 at Line 96: Undefined variable "b"
Error type 7 at Line 96: Type mismatched for operands "<"
Error type 1 at Line 96: Undefined variable "d"
Error type 7 at Line 96: Type mismatched for operands "<"
Error type 1 at Line 97: Undefined variable "b"
Error type 7 at Line 97: Type mismatched for operands "<="
Error type 1 at Line 97: Undefined variable "d"
Error type 7 at Line 97: Type mismatched for operands "<="
Error type 1 at Line 98: Undefined variable "b"
Error type 7 at Line 98: Type mismatched for operands ">"
Error type 1 at Line 98: Undefined variable "d"
Error type 7 at Line 98: Type mismatched for operands ">"
Error type 1 at Line 99: Undefined variable "b"
Error type 7 at Line 99: Type mismatched for operands ">="
Error type 1 at Line 99: Undefined variable "d"
Error type 7 at Line 99: Type mismatched for operands ">="
Error type 1 at Line 100: Undefined variable "b"
Error type 7 at Line 100: Type mismatched for operands "=="
Error type 1 at Line 100: Undefined variable "d"
Error type 7 at Line 100: Type mismatched for operands "=="
Error type 1 at Line 101: Undefined variable "b"
Error type 7 at Line 101: Type mismatched for operands "!="
Error type 1 at Line 101: Undefined variable "d"
Error type 7 at Line 101: Type mismatched for operands "!="
Error type 1 at Line 102: Undefined variable "b"
Error type 7 at Line 102: Type mismatched for operands "&&"
Error type 1 at Line 102: Undefined variable "d"
Error type 7 at Line 102: Type mismatched for operands "&&"
Error type 1 at Line 103: Undefined variable "b"
Error type 7 at Line 103: Type mismatched for operands "||"
Error type 1 at Line 103: Undefined variable "d"
Error type 7 at Line 103: Type mismatched for operands "||"
Error type 1 at Line 104: Undefined variable "b"
Error type 1 at Line 104: Undefined variable "d"
Error type 5 at Line 104: Type mismatched for assignment "="
Error type 5 at Line 104: Type mismatched for assignment "="
Error type 5 at Line 104: Type mismatched for assignment "="
Error type 5 at Line 104: Type mismatched for assignment "="
Error type 2 at Line 106: Undefined function "nonexist_func"
Error type 8 at Line 106: Type mismatched for return "return"
\ No newline at end of file
......@@ -68,7 +68,7 @@ struct Type_ {
FieldList * structure;
struct {
Type * ret_type;
FieldList * var_list;
FieldList * var_list,* var_type;
} func;
} u;
};
......@@ -138,7 +138,6 @@ typedef struct SymbolTable_t {
int (*insert)(Symbol_Node_t *); //插入节点
int (*remove)(Symbol_Node_t *); //删除节点
Symbol_Node_t * (*find)(char *); //查询元素,返回true,找到,false没有找到
void (*rehash)();
void (*display_node)(unit_t *);
}SymbolTable_t;
extern SymbolTable_t * symbol_table;
......@@ -160,7 +159,6 @@ typedef struct SymbolStack_ele_t {
struct SymbolStack_ele_t * prev, * next;
}SymbolStack_ele_t;
typedef struct SymbolStack_t {
SymbolStack_ele_t last,first; //first栈顶,last是栈底
int stack_size;
......@@ -168,14 +166,15 @@ typedef struct SymbolStack_t {
SymbolStack_ele_t * (* node_alloc)(int ); //分配栈中的节点,由于也是链表,需要分配两个head和tail
void (*init)(); //初始化栈
void (*push)(SymbolStack_ele_t * ); //在push前应调用stack的node_alloc来分配栈中的节点
void (*push)(int); //在push前应调用stack的node_alloc来分配栈中的节点
void (*pop)(); //在pop时free掉所有这一层作用域申请的节点
bool (*empty)();
FieldList * (*pop_var)();
FieldList * (*pop_type)();
SymbolStack_ele_t * (*top)();
}SymbolStack_t;
extern SymbolStack_t * symbol_stack;
/*
每次向散列表中插入元素时,总是将新插入的元素放到该槽下挂的链表以及该层
所对应的链表的表头。每次查表时如果定位到某个槽,则按顺序遍历这个槽下挂的链表并返回
......@@ -207,11 +206,9 @@ extern SymbolStack_t * symbol_stack;
删除:
通常是以作用域为单位删除:找到栈顶的作用域,沿着链表删除,先使用SymbolList中的remove删除hash table slot中的节点(这个节点不会free),
然后free当前节点,然后删除下一个节点,知道end,最后只剩下push时申请的head和end,在stack的链表中删除并free
*/
#define type(A,B) (strcmp((A)->content,B) == 0)
#define type(A,B) ((A) && strcmp((A)->content,B) == 0)
#define MODULE_DEF(type,name) \
......@@ -220,15 +217,6 @@ extern SymbolStack_t * symbol_stack;
type * name = &name ## _mod_t; \
type name ## _mod_t
//需要的接口
/*
* 一个类型表
* 类型表的复制、删除(删除暂时不用实现,struct的定义一定是全局定义)
* 类型表的查询
* 类型表的插入
*/
typedef struct Type_Ops_t {
Type * (*type_copy)(const Type *);
FieldList * (*field_copy)(const FieldList *);
......@@ -284,12 +272,7 @@ static Type Wrong_Type = {
.kind = WRONG,
};
static char * empty = "";
......
No preview for this file type
This diff is collapsed.
#include "data.h"
#include "debug.h"
typedef SymbolInfoList_t list_t;
typedef struct SymbolStack_ele_t stack_ele_t;
//都应该使用static
static void node_init(unit_t * cur,int argc,...);
static void node_delete(void * cur,int mode);
static bool struct_node_equal(unit_t*,unit_t*);
......@@ -23,7 +20,6 @@ struct Info_Node_Ops * nodeop = &InfoNodeOp;
static void SymbolInfoList_insert(list_t * list,unit_t * cur,unit_t * new);
static void SymbolInfoList_remove(list_t * list,unit_t * cur);
static void SymbolInfoList_init(list_t * list);
static void SymbolInfoList_delete(list_t * list);
static unit_t * SymbolInfoList_find(list_t * list,char * name);
static list_t * SymbolInfoList_alloc();
......@@ -31,7 +27,6 @@ static struct Hash_List_Ops {
void (*insert)(list_t * list,unit_t * cur,unit_t * new); //在list链表节点cur之后插入新节点new !!!注意插入节点前要先malloc一个节点
void (*remove)(list_t * list,unit_t * cur); //在list链表中删除cur节点, !!!注意:删除节点时候不free,在stack中pop的时候free;
void (*init)(list_t * list); //初始化
void (*delete)(list_t * list);
unit_t * (* find)(list_t * list,char * name);
list_t * (*alloc)();
}listop = {
......@@ -41,7 +36,6 @@ static struct Hash_List_Ops {
.find = SymbolInfoList_find,
.alloc = SymbolInfoList_alloc,
.delete = SymbolInfoList_delete,
};
//hash table list 接口
......@@ -53,7 +47,6 @@ static int SymbolTable_insert(unit_t * cur);
static int SymbolTable_remove(unit_t * cur);
static unit_t * SymbolTable_find(char *);
static void SymbolTable_node_init(unit_t * cur,char * name);
static void SymbolTable_rehash();
static void SymbolTable_display_node(unit_t *);
//SymbolTable API
......@@ -66,28 +59,29 @@ MODULE_DEF(SymbolTable_t,symbol_table) = {
.remove = SymbolTable_remove,
.find = SymbolTable_find,
.rehash = SymbolTable_rehash,
.display_node = SymbolTable_display_node,
};
static stack_ele_t * SymbolStack_node_alloc(); //分配栈中的节点,由于也是链表,需要分配两个head和tail
static stack_ele_t * SymbolStack_node_alloc(int ); //分配栈中的节点,由于也是链表,需要分配两个head和tail
static void SymbolStack_init(); //初始化栈
static void SymbolStack_push(stack_ele_t * ); //在push前应调用stack的node_alloc来分配栈中的节点
static void SymbolStack_push(int); //在push前应调用stack的node_alloc来分配栈中的节点
static void SymbolStack_pop(); //在pop时free掉所有这一层作用域申请的节点
static stack_ele_t * SymbolStack_top();
static bool SymbolStack_empty();
static FieldList * SymbolStack_pop_var();
static FieldList * SymbolStack_pop_type();
MODULE_DEF(SymbolStack_t,symbol_stack) = {
.node_alloc = SymbolStack_node_alloc,
.init = SymbolStack_init,
.push = SymbolStack_push,
.pop = SymbolStack_pop,
.top = SymbolStack_top,
.empty = SymbolStack_empty,
.pop_var = SymbolStack_pop_var,
.pop_type = SymbolStack_pop_type,
};
//Symbol Table
static void SymbolTable_display_node(unit_t * cur) {
printf("Name: %s, deep: %d\n",cur->name,cur->deep);
......@@ -124,8 +118,6 @@ static void SymbolTable_node_init(unit_t * cur,char * name) {
nodeop->init(cur,3,name,symbol_stack->stack_size,INFONODE);
}
static int SymbolTable_insert(unit_t * cur) {
int id = symbol_table->hash(cur->name);
list_t * list = symbol_table->table[id];
......@@ -180,22 +172,15 @@ static unit_t * SymbolTable_find(char * name) {
}
}
static void SymbolTable_rehash() {
panic("Not implemented");
}
/*
* 在stack中,unit_t *的指针作用
* scope,用于纵向连接hash table中元素
* hash,用于在stack中连接栈中的元素
*/
//Symbol Stack
static stack_ele_t * SymbolStack_node_alloc(int field_type) {
static stack_ele_t * SymbolStack_node_alloc(int field) {
stack_ele_t * node = (stack_ele_t *) malloc(sizeof(stack_ele_t));
node->field_type = field_type;
node->field_type = field;
node->prev = node->next = NULL;
unit_t * head = &node->head;
......@@ -223,7 +208,8 @@ static void SymbolStack_init() {
last->prev = first;
}//初始化栈中的两个节点
static void SymbolStack_push(stack_ele_t * item) {
static void SymbolStack_push(int field) {
SymbolStack_ele_t * item = symbol_stack->node_alloc(field);
stack_ele_t * first = &symbol_stack->first, * next = first->next;
first->next = item;
item->next = next;
......@@ -264,6 +250,40 @@ static bool SymbolStack_empty() {
if(symbol_stack->stack_size == 0) return true;
else return false;
}
static FieldList * SymbolStack_pop_var() {
stack_ele_t * top = symbol_stack->top();
unit_t * cur = top->head.scope_next;
FieldList * ret = NULL, * tail = ret;
while (cur != &top->tail) {
assert(cur->deep == top->head.deep);
if(cur->type->kind == STRUCTURE && strcmp(cur->name,cur->type->u.structure->name) == 0) {
cur = cur->scope_next;
continue;
}
ret = type_ops->field_alloc_init(cur->name,cur->line,cur->type);
ret->tail = tail;
tail = ret;
cur = cur->scope_next;
}
return ret;
}
static FieldList * SymbolStack_pop_type() {
stack_ele_t * top = symbol_stack->top();
unit_t * cur = top->head.scope_next;
FieldList * ret = NULL, * tail = ret;
while (cur != &top->tail) {
assert(cur->deep == top->head.deep);
if(cur->type->kind == STRUCTURE && strcmp(cur->name,cur->type->u.structure->name) == 0) {
ret = type_ops->field_alloc_init(cur->name,cur->line,cur->type);
ret->tail = tail;
tail = ret;
}
cur = cur->scope_next;
}
return ret;
}
//Symbol Stack
......@@ -301,9 +321,6 @@ static void SymbolInfoList_remove(list_t * list,unit_t * cur) {
//在这里不删除分配的内存,最后统一删除
}
static void SymbolInfoList_delete(list_t * list) {
panic("Not implemented");
}
static unit_t * SymbolInfoList_find(list_t * list,char * name) {
unit_t * cur = list->head.hash_next;
......@@ -358,17 +375,13 @@ static void node_delete(void * cur,int mode) {
break;
case HASHLIST:
panic("Delete hash list node not allowed!");
//不允许通过该API删除
//hash table中每个链表的头尾节点
break;
//不允许通过该API删除hash table中每个链表的头尾节点
case STACKNODE:
free(stack_node);
break;
case STACKLIST:
panic("Delete stack list node not allowed!");
//不允许通过该API删除
//stack中的
break;
//不允许通过该API删除stack中的
default:
panic("Wrong mode");
}
......@@ -502,13 +515,15 @@ static Type * Type_Ops_Type_copy(const Type * type) {
break;
case ARRAY:
ret->u.array.size = type->u.array.size;
ret->u.array.elem = Type_Ops_Type_copy(type->u.array.elem);
break;
case STRUCTURE:
ret->u.structure = Type_Ops_Field_Copy(type->u.structure);
break;
case FUNC_IMPL:
case FUNC_DECL:
panic("Not Implemented");
ret->u.func.ret_type = Type_Ops_Type_copy(type->u.func.ret_type);
ret->u.func.var_list = Type_Ops_Field_Copy(type->u.func.var_list);
break;
case REMAINED:
panic("Wrong Remained Modified Type");
......@@ -539,7 +554,6 @@ static void Type_Ops_Type_delete(Type * type) {
else {
switch (type->kind) {
case BASIC:
//do nothing
break;
case ARRAY:
Type_Ops_Type_delete(type->u.array.elem);
......@@ -591,9 +605,7 @@ static FieldList * Type_Ops_Field_alloc_init(char * name,int line,const Type * t
static bool Type_Ops_Type_Equal(const Type * t1,const Type * t2) {
if(t1 == t2) return true;
if(t1 == NULL && t2 == NULL) return true;
if(t1 && !t2 ) return false;
if(!t1 && t2 ) return false;
if(!t1 || !t2 ) return false;
if(t1->kind != t2->kind) {
if((t1->kind != FUNC_IMPL && t1->kind != FUNC_DECL) && (t2->kind != FUNC_IMPL && t2->kind != FUNC_DECL )) {
return false;
......@@ -607,7 +619,6 @@ static bool Type_Ops_Type_Equal(const Type * t1,const Type * t2) {
case BASIC:
return t1->u.basic == t2->u.basic;
case ARRAY:
//if(t1->u.array.size != t2->u.array.size) return false;
return Type_Ops_Type_Equal(t1->u.array.elem,t2->u.array.elem);
case STRUCTURE:
return Type_Ops_Field_Equal(t1->u.structure,t2->u.structure);
......@@ -619,15 +630,8 @@ static bool Type_Ops_Type_Equal(const Type * t1,const Type * t2) {
}
static bool Type_Ops_Field_Equal(const FieldList * f1,const FieldList * f2) {
if(f1 == NULL && f2 == NULL) return true;
if(f1 && !f2 ) return false;
if(!f1 && f2 ) return false;
/*
if(strcmp(f1->name,f2->name) != 0 ) {
if(!(f1->type->kind == STRUCTURE && f2->type->kind == STRUCTURE)) {
return false;
}
}*/
if(f1 == f2) return true;
if(!f1 || !f2) return false;
if(!Type_Ops_Type_Equal(f1->type,f2->type)) return false;
if(!Type_Ops_Field_Equal(f1->tail,f2->tail)) return false;
return true;
......
/* Test by Zhao Chaoyi */
int global1, global2;
struct {
int a,b;
}a;
int;
struct type_1 {
float c;
int d;
/* anonymous structure */
struct
{
int field1;
};
struct type_2 {
float a;
struct type_1 t1;
}t1,t2,t3,t4;
struct
{
int field1;
float field2;
} s1, s2;
int func_1() {
return 1;
}
/* structure */
struct Complex
{
int real;
int imag;
} c1, c2, carray[100], multi_dim[1][2][3];
int main() {
int a;
b;
if(1) {
non_exists_func(a,t1);
} else {
/* nested structure */
struct Complex_pair
{
struct Complex x;
struct Complex y;
struct withname
{
int field;
} s1;
struct
{
float field;
} s2;
};
// Note: function declaration not allowed
int main()
{
/* local variable declarations */
int a;
float a;
}
return 0;
int barray[10][2];
int i = 0;
int a1, a2, a3;
struct Complex c;
struct Complex_pair cp;
/* main body */
nonexist_func(1, 2, a, barray[1], barray);
1;
{
int x;
}
float func_1(int c) {
return 1;
true = 1;
false = true - 1;
if (true) {
return false;
}
float func_2() {
int a;
a = 1.0;
1 = a;
t1 = t3 + t4;
return a;
/* dangling-else problem */
if (a && true)
if (a && false)
return true;
else
return which_if;
while (i > 0) {
i = i + 1;
if (some_condition(1, 2, 3)) {
do_nothing();
}
}
int func_3(int c,int d) {
int e = func_1(0.1);
return d[1];
/* member access */
c.imag = 1;
c.real = 2;
c.real = c.imag + c.real;
cp.s1.field = 1;
multi_dim[0][some_func()][0].real = 1;
/* precedence of operators */
non_exist_bool = true && false || (1 + 2) != (1 + 2 * 3)
> barray[7] <= c.imag = (!a / 8) == 9;
/* associativity of operators */
a = -- --b;
a = !!!!!b;
a = b * c * d;
a = b / c / d;
a = b + c + d;
a = b - c - d;
a = b < c < d;
a = b <= c <= d;
a = b > c > d;
a = b >= c >= d;
a = b == c == d;
a = b != c != d;
a = b && c && d;
a = b || c || d;
a = b = c = d = 1;
return nonexist_func();
}
struct type_1 func_4(int d) {
struct type_2 t;
int array[100];
t();
array[1.5];
/*
* block comment
* @#$%^&*()
*/
// line comment #$%^&*()~!@#$%^&*()_+
/* function definition */
int func(int ival, float fval, float arr[10])
{
int c = d.a;
t.t1.a;
}
int a = 1;
}
struct type_2 {
float a;
int d = 0;
struct non_exist tt;
};
/* Extra requirements */
int extra()
{
int oct1 = 0123;
int oct2 = 00000000010;
int oct3 = -007;
int hex1 = 0x3f;
int hex2 = 0XABCDEF;
int hex3 = 0xAbCdEf;
float f1 = 1.05e-4;
float f2 = 1.0e111;
float f3 = 0.77e111;
float f4 = 7.0e11;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment