Пример #1
0
static void ast_dump_html_rec(AST a, FILE* f, const char* root_id, int id_node)
{
    if (a == NULL)
        return;

    char current_id_node[64];
    memset(current_id_node, 0, sizeof(current_id_node));
    snprintf(current_id_node, 63, "%s.%d", root_id, id_node);
    current_id_node[63] = '\0';

    fprintf(f, "<div id=\"%s\" class=\"node\" style=\"display: none;\">\n"
            "<div class=\"node_info\">"
            "<span id=\"%s.handle\" class=\"handle\">+</span>"
            "<span id=\"%s.kind\" class=\"node_kind\">%s</span>"
            "<span id=\"%s.locus\" class=\"node_locus\">%s</span>",
            current_id_node, // div
            current_id_node, // handle
            current_id_node, ast_node_type_name(ASTType(a)),
            current_id_node, mini_strip_html(ast_location(a))
           ); // kind

    if (ASTText(a) != NULL)
    {
        fprintf(f, 
            "<span id=\"%s.text\" class=\"node_text\">%s</span>",
            current_id_node,
            mini_strip_html(ASTText(a)));
    }

    fprintf(f, "</div>\n");

    if (ASTType(a) == AST_NODE_LIST)
    {
        fprintf(f, "%s", "<div class=\"node_list\">");
        int k = 0;
        AST list = a, iter;
        for_each_element(list, iter)
        {
            AST element = ASTSon1(iter);
            ast_dump_html_rec(element, f, current_id_node, k);

            k++;
        }
Пример #2
0
static void gather_ms_declspec_item(AST a,
        gather_decl_spec_t* gather_info,
        const decl_context_t* decl_context)
{
    ERROR_CONDITION(ASTKind(a) != AST_MS_DECLSPEC_ITEM, "Invalid node", 0);

    const char* declspec_name = ASTText(a);
    ERROR_CONDITION(declspec_name == NULL, "Invalide node", 0);

    if (strcmp(declspec_name, "align") == 0)
    {
        AST expr_list = ASTSon0(a);
        int num_items = 0;
        if (expr_list != NULL)
        {
            AST it = NULL;
            for_each_element(expr_list, it)
            {
                num_items++;
            }
        }
Пример #3
0
 void Source::fortran_check_expression_adapter(AST a, const decl_context_t* decl_context, nodecl_t* nodecl_output)
 {
     if (ASTKind(a) == AST_COMMON_NAME)
     {
         // We allow common names in expressions
         scope_entry_t* entry = ::query_common_name(decl_context, ASTText(ASTSon0(a)),
                 ast_get_locus(ASTSon0(a)));
         if (entry != NULL)
         {
             *nodecl_output = ::nodecl_make_symbol(entry, ast_get_locus(a));
         }
         else
         {
             *nodecl_output = ::nodecl_make_err_expr(ast_get_locus(a));
         }
     }
     else
     {
         ::fortran_check_expression(a, decl_context, nodecl_output);
     }
 }
Пример #4
0
 std::string AST_t::get_text() const
 {
     return ASTText(_ast);
 }
Пример #5
0
 bool AST_t::has_text() const
 {
     return ASTText(_ast) != NULL;
 }
Пример #6
0
--------------------------------------------------------------------*/

#include "cxx-pragma.h"
#include "cxx-nodecl-output.h"
#include "cxx-ast.h"
#include "cxx-tltype.h"
#include "cxx-scope.h"
#include "string_utils.h"
#include <stdio.h>
        

static void common_build_scope_pragma_custom_clause_argument(AST a, 
        const decl_context_t* decl_context UNUSED_PARAMETER,
        nodecl_t *nodecl_output)
{
    *nodecl_output = nodecl_make_pragma_clause_arg(ASTText(a), ast_get_locus(a));
}

static void common_build_scope_pragma_custom_clause(AST a, const decl_context_t* decl_context, nodecl_t* nodecl_output)
{
    nodecl_t nodecl_argument = nodecl_null();
    if (ASTSon0(a) != NULL)
    {
        common_build_scope_pragma_custom_clause_argument(ASTSon0(a), decl_context, &nodecl_argument);
        // This is a list because it may be extended in later phases
        nodecl_argument = nodecl_make_list_1(nodecl_argument);
    }

    *nodecl_output = nodecl_make_pragma_custom_clause(nodecl_argument, strtolower(ASTText(a)), ast_get_locus(a));
}
Пример #7
0
static void ast_dump_graphviz_rec(AST a, FILE* f, int parent_node, int position)
{
    // static char* octagon = "octagon";
    // static char* doubleoctagon = "doubleoctagon";
    static char* ellipse = "ellipse";
    static char* mdiamond = "Mdiamond";
    static char* box = "box";
    char* shape;

    int node_actual = nodes_counter++;
    if (a != NULL)
    {
        // Select shape
        shape = box;
        if (ASTType(a) == AST_AMBIGUITY) shape = ellipse;
        if (ASTType(a) == AST_NODE_LIST) shape = mdiamond;
        // if (a->construct_type == CT_SPECIFICATION) shape = ellipse;
        // else if (a->construct_type == CT_OMP_SPECIFICATION) shape = mdiamond;
        // else if (a->construct_type == CT_EXECUTABLE) shape = octagon;
        // else if (a->construct_type == CT_OMP_EXECUTABLE) shape = doubleoctagon;

        if (ASTText(a))
        {
            fprintf(f, "n%d[shape=%s,label=\"%s\\nNode=%p\\nParent=%p\\n%s\\nText: -%s-\"]\n", 
                    node_actual, shape, ast_print_node_type(ASTType(a)), a, ASTParent(a), ast_location(a), ASTText(a));
        }
        else
        {
            fprintf(f, "n%d[shape=%s,label=\"%s\\nNode=%p\\nParent=%p\\n%s\"]\n", 
                    node_actual, shape, ast_print_node_type(ASTType(a)), a, ASTParent(a), ast_location(a));
        }

        if (parent_node != 0)
        {
            fprintf(f, "n%d -> n%d [label=\"%d\"]\n", parent_node, node_actual, position);
        }


        if (ASTType(a) != AST_AMBIGUITY)
        {
            int i;
            for(i = 0; i < ASTNumChildren(a); i++)
            {
                ast_dump_graphviz_rec(ASTChild(a, i),f,  node_actual, i);
            }
        }
        else if (ASTType(a) == AST_AMBIGUITY)
        {
            int i;
            for(i = 0; i < ast_get_num_ambiguities(a); i++)
            {
                ast_dump_graphviz_rec(ast_get_ambiguity(a, i), f, node_actual, i);
            }
        }
    }
    else
    {
        fprintf(f, "n%d[shape=circle,label=\"\",fixedsize=true,style=filled,fillcolor=black,height=0.1,width=0.1]\n", node_actual);
        if (parent_node != 0)
        {
            fprintf(f, "n%d -> n%d [label=\"%d\"]\n", parent_node, node_actual, position);
        }
    }
}
static void ast_dump_graphviz_rec(AST a, FILE* f, size_t parent_node, int position, char is_extended UNUSED_PARAMETER)
{
    // static char* octagon = "octagon";
    // static char* doubleoctagon = "doubleoctagon";
    static char* ellipse = "ellipse";
    static char* mdiamond = "Mdiamond";
    static char* box = "box";
    char* shape;

    // I know this is not exact, but there is a %z qualifier in printf
    // while there is not such thing for intptr_t
    size_t current_node = (size_t)a;

    if (a != NULL)
    {
        // Select shape
        shape = box;
        if (ASTType(a) == AST_AMBIGUITY) shape = ellipse;
        if (ASTType(a) == AST_NODE_LIST) shape = mdiamond;
        // if (a->construct_type == CT_SPECIFICATION) shape = ellipse;
        // else if (a->construct_type == CT_OMP_SPECIFICATION) shape = mdiamond;
        // else if (a->construct_type == CT_EXECUTABLE) shape = octagon;
        // else if (a->construct_type == CT_OMP_EXECUTABLE) shape = doubleoctagon;

        if (ASTText(a))
        {
            char *quoted = quote_protect(ASTText(a));

            fprintf(f, "n%zd[shape=%s,label=\"%s\\nNode=%p\\nParent=%p\\n%s\\nText: \\\"%s\\\"\"]\n", 
                    current_node, shape, ast_print_node_type(ASTType(a)), a, ASTParent(a), ast_location(a), quoted);

            free(quoted);
        }
        else
        {
            fprintf(f, "n%zd[shape=%s,label=\"%s\\nNode=%p\\nParent=%p\\n%s\"]\n", 
                    current_node, shape, ast_print_node_type(ASTType(a)), a, ASTParent(a), ast_location(a));
        }

        // Print this only for non extended referenced nodes
        if (parent_node != 0)
        {
            fprintf(f, "n%zd -> n%zd [label=\"%d\"]\n", parent_node, current_node, position);
        }

        if (ASTType(a) != AST_AMBIGUITY)
        {
            int i;
            if (!is_extended)
            {
                for(i = 0; i < ASTNumChildren(a); i++)
                {
                    if (ASTChild(a, i) != NULL)
                    {
                        ast_dump_graphviz_rec(ASTChild(a, i), f, current_node, i, /* is_extended */ is_extended);
                    }
                }
            }

            // Now print all extended trees referenced here
            // First get all TL_AST in 'orig' that point to its childrens

            extensible_struct_t* extended_data = ast_get_extensible_struct(a);

            if (extended_data != NULL
                    && !is_extended)
            {
                int num_fields = 0;
                const char** keys = NULL;
                const void** values = NULL;

                extensible_struct_get_all_data(extended_data, &num_fields, &keys, &values);

                for (i = 0; i < num_fields; i++)
                {
                    const char* field_name = keys[i];
                    tl_type_t* tl_data = (tl_type_t*)values[i];
                    if (tl_data->kind == TL_AST)
                    {
                        if (tl_data->data._ast != a)
                        {
                            ast_dump_graphviz_rec(tl_data->data._ast, f, /* parent_node */ 0, /* position */ 0, /* is_extended */ 1);
                        }

                        // Add an edge
                        fprintf(f, "n%zd -> n%zd [label=\"%s\",style=dashed]\n",
                                current_node,
                                (size_t)(tl_data->data._ast),
                                field_name);
                    }
                }
            }
        }
        else if (ASTType(a) == AST_AMBIGUITY)
        {
            int i;
            for(i = 0; i < ast_get_num_ambiguities(a); i++)
            {
                ast_dump_graphviz_rec(ast_get_ambiguity(a, i), f, current_node, i, /* is_extended */ 0);
            }
        }
    }
    else
    {
        fprintf(f, "n%zd[shape=circle,label=\"\",fixedsize=true,style=filled,fillcolor=black,height=0.1,width=0.1]\n", current_node);
        if (parent_node != 0)
        {
            fprintf(f, "n%zd -> n%zd [label=\"%d\"]\n", parent_node, current_node, position);
        }
    }
}