source: src/Parser/TypeData.h @ d734fa1

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

Removed unused field from TypeData?.

  • Property mode set to 100644
File size: 6.5 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                DeclarationNode * params = nullptr;
51                ExpressionNode * actuals = nullptr;                             // holds actual parameters later applied to AggInst
52                DeclarationNode * fields = nullptr;
53                std::vector<ast::ptr<ast::Attribute>> attributes;
54                bool body;
55                bool anon;
56        };
57
58        struct AggInst_t {
59                TypeData * aggregate = nullptr;
60                ExpressionNode * params = nullptr;
61                bool hoistType;
62        };
63
64        struct Array_t {
65                ExpressionNode * dimension = nullptr;
66                bool isVarLen;
67                bool isStatic;
68        };
69
70        struct Enumeration_t {
71                const std::string * name = nullptr;
72                DeclarationNode * constants = nullptr;
73                bool body;
74                bool anon;
75                bool typed;
76                EnumHiding hiding;
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        Enumeration_t enumeration;
117        Function_t function;
118        Symbolic_t symbolic;
119        Qualified_t qualified;
120        DeclarationNode * tuple = nullptr;
121        ExpressionNode * typeexpr = nullptr;
122
123        TypeData( Kind k = Unknown );
124        ~TypeData();
125        void print( std::ostream &, int indent = 0 ) const;
126        TypeData * clone() const;
127
128        const std::string * leafName() const;
129
130        TypeData * getLastBase();
131        void setLastBase( TypeData * );
132};
133
134
135TypeData * build_type_qualifier( ast::CV::Qualifiers );
136TypeData * build_basic_type( TypeData::BasicType );
137TypeData * build_complex_type( TypeData::ComplexType );
138TypeData * build_signedness( TypeData::Signedness );
139TypeData * build_builtin_type( TypeData::BuiltinType );
140TypeData * build_length( TypeData::Length );
141TypeData * build_forall( DeclarationNode * );
142TypeData * build_global_scope();
143TypeData * build_qualified_type( TypeData *, TypeData * );
144TypeData * build_typedef( const std::string * name );
145TypeData * build_type_gen( const std::string * name, ExpressionNode * params );
146TypeData * build_vtable_type( TypeData * );
147
148TypeData * addQualifiers( TypeData * ltype, TypeData * rtype );
149TypeData * addType( TypeData * ltype, TypeData * rtype, std::vector<ast::ptr<ast::Attribute>> & );
150TypeData * addType( TypeData * ltype, TypeData * rtype );
151TypeData * cloneBaseType( TypeData * type, TypeData * other );
152TypeData * makeNewBase( TypeData * type );
153
154
155ast::Type * typebuild( const TypeData * );
156TypeData * typeextractAggregate( const TypeData * td, bool toplevel = true );
157ast::CV::Qualifiers buildQualifiers( const TypeData * td );
158ast::Type * buildBasicType( const TypeData * );
159ast::PointerType * buildPointer( const TypeData * );
160ast::ArrayType * buildArray( const TypeData * );
161ast::ReferenceType * buildReference( const TypeData * );
162ast::AggregateDecl * buildAggregate( const TypeData *, std::vector<ast::ptr<ast::Attribute>> );
163ast::BaseInstType * buildComAggInst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> && attributes, ast::Linkage::Spec linkage );
164ast::BaseInstType * buildAggInst( const TypeData * );
165ast::TypeDecl * buildVariable( const TypeData * );
166ast::EnumDecl * buildEnum( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec );
167ast::TypeInstType * buildSymbolicInst( const TypeData * );
168ast::TupleType * buildTuple( const TypeData * );
169ast::TypeofType * buildTypeof( const TypeData * );
170ast::VTableType * buildVtable( const TypeData * );
171ast::Decl * buildDecl(
172        const TypeData *, const std::string &, ast::Storage::Classes, ast::Expr *,
173        ast::Function::Specs funcSpec, ast::Linkage::Spec, ast::Expr * asmName,
174        ast::Init * init = nullptr, std::vector<ast::ptr<ast::Attribute>> && attributes = std::vector<ast::ptr<ast::Attribute>>() );
175ast::FunctionType * buildFunctionType( const TypeData * );
176void buildKRFunction( const TypeData::Function_t & function );
177
178static inline ast::Type * maybeMoveBuildType( TypeData * type ) {
179        ast::Type * ret = type ? typebuild( type ) : nullptr;
180        delete type;
181        return ret;
182}
183
184// Local Variables: //
185// tab-width: 4 //
186// mode: c++ //
187// compile-command: "make install" //
188// End: //
Note: See TracBrowser for help on using the repository browser.