source: src/Parser/TypeData.h@ fa2c005

ADT
Last change on this file since fa2c005 was fa2c005, checked in by JiadaL <j82liang@…>, 3 years ago

Finish Adt POC

  • Property mode set to 100644
File size: 5.1 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 : Andrew Beach
12// Last Modified On : Wed Mar 1 10:44:00 2023
13// Update Count : 206
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 enum Kind { Basic, Pointer, Reference, Array, Function, Aggregate, AggregateInst, Enum, EnumConstant, Symbolic,
27 SymbolicInst, Tuple, Basetypeof, Typeof, Vtable, Builtin, GlobalScope, Qualified, Adt, Unknown };
28
29 struct Aggregate_t {
30 ast::AggregateDecl::Aggregate kind;
31 const std::string * name = nullptr;
32 DeclarationNode * params = nullptr;
33 ExpressionNode * actuals = nullptr; // holds actual parameters later applied to AggInst
34 DeclarationNode * fields = nullptr;
35 bool body;
36 bool anon;
37 bool tagged;
38 const std::string * parent = nullptr;
39 };
40
41 struct AggInst_t {
42 TypeData * aggregate = nullptr;
43 ExpressionNode * params = nullptr;
44 bool hoistType;
45 };
46
47 struct Array_t {
48 ExpressionNode * dimension = nullptr;
49 bool isVarLen;
50 bool isStatic;
51 };
52
53 struct Enumeration_t {
54 const std::string * name = nullptr;
55 DeclarationNode * constants = nullptr;
56 bool body;
57 bool anon;
58 bool typed;
59 EnumHiding hiding;
60 bool isData = false;
61 };
62
63 struct ADT_t {
64 const std::string * name = nullptr;
65 DeclarationNode * data_constructors;
66 };
67
68 struct Function_t {
69 mutable DeclarationNode * params = nullptr; // mutables modified in buildKRFunction
70 mutable DeclarationNode * idList = nullptr; // old-style
71 mutable DeclarationNode * oldDeclList = nullptr;
72 StatementNode * body = nullptr;
73 ExpressionNode * withExprs = nullptr; // expressions from function's with_clause
74 };
75
76 struct Symbolic_t {
77 const std::string * name = nullptr;
78 bool isTypedef; // false => TYPEGENname, true => TYPEDEFname
79 DeclarationNode * params = nullptr;
80 ExpressionNode * actuals = nullptr;
81 DeclarationNode * assertions = nullptr;
82 };
83
84 struct Qualified_t { // qualified type S.T
85 TypeData * parent = nullptr;
86 TypeData * child = nullptr;
87 };
88
89 CodeLocation location;
90
91 Kind kind;
92 TypeData * base;
93 DeclarationNode::BasicType basictype = DeclarationNode::NoBasicType;
94 DeclarationNode::ComplexType complextype = DeclarationNode::NoComplexType;
95 DeclarationNode::Signedness signedness = DeclarationNode::NoSignedness;
96 DeclarationNode::Length length = DeclarationNode::NoLength;
97 DeclarationNode::BuiltinType builtintype = DeclarationNode::NoBuiltinType;
98
99 ast::CV::Qualifiers qualifiers;
100 DeclarationNode * forall = nullptr;
101
102 Aggregate_t aggregate;
103 AggInst_t aggInst;
104 Array_t array;
105 Enumeration_t enumeration;
106 ADT_t adt;
107
108 Function_t function;
109 Symbolic_t symbolic;
110 Qualified_t qualified;
111 DeclarationNode * tuple = nullptr;
112 ExpressionNode * typeexpr = nullptr;
113
114 TypeData( Kind k = Unknown );
115 ~TypeData();
116 void print( std::ostream &, int indent = 0 ) const;
117 TypeData * clone() const;
118
119 const std::string * leafName() const;
120};
121
122ast::Type * typebuild( const TypeData * );
123TypeData * typeextractAggregate( const TypeData * td, bool toplevel = true );
124ast::CV::Qualifiers buildQualifiers( const TypeData * td );
125ast::Type * buildBasicType( const TypeData * );
126ast::PointerType * buildPointer( const TypeData * );
127ast::ArrayType * buildArray( const TypeData * );
128ast::ReferenceType * buildReference( const TypeData * );
129ast::AggregateDecl * buildAggregate( const TypeData *, std::vector<ast::ptr<ast::Attribute>> );
130ast::BaseInstType * buildComAggInst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> && attributes, ast::Linkage::Spec linkage );
131ast::BaseInstType * buildAggInst( const TypeData * );
132ast::TypeDecl * buildVariable( const TypeData * );
133ast::EnumDecl * buildEnum( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec );
134ast::EnumDecl * buildAst( const TypeData *, std::vector<ast::ptr<ast::Attribute>> &&, ast::Linkage::Spec );
135ast::TypeInstType * buildSymbolicInst( const TypeData * );
136ast::TupleType * buildTuple( const TypeData * );
137ast::TypeofType * buildTypeof( const TypeData * );
138ast::VTableType * buildVtable( const TypeData * );
139ast::Decl * buildDecl(
140 const TypeData *, const std::string &, ast::Storage::Classes, ast::Expr *,
141 ast::Function::Specs funcSpec, ast::Linkage::Spec, ast::Expr * asmName,
142 ast::Init * init = nullptr, std::vector<ast::ptr<ast::Attribute>> && attributes = std::vector<ast::ptr<ast::Attribute>>() );
143ast::FunctionType * buildFunctionType( const TypeData * );
144ast::Decl * addEnumBase( Declaration *, const TypeData * );
145void buildKRFunction( const TypeData::Function_t & function );
146
147// Local Variables: //
148// tab-width: 4 //
149// mode: c++ //
150// compile-command: "make install" //
151// End: //
Note: See TracBrowser for help on using the repository browser.