WSF
ParseResults.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef PARSERESULTS_HPP
13#define PARSERESULTS_HPP
14
15#include <string>
16#include <vector>
17
18#include "ProxyMerge.hpp"
19#include "UtTextDocument.hpp"
20#include "ViExport.hpp"
21#include "WsfPProxyNode.hpp"
22#include "WsfPProxyRegistry.hpp"
23#include "WsfPProxyType.hpp"
24
25class WsfPProxy;
26class WsfPProxyIndex;
27class WsfParseError;
28class WsfParseIndex;
29class WsfParseNode;
31class WsfParser;
32
33namespace wizard
34{
35class ParseResults;
36class ParseWorker;
37class Project;
38class TextSource;
39class WsfScriptData;
40class WsfScriptTypes;
41
43{
44public:
46 : mProxyHashPtr(nullptr)
47 , mProxy(nullptr)
48 {
49 }
50
55
56 virtual ~ParseResultsProxyData() = default;
57 // Swap ownership of proxy data
58 void SwapProxy(ParseResultsProxyData& aOtherParseResults, bool aSwapProxyPointer);
59
60 void GiveProxy(std::unique_ptr<WsfPProxy> aProxy, std::unique_ptr<ProxyHash> aProxyHashPtr);
61
62 // Given a proxy path, finds other proxy objects which are related; Does not traverse to the base type.
63 // For instance, here 'rdr-1' could be copied across of of these locations, accumulating changes on the way:
64 // platform.P1.sensor.rdr-1
65 // platformType.PT1.sensor.rdr-1
66 // platformType.PT2.sensor.rdr-1
67 // ----------------------
68 // sensorType.RADAR_TYPE
69 //
70 // This routine returns the first 3 paths. The last path is the type which can be found by other means.
71 void FindProxySourcePaths(const WsfPProxyPath& aPath, std::vector<WsfPProxyPath>& aSources);
72
73 UtTextDocumentRange FindDefinitionLocation(const WsfPProxyPath& aPath);
74
78 void FindModificationLocations(const WsfPProxyPath& aPath, std::vector<UtTextDocumentRange>& aLocations);
79
83 void FindDefinitionStartLocations(const WsfPProxyPath& aPath, std::vector<UtTextDocumentRange>& aLocations);
84
89 void FindModificationLocationsExtended(const WsfPProxyPath& aPath, std::vector<UtTextDocumentRange>& aLocations);
90
95 void FindDefinitionStartLocationsExtended(const WsfPProxyPath& aPath, std::vector<UtTextDocumentRange>& aLocations);
96
97 void FindDerivedTypes(const WsfPProxyPath& aTypePath, std::vector<WsfPProxyPath>& aDerivedTypePaths);
98
99 WsfPProxy* Proxy() const { return mProxy.get(); }
102 const std::shared_ptr<WsfPProxyRegistry>& ProxyRegistry() { return mProxy->GetRegistry(); }
104 WsfPProxyIndex* ProxyIndex() { return mProxy ? mProxy->mIndex.get() : nullptr; }
105 WsfPProxyPathMap* ProxyPathMap() { return mProxy ? mProxy->mPathMap.get() : nullptr; }
106 bool isProxyDataOld() const { return !mProxy || !mProxy->mIndex; }
107
108protected:
109 std::unique_ptr<ProxyHash> mProxyHashPtr;
110 std::unique_ptr<WsfPProxy> mProxy;
111};
112
113typedef std::map<UtTextDocument*, WsfParseSourceInclude*> ParseIncludes;
114typedef std::vector<UtStringRef> ParseIncludePaths;
115
118{
119public:
120 explicit ParseResultsTiny(Project* aProjectPtr);
121 ~ParseResultsTiny() override;
122
123 void FreeScriptTypes();
124
125 void TakeResults(ParseResults& aResults);
126
127 bool IncludesFile(TextSource* aSourcePtr) const;
128
129 bool FindBestRelativePath(UtPath aFullPath, std::string& aRelativeIncludePath);
130
131 // The last modification sequence number that was applied before these results were computed
134
135 // note: the WsfParseSourceInclude values should not be accessed.
136 // this map should only be used to determine if a file is included.
139
142};
143
144
147{
148public:
149 friend class ParseWorker;
150
151 explicit ParseResults(Project* aProjectPtr);
152 ~ParseResults() override;
153 void Clear();
154
155 void AssignResults(Project* aProjectPtr,
156 WsfParser* aParserPtr,
157 const WsfParseSourceInclude* aRootInclude,
158 WsfParseNode* aParseTreePtr,
159 WsfParseNode* aLastNodePtr,
160 std::map<UtTextDocument*, WsfParseSourceInclude*>& aFirstIncludes);
161
162 WsfParseSourceInclude* FindSourceData(UtTextDocument* aSourcePtr);
163 bool GetRangeNodes(const UtTextDocumentRange& aRange, std::vector<WsfParseNode*>& aNodes);
164
165 bool FindIncludeAtPoint(UtTextDocument* aSourcePtr,
166 const UtTextRange& aLocation,
167 WsfParseSourceInclude*& aSourceIncludePtr,
168 int& aEntryIndex,
169 TextSource*& aIncludeSourcePtr);
170 WsfParseNode* FindLastParseNode(const UtTextDocumentRange& aPosition);
171
173
174 void FindSubcommands(WsfParseNode* aNodePtr, std::vector<std::string>& aCommands);
175
176 void FindDefinitions(const std::string& aName, const std::string& aDefinitionKind, std::vector<WsfParseNode*>& aNodes);
177
178 void FindReferences(const std::string& aName, const std::string& aDefinitionKind, std::vector<WsfParseNode*>& aNodes);
179
180 void FindDefinitionsOfType(const WsfParseTypePath& aPath, std::vector<WsfParseNode*>& aNodes, bool aAllowNested = false);
181 void FindDefinitionsOfType(const std::string& aDefinitionType,
182 std::vector<WsfParseNode*>& aNodes,
183 bool aAllowNested = false);
184
185 void FindNamedNodes(const std::string& aCategory, const std::string& aName, std::vector<WsfParseNode*>& aNodes);
186 void GetBaseTypes(const WsfParseTypePath& aKind, std::vector<std::string>& aBaseTypeNames, bool aIncludeUserTypes = true);
187
192 void FindNames(const std::string& aNameType, std::vector<std::string>& aNameList);
193
194 void FindIncludes(TextSource* aSourcePtr, std::vector<UtTextDocumentRange>& aIncludes);
195
196 void FindReferencedFiles(std::vector<WsfParseNode*>& aFileReferenceNodes);
197
198 // aEntryTypeRef is of type WsfParseIndex::EntryType
199 WsfPProxyPath FindProxyPathFromLocation(const UtTextDocumentRange& aLocation, int& aEntryTypeRef);
200
202
204
206 {
207 // indicates there is an error (usually about a required type not being found)
208 cERROR_BIT = 1 << 29,
209 // indicates there is a warning (usually about a type not being found)
210 cWARNING_BIT = 1 << 28,
211 // indicates there is some information to be had
212 // this is not set for things like syntax errors with unknown causes
214 // The notification type bitwise-and'd with this is the notification 'kind'
215 cKIND_MASK = 0xffff,
216 // Information about a type definition
218 // Information about an include
220 // Information about a type reference
222 // Error from the parse phase -- unmatched text
224 };
225
227 {
228 bool operator<(FileNotification& aRhs) const { return mRange.GetBegin() < aRhs.mRange.GetBegin(); }
229 FileNotification(const UtTextRange& aRange, unsigned int aNotificationType)
230 : mRange(aRange)
231 , mNotificationType(aNotificationType)
232 {
233 }
234 bool IsValid() const { return mNotificationType != 0; }
236 UtTextRange mRange;
237 unsigned int mNotificationType;
238 };
239 using FileNotificationList = std::vector<FileNotification>;
241 FileNotification GetNotification(const UtTextDocumentLocation& aLocation);
242
243
247 {
260 : mParent(nullptr)
261 , mType(nullptr)
262 , mFlags(0)
263 {
264 }
265 bool IsValid() const { return (mFlags & cTYPE_LOOKUP_FAIL) == 0; }
268 WsfParseType* mType; // may be empty
269
271 };
272
273 bool FindTypeInfo(TypeInformation& aInformation);
274 bool FindUserTypeDocumentation(TypeInformation& aType, std::string& aDocumentation);
275
276 bool TypeInformationFromPosition(const UtTextDocumentLocation& aLocation, TypeInformation& aInformation);
277 bool TypeInformationFromNode(WsfParseNode* aNodePtr, TypeInformation& aInformation);
278 bool FindBaseType(const TypeInformation& aType, TypeInformation& aBaseType);
281 std::vector<WsfParseNode*> FindTypeReferenceNodes(const TypeInformation& aType);
282
284
285 bool TypeKeyMatches(const WsfParseTypePath& aQuery, const WsfParseTypePath& aTest)
286 {
287 if (aQuery.size() >= 2 && aTest.size() >= 2)
288 {
289 if (aQuery[1] == aTest[1])
290 {
291 if (aQuery[0] == "platform_part")
292 {
293 for (auto&& it : mPlatformPartKinds)
294 {
295 if (it == aTest[0])
296 {
297 return true;
298 }
299 }
300 return false;
301 }
302 return aQuery[0] == aTest[0];
303 }
304 }
305 return false;
306 }
307
308
309 WsfParser* parser() const { return mParserPtr; }
310 const std::vector<WsfParseError*>& errors() const { return mErrors; }
312 WsfParseNode* lastNode() const { return mLastNodePtr; }
314
317 std::vector<WsfParseNode*> mFileTransitionNodes;
318
319protected:
321
322 std::vector<WsfParseError*> mErrors;
323
325
329
331
332 std::vector<UtStringRef> mPlatformPartKinds;
333
334 void IndexNames(); // WIZARD_TODO
335
336 void FindSubcommandsP(WsfParseRule* aReaderPtr, std::vector<std::string>& aCommands);
337
338 typedef std::map<UtTextDocument*, FileNotificationList> FileNotificationMap;
340 std::set<WsfParseTypePath> mTypeNames;
342};
343} // namespace wizard
344
345#endif
#define VI_EXPORT
Definition ViExport.hpp:38
std::map< WsfPProxyPath, WsfPProxyPathSet > WsfPProxyPathMap
Definition WsfPProxyPath.hpp:180
std::vector< UtStringRef > WsfParseTypePath
Definition WsfParseTypePath.hpp:21
Definition WsfPProxyIndex.hpp:96
Definition WsfPProxyNode.hpp:60
static WsfPProxyNode FromProxy(WsfPProxy *aProxy)
Definition WsfPProxyNode.cpp:69
Represents a path or unique key to a value in the proxy.
Definition WsfPProxyPath.hpp:64
Definition WsfPProxyStructValue.hpp:23
Definition WsfPProxy.hpp:32
Definition WsfParser.hpp:270
Definition WsfParseIndex.hpp:40
Definition WsfParseNode.hpp:61
Definition WsfParseRule.hpp:131
Definition WsfParseSourceInclude.hpp:31
Definition WsfParseType.hpp:40
Definition WsfParser.hpp:36
UtTextDocumentRange FindDefinitionLocation(const WsfPProxyPath &aPath)
Definition ParseResults.cpp:1489
void SwapProxy(ParseResultsProxyData &aOtherParseResults, bool aSwapProxyPointer)
Definition ParseResults.cpp:1414
void FindProxySourcePaths(const WsfPProxyPath &aPath, std::vector< WsfPProxyPath > &aSources)
Definition ParseResults.cpp:1436
bool isProxyDataOld() const
Definition ParseResults.hpp:106
void FindModificationLocations(const WsfPProxyPath &aPath, std::vector< UtTextDocumentRange > &aLocations)
Definition ParseResults.cpp:1517
void FindDerivedTypes(const WsfPProxyPath &aTypePath, std::vector< WsfPProxyPath > &aDerivedTypePaths)
Definition ParseResults.cpp:1556
void FindDefinitionStartLocations(const WsfPProxyPath &aPath, std::vector< UtTextDocumentRange > &aLocations)
Definition ParseResults.cpp:1500
ParseResultsProxyData(const ParseResultsProxyData &)=delete
virtual ~ParseResultsProxyData()=default
ParseResultsProxyData & operator=(ParseResultsProxyData &&)=default
void GiveProxy(std::unique_ptr< WsfPProxy > aProxy, std::unique_ptr< ProxyHash > aProxyHashPtr)
Definition ParseResults.cpp:1388
ProxyHash * GetProxyHash()
Definition ParseResults.hpp:103
WsfPProxyStructValue ProxyRoot() const
Definition ParseResults.hpp:101
ParseResultsProxyData()
Definition ParseResults.hpp:45
std::unique_ptr< ProxyHash > mProxyHashPtr
Definition ParseResults.hpp:109
ParseResultsProxyData & operator=(const ParseResultsProxyData &)=delete
void FindDefinitionStartLocationsExtended(const WsfPProxyPath &aPath, std::vector< UtTextDocumentRange > &aLocations)
Definition ParseResults.cpp:1545
WsfPProxyIndex * ProxyIndex()
Definition ParseResults.hpp:104
std::unique_ptr< WsfPProxy > mProxy
Definition ParseResults.hpp:110
WsfPProxyNode ProxyRootNode() const
Definition ParseResults.hpp:100
const std::shared_ptr< WsfPProxyRegistry > & ProxyRegistry()
Definition ParseResults.hpp:102
WsfPProxy * Proxy() const
Definition ParseResults.hpp:99
WsfPProxyPathMap * ProxyPathMap()
Definition ParseResults.hpp:105
void FindModificationLocationsExtended(const WsfPProxyPath &aPath, std::vector< UtTextDocumentRange > &aLocations)
Definition ParseResults.cpp:1534
ParseResultsProxyData(ParseResultsProxyData &&)=default
Project * mProjectPtr
Definition ParseResults.hpp:133
bool IncludesFile(TextSource *aSourcePtr) const
Definition ParseResults.cpp:1347
bool FindBestRelativePath(UtPath aFullPath, std::string &aRelativeIncludePath)
Definition ParseResults.cpp:1352
void TakeResults(ParseResults &aResults)
Copies a minimal subset of results from aResults.
Definition ParseResults.cpp:1320
ParseIncludes mFirstIncludes
Definition ParseResults.hpp:137
WsfScriptTypes * mScriptTypesPtr
Definition ParseResults.hpp:141
ParseIncludePaths mIncludePaths
Definition ParseResults.hpp:138
ParseResultsTiny(Project *aProjectPtr)
Definition ParseResults.cpp:1301
WsfScriptData * mScriptDataPtr
Definition ParseResults.hpp:140
void FreeScriptTypes()
Definition ParseResults.cpp:1372
long long mSequenceNumber
Definition ParseResults.hpp:132
Provides access to the results of parsing the WSF inputs.
Definition ParseResults.hpp:147
bool TypeKeyMatches(const WsfParseTypePath &aQuery, const WsfParseTypePath &aTest)
Definition ParseResults.hpp:285
void FindDefinitions(const std::string &aName, const std::string &aDefinitionKind, std::vector< WsfParseNode * > &aNodes)
Definition ParseResults.cpp:181
WsfParseNode * FindTypeDefinitionNode(const TypeInformation &aType)
Searches for the parse node which defined aType.
Definition ParseResults.cpp:1192
FileNotificationMap mFileNotifications
Definition ParseResults.hpp:339
bool FindTypeInfo(TypeInformation &aInformation)
Fills aInformation given the type key. Returns 'true' if the type information was found successfully.
Definition ParseResults.cpp:829
std::set< WsfParseTypePath > mTypeNames
Definition ParseResults.hpp:340
WsfParseNode * mLastNodePtr
Definition ParseResults.hpp:328
void IndexNames()
Definition ParseResults.cpp:740
std::map< UtTextDocument *, FileNotificationList > FileNotificationMap
Definition ParseResults.hpp:338
void Clear()
Definition ParseResults.cpp:56
WsfParseNode * lastNode() const
Definition ParseResults.hpp:312
WsfParseNode * parseTree() const
Definition ParseResults.hpp:311
bool mTypeNamesIndexed
Definition ParseResults.hpp:341
void FindIncludes(TextSource *aSourcePtr, std::vector< UtTextDocumentRange > &aIncludes)
Definition ParseResults.cpp:388
bool FindBaseType(const TypeInformation &aType, TypeInformation &aBaseType)
Searches for the type information of aType's base type.
Definition ParseResults.cpp:1039
void FindReferences(const std::string &aName, const std::string &aDefinitionKind, std::vector< WsfParseNode * > &aNodes)
Definition ParseResults.cpp:205
std::vector< WsfParseNode * > FindTypeReferenceNodes(const TypeInformation &aType)
Definition ParseResults.cpp:1146
void FindSubcommands(WsfParseNode *aNodePtr, std::vector< std::string > &aCommands)
bool TypeInformationFromNode(WsfParseNode *aNodePtr, TypeInformation &aInformation)
Definition ParseResults.cpp:963
WsfParseNode * mParseTreePtr
Definition ParseResults.hpp:324
void FindNamedNodes(const std::string &aCategory, const std::string &aName, std::vector< WsfParseNode * > &aNodes)
Definition ParseResults.cpp:290
bool FindUserTypeDocumentation(TypeInformation &aType, std::string &aDocumentation)
Definition ParseResults.cpp:915
WsfParseNode * FindLastParseNode(const UtTextDocumentRange &aPosition)
Definition ParseResults.cpp:142
WsfParser * mParserPtr
Definition ParseResults.hpp:320
std::vector< WsfParseError * > mErrors
Definition ParseResults.hpp:322
WsfParseNode * FindBlock(WsfParseNode *aNodePtr)
Definition ParseResults.cpp:152
std::vector< FileNotification > FileNotificationList
Definition ParseResults.hpp:239
static WsfPProxyNode FindProxyReference(WsfPProxyNode aContext, WsfParseTypePath aPath)
Definition ParseResults.cpp:1248
bool FindIncludeAtPoint(UtTextDocument *aSourcePtr, const UtTextRange &aLocation, WsfParseSourceInclude *&aSourceIncludePtr, int &aEntryIndex, TextSource *&aIncludeSourcePtr)
Definition ParseResults.cpp:100
void FindSubcommandsP(WsfParseRule *aReaderPtr, std::vector< std::string > &aCommands)
WsfParseType * FindCurrentType(WsfParseNode *aNodePtr)
Return the type lookup for the type located at aNodePtr.
Definition ParseResults.cpp:759
void AssignResults(Project *aProjectPtr, WsfParser *aParserPtr, const WsfParseSourceInclude *aRootInclude, WsfParseNode *aParseTreePtr, WsfParseNode *aLastNodePtr, std::map< UtTextDocument *, WsfParseSourceInclude * > &aFirstIncludes)
Definition ParseResults.cpp:76
WsfParseIndex * GetParseIndex()
Definition ParseResults.cpp:1291
WsfParser * parser() const
Definition ParseResults.hpp:309
friend class ParseWorker
Definition ParseResults.hpp:149
void GetBaseTypes(const WsfParseTypePath &aKind, std::vector< std::string > &aBaseTypeNames, bool aIncludeUserTypes=true)
Definition ParseResults.cpp:308
const WsfParseSourceInclude * mRootInclude
Definition ParseResults.hpp:330
void FindNames(const std::string &aNameType, std::vector< std::string > &aNameList)
Definition ParseResults.cpp:359
FileNotificationList * GetFileNotifications(TextSource *aSourcePtr)
Definition ParseResults.cpp:432
WsfParseNode * FindCreateTypeNode(const TypeInformation &aType)
Searches for the parse node that created the specified type.
Definition ParseResults.cpp:1067
WsfParseSourceInclude * FindSourceData(UtTextDocument *aSourcePtr)
Definition ParseResults.cpp:128
std::vector< WsfParseNode * > mFileTransitionNodes
Definition ParseResults.hpp:317
WsfPProxyPath FindProxyPathFromLocation(const UtTextDocumentRange &aLocation, int &aEntryTypeRef)
Definition ParseResults.cpp:1223
ParseResults(Project *aProjectPtr)
Definition ParseResults.cpp:36
void FindReferencedFiles(std::vector< WsfParseNode * > &aFileReferenceNodes)
Definition ParseResults.cpp:419
bool GetRangeNodes(const UtTextDocumentRange &aRange, std::vector< WsfParseNode * > &aNodes)
Definition ParseResults.cpp:646
const std::vector< WsfParseError * > & errors() const
Definition ParseResults.hpp:310
FileNotificationType
Definition ParseResults.hpp:206
@ cWARNING_BIT
Definition ParseResults.hpp:210
@ cREFERENCE_KIND
Definition ParseResults.hpp:221
@ cSYNTAX_ERROR_KIND
Definition ParseResults.hpp:223
@ cERROR_BIT
Definition ParseResults.hpp:208
@ cINFORMATION_BIT
Definition ParseResults.hpp:213
@ cTYPE_KIND
Definition ParseResults.hpp:217
@ cINCLUDE_KIND
Definition ParseResults.hpp:219
@ cKIND_MASK
Definition ParseResults.hpp:215
std::vector< UtStringRef > mPlatformPartKinds
Definition ParseResults.hpp:332
void FindDefinitionsOfType(const WsfParseTypePath &aPath, std::vector< WsfParseNode * > &aNodes, bool aAllowNested=false)
Definition ParseResults.cpp:255
bool TypeInformationFromPosition(const UtTextDocumentLocation &aLocation, TypeInformation &aInformation)
Definition ParseResults.cpp:818
const WsfParseSourceInclude * rootInclude() const
Definition ParseResults.hpp:313
FileNotification GetNotification(const UtTextDocumentLocation &aLocation)
Definition ParseResults.cpp:620
Definition ParseWorker.hpp:50
A WSF 'project'. Manages WSF sources files in a WSF project.
Definition Project.hpp:66
Definition ProxyMerge.hpp:56
Definition TextSource.hpp:48
Definition WsfScriptData.hpp:177
Definition WsfScriptData.hpp:213
Definition Runner.hpp:22
std::map< UtTextDocument *, WsfParseSourceInclude * > ParseIncludes
Definition ParseResults.hpp:113
std::vector< UtStringRef > ParseIncludePaths
Definition ParseResults.hpp:114
Definition ParseResults.hpp:227
FileNotification(const UtTextRange &aRange, unsigned int aNotificationType)
Definition ParseResults.hpp:229
UtTextRange mRange
Definition ParseResults.hpp:236
unsigned int mNotificationType
Definition ParseResults.hpp:237
int GetNotificationKind() const
Definition ParseResults.hpp:235
bool operator<(FileNotification &aRhs) const
Definition ParseResults.hpp:228
bool IsValid() const
Definition ParseResults.hpp:234
Definition ParseResults.hpp:247
bool IsValid() const
Definition ParseResults.hpp:265
WsfParseTypePath mTypeKey
Definition ParseResults.hpp:267
WsfParseType * mType
Definition ParseResults.hpp:268
WsfParseType * mParent
Definition ParseResults.hpp:266
int mFlags
Definition ParseResults.hpp:270
TypeInformation()
Definition ParseResults.hpp:259
TypeFlags
Definition ParseResults.hpp:249
@ cBASIC_TYPE
Is it a built-in type like WSF_PLATFORM.
Definition ParseResults.hpp:251
@ cLAZY_TYPE
Is it a 'lazy' type which has no entry in the symbol table – like antenna patterns.
Definition ParseResults.hpp:253
@ cTYPE_LOOKUP_FAIL
Did the parser fail to find the type?
Definition ParseResults.hpp:255
@ cDUPLICATE_NAME
Is the name invalid because of duplication.
Definition ParseResults.hpp:257
Copyrights Multiple, All Rights Reserved