[cfe-dev] C++ Language Support Library

Eli Friedman eli.friedman at gmail.com
Sun Nov 9 10:51:38 PST 2008


On Sun, Nov 9, 2008 at 8:23 AM, Sebastian Redl
<sebastian.redl at getdesigned.at> wrote:
> 2) How do we access its types?
> The types from the support library are accessed within Sema - play a
> crucial role in some situations, even. There needs to be a nice
> interface to declare and access these types. The C support types -
> ptrdiff_t, size_t, etc. - are simply present in the ASTContext, always.

Not true; we actually compute them as needed.  Computing those types
isn't very expensive, though.

> With the C++ types, this may be considered a waste.

A waste in what sense?  We need to define them somewhere, and the
ASTContext seems as good a place as any.  It's not as if putting the
methods on the ASTContext restricts the implementation in any
significant way.  And if computing the types has a significant cost,
we can cache them.

> Here's a summary of which parts of the language use which types (may be
> incomplete):
>
> a) typeid: Uses std::type_info as the return value, may throw
> std::bad_typeid. The exception type isn't necessarily accessed within
> the Sema; type_info most definitely is.
> b) dynamic_cast: May throw bad_cast. Not necessarily accessed within the
> Sema.
> c) new: Uses operator new and operator delete. May throw std::bad_alloc.
> None of these is necessarily used in Sema, but they will be needed
> during CodeGen.
> d) Exceptions: exceptions use std::bad_exception, std::terminate,
> std::unexpected and more. Accessed by CodeGen, if not Sema.
> e) Globals: Destructors for globals and statics are registered with
> atexit() or __cxa_atexit(). CodeGen would generate these calls.
>
> C++0x adds some more:
> f) Initializer lists: use std::initializer_list, which uses the
> ObjectType concept. Required in Sema for overload resolution.
> g) Null pointers: use std::nullptr_t. This special type is considered
> fundamental and even participates in implicit conversions.
> h) Range loop: uses the std::Range concept.

All right, so ignoring the concept stuff, all we need is type_info,
nullptr_t, and maybe a few of the exception types depending on the
implementation.  I'd say just add them to the ASTContext.

-Eli



More information about the cfe-dev mailing list