undoStudio
The IDE of the undoRT ecosystem
Loading...
Searching...
No Matches
undoAppSTSemantic.hpp
Go to the documentation of this file.
1
18#pragma once
19
20#include "ast/AST.h"
21#include "semantic/SymbolTable.h"
22
23#include <functional>
24#include <string>
25#include <unordered_map>
26#include <vector>
27
28namespace undoApp {
29namespace ST {
30
34enum class SymCategory
35{
38 Constant,
40 Function,
41 Type,
42 Field,
44};
45
56
61{
62 std::vector<SemanticToken> tokens;
63};
64
79 const st2cpp::semantic::SymbolTable& symTab,
80 const std::vector<std::string>& srcLines);
81
93st2cpp::semantic::ScopeId findMemberScopeFor(const st2cpp::semantic::SymbolTable& symTab,
94 const std::string& ownerName,
95 bool method);
96
102std::string describeType(const TypeRef& type);
103
111{
112 int line = 0;
113 int col = 0;
114 std::string name;
115 int ownerLine = 0;
116 std::string scope;
118 std::string typeText;
119 std::string kindText;
120};
121
129using DeclarationIndex = std::unordered_map<std::string, std::vector<Declaration>>;
130
138 const st2cpp::semantic::SymbolTable& symTab);
139
140// ============================================================================
141// Member access
142//
143// What the '.' operator can reach on a value: the call interface, the
144// internal state and the methods of a function block, inheritance included.
145// ============================================================================
146
154{
155 bool matched = false;
156 int score = 0;
157 std::vector<int> positions;
158};
159
175NameMatch matchName(const std::string& name, const std::string& pattern);
176
186{
188 enum class Kind
189 {
190 Parameter,
191 State,
192 Method,
193 Constant,
194 Function,
195 Block,
196 Type,
198 };
199
200 std::string name;
201 std::string typeText;
203 bool isConstant = false;
204 bool isRetain = false;
205 bool isAbstract = false;
206 bool isOverride = false;
207 bool inherited = false;
208 std::string declaredIn;
209 std::vector<std::string> parameterTypes;
210 std::vector<std::string> parameterNames;
211 std::vector<std::string> parameterDirs;
212 std::string note;
213
215 bool matches(const std::string& prefix) const;
216
218 std::vector<int> matchPositions;
219};
220
224using MemberList = std::vector<Suggestion>;
225
235void rankMembers(MemberList& members, const std::string& pattern);
236
247MemberList collectBlockMembers(const st2cpp::semantic::SymbolTable& symTab,
248 st2cpp::semantic::SymbolId fbId);
249
262st2cpp::semantic::SymbolId findInstanceBlock(const st2cpp::semantic::SymbolTable& symTab,
263 st2cpp::semantic::ScopeId scopeId,
264 const std::string& name);
265
270{
271 bool active = false;
272 std::string objectName;
273 std::string prefix;
274 int dotColumn = -1;
275};
276
287MemberAccessPoint memberAccessPointAt(const std::string& line, int cursorCol);
288
294std::string describeMember(const Suggestion& member);
295
309MemberList collectScopeNames(const st2cpp::semantic::SymbolTable& symTab,
310 st2cpp::semantic::ScopeId scopeId,
311 bool includeOwnMethods = true);
312
313// ============================================================================
314// Call sites and signature help
315//
316// What a call looks like from the inside: the callee, the argument the cursor
317// sits in, and the parameter list to show while it is being typed.
318// ============================================================================
319
324{
325 bool active = false;
326 std::string objectName;
327 std::string calleeName;
328 std::string label;
330 int parenLine = -1;
331 int parenColumn = -1;
332 int argumentLine = -1;
333 int argumentColumn = -1;
334};
335
348CallSite callSiteAt(const std::vector<std::string>& lines, int line, int col);
349
354{
355 std::string name;
356 std::string type;
357 std::string direction;
358 bool hasDefault = false;
359};
360
365{
366 std::string name;
367 std::string owner;
368 std::string returnType;
369 bool inherited = false;
370 std::string declaredIn;
371 std::vector<SignatureParam> params;
372};
373
387bool resolveCallSignature(const st2cpp::semantic::SymbolTable& symTab,
388 st2cpp::semantic::ScopeId scopeId,
389 const CallSite& call,
390 CallSignature& out);
391
396{
397 std::string text;
398 bool isParameter = false;
399};
400
410std::vector<SignatureSegment> signatureSegments(const CallSignature& signature, int activeArgument);
411
418std::string formatSignature(const CallSignature& signature, int activeArgument);
419
420} // namespace ST
421} // namespace undoApp
std::vector< Suggestion > MemberList
Definition undoAppSTSemantic.hpp:224
DeclarationIndex collectDeclarations(const TranslationUnit &tu, const st2cpp::semantic::SymbolTable &symTab)
Index every declaration a navigation could target.
SymCategory
Category of a resolved symbol, as far as highlighting cares.
Definition undoAppSTSemantic.hpp:35
@ Unresolved
Not in the symbol table: leave the text as the lexer saw it.
@ Field
PROGRAM / FUNCTION_BLOCK instance, STRUCT member.
@ Type
Built-in or user-defined type, INTERFACE.
@ Constant
VAR CONSTANT, or any symbol flagged constant.
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.
MemberList collectBlockMembers(const st2cpp::semantic::SymbolTable &symTab, st2cpp::semantic::SymbolId fbId)
Everything reachable through '.' on a value of a function block type.
std::unordered_map< std::string, std::vector< Declaration > > DeclarationIndex
Declarations of a translation unit, keyed by normalized name.
Definition undoAppSTSemantic.hpp:129
std::string describeType(const TypeRef &type)
Render a type reference the way it is written in source.
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.
void rankMembers(MemberList &members, const std::string &pattern)
Keep the members a pattern matches and order them best first.
MemberAccessPoint memberAccessPointAt(const std::string &line, int cursorCol)
Decide whether the cursor sits in a member access.
SemanticTokenSet collectSemanticTokens(const TranslationUnit &tu, const st2cpp::semantic::SymbolTable &symTab, const std::vector< std::string > &srcLines)
Classify every identifier the analyzer could resolve.
std::string formatSignature(const CallSignature &signature, int activeArgument)
Render a signature as one line, the way the tests and the label use it.
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.
NameMatch matchName(const std::string &name, const std::string &pattern)
Match a typed pattern against a candidate name, fuzzily.
std::vector< SignatureSegment > signatureSegments(const CallSignature &signature, int activeArgument)
Break a signature into the runs the popup draws.
CallSite callSiteAt(const std::vector< std::string > &lines, int line, int col)
Find the call whose argument list the cursor is inside.
std::string describeMember(const Suggestion &member)
Render a member the way it is offered in the completion list.
::TranslationUnit TranslationUnit
Definition undoAppST.hpp:36
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.
Definition undoAppCpp.hpp:26
The parameter list of a callable.
Definition undoAppSTSemantic.hpp:365
std::string returnType
Return type, empty for a call with no result.
Definition undoAppSTSemantic.hpp:368
std::string owner
Block the method belongs to, empty for a plain call.
Definition undoAppSTSemantic.hpp:367
std::string name
Member or function name, without the object.
Definition undoAppSTSemantic.hpp:366
bool inherited
Definition undoAppSTSemantic.hpp:369
std::string declaredIn
Definition undoAppSTSemantic.hpp:370
std::vector< SignatureParam > params
Definition undoAppSTSemantic.hpp:371
The call the cursor sits inside, if any.
Definition undoAppSTSemantic.hpp:324
std::string label
"motore.Reset" or "MAX", as it appears in the source
Definition undoAppSTSemantic.hpp:328
std::string calleeName
Member or function being called.
Definition undoAppSTSemantic.hpp:327
bool active
The cursor is between a callee's parentheses.
Definition undoAppSTSemantic.hpp:325
int argumentIndex
Which argument the cursor is in, 0-based.
Definition undoAppSTSemantic.hpp:329
int argumentLine
Line the current argument's text starts on.
Definition undoAppSTSemantic.hpp:332
int parenColumn
Column of the opening parenthesis.
Definition undoAppSTSemantic.hpp:331
std::string objectName
Instance before the '.', empty for a plain call.
Definition undoAppSTSemantic.hpp:326
int parenLine
Line of the opening parenthesis.
Definition undoAppSTSemantic.hpp:330
int argumentColumn
Its first column, just past '(' or the last ','.
Definition undoAppSTSemantic.hpp:333
One declaration that a usage can be navigated back to.
Definition undoAppSTSemantic.hpp:111
std::string kindText
"VAR", "METHOD", "FUNCTION_BLOCK", ... for display
Definition undoAppSTSemantic.hpp:119
std::string typeText
Declared or return type, when known.
Definition undoAppSTSemantic.hpp:118
int ownerLine
For a METHOD parameter: the line of its METHOD.
Definition undoAppSTSemantic.hpp:115
int col
Column of the first character of the name.
Definition undoAppSTSemantic.hpp:113
SymCategory category
Definition undoAppSTSemantic.hpp:117
int line
Line of the declared name.
Definition undoAppSTSemantic.hpp:112
std::string name
Identifier as spelled in the source.
Definition undoAppSTSemantic.hpp:114
std::string scope
Empty for POU level, else the owning METHOD name.
Definition undoAppSTSemantic.hpp:116
What a line looks like at the cursor, for member completion.
Definition undoAppSTSemantic.hpp:270
std::string prefix
Part of the member name already typed.
Definition undoAppSTSemantic.hpp:273
int dotColumn
0-based column of the '.', -1 when inactive
Definition undoAppSTSemantic.hpp:274
bool active
A '.' was typed and the cursor follows it.
Definition undoAppSTSemantic.hpp:271
std::string objectName
Identifier before the '.'.
Definition undoAppSTSemantic.hpp:272
How a typed pattern lines up with a candidate name.
Definition undoAppSTSemantic.hpp:154
std::vector< int > positions
Matched indices into the name, ascending.
Definition undoAppSTSemantic.hpp:157
bool matched
Pattern occurs in order inside the name.
Definition undoAppSTSemantic.hpp:155
int score
Higher is better; only meaningful if matched.
Definition undoAppSTSemantic.hpp:156
One classified identifier occurrence.
Definition undoAppSTSemantic.hpp:50
int col
0-based column of the first character
Definition undoAppSTSemantic.hpp:52
int line
1-based line in the generated file
Definition undoAppSTSemantic.hpp:51
int length
Number of characters.
Definition undoAppSTSemantic.hpp:53
SymCategory category
Definition undoAppSTSemantic.hpp:54
Result of a classification pass.
Definition undoAppSTSemantic.hpp:61
std::vector< SemanticToken > tokens
Definition undoAppSTSemantic.hpp:62
One parameter of a call, as the signature popup shows it.
Definition undoAppSTSemantic.hpp:354
bool hasDefault
Declared with an initial value, so it may be omitted.
Definition undoAppSTSemantic.hpp:358
std::string name
As declared, empty when the declaration is unnamed.
Definition undoAppSTSemantic.hpp:355
std::string direction
"IN", "OUT" or "IN_OUT"; empty when not a parameter
Definition undoAppSTSemantic.hpp:357
std::string type
Declared type.
Definition undoAppSTSemantic.hpp:356
One run of text in a rendered signature.
Definition undoAppSTSemantic.hpp:396
std::string text
Definition undoAppSTSemantic.hpp:397
bool isParameter
A parameter, which is what gets highlighted.
Definition undoAppSTSemantic.hpp:398
One entry of a completion list.
Definition undoAppSTSemantic.hpp:186
Kind kind
Definition undoAppSTSemantic.hpp:202
std::string declaredIn
Base block name, set when inherited.
Definition undoAppSTSemantic.hpp:208
bool isOverride
Definition undoAppSTSemantic.hpp:206
std::string name
Identifier as spelled in the source.
Definition undoAppSTSemantic.hpp:200
std::vector< std::string > parameterNames
Method parameter names, for signature help.
Definition undoAppSTSemantic.hpp:210
std::vector< std::string > parameterTypes
Method parameter types, for display.
Definition undoAppSTSemantic.hpp:209
bool isAbstract
Definition undoAppSTSemantic.hpp:205
std::string typeText
Declared type, or the return type of a method.
Definition undoAppSTSemantic.hpp:201
bool inherited
Declared by a base block, not by this one.
Definition undoAppSTSemantic.hpp:207
bool isConstant
Definition undoAppSTSemantic.hpp:203
Kind
What kind of thing this is, which is also what its colour means.
Definition undoAppSTSemantic.hpp:189
@ Enumerator
An enumerator of an enum.
@ State
VAR / VAR_TEMP / VAR RETAIN.
@ Parameter
VAR_INPUT / VAR_OUTPUT / VAR_IN_OUT.
@ Block
A FUNCTION_BLOCK instance, or the block's type name.
std::string note
Short remark after the name, such as "given".
Definition undoAppSTSemantic.hpp:212
bool matches(const std::string &prefix) const
True when the pattern occurs in this name, fuzzily and case-insensitively.
std::vector< std::string > parameterDirs
"IN", "OUT" or "IN_OUT", empty when unknown
Definition undoAppSTSemantic.hpp:211
std::vector< int > matchPositions
Indices of name that the last matches call matched, for highlighting.
Definition undoAppSTSemantic.hpp:218
bool isRetain
Definition undoAppSTSemantic.hpp:204