forked from xoofx/CppAst.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCppArrayType.cs
47 lines (41 loc) · 1.55 KB
/
CppArrayType.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) Alexandre Mutel. All rights reserved.
// Licensed under the BSD-Clause 2 license.
// See license.txt file in the project root for full license information.
using System;
namespace CppAst
{
/// <summary>
/// A C++ array (e.g int[5] or int[])
/// </summary>
public sealed class CppArrayType : CppTypeWithElementType
{
/// <summary>
/// Constructor of a C++ array.
/// </summary>
/// <param name="elementType">The element type (e.g `int`)</param>
/// <param name="size">The size of the array. 0 means an unbound array</param>
public CppArrayType(CppType elementType, int size) : base(CppTypeKind.Array, elementType)
{
Size = size;
}
/// <summary>
/// Gets the size of the array.
/// </summary>
public int Size { get; }
public override int SizeOf
{
get => Size * ElementType.SizeOf;
set => throw new InvalidOperationException("Cannot set the SizeOf an array type. The SizeOf is calculated by the SizeOf its ElementType and the number of elements in the fixed array");
}
public override CppType GetCanonicalType()
{
var elementTypeCanonical = ElementType.GetCanonicalType();
if (ReferenceEquals(elementTypeCanonical, ElementType)) return this;
return new CppArrayType(elementTypeCanonical, Size);
}
public override string ToString()
{
return $"{ElementType.GetDisplayName()}[{Size}]";
}
}
}