source: src/SynTree/Type.cc @ 47498bd

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexer
Last change on this file since 47498bd was 47498bd, checked in by Rob Schluntz <rschlunt@…>, 4 years ago

Add nodes for global scope type

  • Property mode set to 100644
File size: 3.9 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// Type.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon Sep 25 15:16:32 2017
13// Update Count     : 38
14//
15#include "Type.h"
16
17#include "Attribute.h"                // for Attribute
18#include "Common/utility.h"           // for cloneAll, deleteAll, printAll
19#include "InitTweak/InitTweak.h"      // for getPointerBase
20#include "SynTree/BaseSyntaxNode.h"   // for BaseSyntaxNode
21#include "SynTree/Declaration.h"      // for TypeDecl
22#include "SynTree/TypeSubstitution.h" // for TypeSubstitution
23
24using namespace std;
25
26const char *BasicType::typeNames[] = {
27        "_Bool",
28        "char",
29        "signed char",
30        "unsigned char",
31        "signed short int",
32        "unsigned short int",
33        "signed int",
34        "unsigned int",
35        "signed long int",
36        "unsigned long int",
37        "signed long long int",
38        "unsigned long long int",
39        "float",
40        "double",
41        "long double",
42        "float _Complex",
43        "double _Complex",
44        "long double _Complex",
45        "float _Imaginary",
46        "double _Imaginary",
47        "long double _Imaginary",
48        "__int128",
49        "unsigned __int128",
50        "__float80",
51        "__float128"
52};
53static_assert(
54        sizeof(BasicType::typeNames)/sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
55        "Each basic type name should have a corresponding kind enum value"
56);
57
58Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
59
60Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) {
61        cloneAll( other.forall, forall );
62        cloneAll( other.attributes, attributes );
63}
64
65Type::~Type() {
66        deleteAll( forall );
67        deleteAll( attributes );
68}
69
70// These must remain in the same order as the corresponding bit fields.
71const char * Type::FuncSpecifiersNames[] = { "inline", "fortran", "_Noreturn" };
72const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" };
73const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "lvalue", "mutex", "_Atomic" };
74
75Type * Type::stripDeclarator() {
76        Type * type, * at;
77        for ( type = this; (at = InitTweak::getPointerBase( type )); type = at );
78        return type;
79}
80
81Type * Type::stripReferences() {
82        Type * type;
83        ReferenceType * ref;
84        for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base );
85        return type;
86}
87
88int Type::referenceDepth() const { return 0; }
89
90TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }
91
92void Type::print( std::ostream &os, Indenter indent ) const {
93        if ( ! forall.empty() ) {
94                os << "forall" << std::endl;
95                printAll( forall, os, indent+1 );
96                os << ++indent;
97        } // if
98
99        if ( ! attributes.empty() ) {
100                os << "with attributes" << endl;
101                printAll( attributes, os, indent+1 );
102        } // if
103
104        tq.print( os );
105}
106
107
108QualifiedType::QualifiedType( const Type::Qualifiers & tq, const std::list< Type * > & types ) : Type( tq, {} ), types( types ) {
109}
110
111QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ) {
112        cloneAll( other.types, types );
113}
114
115QualifiedType::~QualifiedType() {
116        deleteAll( types );
117}
118
119void QualifiedType::print( std::ostream & os, Indenter indent ) const {
120        os << "Qualified Type: " << endl;
121        printAll( types, os, indent+1 );
122        Type::print( os, indent+1 );
123}
124
125GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {}
126
127void GlobalScopeType::print( std::ostream & os, Indenter indent ) const {
128        os << "Global Scope Type" << endl;
129}
130
131
132// Empty Variable declarations:
133const Type::FuncSpecifiers noFuncSpecifiers;
134const Type::StorageClasses noStorageClasses;
135const Type::Qualifiers noQualifiers;
136
137// Local Variables: //
138// tab-width: 4 //
139// mode: c++ //
140// compile-command: "make install" //
141// End: //
Note: See TracBrowser for help on using the repository browser.