aspectc中this可以获取的东西

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*

 

 



posted @ 2015-06-18 16:48  LittlePenguin  阅读(255)  评论(0编辑  收藏  举报