?? detaildesign.txt
字號:
FinC 0.3 detail design----------------------Design for Token classClass Token is main for convert source to token.declaration and members:struct TokenEnv{ Bool eof; Bool replay; int line; int position; FinCTokenType current_token; String* line_str; String* last_str; char last_char; double last_double; float last_float; long last_long; const char* (*read_line)(char* arg); const char* arg;};Design for App class(class App will rename to Context for plan thread support in 0.3 version )Context includes some global information for a single script application.such as symbol, global variable table and static variable table.declaration and members:struct FinCApp{ Object parent; HashTable* hash_global; HashTable* hash_local; HashTable* hash_functions; HashTable* hash_struct;}hash_global, 全局變量hash_local, 局部變量,會隨著每次調用上下文而變動。hash_functions, 函數符號表hash_struct, 結構體符號表Data類設計(0.2版本重點更新項目)Action新建消亡建立引用取消引用調用域成員和其他類的接口FinCData聲明struct FinCData{ Object parent;//引用位 FinCType type//類型 Vector* child; FinCData* pointer;//當它是指針類型時,只想的實際的FinCData數據變量 ADT raw; Bool ref;};parent指示出它的引用參考type指示出數據的類型。其中raw為最關鍵的數據區域,每個類型的數據有具體的大小,raw域按大小來分配。ref指示出raw是否是引用方式,如果是引用方式,將沒有權力釋放數據域。child,sub Data矢量表,主要存儲的結構為FinCData,從而實現struct聲明的可遞歸性。由于采用的是vector,所以對域成員的引用采用index的方式。指針的處理:raw:指針只是一個4字節長度(不同的機器可能不一樣,x86為4字節)的數據域,放置實際的數據塊的地址。pointer指向實際的FinCData類型的數據變量。API操作說明FinCData* finc_data_new (FinCType* p_type, ADT p_ref)新建數據,主要是新開辟Type數據類型大小的數據區域。參數:p_type,生成數據塊的數據類型p_ref,是否為引用類型返回:新開辟的數據塊結構void finc_data_destroy (Object* self)銷毀數據參數:self,FinCData本地數據返回:無void finc_data_init_data (ADT self, ADT data)初始化數據參數:self,FinCData本地數據data,數據塊載入點返回:無void finc_data_assign (FinCData* self, FinCData* p_src)賦值(復制)內存區參數:self,FinCData本地數據p_src,復制數據塊的數據源返回:無void finc_data_set_string (FinCData* self, String* p_value)設置字符串類型數據參數:self,FinCData本地數據p_value,需要設置的字符串返回:無獲得字符串類型數據參數:self,FinCData本地數據返回:數據塊中的字符串類型void finc_data_set_data (FinCData* self, ADT p_ptr)設置原始內存區指針參數:self,FinCData本地數據p_ptr,設置數據的數據指針返回:無ADT finc_data_get_data (FinCData* self)獲得原始內存塊參數:self,FinCData本地數據返回:抽象數據類型ADTFinCData* finc_data_convert (FinCData* self, FinCType* p_type)轉換數據類型參數:self,FinCData本地數據p_type,需要轉換的數據類型返回:轉換了的數據結構FinCData* finc_data_get_field (FinCData* self, String* p_name)獲得結構體的域數據參數:self,FinCData本地數據p_name,域成員名字返回:獲得的域數據Type類修正:FinCType包含如下類型FinCType_CharFinCType_ShortFinCType_IntFinCType_FloatFinCType_DoubleFinCType_BoolFinCType_StringFinCType_PointerFinCType_VoidFinCType_StructFinCTYpe_StaticFinCTYpe_NativeArray類型FinCTypeArray_NoneFinCTypeArray_FixedFinCTypeArray_Dynamicfinc_type_newfinc_type_new_name通過名字獲得類型finc_type_get_sizefinc_type_destroyStruct類設計:struct FinCStruct{ Object parent; String name; HashTable hash_field; int size;};結構成員hash_field采用hash表的方法方法newdestoryadd_fieldget_fieldget_sizeFinCSys系統函數庫FinCSys都具有統一的函數聲明格式void function (FinCNode* p_node)參數:p_node,語法樹結點增加:void finc_sys_pkg (FinCNode* p_node)void finc_sys_struct (FinCNode* p_node)void finc_sys_native_func (FinCNode* p_node)void finc_sys_break (FinCNode* p_node)void finc_sys_continue (FinCNode* p_node)void finc_sys_access (FinCNode* p_node)修正:void finc_sys_cast (FinCNode* p_node)void finc_sys_global (FinCNode* p_node)void finc_sys_local (FinCNode* p_node)void finc_sys_condition (FinCNode* p_node)void finc_sys_comma (FinCNode* p_node)void finc_sys_content_of (FinCNode* p_node)void finc_sys_addr_of (FinCNode* p_node)void finc_sys_continue (FinCNode* p_node)void finc_sys_break (FinCNode* p_node)Design for Parser classClass Parser is the most important class for 0.2 to 0.3 change.It use a recursive descent parse method to parser FinC source file.However, there are some famous conflict in recursive descent parse,such as left recursion and left gene. In FinC grammar[detail pleasesee FinC grammar spec v0.3], the great conflict is variable declarationand function declaration. There are both some type prefix. So, ifwant to resolve it, can do as normally apart left gene and breakoutleft recursive descent and also can do as look aheard for 1 token.There are only talk about how to resolve the conflict in grammar.conflict:variable declaration , function declarationexample:(map is a struct data type)int a;int a=100, b;static int a;map a;int func();map func();function 'proc_type_prefix' will process the prefix of all declaration,and generate it to two global variable: g_type and g_id.for 'int a;'g_type is 'int' node, g_id is 'a' node.for 'static int a;'g_type is 'static int' node, g_id is 'a' node.fro 'map func()'g_type is 'map' node, g_id is 'func' node.after process prefix, there are some case for follow process.if it's ',' , it's a variable declaration.if it's ';' , it's a variable declaration.if it's '[' , it's a variable declaration, an array variable declaration.if it's '=' , it's a variable declaration.if it's '(' , it's a function declaration.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -