Skip to content

Commit

Permalink
Improved vala attributes model
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Kochkov committed Sep 6, 2012
1 parent e370398 commit 2ac6bc3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
3 changes: 2 additions & 1 deletion libr/anal/cparse/cdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

26 changes: 16 additions & 10 deletions libr/anal/cparse/cparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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 *}
Expand Down Expand Up @@ -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; }
Expand Down
11 changes: 10 additions & 1 deletion libr/anal/cparse/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions libr/include/r_anal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2ac6bc3

Please sign in to comment.