NewLang Project
Yet another programm language
Loading...
Searching...
No Matches
newlang::NameLookupStack Class Reference

#include <term.h>

Inheritance diagram for newlang::NameLookupStack:

Public Member Functions

 NameLookupStack (GlobalObjects &glob, StorageTerm::ModuleMapType &modules)
 
void clear ()
 
virtual ~NameLookupStack ()
 
void PushScope (TermPtr ns, bool is_function=false)
 
void PopScope ()
 
void SetLookupNamespace (TermPtr ns)
 
bool AddName (const TermPtr var, const char *alt_name=nullptr)
 
TermPtr FindInternalName (std::string_view int_name)
 
TermPtr LookupName (std::string name)
 
TermPtr LookupNameVars (const std::string_view name)
 
TermPtr LookupNameNamespace (const std::string_view ns, const std::string_view name)
 
std::string MakeInternalName (const TermPtr &term, bool is_static)
 
std::string MakeInternalName (const std::string_view name, bool is_static)
 
void ExpandNamespace (std::string &name)
 
std::string GetNamespace ()
 
std::string GetFuntionName ()
 
std::string MakeNamespace (int skip, bool is_global)
 
bool CheckInterrupt (std::string_view name)
 
std::string GetOffer ()
 
bool LookupBlock_ (TermPtr &term)
 
std::string GetOfferBlock ()
 
std::string Dump ()
 

Static Public Member Functions

static std::string EnumerateString (const StringArray &names)
 

Public Attributes

GlobalObjectsm_glob
 Buildin in Runtime.
 
StorageTerm::ModuleMapTypem_modules
 Use as a pre-declaration of (an "external") object.
 
size_t m_block_num
 Нумератор безымянных блоков кода
 

Detailed Description

Класс для разрешния имен при работе анализатора. Формирует текущую область видимости при анализе кода, реализует алгоритм разрешения имен, проверяет наличие (корректность) имен объектов включая глобальные.

На выходе работы анализатора имеет объект - модуль со списком имен:

  • Глобальных (заимствованы из RunTime и сохранены локально для использования в качестве прототипа)
  • Внешних (присутсвует объявление внешнего объекта, но сам объект отсуствует)
  • Статических (модуля и глобальных объявленных в модуле)
  • Локальных для потока (thread_local)
  • каждый объект имеет внутренне имя

При выполнении JIT создает из текущих загруженных модулей единый объект контекст для каждого потока свой. Состав модулей определяется компиляции программы и не изменяется при выполнении. Динамическая загрузка модуля происходит в конкретном контексте (потоке) и не влияет на глобальный контекст?

В TermPtr не должно быть никаких данных, чтобы их (код) можно было шарить между потоками.

Definition at line 234 of file term.h.

Constructor & Destructor Documentation

◆ NameLookupStack()

NameLookupStack::NameLookupStack ( GlobalObjects & glob,
StorageTerm::ModuleMapType & modules )

Definition at line 164 of file term.cpp.

References clear().

◆ ~NameLookupStack()

virtual newlang::NameLookupStack::~NameLookupStack ( )
inlinevirtual

Definition at line 245 of file term.h.

Member Function Documentation

◆ clear()

void NameLookupStack::clear ( )

Definition at line 169 of file term.cpp.

References newlang::Term::Create(), m_modules, and newlang::NAME.

Referenced by NameLookupStack().

◆ EnumerateString()

static std::string newlang::NameLookupStack::EnumerateString ( const StringArray & names)
inlinestatic

Definition at line 248 of file term.h.

◆ PushScope()

void NameLookupStack::PushScope ( TermPtr ns,
bool is_function = false )

◆ PopScope()

void newlang::NameLookupStack::PopScope ( )
inline

Definition at line 264 of file term.h.

References ASSERT.

Referenced by newlang::ScopePush::~ScopePush().

◆ SetLookupNamespace()

void NameLookupStack::SetLookupNamespace ( TermPtr ns)

Definition at line 200 of file term.cpp.

References LOG_LEVEL_INFO, and NL_MESSAGE.

Referenced by newlang::AstAnalysis::CreateOp_().

◆ AddName()

bool NameLookupStack::AddName ( const TermPtr var,
const char * alt_name = nullptr )

Добавялет в текущую область имен новый объект с указанным внутренним именем (int_name). или альтернативным именем (alt_name), которое должно быть нормализованным Имя сразу добавляется в текщее хранилище (на постоянной основе), и в стек простарнства имен для поиска по простому имени. У одной и той же перменной может быть несколько внутренних имен (например, синонимы у аругментов функций), потому термин (его внутреннее имя) не модифицируеься.

Parameters
int_name
var
Returns
Истина, если нет пересечений с уже зарегистрированными именами

Definition at line 426 of file term.cpp.

References ASSERT, newlang::Term::CheckTermEq(), newlang::isGlobalScope(), newlang::isStaticName(), LOG_LEVEL_INFO, LOG_RUNTIME, m_glob, m_modules, newlang::StorageTerm::MODULE_MAIN, NL_MESSAGE, and newlang::GlobalObjects::RegisterObject().

Referenced by newlang::AstAnalysis::CreateOp_().

◆ FindInternalName()

TermPtr NameLookupStack::FindInternalName ( std::string_view int_name)

Выполняет поиск объекта по <внутреннему имени (int_name)> Расширение имен согласно name lookup ны выполняется!

Parameters
int_nameВнутреннему имя объекта для поиска
local_onlyИскать только в локальном хранилище (для чистых функций)
Returns
Найденный объект (если он есть)

Definition at line 475 of file term.cpp.

References newlang::GlobalObjects::FindObject(), m_glob, m_modules, newlang::StorageTerm::MODULE_MAIN, and newlang::VariablePair::term.

Referenced by LookupName(), and LookupNameVars().

◆ LookupName()

TermPtr NameLookupStack::LookupName ( std::string name)

Производит поиск <простого имени в соответствии с name lookup>

Parameters
nameПростое имя для поиска
local_onlyИскать только в локальном хранилище (для чистых функций)
Returns
Найденный объект (если он есть)

Definition at line 541 of file term.cpp.

References FindInternalName(), newlang::isInternalName(), newlang::isTrivialName(), LookupNameNamespace(), LookupNameVars(), MakeNamespace(), and newlang::NormalizeName().

Referenced by newlang::AstAnalysis::LookupName().

◆ LookupNameVars()

TermPtr NameLookupStack::LookupNameVars ( const std::string_view name)

Definition at line 494 of file term.cpp.

References FindInternalName(), m_modules, and newlang::StorageTerm::MODULE_MAIN.

Referenced by LookupName(), and LookupNameNamespace().

◆ LookupNameNamespace()

TermPtr NameLookupStack::LookupNameNamespace ( const std::string_view ns,
const std::string_view name )

Definition at line 526 of file term.cpp.

References LookupNameVars().

Referenced by LookupName().

◆ MakeInternalName() [1/2]

std::string NameLookupStack::MakeInternalName ( const TermPtr & term,
bool is_static )

Definition at line 309 of file term.cpp.

References ASSERT, and MakeInternalName().

Referenced by newlang::AstAnalysis::CreateOp_(), and MakeInternalName().

◆ MakeInternalName() [2/2]

std::string NameLookupStack::MakeInternalName ( const std::string_view name,
bool is_static )

◆ ExpandNamespace()

void NameLookupStack::ExpandNamespace ( std::string & name)

Definition at line 223 of file term.cpp.

References GetFuntionName(), and GetNamespace().

Referenced by LookupBlock_().

◆ GetNamespace()

std::string NameLookupStack::GetNamespace ( )

Definition at line 289 of file term.cpp.

References ASSERT, and result.

Referenced by ExpandNamespace(), and MakeInternalName().

◆ GetFuntionName()

std::string NameLookupStack::GetFuntionName ( )

Definition at line 277 of file term.cpp.

References ASSERT, and LOG_RUNTIME.

Referenced by ExpandNamespace(), and MakeInternalName().

◆ MakeNamespace()

std::string NameLookupStack::MakeNamespace ( int skip,
bool is_global )

Definition at line 250 of file term.cpp.

References result.

Referenced by LookupName().

◆ CheckInterrupt()

bool NameLookupStack::CheckInterrupt ( std::string_view name)

Definition at line 234 of file term.cpp.

References LOG_RUNTIME.

◆ GetOffer()

std::string newlang::NameLookupStack::GetOffer ( )
inline

Definition at line 317 of file term.h.

◆ LookupBlock_()

bool NameLookupStack::LookupBlock_ ( TermPtr & term)

Definition at line 647 of file term.cpp.

References ASSERT, Dump(), ExpandNamespace(), LOG_LEVEL_INFO, and NL_MESSAGE.

Referenced by newlang::AstAnalysis::RecursiveAnalyzer().

◆ GetOfferBlock()

std::string NameLookupStack::GetOfferBlock ( )

Definition at line 670 of file term.cpp.

References result.

◆ Dump()

std::string NameLookupStack::Dump ( )

Definition at line 691 of file term.cpp.

References result.

Referenced by LookupBlock_(), and newlang::AstAnalysis::RecursiveAnalyzer().

Member Data Documentation

◆ m_glob

GlobalObjects& newlang::NameLookupStack::m_glob

Buildin in Runtime.

Definition at line 236 of file term.h.

Referenced by AddName(), and FindInternalName().

◆ m_modules

StorageTerm::ModuleMapType& newlang::NameLookupStack::m_modules

Use as a pre-declaration of (an "external") object.

Definition at line 237 of file term.h.

Referenced by AddName(), clear(), FindInternalName(), and LookupNameVars().

◆ m_block_num

size_t newlang::NameLookupStack::m_block_num

Нумератор безымянных блоков кода

Definition at line 238 of file term.h.

Referenced by PushScope().


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