Пример #1
0
/**
 * gv_connect
 *
 * Esta função deve ser utilizada para conectar dois nós da AST na
 * saída em dot. Ela recebe como parâmetro ponteiros para os dois nós
 * da AST que devem ser conectados. Note que esses ponteiros servem
 * como identificadores únicos dos nós da AST.
 */
void gv_connect (const void *p1, const void *p2)
{
  __gv_test_valid_fp (__FUNCTION__);
  __gv_test_valid_ast_pointer (__FUNCTION__, p1);
  __gv_test_valid_ast_pointer (__FUNCTION__, p2);

  fprintf(fp, "node_%p -> node_%p\n", p1, p2);
}
Пример #2
0
/**
 * gv_declare
 *
 * Esta função deve ser chamada para declarar um nó da AST,
 * registrando esse novo nó no arquivo. Ela tem três parâmetros: 

 * 1/ tipo, que deve ser obrigatoriamente um dos valores das
 * constantes declaradas no arquivo iks_ast.h; 

 * 2/ pointer, que deve ser um pointeiro para o nó da árvore AST que
 * está sendo declarado servindo a partir de agora como identificador
 * único do nó; e 

 * 3/ name, que deve ser um lexema válido somente se o tipo for um
 * desses três valores: IKS_AST_IDENTIFICADOR (o lexema do
 * identificador), IKS_AST_LITERAL (o lexema do literal) ou
 * IKS_AST_FUNCAO (o lexema do identificador da função).
 */
void gv_declare (const int tipo, const void *pointer, char *name)
{
  __gv_test_valid_fp (__FUNCTION__);
  __gv_test_valid_ast_pointer (__FUNCTION__, pointer);

  char *description = NULL;

  switch (tipo){
  case IKS_AST_FUNCAO:
  case IKS_AST_IDENTIFICADOR:
  case IKS_AST_LITERAL:
    if (!name){
      fprintf (stderr, "%s: name should be not NULL\n", __FUNCTION__);
      abort();
    }
    description = name;
    break;

  case -1:
  case IKS_AST_PROGRAMA:
  case IKS_AST_IF_ELSE:
  case IKS_AST_DO_WHILE:
  case IKS_AST_WHILE_DO:
  case IKS_AST_INPUT:
  case IKS_AST_OUTPUT:
  case IKS_AST_ATRIBUICAO:
  case IKS_AST_RETURN:
  case IKS_AST_BLOCO:
  case IKS_AST_ARIM_SOMA:
  case IKS_AST_ARIM_SUBTRACAO:
  case IKS_AST_ARIM_MULTIPLICACAO:
  case IKS_AST_ARIM_DIVISAO:
  case IKS_AST_ARIM_INVERSAO:
  case IKS_AST_LOGICO_E:
  case IKS_AST_LOGICO_OU:
  case IKS_AST_LOGICO_COMP_DIF:
  case IKS_AST_LOGICO_COMP_IGUAL:
  case IKS_AST_LOGICO_COMP_LE:
  case IKS_AST_LOGICO_COMP_GE:
  case IKS_AST_LOGICO_COMP_L:
  case IKS_AST_LOGICO_COMP_G:
  case IKS_AST_LOGICO_COMP_NEGACAO:
  case IKS_AST_VETOR_INDEXADO:
  case IKS_AST_CHAMADA_DE_FUNCAO:
  case IKS_AST_MATRIZ_INDEXADO:
    if (name){
      fprintf (stderr, "%s: name should be NULL\n", __FUNCTION__);
      abort();
    }
    description = __gv_description_from_type (tipo);
    break;

  default:
    fprintf (stderr, "%s: unknow tipo provided\n", __FUNCTION__);
    abort();
  }

  fprintf (fp, "node_%p [label=\"%s\"]\n", pointer, description);
}
Пример #3
0
/**
 * gv_declare
 *
 * Esta função deve ser chamada para declarar um nó da AST,
 * registrando esse novo nó no arquivo. Ela tem três parâmetros: 

 * 1/ tipo, que deve ser obrigatoriamente um dos valores das
 * constantes declaradas no arquivo ast.h; 

 * 2/ pointer, que deve ser um pointeiro para o nó da árvore AST que
 * está sendo declarado servindo a partir de agora como identificador
 * único do nó; e 

 * 3/ name, que deve ser um lexema válido somente se o tipo for um
 * desses três valores: AST_IDENTIFICADOR (o lexema do
 * identificador), AST_LITERAL (o lexema do literal) ou
 * AST_FUNCAO (o lexema do identificador da função).
 */
void gv_declare(const int tipo, const void *pointer, char *name) {
    __gv_test_valid_fp(__FUNCTION__);
    __gv_test_valid_ast_pointer(__FUNCTION__, pointer);

    char *description = NULL;

    switch (tipo) {
		case AST_OUT_ARG: 
            if (name){
                description = name;
            }
            else{
                description = __gv_description_from_type (tipo);
            }
        case AST_FUN_DEF:
        case AST_FUNC_CALL:
        case AST_NDEC:
        case AST_POINTER_DEC:
        case AST_ARRAY_DEC:
        case AST_SYMBOL:
		case AST_PARAM_REF:     
		case AST_PARAM:  
        case AST_IN:
            if (!name) {
                fprintf(stderr, "%s: name should be not NULL: %d \n", __FUNCTION__ , tipo);
                //abort();
            }
            description = name;
            break;
        case AST_WORD:
        case AST_BOOL:
        case AST_BYTE:
        case AST_PROGRAM_INI:
        case AST_PROGRAM:
        case AST_IF:
		case AST_CMD_THEN:
        case AST_CMD_ELSE:
		case AST_CMD_LOOP:
        case AST_OUT:
		case AST_BLOCK:
        case AST_RETURN:
        case AST_ATRR:
        case AST_ADD:
        case AST_SUB:
        case AST_MUL:
        case AST_DIV:
        case AST_AND:
        case AST_OR:
        case AST_NE:
        case AST_EQ:
        case AST_LE:
        case AST_GE:
        case AST_LESS:
        case AST_GREATER:
		case AST_BOOLEAN_INV:
		case AST_ARIT_INV:
		case AST_DEC:			
		case AST_DECL:			
		case AST_ATRR_LIT:                   
		case AST_CMD_LIST:                 
		case AST_INDEX:         
		case AST_POINTER_ADDR:  
		case AST_POINTER:    	
		case AST_INV_EXPR:      
		case AST_PAR_EXPR:        
		case AST_PASS_PARAM:    
		case AST_UNDEFINIED:    
            if (name){
                fprintf (stderr, "%s: name should be NULL: %d \n", __FUNCTION__ , tipo);
                abort();
            }
            description = __gv_description_from_type (tipo);
            break;
        default:
            fprintf(stderr, "%s: unknow tipo provided: %d \n", __FUNCTION__ , tipo);
            //abort();
    }

    fprintf(fp, "node_%p [label=\"%s\"]\n", pointer, description);
    fflush(fp);
}