1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include <precomp.h>
23 #include "cs_type.hxx"
24
25 // NOT FULLY DEFINED SERVICES
26 #include <ary/cpp/c_builtintype.hxx>
27
28
29 namespace
30 {
31 const uintt
32 C_nReservedElements = ary::cpp::predefined::t_MAX; // Skipping "0" and the builtin types
33 }
34
35
36 namespace ary
37 {
38 namespace cpp
39 {
40
41
42
43 Type_Storage * Type_Storage::pInstance_ = 0;
44
45
46
47
Type_Storage()48 Type_Storage::Type_Storage()
49 : stg::Storage<Type>(C_nReservedElements),
50 aBuiltInTypes()
51 {
52 Setup_BuiltInTypes();
53
54 csv_assert(pInstance_ == 0);
55 pInstance_ = this;
56 }
57
~Type_Storage()58 Type_Storage::~Type_Storage()
59 {
60 csv_assert(pInstance_ != 0);
61 pInstance_ = 0;
62 }
63
64 Type_id
Search_BuiltInType(const String & i_specializedName) const65 Type_Storage::Search_BuiltInType( const String & i_specializedName ) const
66 {
67 return csv::value_from_map(aBuiltInTypes, i_specializedName, Tid(0));
68 }
69
70 void
Setup_BuiltInTypes()71 Type_Storage::Setup_BuiltInTypes()
72 {
73 Set_BuiltInType( predefined::t_void, "void" );
74 Set_BuiltInType( predefined::t_bool, "bool" );
75 Set_BuiltInType( predefined::t_char, "char" );
76 Set_BuiltInType( predefined::t_signed_char, "char", TYSP_signed );
77 Set_BuiltInType( predefined::t_unsigned_char, "char", TYSP_unsigned );
78 Set_BuiltInType( predefined::t_short, "short" );
79 Set_BuiltInType( predefined::t_unsigned_short, "short", TYSP_unsigned );
80 Set_BuiltInType( predefined::t_int, "int" );
81 Set_BuiltInType( predefined::t_unsigned_int, "int", TYSP_unsigned );
82 Set_BuiltInType( predefined::t_long, "long" );
83 Set_BuiltInType( predefined::t_unsigned_long, "long", TYSP_unsigned );
84 Set_BuiltInType( predefined::t_float, "float" );
85 Set_BuiltInType( predefined::t_double, "double" );
86 Set_BuiltInType( predefined::t_size_t, "size_t" );
87 Set_BuiltInType( predefined::t_wchar_t, "wchar_t" );
88 Set_BuiltInType( predefined::t_ptrdiff_t, "ptrdiff_t" );
89 Set_BuiltInType( predefined::t_ellipse, "..." );
90 }
91
92 void
Set_BuiltInType(Rid i_id,const char * i_sName,ary::cpp::E_TypeSpecialisation i_eSpecialisation)93 Type_Storage::Set_BuiltInType( Rid i_id,
94 const char * i_sName,
95 ary::cpp::E_TypeSpecialisation i_eSpecialisation )
96 {
97 DYN BuiltInType &
98 rNew = *new BuiltInType(i_sName, i_eSpecialisation);
99 Set_Reserved( i_id, rNew); // Here goes the ownership for rNew.
100 aBuiltInTypes[rNew.SpecializedName()] = rNew.TypeId();
101 }
102
103
104
105 } // namespace cpp
106 } // namespace ary
107