• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xoofx / CppAst.NET / 9196889246

22 May 2024 06:14PM UTC coverage: 79.169% (-0.02%) from 79.192%
9196889246

push

github

web-flow
Merge pull request #101 from Xkein/main

fix "Unhandled PrimitiveKind: Long" in CppPrimitiveType.ToString()

1046 of 1667 branches covered (62.75%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

4499 of 5337 relevant lines covered (84.3%)

2299.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.16
/src/CppAst/CppPrimitiveType.cs
1
// Copyright (c) Alexandre Mutel. All rights reserved.
2
// Licensed under the BSD-Clause 2 license.
3
// See license.txt file in the project root for full license information.
4

5
using System;
6

7
namespace CppAst
8
{
9
    /// <summary>
10
    /// A C++ primitive type (e.g `int`, `void`, `bool`...)
11
    /// </summary>
12
    public sealed class CppPrimitiveType : CppType
13
    {
14
        /// <summary>
15
        /// Singleton instance of the `void` type.
16
        /// </summary>
17
        public static readonly CppPrimitiveType Void = new CppPrimitiveType(CppPrimitiveKind.Void);
1✔
18

19
        /// <summary>
20
        /// Singleton instance of the `bool` type.
21
        /// </summary>
22
        public static readonly CppPrimitiveType Bool = new CppPrimitiveType(CppPrimitiveKind.Bool);
1✔
23

24
        /// <summary>
25
        /// Singleton instance of the `wchar` type.
26
        /// </summary>
27
        public static readonly CppPrimitiveType WChar = new CppPrimitiveType(CppPrimitiveKind.WChar);
1✔
28

29
        /// <summary>
30
        /// Singleton instance of the `char` type.
31
        /// </summary>
32
        public static readonly CppPrimitiveType Char = new CppPrimitiveType(CppPrimitiveKind.Char);
1✔
33

34
        /// <summary>
35
        /// Singleton instance of the `short` type.
36
        /// </summary>
37
        public static readonly CppPrimitiveType Short = new CppPrimitiveType(CppPrimitiveKind.Short);
1✔
38

39
        /// <summary>
40
        /// Singleton instance of the `int` type.
41
        /// </summary>
42
        public static readonly CppPrimitiveType Int = new CppPrimitiveType(CppPrimitiveKind.Int);
1✔
43

44
        /// <summary>
45
        /// Singleton instance of the `long` type.
46
        /// </summary>
47
        public static readonly CppPrimitiveType Long = new CppPrimitiveType(CppPrimitiveKind.Long);
1✔
48

49
        /// <summary>
50
        /// Singleton instance of the `long long` type.
51
        /// </summary>
52
        public static readonly CppPrimitiveType LongLong = new CppPrimitiveType(CppPrimitiveKind.LongLong);
1✔
53

54
        /// <summary>
55
        /// Singleton instance of the `unsigned char` type.
56
        /// </summary>
57
        public static readonly CppPrimitiveType UnsignedChar = new CppPrimitiveType(CppPrimitiveKind.UnsignedChar);
1✔
58

59
        /// <summary>
60
        /// Singleton instance of the `unsigned short` type.
61
        /// </summary>
62
        public static readonly CppPrimitiveType UnsignedShort = new CppPrimitiveType(CppPrimitiveKind.UnsignedShort);
1✔
63

64
        /// <summary>
65
        /// Singleton instance of the `unsigned int` type.
66
        /// </summary>
67
        public static readonly CppPrimitiveType UnsignedInt = new CppPrimitiveType(CppPrimitiveKind.UnsignedInt);
1✔
68

69
        /// <summary>
70
        /// Singleton instance of the `unsigned long` type.
71
        /// </summary>
72
        public static readonly CppPrimitiveType UnsignedLong = new CppPrimitiveType(CppPrimitiveKind.UnsignedLong);
1✔
73
        
74
        /// <summary>
75
        /// Singleton instance of the `unsigned long long` type.
76
        /// </summary>
77
        public static readonly CppPrimitiveType UnsignedLongLong = new CppPrimitiveType(CppPrimitiveKind.UnsignedLongLong);
1✔
78

79
        /// <summary>
80
        /// Singleton instance of the `float` type.
81
        /// </summary>
82
        public static readonly CppPrimitiveType Float = new CppPrimitiveType(CppPrimitiveKind.Float);
1✔
83

84
        /// <summary>
85
        /// Singleton instance of the `float` type.
86
        /// </summary>
87
        public static readonly CppPrimitiveType Double = new CppPrimitiveType(CppPrimitiveKind.Double);
1✔
88

89
        /// <summary>
90
        /// Singleton instance of the `long double` type.
91
        /// </summary>
92
        public static readonly CppPrimitiveType LongDouble = new CppPrimitiveType(CppPrimitiveKind.LongDouble);
1✔
93

94
        private readonly int _sizeOf;
95

96
        /// <summary>
97
        /// Base constructor of a primitive
98
        /// </summary>
99
        /// <param name="kind"></param>
100
        private CppPrimitiveType(CppPrimitiveKind kind) : base(CppTypeKind.Primitive)
16✔
101
        {
102
            Kind = kind;
103
            UpdateSize(out _sizeOf);
16✔
104
        }
16✔
105

106
        /// <summary>
107
        /// The kind of primitive.
108
        /// </summary>
109
        public CppPrimitiveKind Kind { get; }
110

111
        private void UpdateSize(out int sizeOf)
112
        {
113
            switch (Kind)
16!
114
            {
115
                case CppPrimitiveKind.Void:
116
                    sizeOf = 0;
1✔
117
                    break;
1✔
118
                case CppPrimitiveKind.Bool:
119
                    sizeOf = 1;
1✔
120
                    break;
1✔
121
                case CppPrimitiveKind.WChar:
122
                    sizeOf = 2;
1✔
123
                    break;
1✔
124
                case CppPrimitiveKind.Char:
125
                    sizeOf = 1;
1✔
126
                    break;
1✔
127
                case CppPrimitiveKind.Short:
128
                    sizeOf = 2;
1✔
129
                    break;
1✔
130
                case CppPrimitiveKind.Int:
131
                    sizeOf = 4;
1✔
132
                    break;
1✔
133
                case CppPrimitiveKind.Long:
134
                case CppPrimitiveKind.UnsignedLong:
135
                    sizeOf = 4; // This is incorrect
2✔
136
                    break;
2✔
137
                case CppPrimitiveKind.LongLong:
138
                    sizeOf = 8;
1✔
139
                    break;
1✔
140
                case CppPrimitiveKind.UnsignedChar:
141
                    sizeOf = 1;
1✔
142
                    break;
1✔
143
                case CppPrimitiveKind.UnsignedShort:
144
                    sizeOf = 2;
1✔
145
                    break;
1✔
146
                case CppPrimitiveKind.UnsignedInt:
147
                    sizeOf = 4;
1✔
148
                    break;
1✔
149
                case CppPrimitiveKind.UnsignedLongLong:
150
                    sizeOf = 8;
1✔
151
                    break;
1✔
152
                case CppPrimitiveKind.Float:
153
                    sizeOf = 4;
1✔
154
                    break;
1✔
155
                case CppPrimitiveKind.Double:
156
                    sizeOf = 8;
1✔
157
                    break;
1✔
158
                case CppPrimitiveKind.LongDouble:
159
                    sizeOf = 8;
1✔
160
                    break;
1✔
161
                default:
162
                    throw new ArgumentOutOfRangeException();
×
163
            }
164
        }
165

166
        /// <inheritdoc />
167
        public override string ToString()
168
        {
169
            switch (Kind)
123!
170
            {
171
                case CppPrimitiveKind.Void:
172
                    return "void";
37✔
173
                case CppPrimitiveKind.WChar:
174
                    return "wchar";
4✔
175
                case CppPrimitiveKind.Char:
176
                    return "char";
4✔
177
                case CppPrimitiveKind.Short:
178
                    return "short";
4✔
179
                case CppPrimitiveKind.Int:
180
                    return "int";
34✔
181
                case CppPrimitiveKind.Long:
NEW
182
                    return "long";
×
183
                case CppPrimitiveKind.UnsignedLong:
NEW
184
                    return "unsigned long";
×
185
                case CppPrimitiveKind.LongLong:
186
                    return "long long";
4✔
187
                case CppPrimitiveKind.UnsignedChar:
188
                    return "unsigned char";
4✔
189
                case CppPrimitiveKind.UnsignedShort:
190
                    return "unsigned short";
4✔
191
                case CppPrimitiveKind.UnsignedInt:
192
                    return "unsigned int";
6✔
193
                case CppPrimitiveKind.UnsignedLongLong:
194
                    return "unsigned long long";
4✔
195
                case CppPrimitiveKind.Float:
196
                    return "float";
8✔
197
                case CppPrimitiveKind.Double:
198
                    return "double";
6✔
199
                case CppPrimitiveKind.LongDouble:
200
                    return "long double";
×
201
                case CppPrimitiveKind.Bool:
202
                    return "bool";
4✔
203
                default:
204
                    throw new InvalidOperationException($"Unhandled PrimitiveKind: {Kind}");
×
205
            }
206
        }
207

208
        private bool Equals(CppPrimitiveType other)
209
        {
210
            return base.Equals(other) && Kind == other.Kind;
×
211
        }
212

213
        /// <inheritdoc />
214
        public override int SizeOf
215
        {
216
            get => _sizeOf;
50✔
217
            set => throw new InvalidOperationException("Cannot set the SizeOf of a primitive type");
×
218
        }
219

220
        /// <inheritdoc />
221
        public override CppType GetCanonicalType()
222
        {
223
            return this;
12✔
224
        }
225
    }
226
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc