-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
CppTypedef.cs
83 lines (71 loc) · 2.56 KB
/
CppTypedef.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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;
using System.Collections.Generic;
namespace CppAst
{
/// <summary>
/// A C++ typedef (e.g `typedef int XXX`)
/// </summary>
public sealed class CppTypedef : CppTypeDeclaration, ICppMemberWithVisibility, ICppAttributeContainer
{
/// <summary>
/// Creates a new instance of a typedef.
/// </summary>
/// <param name="name">Name of the typedef (e.g `XXX`)</param>
/// <param name="type">Underlying type.</param>
public CppTypedef(string name, CppType type) : base(CppTypeKind.Typedef)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
ElementType = type;
Attributes = new List<CppAttribute>();
TokenAttributes = new List<CppAttribute>();
MetaAttributes = new MetaAttributeMap();
}
public List<CppAttribute> Attributes { get; }
[Obsolete("TokenAttributes is deprecated. please use system attributes and annotate attributes")]
public List<CppAttribute> TokenAttributes { get; }
public MetaAttributeMap MetaAttributes { get; private set; }
public CppType ElementType { get; }
/// <summary>
/// Visibility of this element.
/// </summary>
public CppVisibility Visibility { get; set; }
/// <summary>
/// Gets or sets the name of this type.
/// </summary>
public string Name { get; set; }
public override string FullName
{
get
{
string fullparent = FullParentName;
if (string.IsNullOrEmpty(fullparent))
{
return Name;
}
else
{
return $"{fullparent}::{Name}";
}
}
}
/// <inheritdoc />
public override int SizeOf
{
get => ElementType.SizeOf;
set => throw new InvalidOperationException("Cannot set the SizeOf a TypeDef. The SizeOf is determined by the underlying ElementType");
}
/// <inheritdoc />
public override CppType GetCanonicalType()
{
return ElementType.GetCanonicalType();
}
/// <inheritdoc />
public override string ToString()
{
return $"typedef {ElementType.GetDisplayName()} {Name}";
}
}
}