Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Symbol_name Class Reference

A Symbol Name. More...

#include <symbol_name.h>

Collaboration diagram for Symbol_name:

Collaboration graph
[legend]
List of all members.

Public Types

enum  Kind {
  k_Normal, k_Operator, k_Alloc, k_Constructor,
  k_Destructor, k_Conversion
}

Public Methods

 Symbol_name (std::string s, Abstract_scope *scope, Kind k)
 This ctor is used in initialisation. More...

 Symbol_name (Ptree *tree, Abstract_scope *const scope, bool is_fdecl)
 Initialize symbol name. More...

 ~Symbol_name ()
bool is_qualified () const
 True iff this is a qualified symbol ("foo::bar"). More...

std::string get_name () const
 Get base name. More...

Symbol_name::Kind get_kind () const
 Get symbol kind. More...

Abstract_scopeget_scope () const
 Get scope. More...

Type get_type () const
 Get target type if this is a conversion operator. More...

bool is_template () const
 True iff this is a templatized thing. More...

Ptreeget_template_args () const
 Get template arguments. More...

Symbol_pair lookup_for_use (bool qual) const
 Look up symbol in order to use it. More...

Symbol_pair lookup_for_decl () const
 Look up symbol in order to declare it. More...


Static Public Methods

bool is_qualified_name (Ptree *p)
 Helper: true iff p is a qualified name. More...

Abstract_scopelookup_symbol_in_scope (Ptree *p, Abstract_scope *scope, Abstract_scope *start_scope)
 Helper: look up a scope. More...

std::string gensym ()
 Generate a new, unused symbol name. More...

std::string get_unnamed_namespace_name ()
 Get name for nameless namespace. More...

std::string get_mangled_symbol_name (std::string scope, std::string name)
 Mangle symbol name into scope. More...

std::string get_mangled_scope_from_symbol (std::string name)
 Convert symbol name into scope name. More...

std::string get_mangled_function_name (std::string fname, Type t, Type this_type)
 Mangle function prototype into name. More...

std::string get_mangled_template_name (std::string name, const Type_vector &types)
 Mangle template parameters into name. More...

std::string get_mangled_block_scope (std::string fname)
 Generate mangled block scope name. More...

std::string get_basename_from_symbol (std::string sym, std::string::size_type len)
std::string get_block_name ()
 Generate name for a block. More...

const char * get_operator_name (Ptree *tree)
 Given an operator symbol, return its mangled name. More...


Static Public Attributes

const char CONVERSION_OPERATOR_NAME [] = "__cvt"
 Names for certain operators. More...

const char CONSTRUCTOR_NAME [] = "__ctor"
 Names for certain operators. More...

const char DESTRUCTOR_NAME [] = "__dtor"
 Names for certain operators. More...

const char PTR_OPERATOR_NAME [] = "__opar"
 Names for certain operators. More...

const char CALL_OPERATOR_NAME [] = "__opf"
 Names for certain operators. More...

const char ASSIGNMENT_OPERATOR_NAME [] = "__opas"
 Names for certain operators. More...

const char INDEX_OPERATOR_NAME [] = "__opi"
 Names for certain operators. More...

const char NEW_OPERATOR_NAME [] = "__opnew"
 Names for certain operators. More...

const char ANEW_OPERATOR_NAME [] = "__opanew"
 Names for certain operators. More...

const char DELETE_OPERATOR_NAME [] = "__opdel"
 Names for certain operators. More...

const char ADELETE_OPERATOR_NAME [] = "__opadel"
 Names for certain operators. More...

const char COMMA_OPERATOR_NAME [] = "__opcom"
 Names for certain operators. More...


Private Methods

void init_name (Abstract_scope *s, Ptree *p, bool is_fdecl)
 Initialize this Symbol_name. More...


Private Attributes

std::string basename
 base name of symbol (sans scopes, mangled). More...

Abstract_scopescope
 scope in which symbol appears, if qualified name. More...

bool qualified
 true iff this is a qualified name. More...

Type conv_type
 target type for conversion operators, only if kind == k_Conversion. More...

Kind kind
 kind of symbol. More...

Ptreetpl_args
 template args, null if not a template. Format is "[< [a1 , a2] >]". More...

Abstract_scopestart_scope
 starting scope for lookup. More...


Detailed Description

A Symbol Name.

This represents a symbol name, such as `i', `NS::x', `Class::Class' or `Foo::operator='.

If the symbol is a template, as in `vector<Foo>', is_template() is true.

Special case: the last component may also be "*", as in `Class::*', to represent member pointers.

In addition, this class is a container for name mangling related stuff.

Definition at line 27 of file symbol_name.h.


Member Enumeration Documentation

enum Symbol_name::Kind
 

Enumeration values:
k_Normal  a normal name.
k_Operator  "operator foo".
k_Alloc  "new" and "delete".
k_Constructor  constructor.
k_Destructor  destructor.
k_Conversion  "operator<type >"(type conversion).

Definition at line 29 of file symbol_name.h.

Referenced by Function_symbol::Function_symbol(), and Function_symbol::get_function_kind().


Constructor & Destructor Documentation

Symbol_name::Symbol_name std::string    s,
Abstract_scope   scope,
Kind    k
 

This ctor is used in initialisation.

Definition at line 26 of file symbol_name.cc.

Symbol_name::Symbol_name Ptree   tree,
Abstract_scope *const    scope,
bool    is_fdecl
 

Initialize symbol name.

Parameters:
tree  tree as obtained from OpenC++
scope  scope in which this symbol might be looked up (needed for type names in conversion ops)
is_fdecl  true iff this is a declaration of a function.

Definition at line 38 of file symbol_name.cc.

References basename, Ptree::Car(), Ptree::Cdr(), compile_error(), Ptree::Eq(), expect_ptree(), gensym(), Abstract_scope::get_global_scope(), Abstract_scope::get_parent(), init_name(), is_qualified_name(), k_Normal, kind, lookup_symbol_in_scope(), qualified, start_scope, and Ptree::ToString().

Symbol_name::~Symbol_name  
 

Definition at line 93 of file symbol_name.cc.


Member Function Documentation

std::string Symbol_name::gensym   [static]
 

Generate a new, unused symbol name.

Definition at line 331 of file symbol_name.cc.

Referenced by Symbol_name().

std::string Symbol_name::get_basename_from_symbol std::string    sym,
std::string::size_type    len
[static]
 

Definition at line 442 of file symbol_name.cc.

Referenced by Symbol::get_basename().

std::string Symbol_name::get_block_name   [static]
 

Generate name for a block.

Definition at line 455 of file symbol_name.cc.

Referenced by get_mangled_block_scope().

Symbol_name::Kind Symbol_name::get_kind   const [inline]
 

Get symbol kind.

Definition at line 190 of file symbol_name.h.

References kind.

Referenced by Namespace_scope::add_function_decl(), Class_scope::add_function_decl(), Simple_declaration_reader::declare_variable(), and get_type().

std::string Symbol_name::get_mangled_block_scope std::string    fname [static]
 

Generate mangled block scope name.

Given a function "fname", return the name of a new block.

Definition at line 434 of file symbol_name.cc.

References get_block_name().

std::string Symbol_name::get_mangled_function_name std::string    fname,
Type    t,
Type    this_type
[static]
 

Mangle function prototype into name.

For example, to determine the name for "int X::func(void)", use "get_mangled_function_name(func, int(void))".

Definition at line 389 of file symbol_name.cc.

References Type::get_encoded_type(), Type::get_function_signature(), Type::is_qualified(), Type::is_valid(), Type::make_pointer_type(), Type::q_Const, and Type::q_Volatile.

Referenced by Function_symbol::fill_in_mangled_names().

std::string Symbol_name::get_mangled_scope_from_symbol std::string    name [static]
 

Convert symbol name into scope name.

To determine the scope name for class "A::B", use "get_mangled_scope_from_symbol(A::B)".

Definition at line 373 of file symbol_name.cc.

Referenced by Class_symbol::lookup_helper().

std::string Symbol_name::get_mangled_symbol_name std::string    scope,
std::string    name
[static]
 

Mangle symbol name into scope.

For example, to determine the name for symbol "A::B::sym", use "get_mangled_symbol_name(A::B, sym)".

Definition at line 356 of file symbol_name.cc.

References scope.

Referenced by Namespace_scope::get_unique_name(), Class_scope::get_unique_name(), Block_scope::get_unique_name(), and Class_symbol::lookup_helper().

std::string Symbol_name::get_mangled_template_name std::string    name,
const Type_vector   types
[static]
 

Mangle template parameters into name.

For example, to determine the name for "std::vector<int>", use "get_mangled_template_name(vector, [int])".

Definition at line 412 of file symbol_name.cc.

References Type_vector.

Referenced by Template_class_symbol::get_specialisation().

std::string Symbol_name::get_name   const [inline]
 

Get base name.

This is the name under which the declared object will appear in the symbol table.

Definition at line 182 of file symbol_name.h.

References basename.

Referenced by Namespace_scope::add_function_decl(), Class_scope::add_function_decl(), Namespace_scope::add_variable(), Class_scope::add_variable(), Block_scope::add_variable(), Template_visitor::declare_class(), Simple_declaration_reader::declare_variable(), lookup_for_decl(), lookup_for_use(), parse_class(), Declaration_reader::parse_declarator_internal(), parse_enum(), and Expr_annotator::process_member_access().

const char * Symbol_name::get_operator_name Ptree   tree [static]
 

Given an operator symbol, return its mangled name.

Definition at line 486 of file symbol_name.cc.

References ADELETE_OPERATOR_NAME, ANEW_OPERATOR_NAME, ASSIGNMENT_OPERATOR_NAME, CALL_OPERATOR_NAME, Ptree::Car(), COMMA_OPERATOR_NAME, DELETE_OPERATOR_NAME, Ptree::Eq(), INDEX_OPERATOR_NAME, Ptree::IsLeaf(), NEW_OPERATOR_NAME, and PTR_OPERATOR_NAME.

Referenced by init_name(), Expr_annotator::visit_postfix(), and Expr_annotator::visit_unary().

Abstract_scope * Symbol_name::get_scope   const
 

Get scope.

Qualified symbols are looked up in this scope only; unqualified ones are looked up here and in its parents.

Definition at line 273 of file symbol_name.cc.

References scope.

Referenced by Namespace_scope::add_function_decl(), Namespace_scope::add_variable(), lookup_for_decl(), lookup_for_use(), Declaration_reader::parse_declarator_internal(), and Expr_annotator::process_member_access().

Ptree * Symbol_name::get_template_args   const [inline]
 

Get template arguments.

Definition at line 206 of file symbol_name.h.

References tpl_args.

Type Symbol_name::get_type   const
 

Get target type if this is a conversion operator.

Definition at line 282 of file symbol_name.cc.

References conv_type, get_kind(), and k_Conversion.

Referenced by Simple_declaration_reader::declare_variable().

std::string Symbol_name::get_unnamed_namespace_name   [static]
 

Get name for nameless namespace.

Definition at line 344 of file symbol_name.cc.

Referenced by Annotator::visit_namespacespec().

void Symbol_name::init_name Abstract_scope   s,
Ptree   p,
bool    is_fdecl
[private]
 

Initialize this Symbol_name.

Parameters:
s  value for scope
p  symbol name (leaf, or [~ name], [operator X], [X <foo>]
is_fdecl  true iff this is a function declaration/definition. Only in this mode, constructors are recognized. Rationale: looking up "A" in class A yields the class otherwise

Definition at line 152 of file symbol_name.cc.

References ADELETE_OPERATOR_NAME, ANEW_OPERATOR_NAME, basename, bogus_ptree_error(), Ptree::Car(), compile_error(), CONSTRUCTOR_NAME, conv_type, CONVERSION_OPERATOR_NAME, DELETE_OPERATOR_NAME, DESTRUCTOR_NAME, Ptree::Eq(), Ptree::First(), get_operator_name(), Abstract_scope::is_constructor(), Ptree::IsLeaf(), k_Alloc, k_Constructor, k_Conversion, k_Destructor, k_Normal, k_Operator, kind, Ptree::Length(), NEW_OPERATOR_NAME, parse_abstract_declarator(), parse_type(), scope, Ptree::Second(), start_scope, Ptree::ToString(), and tpl_args.

Referenced by Symbol_name().

bool Symbol_name::is_qualified   const
 

True iff this is a qualified symbol ("foo::bar").

Definition at line 263 of file symbol_name.cc.

References qualified.

Referenced by Namespace_scope::add_function_decl(), Class_scope::add_function_decl(), Namespace_scope::add_variable(), Class_scope::add_variable(), Block_scope::add_variable(), Template_visitor::declare_class(), lookup_for_use(), parse_class(), parse_enum(), Expr_annotator::process_member_access(), and Expr_annotator::visit_unary().

bool Symbol_name::is_qualified_name Ptree   p [static]
 

Helper: true iff p is a qualified name.

Unqualified names might also have more than one component (operator, destructor, template).

Definition at line 102 of file symbol_name.cc.

References Ptree::Eq(), Ptree::First(), Ptree::IsLeaf(), Ptree::Length(), and Ptree::Second().

Referenced by Template_visitor::declare_name(), and Symbol_name().

bool Symbol_name::is_template   const [inline]
 

True iff this is a templatized thing.

Definition at line 198 of file symbol_name.h.

References tpl_args.

Referenced by Namespace_scope::add_function_decl(), Class_scope::add_function_decl(), Namespace_scope::add_variable(), Class_scope::add_variable(), Block_scope::add_variable(), Simple_declaration_reader::declare_variable(), lookup_for_use(), parse_class(), Declaration_reader::parse_declarator_internal(), and parse_enum().

Symbol_pair Symbol_name::lookup_for_decl   const
 

Look up symbol in order to declare it.

Definition at line 320 of file symbol_name.cc.

References get_name(), get_scope(), and Abstract_scope::lookup_here().

Referenced by Namespace_scope::add_variable(), Class_scope::add_variable(), Template_visitor::declare_class(), and parse_class().

Symbol_pair Symbol_name::lookup_for_use bool    qual const
 

Look up symbol in order to use it.

This uses the normal name lookup rules.

Parameters:
qual  true to force qualified lookup. This is required in expressions like "foo.bar" where bar, albeit unqualified, is looked up in scope foo only.

Definition at line 296 of file symbol_name.cc.

References compile_error(), get_name(), get_scope(), Template_class_symbol::get_specialisation(), is_qualified(), is_template(), Abstract_scope::lookup_here(), Abstract_scope::lookup_unqualified(), parse_template_arg_list(), start_scope, Symbol_pair::tag, tpl_args, Type_vector, and Symbol_pair::untag.

Referenced by Expr_annotator::process_member_access(), Type_reader::Type_reader(), Expr_annotator::visit_funcall(), and Expr_annotator::visit_unary().

Abstract_scope * Symbol_name::lookup_symbol_in_scope Ptree   p,
Abstract_scope   scope,
Abstract_scope   start_scope
[static]
 

Helper: look up a scope.

Parameters:
p  the symbol (i.e. "std" or "vector<int>")
scope  the scope in which we look up the symbol
start_scope  the scope in which we look up the template args, if any
Returns:
resulting scope, null if none found. Throws if it finds an invalid object.

Definition at line 117 of file symbol_name.cc.

References Ptree::Car(), compile_error(), Symbol::get_kind(), Class_symbol::get_scope(), Symbol::get_scope(), Template_class_symbol::get_specialisation_from_ptree(), Ptree::IsLeaf(), Symbol::k_Function, Symbol::k_Variable, Ptree::Length(), Abstract_scope::lookup_here(), Ptree::Second(), Symbol_pair::tag, Ptree::ToString(), and Symbol_pair::untag.

Referenced by Template_visitor::declare_name(), and Symbol_name().


Member Data Documentation

const char Symbol_name::ADELETE_OPERATOR_NAME = "__opadel" [static]
 

Names for certain operators.

Definition at line 479 of file symbol_name.cc.

Referenced by get_operator_name(), init_default_symbols(), and init_name().

const char Symbol_name::ANEW_OPERATOR_NAME = "__opanew" [static]
 

Names for certain operators.

Definition at line 477 of file symbol_name.cc.

Referenced by get_operator_name(), init_default_symbols(), init_name(), and Expr_annotator::visit_new().

const char Symbol_name::ASSIGNMENT_OPERATOR_NAME = "__opas" [static]
 

Names for certain operators.

Definition at line 474 of file symbol_name.cc.

Referenced by Class_symbol::finish_definition(), get_operator_name(), Class_symbol::implicit_assignment_operator_style(), and Expr_annotator::visit_assign().

std::string Symbol_name::basename [private]
 

base name of symbol (sans scopes, mangled).

Definition at line 44 of file symbol_name.h.

Referenced by get_name(), init_name(), and Symbol_name().

const char Symbol_name::CALL_OPERATOR_NAME = "__opf" [static]
 

Names for certain operators.

Definition at line 473 of file symbol_name.cc.

Referenced by Expr_annotator::do_funcall(), and get_operator_name().

const char Symbol_name::COMMA_OPERATOR_NAME = "__opcom" [static]
 

Names for certain operators.

Definition at line 480 of file symbol_name.cc.

Referenced by get_operator_name(), and Expr_annotator::visit_comma().

const char Symbol_name::CONSTRUCTOR_NAME = "__ctor" [static]
 

Names for certain operators.

Definition at line 470 of file symbol_name.cc.

Referenced by Class_symbol::finish_definition(), gen_constructors(), Init_handler::get_default_initializer_for_type(), Class_symbol::implicit_copy_ctor_is_const(), init_name(), and Init_handler::make_constructor_call().

Type Symbol_name::conv_type [private]
 

target type for conversion operators, only if kind == k_Conversion.

Definition at line 47 of file symbol_name.h.

Referenced by get_type(), and init_name().

const char Symbol_name::CONVERSION_OPERATOR_NAME = "__cvt" [static]
 

Names for certain operators.

Definition at line 469 of file symbol_name.cc.

Referenced by enumerate_conversion_ops(), init_name(), and Class_op_lookup_helper::predicate().

const char Symbol_name::DELETE_OPERATOR_NAME = "__opdel" [static]
 

Names for certain operators.

Definition at line 478 of file symbol_name.cc.

Referenced by get_operator_name(), init_default_symbols(), and init_name().

const char Symbol_name::DESTRUCTOR_NAME = "__dtor" [static]
 

Names for certain operators.

Definition at line 471 of file symbol_name.cc.

Referenced by init_name().

const char Symbol_name::INDEX_OPERATOR_NAME = "__opi" [static]
 

Names for certain operators.

Definition at line 475 of file symbol_name.cc.

Referenced by get_operator_name(), and Expr_annotator::visit_array().

Kind Symbol_name::kind [private]
 

kind of symbol.

Definition at line 48 of file symbol_name.h.

Referenced by get_kind(), init_name(), and Symbol_name().

const char Symbol_name::NEW_OPERATOR_NAME = "__opnew" [static]
 

Names for certain operators.

Definition at line 476 of file symbol_name.cc.

Referenced by get_operator_name(), init_default_symbols(), init_name(), and Expr_annotator::visit_new().

const char Symbol_name::PTR_OPERATOR_NAME = "__opar" [static]
 

Names for certain operators.

Definition at line 472 of file symbol_name.cc.

Referenced by get_operator_name(), and Expr_annotator::visit_arrowmember().

bool Symbol_name::qualified [private]
 

true iff this is a qualified name.

Definition at line 46 of file symbol_name.h.

Referenced by is_qualified(), and Symbol_name().

Abstract_scope* Symbol_name::scope [private]
 

scope in which symbol appears, if qualified name.

Definition at line 45 of file symbol_name.h.

Referenced by get_mangled_symbol_name(), get_scope(), and init_name().

Abstract_scope* Symbol_name::start_scope [private]
 

starting scope for lookup.

Definition at line 50 of file symbol_name.h.

Referenced by init_name(), lookup_for_use(), and Symbol_name().

Ptree* Symbol_name::tpl_args [private]
 

template args, null if not a template. Format is "[< [a1 , a2] >]".

Definition at line 49 of file symbol_name.h.

Referenced by get_template_args(), init_name(), is_template(), and lookup_for_use().


The documentation for this class was generated from the following files:
Generated on Mon Feb 10 17:36:40 2003 for VFiasco Semantics Compiler by doxygen1.2.15