Joos1W Compiler Framework
All Classes Functions Typedefs Pages
ast::Modifiers Class Reference

Public Types

enum class  Type {
  Public = 0 , Protected = 1 , Static = 2 , Final = 3 ,
  Abstract = 4 , Native = 5 , NumModifiers = 6
}
 

Public Member Functions

void set (parsetree::Modifier target)
 Will clear + set the modifier given a parsetree::Modifier Will also set the location of the modifier. More...
 
bool set (ast::Modifiers::Type target)
 Will union the modifier with the current modifiers. More...
 
bool set (ast::Modifiers target)
 Will union the modifiers with the current modifiers. More...
 
auto getLocationsMasked (Modifiers target) const
 Returns an iterator over the locations of the modifiers that are set in both this Modifiers object and the given Modifiers object. More...
 
auto getLocation (Type modifier) const
 Returns the location of the given modifier. Returns an undefined location if the modifier is not set.
 
bool isPublic () const
 
bool isProtected () const
 
bool isStatic () const
 
bool isFinal () const
 
bool isAbstract () const
 
bool isNative () const
 
std::string toString () const
 

Detailed Description

Definition at line 265 of file AstNode.h.

Member Function Documentation

◆ getLocationsMasked()

auto ast::Modifiers::getLocationsMasked ( Modifiers  target) const
inline

Returns an iterator over the locations of the modifiers that are set in both this Modifiers object and the given Modifiers object.

Parameters
targetThe set of modifiers to intersect

Definition at line 308 of file AstNode.h.

308  {
309  auto masked = target.modifiers & modifiers;
310  return std::views::iota(0, (int)Type::NumModifiers) |
311  std::views::filter(
312  [masked](int i) { return (masked & (1 << i)) != 0; }) |
313  std::views::transform([this](int i) { return modifierLocations[i]; });
314  }

◆ set() [1/3]

bool ast::Modifiers::set ( ast::Modifiers  target)
inline

Will union the modifiers with the current modifiers.

Parameters
targetThe set of modifiers to union
Returns
True if any of the modifiers were already set

Definition at line 295 of file AstNode.h.

295  {
296  bool wasSet = false;
297  for(int i = 0; i < (int)Type::NumModifiers; i++) {
298  if(test(target.modifiers, (Type)i)) {
299  wasSet |= set((Type)i);
300  }
301  }
302  return wasSet;
303  }
void set(parsetree::Modifier target)
Will clear + set the modifier given a parsetree::Modifier Will also set the location of the modifier.
Definition: Modifiers.cc:5

References set().

◆ set() [2/3]

bool ast::Modifiers::set ( ast::Modifiers::Type  target)
inline

Will union the modifier with the current modifiers.

Parameters
modifierThe modifier to union with this Modifiers object
Returns
True if the modifier was already set

Definition at line 286 of file AstNode.h.

286  {
287  bool wasSet = test(modifiers, target);
288  modifiers |= (1 << (uint8_t)target);
289  return wasSet;
290  }

Referenced by set().

◆ set() [3/3]

void ast::Modifiers::set ( parsetree::Modifier  target)

Will clear + set the modifier given a parsetree::Modifier Will also set the location of the modifier.

Parameters
modifierThe modifier to assign to this Modifiers object

Definition at line 5 of file Modifiers.cc.

5  {
6  Type modifier;
7  switch(target.get_type()) {
8  case parsetree::Modifier::Type::Public:
9  modifier = Type::Public;
10  break;
11  case parsetree::Modifier::Type::Protected:
12  modifier = Type::Protected;
13  break;
14  case parsetree::Modifier::Type::Static:
15  modifier = Type::Static;
16  break;
17  case parsetree::Modifier::Type::Final:
18  modifier = Type::Final;
19  break;
20  case parsetree::Modifier::Type::Abstract:
21  modifier = Type::Abstract;
22  break;
23  case parsetree::Modifier::Type::Native:
24  modifier = Type::Native;
25  break;
26  default:
27  assert(false && "Unknown modifier type");
28  }
29  set(modifier);
30  modifierLocations[(int)modifier] = target.location();
31 }
SourceRange location() const
Get the location of the node.
Definition: ParseTree.h:150

References parsetree::Node::location(), and set().


The documentation for this class was generated from the following files: