source: src/Parser/TypeData.h @ cf191ac

Last change on this file since cf191ac was 7a780ad, checked in by Andrew Beach <ajbeach@…>, 3 months ago

Moved ast::BasicType::Kind to ast::BasicKind? in its own hearder. This is more consistent with other utility enums (although we still use this as a enum class) and reduces what some files need to include. Also did a upgrade in a comment with MAX_INTEGER_TYPE, it is now part of the enum.

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