|
@@ -537,6 +537,11 @@ storage_class:
|
|
|
empty
|
|
empty
|
|
|
{
|
|
{
|
|
|
$$ = 0;
|
|
$$ = 0;
|
|
|
|
|
+}
|
|
|
|
|
+ | storage_class KW_CONST
|
|
|
|
|
+{
|
|
|
|
|
+ // This isn't really a storage class, but it helps with parsing.
|
|
|
|
|
+ $$ = $1 | (int)CPPInstance::SC_const;
|
|
|
}
|
|
}
|
|
|
| storage_class KW_EXTERN
|
|
| storage_class KW_EXTERN
|
|
|
{
|
|
{
|
|
@@ -592,30 +597,6 @@ storage_class:
|
|
|
;
|
|
;
|
|
|
|
|
|
|
|
type_like_declaration:
|
|
type_like_declaration:
|
|
|
- multiple_var_declaration
|
|
|
|
|
-{
|
|
|
|
|
- /* multiple_var_declaration adds itself to the scope. */
|
|
|
|
|
-}
|
|
|
|
|
- | storage_class type_decl ';'
|
|
|
|
|
-{
|
|
|
|
|
- // We don't really care about the storage class here. In fact, it's
|
|
|
|
|
- // not actually legal to define a class or struct using a particular
|
|
|
|
|
- // storage class, but we require it just to help yacc out in its
|
|
|
|
|
- // parsing.
|
|
|
|
|
-
|
|
|
|
|
- current_scope->add_declaration($2, global_scope, current_lexer, @2);
|
|
|
|
|
-}
|
|
|
|
|
- | storage_class function_prototype maybe_initialize_or_function_body
|
|
|
|
|
-{
|
|
|
|
|
- if ($2 != (CPPInstance *)NULL) {
|
|
|
|
|
- $2->_storage_class |= (current_storage_class | $1);
|
|
|
|
|
- current_scope->add_declaration($2, global_scope, current_lexer, @2);
|
|
|
|
|
- $2->set_initializer($3);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
- ;
|
|
|
|
|
-
|
|
|
|
|
-multiple_var_declaration:
|
|
|
|
|
storage_class type_decl
|
|
storage_class type_decl
|
|
|
{
|
|
{
|
|
|
// We don't need to push/pop type, because we can't nest
|
|
// We don't need to push/pop type, because we can't nest
|
|
@@ -631,18 +612,23 @@ multiple_var_declaration:
|
|
|
{
|
|
{
|
|
|
pop_storage_class();
|
|
pop_storage_class();
|
|
|
}
|
|
}
|
|
|
- | storage_class KW_CONST type
|
|
|
|
|
|
|
+ | storage_class type_decl ';'
|
|
|
{
|
|
{
|
|
|
- // We don't need to push/pop type, because we can't nest
|
|
|
|
|
- // multiple_var_declarations.
|
|
|
|
|
- current_type = $3;
|
|
|
|
|
- push_storage_class($1);
|
|
|
|
|
|
|
+ // We don't really care about the storage class here. In fact, it's
|
|
|
|
|
+ // not actually legal to define a class or struct using a particular
|
|
|
|
|
+ // storage class, but we require it just to help yacc out in its
|
|
|
|
|
+ // parsing.
|
|
|
|
|
+
|
|
|
|
|
+ current_scope->add_declaration($2, global_scope, current_lexer, @2);
|
|
|
}
|
|
}
|
|
|
- multiple_const_instance_identifiers
|
|
|
|
|
|
|
+ | storage_class function_prototype maybe_initialize_or_function_body
|
|
|
{
|
|
{
|
|
|
- pop_storage_class();
|
|
|
|
|
|
|
+ if ($2 != (CPPInstance *)NULL) {
|
|
|
|
|
+ $2->_storage_class |= (current_storage_class | $1);
|
|
|
|
|
+ current_scope->add_declaration($2, global_scope, current_lexer, @2);
|
|
|
|
|
+ $2->set_initializer($3);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
/* We don't need to include a rule for variables that point to
|
|
/* We don't need to include a rule for variables that point to
|
|
|
functions, because we get those from the function_prototype
|
|
functions, because we get those from the function_prototype
|
|
|
definition. */
|
|
definition. */
|
|
@@ -651,6 +637,9 @@ multiple_var_declaration:
|
|
|
multiple_instance_identifiers:
|
|
multiple_instance_identifiers:
|
|
|
instance_identifier maybe_initialize_or_function_body
|
|
instance_identifier maybe_initialize_or_function_body
|
|
|
{
|
|
{
|
|
|
|
|
+ if (current_storage_class & CPPInstance::SC_const) {
|
|
|
|
|
+ $1->add_modifier(IIT_const);
|
|
|
|
|
+ }
|
|
|
CPPInstance *inst = new CPPInstance(current_type, $1,
|
|
CPPInstance *inst = new CPPInstance(current_type, $1,
|
|
|
current_storage_class,
|
|
current_storage_class,
|
|
|
@1.file);
|
|
@1.file);
|
|
@@ -659,6 +648,9 @@ multiple_instance_identifiers:
|
|
|
}
|
|
}
|
|
|
| instance_identifier maybe_initialize ',' multiple_instance_identifiers
|
|
| instance_identifier maybe_initialize ',' multiple_instance_identifiers
|
|
|
{
|
|
{
|
|
|
|
|
+ if (current_storage_class & CPPInstance::SC_const) {
|
|
|
|
|
+ $1->add_modifier(IIT_const);
|
|
|
|
|
+ }
|
|
|
CPPInstance *inst = new CPPInstance(current_type, $1,
|
|
CPPInstance *inst = new CPPInstance(current_type, $1,
|
|
|
current_storage_class,
|
|
current_storage_class,
|
|
|
@1.file);
|
|
@1.file);
|
|
@@ -667,28 +659,6 @@ multiple_instance_identifiers:
|
|
|
}
|
|
}
|
|
|
;
|
|
;
|
|
|
|
|
|
|
|
-multiple_const_instance_identifiers:
|
|
|
|
|
- instance_identifier maybe_initialize_or_function_body
|
|
|
|
|
-{
|
|
|
|
|
- $1->add_modifier(IIT_const);
|
|
|
|
|
- CPPInstance *inst = new CPPInstance(current_type, $1,
|
|
|
|
|
- current_storage_class,
|
|
|
|
|
- @1.file);
|
|
|
|
|
- inst->set_initializer($2);
|
|
|
|
|
- current_scope->add_declaration(inst, global_scope, current_lexer, @1);
|
|
|
|
|
-}
|
|
|
|
|
- | instance_identifier maybe_initialize ',' multiple_const_instance_identifiers
|
|
|
|
|
-{
|
|
|
|
|
- $1->add_modifier(IIT_const);
|
|
|
|
|
- CPPInstance *inst = new CPPInstance(current_type, $1,
|
|
|
|
|
- current_storage_class,
|
|
|
|
|
- @1.file);
|
|
|
|
|
- inst->set_initializer($2);
|
|
|
|
|
- current_scope->add_declaration(inst, global_scope, current_lexer, @1);
|
|
|
|
|
-}
|
|
|
|
|
- ;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
typedef_declaration:
|
|
typedef_declaration:
|
|
|
storage_class type_decl
|
|
storage_class type_decl
|
|
|
{
|
|
{
|
|
@@ -704,17 +674,6 @@ typedef_declaration:
|
|
|
typedef_instance_identifiers
|
|
typedef_instance_identifiers
|
|
|
{
|
|
{
|
|
|
pop_storage_class();
|
|
pop_storage_class();
|
|
|
-}
|
|
|
|
|
- | storage_class KW_CONST type
|
|
|
|
|
-{
|
|
|
|
|
- // We don't need to push/pop type, because we can't nest
|
|
|
|
|
- // multiple_var_declarations.
|
|
|
|
|
- current_type = $3;
|
|
|
|
|
- push_storage_class($1);
|
|
|
|
|
-}
|
|
|
|
|
- typedef_const_instance_identifiers
|
|
|
|
|
-{
|
|
|
|
|
- pop_storage_class();
|
|
|
|
|
}
|
|
}
|
|
|
| storage_class function_prototype maybe_initialize_or_function_body
|
|
| storage_class function_prototype maybe_initialize_or_function_body
|
|
|
{
|
|
{
|
|
@@ -733,29 +692,18 @@ typedef_declaration:
|
|
|
typedef_instance_identifiers:
|
|
typedef_instance_identifiers:
|
|
|
instance_identifier maybe_initialize_or_function_body
|
|
instance_identifier maybe_initialize_or_function_body
|
|
|
{
|
|
{
|
|
|
|
|
+ if (current_storage_class & CPPInstance::SC_const) {
|
|
|
|
|
+ $1->add_modifier(IIT_const);
|
|
|
|
|
+ }
|
|
|
CPPType *target_type = current_type;
|
|
CPPType *target_type = current_type;
|
|
|
CPPTypedefType *typedef_type = new CPPTypedefType(target_type, $1, current_scope, @1.file);
|
|
CPPTypedefType *typedef_type = new CPPTypedefType(target_type, $1, current_scope, @1.file);
|
|
|
current_scope->add_declaration(typedef_type, global_scope, current_lexer, @1);
|
|
current_scope->add_declaration(typedef_type, global_scope, current_lexer, @1);
|
|
|
}
|
|
}
|
|
|
| instance_identifier maybe_initialize ',' typedef_instance_identifiers
|
|
| instance_identifier maybe_initialize ',' typedef_instance_identifiers
|
|
|
{
|
|
{
|
|
|
- CPPType *target_type = current_type;
|
|
|
|
|
- CPPTypedefType *typedef_type = new CPPTypedefType(target_type, $1, current_scope, @1.file);
|
|
|
|
|
- current_scope->add_declaration(typedef_type, global_scope, current_lexer, @1);
|
|
|
|
|
-}
|
|
|
|
|
- ;
|
|
|
|
|
-
|
|
|
|
|
-typedef_const_instance_identifiers:
|
|
|
|
|
- instance_identifier maybe_initialize_or_function_body
|
|
|
|
|
-{
|
|
|
|
|
- $1->add_modifier(IIT_const);
|
|
|
|
|
- CPPType *target_type = current_type;
|
|
|
|
|
- CPPTypedefType *typedef_type = new CPPTypedefType(target_type, $1, current_scope, @1.file);
|
|
|
|
|
- current_scope->add_declaration(typedef_type, global_scope, current_lexer, @1);
|
|
|
|
|
-}
|
|
|
|
|
- | instance_identifier maybe_initialize ',' typedef_const_instance_identifiers
|
|
|
|
|
-{
|
|
|
|
|
- $1->add_modifier(IIT_const);
|
|
|
|
|
|
|
+ if (current_storage_class & CPPInstance::SC_const) {
|
|
|
|
|
+ $1->add_modifier(IIT_const);
|
|
|
|
|
+ }
|
|
|
CPPType *target_type = current_type;
|
|
CPPType *target_type = current_type;
|
|
|
CPPTypedefType *typedef_type = new CPPTypedefType(target_type, $1, current_scope, @1.file);
|
|
CPPTypedefType *typedef_type = new CPPTypedefType(target_type, $1, current_scope, @1.file);
|
|
|
current_scope->add_declaration(typedef_type, global_scope, current_lexer, @1);
|
|
current_scope->add_declaration(typedef_type, global_scope, current_lexer, @1);
|