forked from xoofx/CppAst.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCppReferenceType.cs
42 lines (37 loc) · 1.29 KB
/
CppReferenceType.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
// 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++ reference type (e.g `int&`)
/// </summary>
public sealed class CppReferenceType : CppTypeWithElementType
{
/// <summary>
/// Constructor of a reference type.
/// </summary>
/// <param name="elementType">The element type referenced to.</param>
public CppReferenceType(CppType elementType) : base(CppTypeKind.Reference, elementType)
{
}
/// <inheritdoc />
public override int SizeOf
{
get => ElementType.SizeOf;
set => throw new InvalidOperationException("Cannot override the SizeOf of a Reference type");
}
/// <inheritdoc />
public override string ToString()
{
return $"{ElementType.GetDisplayName()}&";
}
/// <inheritdoc />
public override CppType GetCanonicalType()
{
var elementTypeCanonical = ElementType.GetCanonicalType();
return ReferenceEquals(elementTypeCanonical, ElementType) ? this : new CppReferenceType(elementTypeCanonical);
}
}
}