//
// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
//
// The contents of this file are covered under the licence agreement in the
// file "LICENCE" distributed with Cforall.
//
// Type.cc --
//
// Author           : Richard C. Bilson
// Created On       : Mon May 18 07:44:20 2015
// Last Modified By : Peter A. Buhr
// Last Modified On : Sun Dec 15 16:52:37 2019
// Update Count     : 49
//
#include "Type.h"

#include "Attribute.h"                // for Attribute
#include "Common/utility.h"           // for cloneAll, deleteAll, printAll
#include "InitTweak/InitTweak.h"      // for getPointerBase
#include "SynTree/BaseSyntaxNode.h"   // for BaseSyntaxNode
#include "SynTree/Declaration.h"      // for TypeDecl
#include "SynTree/TypeSubstitution.h" // for TypeSubstitution

using namespace std;

// GENERATED START, DO NOT EDIT
// GENERATED BY BasicTypes-gen.cc
const char * BasicType::typeNames[] = {
	"_Bool",
	"char",
	"signed char",
	"unsigned char",
	"signed short int",
	"unsigned short int",
	"signed int",
	"unsigned int",
	"signed long int",
	"unsigned long int",
	"signed long long int",
	"unsigned long long int",
	"__int128",
	"unsigned __int128",
	"_Float16",
	"_Float16 _Complex",
	"_Float32",
	"_Float32 _Complex",
	"float",
	"float _Complex",
	"_Float32x",
	"_Float32x _Complex",
	"_Float64",
	"_Float64 _Complex",
	"double",
	"double _Complex",
	"_Float64x",
	"_Float64x _Complex",
	"__float80",
	"_Float128",
	"_Float128 _Complex",
	"__float128",
	"long double",
	"long double _Complex",
	"_Float128x",
	"_Float128x _Complex",
};
// GENERATED END

Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}

Type::Type( const Type &other ) : BaseSyntaxNode( other ), tq( other.tq ) {
	cloneAll( other.forall, forall );
	cloneAll( other.attributes, attributes );
}

Type::~Type() {
	deleteAll( forall );
	deleteAll( attributes );
}

// These must remain in the same order as the corresponding bit fields.
const char * Type::FuncSpecifiersNames[] = { "inline", "_Noreturn", "fortran" };
const char * Type::StorageClassesNames[] = { "extern", "static", "auto", "register", "_Thread_local" };
const char * Type::QualifiersNames[] = { "const", "restrict", "volatile", "mutex", "_Atomic" };

Type * Type::stripDeclarator() {
	Type * type, * at;
	for ( type = this; (at = InitTweak::getPointerBase( type )); type = at );
	return type;
}

Type * Type::stripReferences() {
	Type * type;
	ReferenceType * ref;
	for ( type = this; (ref = dynamic_cast<ReferenceType *>( type )); type = ref->base );
	return type;
}

const Type * Type::stripReferences() const {
	const Type * type;
	const ReferenceType * ref;
	for ( type = this; (ref = dynamic_cast<const ReferenceType *>( type )); type = ref->base );
	return type;
}

int Type::referenceDepth() const { return 0; }

TypeSubstitution Type::genericSubstitution() const { assertf( false, "Non-aggregate type: %s", toCString( this ) ); }

void Type::print( std::ostream & os, Indenter indent ) const {
	if ( ! forall.empty() ) {
		os << "forall" << std::endl;
		printAll( forall, os, indent+1 );
		os << ++indent;
	} // if

	if ( ! attributes.empty() ) {
		os << "with attributes" << endl;
		printAll( attributes, os, indent+1 );
	} // if

	tq.print( os );
}


QualifiedType::QualifiedType( const Type::Qualifiers & tq, Type * parent, Type * child ) : Type( tq, {} ), parent( parent ), child( child ) {
}

QualifiedType::QualifiedType( const QualifiedType & other ) : Type( other ), parent( maybeClone( other.parent ) ), child( maybeClone( other.child ) ) {
}

QualifiedType::~QualifiedType() {
	delete parent;
	delete child;
}

void QualifiedType::print( std::ostream & os, Indenter indent ) const {
	os << "Qualified Type:" << endl;
	os << indent+1;
	parent->print( os, indent+1 );
	os << endl << indent+1;
	child->print( os, indent+1 );
	os << endl;
	Type::print( os, indent+1 );
}

GlobalScopeType::GlobalScopeType() : Type( Type::Qualifiers(), {} ) {}

void GlobalScopeType::print( std::ostream & os, Indenter ) const {
	os << "Global Scope Type" << endl;
}


// Empty Variable declarations:
const Type::FuncSpecifiers noFuncSpecifiers;
const Type::StorageClasses noStorageClasses;
const Type::Qualifiers noQualifiers;

// Local Variables: //
// tab-width: 4 //
// mode: c++ //
// compile-command: "make install" //
// End: //
