码迷,mamicode.com
首页 > Web开发 > 详细

aspectc中this可以获取的东西

时间:2015-06-18 19:03:04      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

this->kind  操作类型

this->targetName 被调用函数名称

this->funcName 调用函数名称

this->argsCount 参数个数

this->argType(i) 获取编号为i的参数类型

this->arg(i) 获取编号为i的参数类型

this->retType 返回值类型

example:

1.foo.c

char * foo(int a) {
   return "just a test ";
}

void foo2(int a, double b) {
   foo(3);
}

void foo3() {
   foo2(5, 2.2);
}

int main() {
   foo3();
}

2.fooac.acc

before(): call($ $(...)) {
   printf("%s \" %s \" in function %s \n", this->kind, this->targetName, this->funcName);
   
   printf(" \"%s\"  parameter type : \n", this->targetName);

   if ( this->argsCount == 0 ) printf("no parameter \n");
   else {
         for(int i = 1 ; i <= this->argsCount; i++) {
                  printf("arg[%d] = %s  ", i, this->argType(i));
                  
                  if(strcmp(this->argType(i), "int") == 0) {
                         printf(", value = %d ", *(int *)(this->arg(i)));
                  } else if(strcmp(this->argType(i), "double") == 0) {
                         printf(", value = %.2f ", *(double *)(this->arg(i)));
                  }
                  
                  printf("\n");
          }
    }

    printf("return type = %s \n \n", this->retType);
}

3.Compile 2 files with the "tacc" 

>tacc foo.c fooac.acc
>

4. Run the executable file:

>./a.out
call "foo3" in function main "foo3" parameter type: no parameter return type = void call "foo2" in function foo3 "foo2" parameter type: arg[1] = int , value = 5 arg[2] = double , value = 2.20 return type = void call "foo" in function foo2 "foo" parameter type: arg[1] = int , value = 3 return type = char*

 

 



aspectc中this可以获取的东西

标签:

原文地址:http://www.cnblogs.com/xiaohuihui123/p/4586263.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!