source: src/Parser/TypeData.h @ 051aec4

Last change on this file since 051aec4 was 057608a, checked in by Andrew Beach <ajbeach@…>, 4 months ago

Parser clean-up: Removed an unused field, added a comment, fixed a memory leak and reformated a function.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// TypeData.h --
8//
9// Author           : Peter A. Buhr
10// Created On       : Sat May 16 15:18:36 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Feb 22 16:30:31 2024
13// Update Count     : 210
14//
15
16#pragma once
17
18#include <iosfwd>                                   // for ostream
19#include <list>                                     // for list
20#include <string>                                   // for string
21
22#include "AST/Type.hpp"                             // for Type
23#include "DeclarationNode.h"                        // for DeclarationNode
24
25struct TypeData {
26        // Type flags used in this type, and there names (harmonize with implementation).
27        enum BasicType {
28                Void, Bool, Char, Int, Int128,
29                Float, Double, LongDouble, uuFloat80, uuFloat128,
30                uFloat16, uFloat32, uFloat32x, uFloat64, uFloat64x, uFloat128, uFloat128x,
31                NoBasicType
32        };
33        static const char * basicTypeNames[];
34        enum ComplexType { Complex, NoComplexType, Imaginary };
35        // Imaginary unsupported => parse, but make invisible and print error message
36        static const char * complexTypeNames[];
37        enum Signedness { Signed, Unsigned, NoSignedness };
38        static const char * signednessNames[];
39        enum Length { Short, Long, LongLong, NoLength };
40        static const char * lengthNames[];
41        enum BuiltinType { Valist, AutoType, Zero, One, NoBuiltinType };
42        static const char * builtinTypeNames[];
43
44        enum Kind { Basic, Pointer, Reference, Array, Function, Aggregate, AggregateInst, Enum, EnumConstant, Symbolic,
45                                SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Unknown };
46
47        struct Aggregate_t {
48                ast::AggregateDecl::Aggregate kind;
49                const std::string * name = nullptr;
50                const std::string * parent = nullptr;
51                DeclarationNode * params = nullptr;
52                ExpressionNode * actuals = nullptr;                             // holds actual parameters later applied to AggInst
53                DeclarationNode * fields = nullptr;
54                std::vector<ast::ptr<ast::Attribute>> attributes;
55                bool body;
56                bool anon;
57        };
58
59        struct AggInst_t {
60                TypeData * aggregate = nullptr;
61                ExpressionNode * params = nullptr;
62                bool hoistType;
63        };
64
65        struct Array_t {
66                ExpressionNode * dimension = nullptr;
67                bool isVarLen;
68                bool isStatic;
69        };
70
71        struct Enumeration_t {
72                const std::string * name = nullptr;
73                DeclarationNode * constants = nullptr;
74                bool body;
75                bool anon;
76                bool typed;
77                EnumHiding hiding;
78        };
79
80        struct Function_t {
81                mutable DeclarationNode * params = nullptr;             // mutables modified in buildKRFunction
82                mutable DeclarationNode * idList = nullptr;             // old-style
83                mutable DeclarationNode * oldDeclList = nullptr;
84                StatementNode * body = nullptr;
85                ExpressionNode * withExprs = nullptr;                   // expressions from function's with_clause
86        };
87
88        struct Symbolic_t {
89                const std::string * name = nullptr;
90                bool isTypedef;                                                                 // false => TYPEGENname, true => TYPEDEFname
91                DeclarationNode * params = nullptr;
92                ExpressionNode * actuals = nullptr;
93                DeclarationNode * assertions = nullptr;
94        };
95
96        struct Qualified_t {                                                            // qualified type S.T
97                TypeData * parent = nullptr;
98                TypeData * child = nullptr;
99        };
100
101        CodeLocation location;
102
103        Kind kind;
104        TypeData * base;
105        BasicType basictype = NoBasicType;
106        ComplexType complextype = NoComplexType;
107        Signedness signedness = NoSignedness;
108        Length length = NoLength;
109        BuiltinType builtintype = NoBuiltinType;
110
111        ast::CV::Qualifiers qualifiers;
112        DeclarationNode * forall = nullptr;
113
114        Aggregate_t aggregate;
115        AggInst_t aggInst;
116        Array_t array;
117        Enumeration_t enumeration;
118        Function_t function;
119        Symbolic_t symbolic;
120        Qualified_t qualified;
121        DeclarationNode * tuple = nullptr;
122        ExpressionNode * typeexpr = nullptr;
123
124        TypeData( Kind k = Unknown );
125        ~TypeData();
126        void print( std::ostream &, int indent = 0 ) const;
127        TypeData * clone() const;
128
129        const std::string * leafName() const;
130
131        TypeData * getLastBase();
132        void setLastBase( TypeData * );
133};
134
135
136TypeData * build_type_qualifier( ast::CV::Qualifiers );
137TypeData * build_basic_type( TypeData::BasicType );
138TypeData * build_complex_type( TypeData::ComplexType );
139TypeData * build_signedness( TypeData::Signedness );
140TypeData * build_builtin_type( TypeData::BuiltinType );
141TypeData * build_length( TypeData::Length );
142TypeData * build_forall( DeclarationNode * );
143TypeData * build_global_scope();
144TypeData * build_qualified_type( TypeData *, TypeData * );
145TypeData * build_typedef( const std::string * name );
146TypeData * build_type_gen( const std::string * name, ExpressionNode * params );
147TypeData * build_vtable_type( TypeData * );
148
149TypeData * addQualifiers( TypeData * ltype, TypeData * rtype );
150TypeData * addType( TypeData * ltype, TypeData * rtype, std::vector<ast::ptr<ast::Attribute>> & );
151TypeData * addType( TypeData * ltype, TypeData * rtype );
152TypeData * cloneBaseType( TypeData * type, TypeData * other );
153TypeData * makeNewBase( TypeData * type );
154
155
156ast::Type * typebuild( const TypeData * );
157TypeData * typeextractAggregate( const TypeData * td, bool toplevel = true );
158ast::CV::Qualifiers buildQualifiers( const TypeData * td );
159ast::Type * buildBasicType( const TypeData * );
160ast::PointerType * buildPointer( const TypeData * );
161ast::ArrayType * buildArray( const TypeData * );
162ast::ReferenceType * buildReference( const TypeData * );
163ast::AggregateDecl * buildAggregate( const TypeData *, std::vector<ast::ptr<ast::Attribute>> );
164ast::BaseInstType * buildComAggInst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> && attributes, ast::Linkage::Spec linkage );
165ast::BaseInstType * buildAggInst( const TypeData * );
166ast::TypeDecl * buildVariable( const TypeData * );
167ast::EnumDecl * buildEnum( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec );
168ast::TypeInstType * buildSymbolicInst( const TypeData * );
169ast::TupleType * buildTuple( const TypeData * );
170ast::TypeofType * buildTypeof( const TypeData * );
171ast::VTableType * buildVtable( const TypeData * );
172ast::Decl * buildDecl(
173        const TypeData *, const std::string &, ast::Storage::Classes, ast::Expr *,
174        ast::Function::Specs funcSpec, ast::Linkage::Spec, ast::Expr * asmName,
175        ast::Init * init = nullptr, std::vector<ast::ptr<ast::Attribute>> && attributes = std::vector<ast::ptr<ast::Attribute>>() );
176ast::FunctionType * buildFunctionType( const TypeData * );
177void buildKRFunction( const TypeData::Function_t & function );
178
179static inline ast::Type * maybeMoveBuildType( TypeData * type ) {
180        ast::Type * ret = type ? typebuild( type ) : nullptr;
181        delete type;
182        return ret;
183}
184
185// Local Variables: //
186// tab-width: 4 //
187// mode: c++ //
188// compile-command: "make install" //
189// End: //
Note: See TracBrowser for help on using the repository browser.