| 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 | // Decl.hpp --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Aaron B. Moss
|
|---|
| 10 | // Created On : Thu May 9 10:00:00 2019
|
|---|
| 11 | // Last Modified By : Aaron B. Moss
|
|---|
| 12 | // Last Modified On : Thu May 9 10:00:00 2019
|
|---|
| 13 | // Update Count : 1
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #pragma once
|
|---|
| 17 |
|
|---|
| 18 | #include <string>
|
|---|
| 19 | #include <vector>
|
|---|
| 20 |
|
|---|
| 21 | #include "Fwd.hpp" // for UniqueId
|
|---|
| 22 | #include "LinkageSpec.hpp"
|
|---|
| 23 | #include "Node.hpp" // for ptr, readonly
|
|---|
| 24 | #include "ParseNode.hpp"
|
|---|
| 25 | #include "StorageClasses.hpp"
|
|---|
| 26 | #include "Visitor.hpp"
|
|---|
| 27 |
|
|---|
| 28 | namespace ast {
|
|---|
| 29 | class Attribute;
|
|---|
| 30 | class Expr;
|
|---|
| 31 |
|
|---|
| 32 | /// Base declaration class
|
|---|
| 33 | class Decl : public ParseNode {
|
|---|
| 34 | public:
|
|---|
| 35 | std::string name;
|
|---|
| 36 | Storage::Classes storage;
|
|---|
| 37 | Linkage::Spec linkage;
|
|---|
| 38 | UniqueId uniqueId = 0;
|
|---|
| 39 | bool extension = false;
|
|---|
| 40 |
|
|---|
| 41 | Decl( const CodeLocation& loc, const std::string& name, Storage::Classes storage,
|
|---|
| 42 | Linkage::Spec linkage )
|
|---|
| 43 | : ParseNode( loc ), name( name ), storage( storage ), linkage( linkage ) {}
|
|---|
| 44 |
|
|---|
| 45 | Decl* set_extension( bool ex ) { extension = ex; return this; }
|
|---|
| 46 |
|
|---|
| 47 | /// Ensures this node has a unique ID
|
|---|
| 48 | void fixUniqueId();
|
|---|
| 49 | /// Get canonical declaration for unique ID
|
|---|
| 50 | static readonly<Decl> fromId( UniqueId id );
|
|---|
| 51 |
|
|---|
| 52 | virtual Decl* accept( Visitor& v ) override = 0;
|
|---|
| 53 | private:
|
|---|
| 54 | virtual Decl* clone() const override = 0;
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | /// Typed declaration base class
|
|---|
| 58 | class DeclWithType : public Decl {
|
|---|
| 59 | public:
|
|---|
| 60 | /// Represents the type with all types and typedefs expanded.
|
|---|
| 61 | /// This field is generated by SymTab::Validate::Pass2
|
|---|
| 62 | std::string mangleName;
|
|---|
| 63 | /// Stores the scope level at which the variable was declared.
|
|---|
| 64 | /// Used to access shadowed identifiers.
|
|---|
| 65 | int scopeLevel = 0;
|
|---|
| 66 |
|
|---|
| 67 | std::vector<ptr<Attribute>> attributes;
|
|---|
| 68 | Function::Specs funcSpecs;
|
|---|
| 69 | ptr<Expr> asmName;
|
|---|
| 70 | bool isDeleted = false;
|
|---|
| 71 |
|
|---|
| 72 | DeclWithType( const CodeLocation& loc, const std::string& name, Storage::Classes storage,
|
|---|
| 73 | Linkage::Spec linkage, std::vector<ptr<Attribute>>&& attrs, Function::Specs fs )
|
|---|
| 74 | : Decl( loc, name, storage, linkage ), mangleName(), attributes( std::move(attrs) ),
|
|---|
| 75 | funcSpecs(fs), asmName() {}
|
|---|
| 76 | };
|
|---|
| 77 |
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | // Local Variables: //
|
|---|
| 81 | // tab-width: 4 //
|
|---|
| 82 | // mode: c++ //
|
|---|
| 83 | // compile-command: "make install" //
|
|---|
| 84 | // End: //
|
|---|