undoStudio
The IDE of the undoRT ecosystem
Loading...
Searching...
No Matches
undoApp::ST Namespace Reference

Namespaces

namespace  detail
 

Classes

struct  CallSignature
 The parameter list of a callable. More...
 
struct  CallSite
 The call the cursor sits inside, if any. More...
 
struct  Declaration
 One declaration that a usage can be navigated back to. More...
 
struct  FileNode
 Node structure for the file tree representation. More...
 
struct  MemberAccessPoint
 What a line looks like at the cursor, for member completion. More...
 
struct  MethodData
 Data structure for a method inside a FUNCTION_BLOCK. More...
 
struct  MethodEditors
 Editor pair for a single METHOD tab (created lazily on first open) More...
 
struct  NameMatch
 How a typed pattern lines up with a candidate name. More...
 
struct  OutputFilter
 Which severities the Output panel shows. More...
 
struct  OutputLine
 One tagged line in the Output panel. More...
 
struct  SemanticToken
 One classified identifier occurrence. More...
 
struct  SemanticTokenSet
 Result of a classification pass. More...
 
struct  SignatureParam
 One parameter of a call, as the signature popup shows it. More...
 
struct  SignatureSegment
 One run of text in a rendered signature. More...
 
struct  SourceSegment
 One editor-backed block of the generated ST file. More...
 
class  STApp
 Main application class for the Structured Text editor plugin. More...
 
struct  StatementSnippet
 One statement skeleton the suggestion list can write out. More...
 
struct  STDocument
 One open ST file, held whole so it can be put back. More...
 
struct  Suggestion
 One entry of a completion list. More...
 

Typedefs

using TranslationUnit = ::TranslationUnit
 
using ParseError = ::ParseError
 
using DeclarationIndex = std::unordered_map< std::string, std::vector< Declaration > >
 Declarations of a translation unit, keyed by normalized name.
 
using MemberAccess = Suggestion
 
using MemberList = std::vector< Suggestion >
 

Enumerations

enum class  POUType { Program , FunctionBlock , Function }
 Enumeration of POU (Program Organization Unit) types. More...
 
enum class  OutSeverity { Info , Success , Warning , Error }
 Severity of a line in the Output panel. More...
 
enum class  SymCategory {
  Unresolved , Variable , Constant , Parameter ,
  Function , Type , Field , Enumerator
}
 Category of a resolved symbol, as far as highlighting cares. More...
 
enum class  SnippetPane { Variables , Body }
 The pane a snippet is written into. More...
 

Functions

std::vector< OutputLine > searchOutput (const std::vector< OutputLine > &lines, const std::string &needle)
 The lines matching a substring, for the panel's search box.
 
bool isCountSummary (const std::string &line)
 Whether a line from the transpiler is a tally rather than a diagnostic.
 
OutSeverity classifyCompilerLine (const std::string &line)
 How a line the transpiler printed should be coloured in the panel.
 
SemanticTokenSet collectSemanticTokens (const TranslationUnit &tu, const st2cpp::semantic::SymbolTable &symTab, const std::vector< std::string > &srcLines)
 Classify every identifier the analyzer could resolve.
 
st2cpp::semantic::ScopeId findMemberScopeFor (const st2cpp::semantic::SymbolTable &symTab, const std::string &ownerName, bool method)
 The scope holding the variables of a POU or the locals of a METHOD.
 
std::string describeType (const TypeRef &type)
 Render a type reference the way it is written in source.
 
DeclarationIndex collectDeclarations (const TranslationUnit &tu, const st2cpp::semantic::SymbolTable &symTab)
 Index every declaration a navigation could target.
 
NameMatch matchName (const std::string &name, const std::string &pattern)
 Match a typed pattern against a candidate name, fuzzily.
 
void rankMembers (MemberList &members, const std::string &pattern)
 Keep the members a pattern matches and order them best first.
 
MemberList collectBlockMembers (const st2cpp::semantic::SymbolTable &symTab, st2cpp::semantic::SymbolId fbId)
 Everything reachable through '.' on a value of a function block type.
 
st2cpp::semantic::SymbolId findInstanceBlock (const st2cpp::semantic::SymbolTable &symTab, st2cpp::semantic::ScopeId scopeId, const std::string &name)
 The function block an instance name refers to, if any.
 
MemberAccessPoint memberAccessPointAt (const std::string &line, int cursorCol)
 Decide whether the cursor sits in a member access.
 
std::string describeMember (const Suggestion &member)
 Render a member the way it is offered in the completion list.
 
MemberList collectScopeNames (const st2cpp::semantic::SymbolTable &symTab, st2cpp::semantic::ScopeId scopeId, bool includeOwnMethods=true)
 The names visible from a scope, for completing a plain identifier.
 
CallSite callSiteAt (const std::vector< std::string > &lines, int line, int col)
 Find the call whose argument list the cursor is inside.
 
bool resolveCallSignature (const st2cpp::semantic::SymbolTable &symTab, st2cpp::semantic::ScopeId scopeId, const CallSite &call, CallSignature &out)
 Resolve the parameters of the call at a call site.
 
std::vector< SignatureSegment > signatureSegments (const CallSignature &signature, int activeArgument)
 Break a signature into the runs the popup draws.
 
std::string formatSignature (const CallSignature &signature, int activeArgument)
 Render a signature as one line, the way the tests and the label use it.
 
const std::vector< StatementSnippet > & allStatementSnippets ()
 The statements on offer.
 
std::vector< StatementSnippet > snippetsForPane (SnippetPane pane)
 The snippets belonging to one pane.
 
bool hasStatementPrefix (const std::string &prefix)
 Whether the list is worth opening for what has been typed.
 
std::string statementPrefixAt (const std::string &line, int column, int &startCol)
 The word being typed at the caret.
 
void rankSnippets (std::vector< StatementSnippet > &snippets, const std::string &prefix)
 Keep the snippets matching a prefix, best match first.
 
std::string leadingWhitespace (const std::string &line)
 Indentation of a line, spaces and tabs alike.
 
void expandSnippet (const StatementSnippet &snippet, const std::string &base, const std::string &tab, std::string &text, int &caretLine, int &caretCol)
 Write a snippet out at a line, in the indentation already in force there.
 

Typedef Documentation

◆ DeclarationIndex

using undoApp::ST::DeclarationIndex = typedef std::unordered_map<std::string, std::vector<Declaration> >

Declarations of a translation unit, keyed by normalized name.

A name can appear more than once when a METHOD parameter shadows a POU variable, so every declaration is kept and the caller picks the one matching the scope it is navigating from.

◆ MemberAccess

The name a member-completion candidate used to be known by. Kept so callers and tests that only deal with members keep reading correctly.

◆ MemberList

using undoApp::ST::MemberList = typedef std::vector<Suggestion>

◆ ParseError

using undoApp::ST::ParseError = typedef ::ParseError

◆ TranslationUnit

using undoApp::ST::TranslationUnit = typedef ::TranslationUnit

Enumeration Type Documentation

◆ OutSeverity

enum class undoApp::ST::OutSeverity
strong

Severity of a line in the Output panel.

Enumerator
Info 

Debug/detail output, and the generated ST dump.

Success 

Confirmation that a step succeeded.

Warning 

Reported by the analyzer but not blocking.

Error 

Blocks code generation.

◆ POUType

enum class undoApp::ST::POUType
strong

Enumeration of POU (Program Organization Unit) types.

Enumerator
Program 
FunctionBlock 
Function 

◆ SnippetPane

enum class undoApp::ST::SnippetPane
strong

The pane a snippet is written into.

Enumerator
Variables 

The Variables pane, which holds the VAR sections.

Body 

The Body pane, which holds the cyclic code.

◆ SymCategory

enum class undoApp::ST::SymCategory
strong

Category of a resolved symbol, as far as highlighting cares.

Enumerator
Unresolved 

Not in the symbol table: leave the text as the lexer saw it.

Variable 
Constant 

VAR CONSTANT, or any symbol flagged constant.

Parameter 
Function 

FUNCTION / METHOD / IEC conversion.

Type 

Built-in or user-defined type, INTERFACE.

Field 

PROGRAM / FUNCTION_BLOCK instance, STRUCT member.

Enumerator 

Function Documentation

◆ allStatementSnippets()

const std::vector< StatementSnippet > & undoApp::ST::allStatementSnippets ( )

The statements on offer.

Returns
Every snippet, in the order the list shows them

◆ callSiteAt()

CallSite undoApp::ST::callSiteAt ( const std::vector< std::string > &  lines,
int  line,
int  col 
)

Find the call whose argument list the cursor is inside.

Parameters
linesText of the buffer, one entry per line
line0-based line of the cursor
col0-based column of the cursor
Returns
The call, active false when the cursor is not inside one

The scan walks backwards over the whole buffer, so a call split over several lines still resolves. It skips string literals, line comments and block comments, and stops at a ;, which is what keeps a ( from an earlier statement from being attributed to the current one.

◆ classifyCompilerLine()

OutSeverity undoApp::ST::classifyCompilerLine ( const std::string &  line)
inline

How a line the transpiler printed should be coloured in the panel.

The transpiler writes to standard error in a fixed shape, which is what this reads. Matching the bare word "error" anywhere in the line is what marked a count of zero errors as an error, and what would mark a file called errors.st as a failure.

A tally is Info: it reports what the lines above it already said, each of which is coloured on its own, so colouring the summary as well puts one more red line in among the red ones and hides the ones that matter.

◆ collectBlockMembers()

MemberList undoApp::ST::collectBlockMembers ( const st2cpp::semantic::SymbolTable &  symTab,
st2cpp::semantic::SymbolId  fbId 
)

Everything reachable through '.' on a value of a function block type.

Parameters
symTabSymbol table of the analysis the instance belongs to
fbIdSymbol id of the FUNCTION_BLOCK
Returns
Parameters, state and methods, flattened over the EXTENDS chain

The base chain comes first so the listing matches the block's declaration order, and an entry a derived block redeclares appears once, as the derived declaration. Empty when fbId is not a function block.

◆ collectDeclarations()

DeclarationIndex undoApp::ST::collectDeclarations ( const TranslationUnit &  tu,
const st2cpp::semantic::SymbolTable &  symTab 
)

Index every declaration a navigation could target.

Parameters
tuParsed translation unit
symTabSymbol table for that unit, used to classify each declaration
Returns
Declarations keyed by normalized name

◆ collectScopeNames()

MemberList undoApp::ST::collectScopeNames ( const st2cpp::semantic::SymbolTable &  symTab,
st2cpp::semantic::ScopeId  scopeId,
bool  includeOwnMethods = true 
)

The names visible from a scope, for completing a plain identifier.

Parameters
symTabSymbol table of the file being edited
scopeIdScope the caret is in
includeOwnMethodsAlso offer the methods of the block being edited

A name is offered when the source could resolve it from where the caret is: the scopes from that point outwards, plus the library side. The block's own methods are part of that only in its own body, since a method reaches its siblings through an instance rather than by name. Inside a scope the order is declaration order, and a name declared in more than one place appears once, as the innermost declaration, which is the one that wins in the source.

◆ collectSemanticTokens()

SemanticTokenSet undoApp::ST::collectSemanticTokens ( const TranslationUnit &  tu,
const st2cpp::semantic::SymbolTable &  symTab,
const std::vector< std::string > &  srcLines 
)

Classify every identifier the analyzer could resolve.

Parameters
tuParsed translation unit
symTabSymbol table produced by SemanticAnalyzer for that same unit
srcLinesGenerated source, 1-based (index 0 holds line 1)
Returns
Classified tokens, in AST traversal order

The analyzer does not write symbol ids back into the AST, and POU/METHOD members live in scopes unreachable from the global one, so visibility is resolved by name against a per-scope index built here. A few nodes (POU and METHOD names, STRUCT members) carry no position at all and are located in the source text.

◆ describeMember()

std::string undoApp::ST::describeMember ( const Suggestion &  member)

Render a member the way it is offered in the completion list.

Parameters
memberMember to describe
Returns
e.g. "Reset() : BOOL", "ticks : INT", "gain : REAL"

◆ describeType()

std::string undoApp::ST::describeType ( const TypeRef &  type)

Render a type reference the way it is written in source.

Parameters
typeType reference from the AST
Returns
Human-readable type, e.g. "INT", "STRING[80]", "POINTER TO Motor"

◆ expandSnippet()

void undoApp::ST::expandSnippet ( const StatementSnippet &  snippet,
const std::string &  base,
const std::string &  tab,
std::string &  text,
int &  caretLine,
int &  caretCol 
)

Write a snippet out at a line, in the indentation already in force there.

The base indentation of the line the caret is on is prepended to every template line, so a skeleton accepted inside a loop comes out indented like the code around it. The caret is resolved against the written text, where an indent step is as wide as the editor shows a tab.

Parameters
snippetSkeleton to write
baseIndentation to insert under
tabText standing for one indent step
textSet to the text to write, newlines included
caretLineSet to the line the caret belongs on, 0-based in the text
caretColSet to the column it belongs at, 0-based in that line

◆ findInstanceBlock()

st2cpp::semantic::SymbolId undoApp::ST::findInstanceBlock ( const st2cpp::semantic::SymbolTable &  symTab,
st2cpp::semantic::ScopeId  scopeId,
const std::string &  name 
)

The function block an instance name refers to, if any.

Parameters
symTabSymbol table of the current analysis
scopeIdScope the lookup starts from, e.g. a METHOD's scope
nameInstance name as written in the source
Returns
Symbol id of the FUNCTION_BLOCK, or 0 when the name is not one

An instance is a variable whose type resolved to a function block, which is how inst : Motor becomes a member provider. External instances (a block declared in a sibling file) resolve too, once the descriptor carries its members.

◆ findMemberScopeFor()

st2cpp::semantic::ScopeId undoApp::ST::findMemberScopeFor ( const st2cpp::semantic::SymbolTable &  symTab,
const std::string &  ownerName,
bool  method 
)

The scope holding the variables of a POU or the locals of a METHOD.

Parameters
symTabSymbol table of the current analysis
ownerNamePOU or METHOD name, as spelled in the source
methodTrue for a METHOD, false for a POU
Returns
Scope id, or 0 when there is no such scope

st2cpp names these scopes after their owner ("FB_Motor", "METHOD_Reset"). A METHOD scope is nested inside its POU's, so a name visible in the METHOD is also found by walking up from here.

◆ formatSignature()

std::string undoApp::ST::formatSignature ( const CallSignature &  signature,
int  activeArgument 
)

Render a signature as one line, the way the tests and the label use it.

Parameters
signatureWhat resolveCallSignature produced
activeArgumentArgument the cursor is in, 0-based
Returns
e.g. "Reset(set : BOOL, out : INT) : BOOL"

◆ hasStatementPrefix()

bool undoApp::ST::hasStatementPrefix ( const std::string &  prefix)

Whether the list is worth opening for what has been typed.

The gate is stricter than the matching rankSnippets does. Matching inside the list is a subsequence, so "end" finds every END_ and "wh" finds WHILE, but "re" is also a subsequence match for REPEAT while the user is halfway through "reSetFlag" or "motore.re". The list only opens when the word is a genuine prefix of a keyword, which leaves an identifier that happens to begin like a statement to the identifier list.

Parameters
prefixWhat the user has typed
Returns
true when at least one keyword starts with it

◆ isCountSummary()

bool undoApp::ST::isCountSummary ( const std::string &  line)
inline

Whether a line from the transpiler is a tally rather than a diagnostic.

st2cpp closes its diagnostics with a count of what it just reported: 3 error(s), 2 warning(s) generated. Semantic analysis: 0 errors, 3 warnings The word "error" is in those lines, and taking it at its word marks a summary of zero errors as an error. What tells them apart from a real diagnostic is that a number sits immediately in front of the word: a diagnostic names its position instead, as "file.st:12:5: error:", where a colon comes between.

◆ leadingWhitespace()

std::string undoApp::ST::leadingWhitespace ( const std::string &  line)

Indentation of a line, spaces and tabs alike.

Parameters
lineLine to measure
Returns
The leading run of blanks

◆ matchName()

NameMatch undoApp::ST::matchName ( const std::string &  name,
const std::string &  pattern 
)

Match a typed pattern against a candidate name, fuzzily.

Parameters
nameCandidate name as spelled in the source
patternWhat the user has typed so far
Returns
The match, with positions empty when the pattern is empty

Case-insensitive, as IEC 61131-3 identifiers are, and tolerant of interleaved characters: rst matches Reset, Reset matches MotorResetState, and Reset does not match resets.

Ranking prefers, in order: the whole name, then a prefix, then a word boundary, then a plain in-order match. Within that, characters that continue a run, start a word or sit on a camel-case hump raise the score, and every skipped character lowers it slightly, so the tightest match sorts first.

◆ memberAccessPointAt()

MemberAccessPoint undoApp::ST::memberAccessPointAt ( const std::string &  line,
int  cursorCol 
)

Decide whether the cursor sits in a member access.

Parameters
lineText of the current line
cursorCol0-based column of the cursor within that line
Returns
The access being completed, active false when there is none

Only an identifier (or nothing) may precede the '.', so a literal or a closing parenthesis does not open completion. The prefix is the identifier fragment already typed after the '.', which the caller filters on.

◆ rankMembers()

void undoApp::ST::rankMembers ( MemberList &  members,
const std::string &  pattern 
)

Keep the members a pattern matches and order them best first.

Parameters
membersList to filter in place
patternWhat the user has typed after the '.'

Every surviving member gets its matchPositions filled, which is what the list draws highlighted. The sort is stable, so members that score equally keep the block's declaration order.

◆ rankSnippets()

void undoApp::ST::rankSnippets ( std::vector< StatementSnippet > &  snippets,
const std::string &  prefix 
)

Keep the snippets matching a prefix, best match first.

Matching is a subsequence, not a prefix, so "fi" still finds IF and "wh" finds WHILE. Best match is where the match begins: a label opening with what was typed is about that word, one that only contains it further along is not. That is what puts END_IF ahead of IF ... END_IF once "end" has been typed. Snippets that score alike keep the order the table is written in.

Parameters
snippetsIn/out list, reordered in place
prefixWhat the user has typed

◆ resolveCallSignature()

bool undoApp::ST::resolveCallSignature ( const st2cpp::semantic::SymbolTable &  symTab,
st2cpp::semantic::ScopeId  scopeId,
const CallSite &  call,
CallSignature &  out 
)

Resolve the parameters of the call at a call site.

Parameters
symTabSymbol table of the current analysis
scopeIdScope the lookup starts from, so a METHOD local wins
callThe call site to resolve
outFilled with the signature on success, untouched on failure
Returns
True when the callee was found and its parameters were read

Handles the three shapes a call takes in ST: a method through an instance (inst.Method(), a FUNCTION or a FUNCTION_BLOCK instance called directly (MyBlock(), and a POU reached through its type name. A METHOD is looked up over the whole EXTENDS chain, since the block may not declare it itself.

◆ searchOutput()

std::vector< OutputLine > undoApp::ST::searchOutput ( const std::vector< OutputLine > &  lines,
const std::string &  needle 
)
inline

The lines matching a substring, for the panel's search box.

Empty or whitespace-only text matches everything, so clearing the box restores the list without a second way to say "no search".

◆ signatureSegments()

std::vector< SignatureSegment > undoApp::ST::signatureSegments ( const CallSignature &  signature,
int  activeArgument 
)

Break a signature into the runs the popup draws.

Parameters
signatureWhat resolveCallSignature produced
activeArgumentArgument the cursor is in, 0-based
Returns
Segments in reading order, each a plain string or a parameter

A parameter count that has run past the last one still yields a run, so the popup can flag an argument the callee does not take.

◆ snippetsForPane()

std::vector< StatementSnippet > undoApp::ST::snippetsForPane ( SnippetPane  pane)

The snippets belonging to one pane.

Parameters
panePane the caret is in
Returns
The subset offered there, in list order

◆ statementPrefixAt()

std::string undoApp::ST::statementPrefixAt ( const std::string &  line,
int  column,
int &  startCol 
)

The word being typed at the caret.

Parameters
lineThe line the caret is on
columnCaret column, 0-based
startColSet to the first column of the word
Returns
The word left of the caret, empty when there is none

The word has to end at the caret. A caret inside one is editing it, and replacing "IF" with a skeleton there would leave "IF" welded to what followed.