1 // Written in the D programming language.
2 /**
3 Copyright: Copyright (c) 2016, Joakim Brännström. All rights reserved.
4 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
5 Author: Joakim Brännström (joakim.brannstrom@gmx.com)
6 */
7 module clang.info;
8 
9 import clang.Cursor;
10 import clang.Type;
11 
12 import std.format : format;
13 
14 /** Cursor isX represented as a string of letters
15  *
16  * a = isAttribute
17  * A = isAnonymous
18  * d = isDeclaration
19  * D = isDefinition
20  * e = isExpression
21  * n = isEmpty aka isNull
22  * p = isPreprocessing
23  * r = isReference
24  * s = isStatement
25  * t = isTranslationUnit
26  * u = isUnexposed
27  * v = isValid
28  * V = isVirtualBase
29  */
30 string abilities(const(Cursor) c) @trusted {
31     string s = format("%s%s%s%s%s%s%s%s%s%s%s%s%s", c.isAttribute ? "a" : "",
32             c.isAnonymous ? "A" : "", c.isDeclaration ? "d" : "", c.isDefinition
33             ? "D" : "", c.isExpression ? "e" : "", c.isEmpty ? "n" : "",
34             c.isPreprocessing ? "p" : "", c.isReference ? "r" : "", c.isStatement
35             ? "s" : "", c.isTranslationUnit ? "t" : "", c.isUnexposed ? "u" : "",
36             c.isValid ? "v" : "", c.isVirtualBase ? "V" : "");
37 
38     return s;
39 }
40 
41 /** FunctionCursor isX represented as a string of letters
42  *
43  * c = isConst
44  * p = isPureVirtual
45  * s = isStatic
46  * V = isVirtual
47  */
48 string abilities(FunctionCursor c) @trusted {
49     string s = abilities(c.cursor);
50     s ~= format(" %s%s%s%s", c.isConst ? "c" : "", c.isPureVirtual ? "p" : "",
51             c.isStatic ? "s" : "", c.isVirtual ? "V" : "");
52 
53     return s;
54 }
55 
56 /** EnumCursor isX represented as a string of letters
57  *
58  * s = isSigned
59  * u = isUnderlyingTypeEnum
60  */
61 string abilities(EnumCursor c) @trusted {
62     string s = abilities(c.cursor);
63     s ~= format(" %s%s", c.isSigned ? "s" : "", c.isUnderlyingTypeEnum ? "u" : "");
64 
65     return s;
66 }
67 
68 /** Type isX represented as a string of letters
69  *
70  * a = isAnonymous
71  * A = isArray
72  * c = isConst
73  * e = isEnum
74  * E = isExposed
75  * f = isFunctionType
76  * F = isFunctionPointerType
77  * p = isPOD
78  * P = isPointer
79  * r = isRestrict
80  * t = isTypedef
81  * v = isValid
82  * V = isVolatile
83  * w = isWideCharType
84  */
85 string abilities(Type t) @trusted {
86     string s = format("%s%s%s%s%s%s%s%s%s%s%s%s%s%s", t.isAnonymous ? "a" : "",
87             t.isArray ? "A" : "", t.isConst ? "c" : "", t.isEnum ? "e" : "",
88             t.isExposed ? "E" : "", t.isFunctionType ? "f" : "",
89             t.isFunctionPointerType ? "F" : "", t.isPOD ? "p" : "", t.isPointer
90             ? "P" : "", t.isRestrict ? "r" : "", t.isTypedef ? "t" : "", t.isValid
91             ? "v" : "", t.isVolatile ? "V" : "", t.isWideCharType ? "w" : "",);
92 
93     return s;
94 }
95 
96 /** FuncType isX represented as a string of letters
97  *
98  * v = isVariadic
99  */
100 string abilities(ref FuncType t) @trusted {
101     string s = format("%s %s", abilities(t.type), t.isVariadic ? "v" : "",);
102     return s;
103 }