nixd
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
nixf::Sema Class Reference

#include <SemaActions.h>

Public Types

using FormalVector = Formals::FormalVector
 

Public Member Functions

 Sema (std::string_view Src, std::vector< Diagnostic > &Diags)
 
void checkFormalSep (const FormalVector &FV)
 Check if there is a seperator "," between formals.
 
void checkFormalEllipsis (const FormalVector &FV)
 Check if ellipsis "...".
 
void checkFormalEmpty (const FormalVector &FV)
 Diagnose empty formal i.e. single comma.
 
void dedupFormal (std::map< std::string, const Formal * > &Dedup, const FormalVector &FV)
 Deduplicate formals.
 
std::shared_ptr< FormalsonFormals (LexerCursorRange Range, FormalVector FV)
 
void dupAttr (std::string Name, LexerCursorRange Range, LexerCursorRange Prev)
 
void checkAttrRecursiveForMerge (const ExprAttrs &XAttrs, const ExprAttrs &YAttrs)
 Check if these two attrsets has the same "recursive" modifier.
 
void mergeAttrSets (SemaAttrs &XAttrs, const SemaAttrs &YAttrs)
 Perform attrsets merging while duplicated fields are both attrsets.
 
void insertAttr (SemaAttrs &SA, std::shared_ptr< AttrName > Name, std::shared_ptr< Expr > E, Attribute::AttributeKind Kind)
 
SemaAttrsselectOrCreate (SemaAttrs &SA, const std::vector< std::shared_ptr< AttrName > > &Path)
 
void addAttr (SemaAttrs &Attr, const AttrPath &Path, std::shared_ptr< Expr > E)
 Insert the binding: AttrPath = E; into Attr.
 
void lowerInheritName (SemaAttrs &SA, std::shared_ptr< AttrName > Name, std::shared_ptr< Expr > E, Attribute::AttributeKind InheritKind)
 
void lowerInherit (SemaAttrs &Attr, const Inherit &Inherit)
 
void lowerBinds (SemaAttrs &SA, const Binds &B)
 
std::shared_ptr< ExprAttrsonExprAttrs (LexerCursorRange Range, std::shared_ptr< Binds > Binds, std::shared_ptr< Misc > Rec)
 
std::shared_ptr< LambdaArgonLambdaArg (LexerCursorRange Range, std::shared_ptr< Identifier > ID, std::shared_ptr< Formals > F)
 

Static Public Member Functions

static void removeFormal (Fix &F, const FormalVector::const_iterator &Rm, const FormalVector &FV)
 Make text edits to remove a formal.
 
static std::pair< std::shared_ptr< Expr >, Attribute::AttributeKinddesugarInheritExpr (std::shared_ptr< AttrName > Name, std::shared_ptr< Expr > E)
 Desugar inherit (expr) a, inherit a, into select, or variable.
 

Detailed Description

Definition at line 16 of file SemaActions.h.

Member Typedef Documentation

◆ FormalVector

Definition at line 24 of file SemaActions.h.

Constructor & Destructor Documentation

◆ Sema()

nixf::Sema::Sema ( std::string_view Src,
std::vector< Diagnostic > & Diags )
inline

Definition at line 21 of file SemaActions.h.

Member Function Documentation

◆ addAttr()

void nixf::Sema::addAttr ( SemaAttrs & Attr,
const AttrPath & Path,
std::shared_ptr< Expr > E )

Insert the binding: AttrPath = E; into Attr.

Definition at line 155 of file SemaActions.cpp.

References insertAttr(), nixf::Attribute::Plain, and selectOrCreate().

Referenced by lowerBinds().

◆ checkAttrRecursiveForMerge()

void nixf::Sema::checkAttrRecursiveForMerge ( const ExprAttrs & XAttrs,
const ExprAttrs & YAttrs )

Check if these two attrsets has the same "recursive" modifier.

Official nix implementation implicitly discards the second modifier, this is somehow error-prone, let's detect it.

Definition at line 22 of file SemaActions.cpp.

References nixf::ExprAttrs::isRecursive(), nixf::Node::range(), and nixf::ExprAttrs::rec().

Referenced by insertAttr().

◆ checkFormalEllipsis()

void nixf::Sema::checkFormalEllipsis ( const FormalVector & FV)

◆ checkFormalEmpty()

void nixf::Sema::checkFormalEmpty ( const FormalVector & FV)

◆ checkFormalSep()

void nixf::Sema::checkFormalSep ( const FormalVector & FV)

Check if there is a seperator "," between formals.

Definition at line 215 of file SemaActions.cpp.

References nixf::Formal::comma(), nixf::Fix::edit(), nixf::Diagnostic::fix(), nixf::Node::lCur(), nixf::TextEdit::mkInsertion(), and nixf::Node::range().

Referenced by onFormals().

◆ dedupFormal()

void nixf::Sema::dedupFormal ( std::map< std::string, const Formal * > & Dedup,
const FormalVector & FV )

Deduplicate formals.

Definition at line 251 of file SemaActions.cpp.

References nixf::Formal::id(), nixf::Identifier::name(), nixf::Diagnostic::note(), and nixf::Node::range().

Referenced by onFormals().

◆ desugarInheritExpr()

std::pair< std::shared_ptr< Expr >, Attribute::AttributeKind > nixf::Sema::desugarInheritExpr ( std::shared_ptr< AttrName > Name,
std::shared_ptr< Expr > E )
static

Desugar inherit (expr) a, inherit a, into select, or variable.

Definition at line 337 of file SemaActions.cpp.

References nixf::Attribute::Inherit, and nixf::Attribute::InheritFrom.

Referenced by lowerInherit().

◆ dupAttr()

void nixf::Sema::dupAttr ( std::string Name,
LexerCursorRange Range,
LexerCursorRange Prev )

Definition at line 15 of file SemaActions.cpp.

Referenced by insertAttr(), lowerInheritName(), mergeAttrSets(), and selectOrCreate().

◆ insertAttr()

void nixf::Sema::insertAttr ( SemaAttrs & SA,
std::shared_ptr< AttrName > Name,
std::shared_ptr< Expr > E,
Attribute::AttributeKind Kind )
Note
Name must not be null

Definition at line 67 of file SemaActions.cpp.

References checkAttrRecursiveForMerge(), dupAttr(), and mergeAttrSets().

Referenced by addAttr().

◆ lowerBinds()

void nixf::Sema::lowerBinds ( SemaAttrs & SA,
const Binds & B )

Definition at line 316 of file SemaActions.cpp.

References addAttr(), nixf::Binds::bindings(), and lowerInherit().

Referenced by onExprAttrs().

◆ lowerInherit()

void nixf::Sema::lowerInherit ( SemaAttrs & Attr,
const Inherit & Inherit )

◆ lowerInheritName()

void nixf::Sema::lowerInheritName ( SemaAttrs & SA,
std::shared_ptr< AttrName > Name,
std::shared_ptr< Expr > E,
Attribute::AttributeKind InheritKind )

◆ mergeAttrSets()

void nixf::Sema::mergeAttrSets ( SemaAttrs & XAttrs,
const SemaAttrs & YAttrs )

Perform attrsets merging while duplicated fields are both attrsets.

e.g.

{
a = { x = 1; };
a = { y = 1; };
}

We may want to merge both "a = " attrsets into a single one, instead of report duplicating attrs.

Definition at line 42 of file SemaActions.cpp.

References dupAttr().

Referenced by insertAttr().

◆ onExprAttrs()

std::shared_ptr< ExprAttrs > nixf::Sema::onExprAttrs ( LexerCursorRange Range,
std::shared_ptr< Binds > Binds,
std::shared_ptr< Misc > Rec )

Definition at line 352 of file SemaActions.cpp.

References lowerBinds().

Referenced by nixf::Parser::parseExprAttrs(), and nixf::Parser::parseExprLet().

◆ onFormals()

std::shared_ptr< Formals > nixf::Sema::onFormals ( LexerCursorRange Range,
FormalVector FV )

◆ onLambdaArg()

std::shared_ptr< LambdaArg > nixf::Sema::onLambdaArg ( LexerCursorRange Range,
std::shared_ptr< Identifier > ID,
std::shared_ptr< Formals > F )

Definition at line 362 of file SemaActions.cpp.

References nixf::Diagnostic::note().

Referenced by nixf::Parser::parseLambdaArg().

◆ removeFormal()

void nixf::Sema::removeFormal ( Fix & F,
const FormalVector::const_iterator & Rm,
const FormalVector & FV )
static

Make text edits to remove a formal.

Definition at line 170 of file SemaActions.cpp.

References nixf::Formal::comma(), nixf::Fix::edit(), nixf::TextEdit::mkRemoval(), and nixf::Node::range().

Referenced by checkFormalEllipsis().

◆ selectOrCreate()

SemaAttrs * nixf::Sema::selectOrCreate ( SemaAttrs & SA,
const std::vector< std::shared_ptr< AttrName > > & Path )

Select into Attr the attribute specified by Path, or create one if not exists, until reached the inner-most attr. Similar to mkdir -p.

Returns
The selected or created attribute.

Definition at line 104 of file SemaActions.cpp.

References dupAttr(), and nixf::Attribute::Plain.

Referenced by addAttr().


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