Improved vala attributes model

This commit is contained in:
Anton Kochkov 2012-09-07 02:32:26 +04:00
parent e37039862a
commit 2ac6bc345d
4 changed files with 35 additions and 12 deletions

View File

@ -36,5 +36,6 @@ RAnalType* new_struct_node(char* name, RAnalType *defs);
RAnalType* new_union_node(char* name, RAnalType *defs);
RAnalType* new_alloca_node(long address, long size, RAnalType *defs);
RAnalLocals* new_locals_node(RAnalType *defs);
RAnalType* new_function_node(char* name, short ret_type, RAnalType *args, short fmodifier, short callconvention, char* attributes, RAnalLocals *locals);
RAnalFcnAttr* new_attribute(char* name, char* value);
RAnalType* new_function_node(char* name, short ret_type, RAnalType *args, short fmodifier, short callconvention, char* attributes, RAnalLocals *locals, RAnalFcnAttr *valattr);

View File

@ -21,6 +21,8 @@
%type deflist {RAnalType *}
%type def {RAnalType *}
%type function {RAnalType *}
%type attriblist {RAnalFcnAttr *}
%type attrib {RAnalFcnAttr *}
%type arglist {RAnalType *}
%type argdef {RAnalType *}
%type struct {RAnalType *}
@ -53,33 +55,37 @@ def(A) ::= variable(B). { A = B; }
def(A) ::= pointer(B). { A = B; }
def(A) ::= array(B). { A = B; }
function(A) ::= attrib(T) FUNCTION type(B) name(C) LPARENT arglist(D) RPARENT locals(E). {
function(A) ::= attriblist(T) FUNCTION type(B) name(C) LPARENT arglist(D) RPARENT locals(E). {
A = new_function_node(C.sval, B.dval, D, R_ANAL_FQUALIFIER_NONE, R_ANAL_CC_TYPE_NONE, NULL, E, T);
}
function(A) ::= attrib(T) FUNCTION fqualifier(B) type(C) name(D) LPARENT arglist(E) RPARENT locals(F). {
function(A) ::= attriblist(T) FUNCTION fqualifier(B) type(C) name(D) LPARENT arglist(E) RPARENT locals(F). {
A = new_function_node(D.sval, C.dval, E, B.dval, R_ANAL_CC_TYPE_NONE, NULL, F, T);
}
function(A) ::= attrib(T) FUNCTION callconvention(B) type(C) name(D) LPARENT arglist(E) RPARENT locals(F). {
function(A) ::= attriblist(T) FUNCTION callconvention(B) type(C) name(D) LPARENT arglist(E) RPARENT locals(F). {
A = new_function_node(D.sval, C.dval, E, R_ANAL_FQUALIFIER_NONE, B.dval, NULL, F, T);
}
function(A) ::= attrib(T) FUNCTION callconvention(B) fqualifier(C) type(D) name(E) LPARENT arglist(F) RPARENT locals(G). {
function(A) ::= attriblist(T) FUNCTION callconvention(B) fqualifier(C) type(D) name(E) LPARENT arglist(F) RPARENT locals(G). {
A = new_function_node(E.sval, D.dval, F, C.dval, B.dval, NULL, G, T);
}
function(A) ::= attrib(T) FUNCTION attribute(B) fqualifier(C) type(D) name(E) LPARENT arglist(F) RPARENT locals(G). {
function(A) ::= attriblist(T) FUNCTION attribute(B) fqualifier(C) type(D) name(E) LPARENT arglist(F) RPARENT locals(G). {
A = new_function_node(E.sval, D.dval, F, C.dval, R_ANAL_CC_TYPE_NONE, B.sval, G, T);
}
function(A) ::= attrib(T) FUNCTION attribute(B) callconvention(C) fqualifier(D) type(E) name(F) LPARENT arglist(G) RPARENT locals(H). {
function(A) ::= attriblist(T) FUNCTION attribute(B) callconvention(C) fqualifier(D) type(E) name(F) LPARENT arglist(G) RPARENT locals(H). {
A = new_function_node(F.sval, E.dval, G, D.dval, C.dval, B.sval, H, T);
}
attrib(A) ::=.
attriblist ::=.
attriblist(A) ::= attrib(B) attriblist(C). {
B->next = C;
A = B;
}
attrib(A) ::= LBRACKET name(B) RBRACKET. {
A.sval = B.sval; A.dval = 0;
A = new_attribute(B.sval, NULL);
}
attrib(A) ::= LBRACKET name(B) EQUATION attrval(C) RBRACKET. {
A.sval = B.sval; A.dval = C.dval;
A = new_attribute(B.sval, C.sval);
}
attrval(A) ::= NUMBER(B). { A.dval = B.dval; }
attrval(A) ::= IDENTIFIER(B). { A.sval = B.sval; }
fqualifier(A) ::= INLINE. { A.sval = "inline"; A.dval = R_ANAL_FQUALIFIER_INLINE; }
fqualifier(A) ::= VOLATILE. { A.sval = "volatile"; A.dval = R_ANAL_FQUALIFIER_VOLATILE; }

View File

@ -116,11 +116,20 @@ RAnalLocals* new_locals_node(RAnalType *defs) {
return il;
}
RAnalFcnAttr* new_attribute(char* name, char* value) {
RAnalFcnAttr *tmp = R_NEW0 (RAnalFcnAttr);
/* TODO: add parsing of various attributes */
tmp->key = name;
tmp->value = atol(value);
tmp->next = NULL;
return tmp;
}
/* Function can return another function or have multiple returns */
//item_list* new_function_node(char* name, item_list *rets, item_list *args)
RAnalType* new_function_node(char* name, short ret_type, RAnalType *args,
short fmodifier, short callconvention, char* attributes,
RAnalLocals *locals, RAnalType* valaattr) {
RAnalLocals *locals, RAnalFcnAttr* valattr) {
RAnalFunction *ifnc = R_NEW (RAnalFunction);
RAnalType *tmp = R_NEW (RAnalType);
ifnc->name = name;

View File

@ -269,6 +269,13 @@ typedef struct r_anal_locals_t {
RAnalType *items;
} RAnalLocals;
typedef struct r_anal_fcn_attr_t RAnalFcnAttr;
struct r_anal_fcn_attr_t {
char *key;
long value;
RAnalFcnAttr *next;
};
typedef struct r_anal_fcn_store_t {
RHashTable64 *h;
RList *l;