📄 psdl_scope.cpp
字号:
// -*- C++ -*-
// PSDL_Scope.cpp,v 1.4 2003/11/26 10:45:50 jwillemsen Exp
#include "PSDL_Scope.h"
#include "PSDL_Root_Scope.h"
#include "PSDL_Simple_Scope.h"
#include "PSDL_Module_Scope.h"
#include "PSDL_Interface_Scope.h"
#include "PSDL_Struct_Scope.h"
#include "PSDL_Exception_Scope.h"
#include "PSDL_Op_Dcl_Scope.h"
#include "PSDL_Stream.h"
#include "ace/OS_NS_ctype.h"
ACE_RCSID (PSS, PSDL_Scope, "PSDL_Scope.cpp,v 1.4 2003/11/26 10:45:50 jwillemsen Exp")
#undef INCREMENT
#define INCREMENT 40
TAO_PSDL_Scope::TAO_PSDL_Scope (void)
: psdl_scope_ (new TAO_PSDL_Scope *[INCREMENT]),
ast_scope_ (0),
module_names_ (0),
interface_names_ (0),
psdl_scope_top_ (0),
root_scope_ (0),
identifier_ (),
name_space_ (),
interface_name_ (),
ps_sh_ (0),
ps_si_ (0),
ps_sin_ (0)
{
}
TAO_PSDL_Scope::~TAO_PSDL_Scope (void)
{
}
void
TAO_PSDL_Scope::to_lower_case (ACE_CString &identifier)
{
size_t len = identifier.length ();
for (size_t i = 0; i <= len; ++i)
{
identifier[i] = ACE_OS::to_lower (identifier[i]);
}
}
int
TAO_PSDL_Scope::check_identifier (ACE_CString identifier,
TAO_PSDL_Scope *scope)
{
int result = 0;
this->to_lower_case (identifier);
// Check in the ROOT_SCOPE
if (scope->scope_map () != 0)
result = scope->scope_map ()->find (identifier);
if (result != 0)
{
// Didnt find in this scope. Check in the parents scope
// since that also counts.
if (scope->parent_scope () != 0)
{
result =
this->check_identifier (identifier,
scope->parent_scope ());
}
}
return result;
}
void
TAO_PSDL_Scope::check_name_in_scope (ACE_CString identifier,
TAO_PSDL_Scope *scope)
{
// This method is to be used in the cases when the identifier should
// have been declared before: for example, forward declarations.
// Check if it is a user-defined type defined in this scope.
int check_result = this->check_identifier (identifier,
scope);
if (check_result == -1)
{
ACE_DEBUG ((LM_DEBUG,
"Identifier %s not defined before in the scope..aborting..\n",
identifier.c_str ()));
ACE_OS::exit (1);
}
}
int
TAO_PSDL_Scope::add_module (ACE_CString)
{
return 0;
}
int
TAO_PSDL_Scope::add_module_to_scope (ACE_CString identifier,
TAO_PSDL_Scope *scope)
{
ACE_CString lower_identifier = identifier;
this->to_lower_case (lower_identifier);
if (this->check_identifier (lower_identifier, scope) == -1)
{
TAO_PSDL_Module_Scope *psdl_module =
new TAO_PSDL_Module_Scope (scope);
scope->scope_map ()->bind (lower_identifier,
psdl_module);
size_t cur_size = this->module_names_.size ();
/// @@ Rather than here .. you must have actually save the
/// identifier name in the instance of the module itself .. or
/// may be I should rather figure out a
this->module_names_.size (cur_size + 1);
this->module_names_[cur_size] = identifier;
TAO_PSDL_Scope::instance ()->push_scope (psdl_module);
}
else
{
ACE_DEBUG ((LM_DEBUG,
"Error: module name re-defined: ABORTING\n"));
return -1;
}
return 0;
}
int
TAO_PSDL_Scope::add_interface_dcl_to_scope (ACE_CString identifier,
TAO_PSDL_Scope *scope)
{
this->to_lower_case (identifier);
if (this->check_identifier (identifier, scope) == -1)
{
TAO_PSDL_Simple_Scope *psdl_simple =
new TAO_PSDL_Simple_Scope (scope,
"forward_dcl");
scope->scope_map ()->bind (identifier,
psdl_simple);
}
else
{
ACE_DEBUG ((LM_DEBUG,
"Error: interface_name %s re-defined\n",
identifier.c_str ()));
ACE_OS::exit (1);
return -1;
}
return 0;
}
int
TAO_PSDL_Scope::add_interface (ACE_CString)
{
return 0;
}
int
TAO_PSDL_Scope::add_interface_to_scope (ACE_CString identifier,
TAO_PSDL_Scope *scope)
{
this->to_lower_case (identifier);
if (this->check_identifier (identifier, scope) == -1)
{
TAO_PSDL_Interface_Scope *psdl_interface =
new TAO_PSDL_Interface_Scope (scope);
scope->scope_map ()->bind (identifier,
psdl_interface);
TAO_PSDL_Scope::instance ()->push_scope (psdl_interface);
}
else
{
ACE_DEBUG ((LM_DEBUG,
"Error: interface_name %s re-defined\n",
identifier.c_str ()));
ACE_OS::exit (1);
return -1;
}
return 0;
}
int
TAO_PSDL_Scope::add_struct (ACE_CString)
{
return 0;
}
int
TAO_PSDL_Scope::add_struct_to_scope (ACE_CString struct_name,
TAO_PSDL_Scope *scope)
{
this->to_lower_case (struct_name);
if (this->check_identifier (struct_name, scope) == -1)
{
TAO_PSDL_Struct_Scope *psdl_struct =
new TAO_PSDL_Struct_Scope (scope);
scope->scope_map ()->bind (struct_name,
psdl_struct);
TAO_PSDL_Scope::instance ()->push_scope (psdl_struct);
}
else
{
ACE_DEBUG ((LM_DEBUG,
"Error: identifier re-defined: ABORTING\n"));
ACE_OS::exit (1);
return -1;
}
return 0;
}
int
TAO_PSDL_Scope::add_typedef (ACE_CString,
ACE_CString)
{
return 0;
}
int
TAO_PSDL_Scope::add_typedef_to_scope (ACE_CString identifier,
ACE_CString identifier_type,
TAO_PSDL_Scope *scope)
{
this->to_lower_case (identifier);
this->to_lower_case (identifier_type);
if (this->check_identifier (identifier, scope) == -1)
{
TAO_PSDL_Simple_Scope *psdl_simple =
new TAO_PSDL_Simple_Scope (scope,
identifier_type);
scope->scope_map ()->bind (identifier,
psdl_simple);
}
else
{
ACE_DEBUG ((LM_ERROR,
"Error: trying to redefine typedef %s\n",
identifier.c_str ()));
ACE_OS::exit (1);
return -1;
}
return 0;
}
int
TAO_PSDL_Scope::add_const_decl (ACE_CString,
ACE_CString)
{
return 0;
}
int
TAO_PSDL_Scope::add_const_decl_to_scope (ACE_CString identifier,
ACE_CString identifier_type,
TAO_PSDL_Scope *scope)
{
this->to_lower_case (identifier);
this->to_lower_case (identifier_type);
// First check if the identifier_type is either a predefined type
// or if it is defined before. If it is defined before, we will
// proceed.
this->check_name_in_scope (identifier_type, scope);
if (this->check_identifier (identifier, scope) == -1)
{
TAO_PSDL_Simple_Scope *psdl_simple =
new TAO_PSDL_Simple_Scope (scope,
identifier_type);
scope->scope_map ()->bind (identifier,
psdl_simple);
}
else
{
ACE_DEBUG ((LM_ERROR,
"Error: const_decl re-defined %s\n",
identifier.c_str ()));
ACE_OS::exit (1);
return -1;
}
return 0;
}
int
TAO_PSDL_Scope::add_except_decl (ACE_CString,
ACE_CString)
{
return 0;
}
int
TAO_PSDL_Scope::add_except_decl_to_scope (ACE_CString identifier,
ACE_CString identifier_type,
TAO_PSDL_Scope *scope)
{
this->to_lower_case (identifier);
this->to_lower_case (identifier_type);
if (this->check_identifier (identifier, scope) == -1)
{
TAO_PSDL_Simple_Scope *psdl_simple =
new TAO_PSDL_Simple_Scope (scope,
identifier_type);
scope->scope_map ()->bind (identifier,
psdl_simple);
}
else
{
ACE_DEBUG ((LM_DEBUG,
"Error: exception_name %s re-defined\n",
identifier.c_str ()));
ACE_OS::exit (1);
return -1;
}
return 0;
}
int
TAO_PSDL_Scope::add_op_dcl (ACE_CString)
{
return 0;
}
int
TAO_PSDL_Scope::add_op_dcl_to_scope (ACE_CString op_name,
TAO_PSDL_Scope *scope)
{
this->to_lower_case (op_name);
if (this->check_identifier (op_name, scope) == -1)
{
TAO_PSDL_Op_Dcl_Scope *psdl_op_dcl =
new TAO_PSDL_Op_Dcl_Scope (scope);
scope->scope_map ()->bind (op_name,
psdl_op_dcl);
TAO_PSDL_Scope::instance ()->push_scope (psdl_op_dcl);
}
else
{
ACE_DEBUG ((LM_DEBUG,
"Error: op_name %s re-defined\n",
op_name.c_str ()));
ACE_OS::exit (1);
return -1;
}
return 0;
}
int
TAO_PSDL_Scope::add_member_decl (ACE_CString,
ACE_CString)
{
return 0;
}
int
TAO_PSDL_Scope::add_member_decl_to_scope (ACE_CString identifier,
ACE_CString identifier_type,
TAO_PSDL_Scope *scope)
{
this->to_lower_case (identifier);
this->to_lower_case (identifier_type);
if (this->check_identifier (identifier, scope) == -1)
{
TAO_PSDL_Simple_Scope *psdl_simple =
new TAO_PSDL_Simple_Scope (scope,
identifier_type);
scope->scope_map ()->bind (identifier,
psdl_simple);
}
else
{
ACE_DEBUG ((LM_DEBUG,
"Error: member_decl %s re-defined\n",
identifier.c_str ()));
ACE_OS::exit (1);
return -1;
}
return 0;
}
int
TAO_PSDL_Scope::add_exception (ACE_CString)
{
return 0;
}
int
TAO_PSDL_Scope::add_exception_to_scope (ACE_CString identifier,
TAO_PSDL_Scope *scope)
{
this->to_lower_case (identifier);
if (this->check_identifier (identifier, scope) == -1)
{
TAO_PSDL_Exception_Scope *psdl_exception =
new TAO_PSDL_Exception_Scope (scope);
scope->scope_map ()->bind (identifier,
psdl_exception);
TAO_PSDL_Scope::instance ()->push_scope (psdl_exception);
}
else
{
ACE_DEBUG ((LM_DEBUG,
"Error: exception %s re-defined: aborting\n",
identifier.c_str ()));
ACE_OS::exit (1);
return -1;
}
return 0;
}
int
TAO_PSDL_Scope::add_scoped_decl_to_scope (ACE_CString identifier,
ACE_CString identifier_type,
TAO_PSDL_Scope *scope)
{
this->to_lower_case (identifier);
this->to_lower_case (identifier_type);
TAO_PSDL_Simple_Scope *psdl_simple =
new TAO_PSDL_Simple_Scope (scope,
identifier_type);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -