WSF
WsfScriptLookup.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#ifndef WSFSCRIPTLOOKUP_HPP
12#define WSFSCRIPTLOOKUP_HPP
13
14#include <map>
15
16#include "Us/UsSymbolTable.hpp"
17#include "UtMemory.hpp"
18#include "UtTextDocument.hpp"
19#include "ViExport.hpp"
20#include "WsfScriptData.hpp"
21
22namespace wizard
23{
24class Project;
25
26// Wraps lookup of script symbols given a location.
28{
29public:
30 explicit WsfScriptLookup(Project* aProjectPtr);
35
37 void SetScenario(Project* aProjectPtr);
39 {
40 // Parse the script up to the given location. This allows lookup of symbols available at the current scope.
41 // This is usually the desired functionality for auto-complete purposes.
43 // Parse the entire function.
44 // Doing this makes it hard to determine the symbols available at some location in the source.
46 // Same as cSTOP_AT_LOCATION, except parse until the end of the statement.
47 // This allows lookup of a variable created in that statement, but will not be able to identify method calls by name.
49 };
50 void SetLocation(UtTextDocumentLocation aLocation, StopLocation aParseStopLocation = cSTOP_AT_LOCATION);
51 void SetStoreErrors(bool aStoreErrors);
52
53
61
62 UpdateResult Update();
63
64 // A symbol map maps the identifier string to the symbol that matches it.
65 typedef std::map<std::string, UsValRef> SymbolMap;
67 UsSymbol* Search(const std::string& aSymbolName);
68 UsType* FindType(const std::string& aName);
69 UsType* GetType(int aTypeId);
70
71 bool AddSymbolsInScope(SymbolMap& aSymbols);
72 bool AddSymbolsFromThis(SymbolMap& aSymbols);
73 bool AddSymbolsFromBuiltins(SymbolMap& aSymbols);
74 bool AddSymbolsFromType(SymbolMap& aSymbols, UsType* aTypePtr);
75 bool HasMethodSymbols();
76 bool AddMethodSymbols(SymbolMap& aSymbols);
77
78 size_t GetInsertPosition() const { return mInsertPosition; }
79 size_t GetReplaceCharacters() const { return mReplaceCharacters; }
80 std::string GetIdentifierLeftOfCursor() const { return mIdentifierLeftOfCursor; }
81
82 WsfScriptData* GetScriptData() const { return mSharedScriptDataPtr; }
83 WsfScriptInfo* GetScriptInfo() const { return mScriptInfoPtr.get(); }
84
85 UtTextDocumentRange GetDefinitionLocation(UsSymbol* aSymPtr);
86
87 static bool
88 IdentifierToken(const char* aBufferBegin, const char* aBufferEnd, size_t aCharOffset, size_t& aBegin, size_t& aEnd);
89
90 static UtTextDocumentRange IdentifierRange(UtTextDocumentLocation aLocation);
91 std::vector<WsfScriptParser::ErrorRecord>* GetErrors();
92 std::string GetFunctionDescription(const std::string& aFunctionName,
93 const UsFunction& aFunc,
94 const std::string& aClassName = std::string());
95 std::string GetScriptValDescription(UsValRef aVal);
96
97 UtTextDocumentLocation GetLocation() const { return mLocation; }
98
99 bool GetCurrentCallInfo(int& aArgNumber,
100 size_t& aOpenParenPos,
101 size_t& aCloseParenPos,
102 std::string& aFunctionName,
103 std::vector<UsFunction>& aFunctionOptions);
104
105private:
106 void FreeParseData();
107
108
109 UpdateResult Parse(UtTextDocumentLocation aLocation);
110
111 void GetText(UtTextDocumentLocation& aScriptStart,
112 size_t aCursorPos,
113 long long aSequenceNumber,
114 std::string& aText,
115 size_t& aFinalScriptStartPos);
116
117 Project* mProjectPtr;
118
119 UtTextDocumentLocation mLocation;
120 StopLocation mParseStopLocation;
121
122 std::string mScriptText;
123 // Sequence number from parse results the last time we computed the script data
124 long long mComputedDataSequenceNumber;
125
126 // Location in document where an insertion is to be made when doing
127 // autocomplete
128 size_t mInsertPosition;
129 // The number of characters to delete when doing autocomplete insertion
130 size_t mReplaceCharacters;
131 // The symbol characters the user has already typed left of the cursor
132 std::string mIdentifierLeftOfCursor;
133 int mSymbolSequenceNumber;
134
135 bool mStoreErrors;
136 WsfScriptData* mSharedScriptDataPtr;
137 std::unique_ptr<WsfScriptInfo> mScriptInfoPtr;
138 std::unique_ptr<WsfScriptDetailObserver> mScriptDetailObserverPtr;
139};
140} // namespace wizard
141
142#endif
#define VI_EXPORT
Definition ViExport.hpp:38
aObjectPtr Update(simTime)
Definition UsSymbolTable.hpp:115
Definition UsSymbolTable.hpp:339
Definition UsSymbolTable.hpp:281
Definition UsSymbolTable.hpp:202
A WSF 'project'. Manages WSF sources files in a WSF project.
Definition Project.hpp:66
Definition WsfScriptData.hpp:177
Definition WsfScriptData.hpp:77
bool AddSymbolsFromThis(SymbolMap &aSymbols)
Definition WsfScriptLookup.cpp:350
bool AddMethodSymbols(SymbolMap &aSymbols)
Definition WsfScriptLookup.cpp:400
UsType * FindType(const std::string &aName)
Definition WsfScriptLookup.cpp:512
size_t GetInsertPosition() const
Definition WsfScriptLookup.hpp:78
WsfScriptLookup & operator=(WsfScriptLookup &&)=default
std::string GetIdentifierLeftOfCursor() const
Definition WsfScriptLookup.hpp:80
void SetScenario(Project *aProjectPtr)
Definition WsfScriptLookup.cpp:255
size_t GetReplaceCharacters() const
Definition WsfScriptLookup.hpp:79
UsSymbolTable * GetLocalScope()
Definition WsfScriptLookup.cpp:337
bool AddSymbolsInScope(SymbolMap &aSymbols)
Definition WsfScriptLookup.cpp:317
WsfScriptInfo * GetScriptInfo() const
Definition WsfScriptLookup.hpp:83
UsType * GetType(int aTypeId)
Definition WsfScriptLookup.cpp:521
WsfScriptLookup(const WsfScriptLookup &)=delete
WsfScriptLookup(Project *aProjectPtr)
Definition WsfScriptLookup.cpp:24
WsfScriptData * GetScriptData() const
Definition WsfScriptLookup.hpp:82
UsSymbol * Search(const std::string &aSymbolName)
Definition WsfScriptLookup.cpp:496
WsfScriptLookup(WsfScriptLookup &&)=default
StopLocation
Definition WsfScriptLookup.hpp:39
@ cSTOP_AT_END_OF_FUNCTION
Definition WsfScriptLookup.hpp:45
@ cSTOP_AT_LOCATION
Definition WsfScriptLookup.hpp:42
@ cSTOP_AT_END_OF_STATEMENT
Definition WsfScriptLookup.hpp:48
bool HasMethodSymbols()
Definition WsfScriptLookup.cpp:377
bool AddSymbolsFromType(SymbolMap &aSymbols, UsType *aTypePtr)
Definition WsfScriptLookup.cpp:368
UtTextDocumentLocation GetLocation() const
Definition WsfScriptLookup.hpp:97
WsfScriptLookup & operator=(const WsfScriptLookup &)=delete
UpdateResult
Definition WsfScriptLookup.hpp:55
@ cNO_SCRIPT
Definition WsfScriptLookup.hpp:56
@ cSUCCESS
Definition WsfScriptLookup.hpp:58
@ cSUCCESS_NO_CHANGES
Definition WsfScriptLookup.hpp:59
@ cFAILURE
Definition WsfScriptLookup.hpp:57
std::map< std::string, UsValRef > SymbolMap
Definition WsfScriptLookup.hpp:65
bool AddSymbolsFromBuiltins(SymbolMap &aSymbols)
Definition WsfScriptLookup.cpp:671
Definition Runner.hpp:22
Definition UsSymbolTable.hpp:415
Copyrights Multiple, All Rights Reserved