PIPS
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "misc.h"
#include "ri.h"
#include "ri-util.h"
#include "cyacc.h"
#include "c_syntax.h"
#include "resources.h"
#include "database.h"
#include "pipsdbm.h"
#include "workspace-util.h"
#include "text-util.h"
Go to the source code of this file.
Variables | |
string | compilation_unit_name |
cproto-generated files More... | |
list | CalledModules = NIL |
statement | ModuleStatement = statement_undefined |
static string | c_parser_current_file_name = string_undefined |
static string | c_parser_current_user_input_file_name = string_undefined |
stack | ContextStack = stack_undefined |
stack | FunctionStack = stack_undefined |
stack | FormalStack = stack_undefined |
stack | OffsetStack = stack_undefined |
stack | StructNameStack = stack_undefined |
int | loop_counter = 1 |
Global counter. More... | |
int | derived_counter = 1 |
static hash_table | entity_to_type_stack_table = hash_table_undefined |
bool | compilation_unit_parser_is_running_p = false |
To pass down the information to functions used by the syntactical analyzer. More... | |
list | removable_extern_entities = list_undefined |
|
static |
FI: not clean, but useful for debugging statement
{
set_prettyprint_language_tag(is_language_c);
}
Special case, set the compilation unit as the current module
I do not know to put this where to avoid repeated creations
Rather than dealing with the issue in error handling
Mainly reset the line number:
yacc parser is called
pips_debug(2,"Module statement: \n");
print_statement_of_module(ModuleStatement, module_name);
Even if you are not in a compilation unit, external functions may be declared many times within one scope.
Variables allocated within the compilation unit should be declared only once, no?
alue_code_p(v) &&
Beware : the rule in pipsmake-rc.tex for compilation_unit_parser does not include the production of parsed_code and callees. This is not very clean, and is done to work around the way pipsmake handles compilation units and modules. There was no simple solution... BC.
Used to be done in ResetCurrentCompilationUnitEntity()
Definition at line 544 of file c_parser.c.
References basic_domain, c_in, c_parse(), c_parser_context_domain, CalledModules, check_declaration_uniqueness_p(), code_domain, compilation_unit_name, compilation_unit_of_module(), compilation_unit_p(), compilation_unit_parser_is_running_p, concatenate(), ContextStack, db_get_current_workspace_directory(), db_get_file_resource, db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, derived_counter, ENDP, ENTITY, entity_domain, entity_initial, entity_storage, entity_type, file_name, FixCInternalLabels(), FixCReturnStatements(), FOREACH, FormalStack, free(), FunctionStack, gen_free_list(), ifdebug, init_C_comment(), init_c_parser_scope_stack(), init_entity_type_storage_table(), InitScope(), is_language_c, keyword_typedef_table, list_undefined_p, loop_counter, make_callees(), make_predefined_C_entities(), MakeCurrentCompilationUnitEntity(), MakeTopLevelEntity(), module_name(), ModuleStatement, NIL, OffsetStack, parser_init_keyword_typedef_table(), pips_assert, pips_debug, print_entities(), printf(), removable_extern_entities, RemoveFromExterns(), reset_C_comment(), reset_c_parser_current_input_file_name(), reset_c_parser_current_user_input_file_name(), reset_c_parser_scope_stack(), reset_current_C_line_number(), reset_current_dummy_parameter_number(), reset_declaration_counter(), reset_entity_type_stack_table(), reset_expression_comment(), reset_preprocessor_line_analysis(), ResetCurrentCompilationUnitEntity(), safe_fclose(), safe_fopen(), set_c_parser_current_input_file_name(), set_c_parser_current_user_input_file_name(), set_current_C_line_number(), set_prettyprint_language_tag(), stack_empty_p(), stack_free(), stack_make(), stack_undefined, statement_consistent_p(), statement_declarations, statement_normalize_subscripts(), storage_undefined_p, strdup(), STRING, StructNameStack, type_undefined_p, type_variable_p, and value_undefined_p.
Referenced by c_parser(), and compilation_unit_parser().
bool c_parser | ( | const char * | module_name | ) |
When the compilation_unit is parsed, it is parsed a second time and multiple declarations are certain to happen.
module_name | odule_name |
Definition at line 739 of file c_parser.c.
References actual_c_parser(), and module_name().
bool c_parser_error | ( | const char * | func, |
const char * | msg | ||
) |
Output a parser message error.
At the end there is a pips_user_error that launch an exception so that this function may not really exit but may be caught at a higher level...
This function is called by macro CParserError()
Since many information are lost by the various resetting, first save them for later display:
Reset the parser global variables ?
The error may occur before the current module entity is defined
Stacks are not allocated yet when dealing with external declarations. I assume that all stacks are declared simultaneously, hence a single test before freeing.
Reset them to stack_undefined_p instead of STACK_NULL
get rid of all collected comments
ffective_line_number,
func | unc |
msg | sg |
Definition at line 266 of file c_parser.c.
References BlockStack, c_reset_lex(), CleanLocalEntities(), code_declarations, code_decls_text, ContextStack, entity_initial, entity_undefined, entity_undefined_p, entity_user_name(), error_reset_c_parser_current_input_file_name(), error_reset_c_parser_current_user_input_file_name(), error_reset_current_C_line_number(), error_reset_current_module_entity(), force_reset_c_parser_scope_stack(), FormalStack, FunctionStack, get_c_parser_current_user_input_file_name(), get_current_C_line_number(), get_current_module_entity(), LoopStack, NIL, OffsetStack, pips_debug, pips_user_error, pips_user_warning, reset_C_comment(), Reset_C_ReturnStatement(), reset_current_dummy_parameter_number(), reset_declaration_counter(), reset_entity_type_stack_table(), reset_expression_comment(), stack_free(), stack_undefined, stack_undefined_p, string_undefined, StructNameStack, SwitchControllerStack, SwitchGotoStack, user_line_number, and value_code.
Referenced by make_C_constant_entity().
bool compilation_unit_parser | ( | const char * | module_name | ) |
module_name | odule_name |
Definition at line 746 of file c_parser.c.
References actual_c_parser(), and module_name().
Referenced by AddEntityToCompilationUnit(), and outliner_independent().
void error_reset_c_parser_current_input_file_name | ( | void | ) |
Definition at line 81 of file c_parser.c.
References c_parser_current_file_name, and string_undefined.
Referenced by c_parser_error().
void error_reset_c_parser_current_user_input_file_name | ( | void | ) |
Definition at line 112 of file c_parser.c.
References c_parser_current_user_input_file_name, and string_undefined.
Referenced by c_parser_error().
|
static |
To avoid label name conflicts, the parser uses a special character that cannot appear in a C label.
Any label that uses this character must be replaced. A new label entity must be introduced.
Build the substitution table while avoiding label name conflicts
Here we end up with a conflict free label name
Substitute the labels by the new labels in all substatement of s
Get rid of useless label entities, unless it has already been performed by substitute_statement_label().
Definition at line 373 of file c_parser.c.
References concatenate(), count, ENTITY, entity_module_name(), FindOrCreateEntity(), FOREACH, free(), gen_context_recurse, gen_null2(), get_label_prefix, hash_pointer, hash_put(), hash_table_free(), hash_table_make(), label_local_name(), label_name_conflict_with_labels(), LABEL_PREFIX, statement_domain, statement_to_labels(), strdup(), and substitute_statement_label().
Referenced by actual_c_parser().
string get_c_parser_current_input_file_name | ( | void | ) |
Definition at line 58 of file c_parser.c.
References c_parser_current_file_name, pips_internal_error, and string_undefined_p.
Referenced by c_parser_user_warning_alist(), and UpdateEntity().
string get_c_parser_current_user_input_file_name | ( | void | ) |
Definition at line 89 of file c_parser.c.
References c_parser_current_user_input_file_name, pips_internal_error, and string_undefined_p.
Referenced by c_parser_error(), and c_parser_user_warning_alist().
key | ey |
Definition at line 146 of file c_parser.c.
References entity_name, entity_to_type_stack_table, hash_get(), HASH_UNDEFINED_VALUE, and stack_undefined.
Referenced by FindOrCreateCurrentEntity(), RenameFunctionEntity(), SubstituteDummyParameters(), UpdateAbstractEntity(), UpdateDerivedEntity(), UpdateEntity(), and UseFormalArguments().
void init_entity_type_storage_table | ( | void | ) |
Definition at line 131 of file c_parser.c.
References entity_to_type_stack_table, hash_string, hash_table_make(), hash_table_undefined_p, and reset_entity_type_stack_table().
Referenced by actual_c_parser().
void make_predefined_C_entities | ( | string | compilation_unit_name | ) |
Predefined type(s): __builtin_va_list
Let's lie about the real type
Predefined functions(s): __builtin_va_end (va_arg() is parsed directly)
Let's lie about the real type...
Let's lie about the real type
Let's lie about the real type
compilation_unit_name | ompilation_unit_name |
Definition at line 425 of file c_parser.c.
References BUILTIN_VA_COPY, BUILTIN_VA_END, BUILTIN_VA_START, compilation_unit_name, CONS, copy_parameter(), DEFAULT_COMPLEX_TYPE_SIZE, DEFAULT_INTEGER_TYPE_SIZE, DEFAULT_LOGICAL_TYPE_SIZE, entity_initial, entity_storage, entity_type, entity_undefined, FindOrCreateEntity(), is_basic_pointer, is_basic_typedef, is_mode_value, is_type_functional, is_type_variable, is_type_void, make_basic(), make_basic_complex(), make_basic_int(), make_basic_logical(), make_dummy_unknown(), make_functional(), make_mode(), make_mode_value(), make_parameter(), make_storage_rom(), make_type(), make_type_void(), make_value_intrinsic(), make_value_unknown(), make_variable(), NIL, PARAMETER, storage_undefined_p, TYPEDEF_PREFIX, and UU.
Referenced by actual_c_parser().
void parser_init_keyword_typedef_table | ( | void | ) |
FI: keyword_typedef_table is also a global variable. I am trying to move towards some kind of functional wrapping around the global variable, which I would like to declare static in ri-util/static.c.
GNU predefined type(s), expecting no conflict with user named type
AM: en attendant mieux...
typedef names are added later when encoutered.
Definition at line 193 of file c_parser.c.
References hash_put(), keyword_typedef_table, make_keyword_typedef_table(), TK_ASM, TK_AUTO, TK_BREAK, TK_BUILTIN_VA_ARG, TK_CASE, TK_CHAR, TK_COMPLEX, TK_CONST, TK_CONTINUE, TK_DEFAULT, TK_DO, TK_DOUBLE, TK_ELSE, TK_ENUM, TK_EXTERN, TK_FLOAT, TK_FOR, TK_GOTO, TK_IF, TK_INLINE, TK_INT, TK_INT128, TK_LONG, TK_NAMED_TYPE, TK_REGISTER, TK_RESTRICT, TK_RETURN, TK_SHORT, TK_SIGNED, TK_SIZEOF, TK_STATIC, TK_STRUCT, TK_SWITCH, TK_THREAD, TK_TYPEDEF, TK_UINT128, TK_UNION, TK_UNSIGNED, TK_VOID, TK_VOLATILE, and TK_WHILE.
Referenced by actual_c_parser().
key | ey |
Definition at line 139 of file c_parser.c.
References entity_name, entity_to_type_stack_table, hash_put(), pips_internal_error, and stack_undefined_p.
Referenced by RenameFunctionEntity(), and SubstituteDummyParameters().
void remove_entity_type_stack | ( | entity | e | ) |
Definition at line 156 of file c_parser.c.
References entity_name, entity_to_type_stack_table, fprintf(), hash_del(), hash_get(), HASH_UNDEFINED_VALUE, ifdebug, pips_debug, stack_free(), and stack_undefined_p.
Referenced by remove_entity_type_stacks(), and SubstituteDummyParameters().
void remove_entity_type_stacks | ( | list | el | ) |
el | l |
Definition at line 179 of file c_parser.c.
References ENTITY, FOREACH, and remove_entity_type_stack().
Referenced by RemoveDummyArguments(), and UseFormalArguments().
void reset_c_parser_current_input_file_name | ( | void | ) |
Definition at line 73 of file c_parser.c.
References c_parser_current_file_name, pips_internal_error, string_undefined, and string_undefined_p.
Referenced by actual_c_parser().
void reset_c_parser_current_user_input_file_name | ( | void | ) |
Definition at line 104 of file c_parser.c.
References c_parser_current_user_input_file_name, pips_internal_error, string_undefined, and string_undefined_p.
Referenced by actual_c_parser().
void reset_entity_type_stack_table | ( | void | ) |
Definition at line 186 of file c_parser.c.
References entity_to_type_stack_table, HASH_MAP, hash_table_free(), hash_table_undefined, and stack_free().
Referenced by actual_c_parser(), c_parser_error(), and init_entity_type_storage_table().
void set_c_parser_current_input_file_name | ( | string | file_name | ) |
file_name | ile_name |
Definition at line 65 of file c_parser.c.
References c_parser_current_file_name, file_name, pips_internal_error, and string_undefined_p.
Referenced by actual_c_parser().
void set_c_parser_current_user_input_file_name | ( | string | file_name | ) |
file_name | ile_name |
Definition at line 96 of file c_parser.c.
References c_parser_current_user_input_file_name, file_name, pips_internal_error, and string_undefined_p.
Referenced by actual_c_parser().
|
static |
FI: entity l could be destroyed right away...
Definition at line 354 of file c_parser.c.
References entity_empty_label_p(), hash_get(), HASH_UNDEFINED_VALUE, and statement_label.
Referenced by FixCInternalLabels().
|
static |
Definition at line 56 of file c_parser.c.
Referenced by error_reset_c_parser_current_input_file_name(), get_c_parser_current_input_file_name(), reset_c_parser_current_input_file_name(), and set_c_parser_current_input_file_name().
|
static |
Definition at line 87 of file c_parser.c.
Referenced by error_reset_c_parser_current_user_input_file_name(), get_c_parser_current_user_input_file_name(), reset_c_parser_current_user_input_file_name(), and set_c_parser_current_user_input_file_name().
Definition at line 51 of file c_parser.c.
Referenced by actual_c_parser(), and AddToCalledModules().
string compilation_unit_name |
cproto-generated files
Definition at line 49 of file c_parser.c.
Referenced by actual_c_parser(), add_new_compilation_unit(), add_new_module_from_text(), build_real_resources(), compilation_unit_of_module(), CreateEntityFromLocalNameAndPrefix(), CreateMemberScope(), FindEntityFromLocalName(), FindEntityFromLocalNameAndPrefix(), FindOrCreateCurrentEntity(), get_current_compilation_unit_entity(), init_c_areas(), make_predefined_C_entities(), and MakeStorageRam().
To pass down the information to functions used by the syntactical analyzer.
Definition at line 541 of file c_parser.c.
Referenced by actual_c_parser(), and analyze_preprocessor_line().
stack ContextStack = stack_undefined |
Definition at line 117 of file c_parser.c.
Referenced by actual_c_parser(), c_parser_error(), EnterScope(), ExitScope(), GetContext(), GetContextCopy(), GetParentScope(), GetScope(), PopContext(), PushContext(), ScopeStackSize(), UpdateAbstractEntity(), UpdateDerivedEntities(), UpdateDerivedEntity(), UpdateEntities(), and UpdateEntity().
int derived_counter = 1 |
Definition at line 125 of file c_parser.c.
Referenced by actual_c_parser().
|
static |
Definition at line 128 of file c_parser.c.
Referenced by get_from_entity_type_stack_table(), init_entity_type_storage_table(), put_to_entity_type_stack_table(), remove_entity_type_stack(), and reset_entity_type_stack_table().
stack FormalStack = stack_undefined |
Definition at line 119 of file c_parser.c.
Referenced by actual_c_parser(), c_parser_error(), FindOrCreateCurrentEntity(), UpdateEntities(), and UpdateEntity().
stack FunctionStack = stack_undefined |
Definition at line 118 of file c_parser.c.
Referenced by actual_c_parser(), c_parser_error(), FindOrCreateCurrentEntity(), GetFunction(), MakeParameterList(), PopFunction(), PushFunction(), UpdateEntities(), and UpdateEntity().
int loop_counter = 1 |
statement ModuleStatement = statement_undefined |
Definition at line 53 of file c_parser.c.
Referenced by actual_c_parser(), CCompilationUnitMemoryAllocations(), and CModuleMemoryAllocation().
stack OffsetStack = stack_undefined |
Definition at line 120 of file c_parser.c.
Referenced by actual_c_parser(), c_parser_error(), StackPop(), StackPush(), UpdateEntities(), and UpdateEntity().
list removable_extern_entities = list_undefined |
Definition at line 542 of file c_parser.c.
Referenced by actual_c_parser(), and CleanUpEntities().
stack StructNameStack = stack_undefined |
Definition at line 121 of file c_parser.c.
Referenced by actual_c_parser(), and c_parser_error().