Base¶
This section contains a selection of the definitions declared in the chpl namespace. The entries may not be exhaustive.
-
using chpl::ChplEnvMap = std::unordered_map<std::string, std::string>¶
-
class chpl::CommentID¶
This class represents a unique ID for a comment It is separate from ID because it does not participate in the query system
Public Functions
-
CommentID() = default¶
-
inline CommentID(int index)¶
-
inline int index() const¶
Return the index of the comment id
-
inline void serialize(Serializer &ser) const¶
Public Static Functions
-
static inline CommentID deserialize(Deserializer &des)¶
-
CommentID() = default¶
-
class chpl::Context¶
This Context class stores the compilation-wide context. Another name for this compilation-wide context is program database. It handles unique’d strings and also stores the results of queries (so that they are are memoized). It tracks dependencies of queries in order to update them appropriately when a dependency changes.
Please see Query Framework for more information about how to implement queries and how the query framework functions.
Public Types
Public Functions
-
Context(std::string chplHome = "", std::unordered_map<std::string, std::string> chplEnvOverrides = {})¶
Create a new AST Context. Optionally, specify the value of the CHPL_HOME environment variable, which is used for determining chapel environment variables.
-
~Context()¶
-
const std::string &chplHome() const¶
-
void setDetailedErrorOutput(bool useDetailed)¶
-
llvm::ErrorOr<const ChplEnvMap&> getChplEnv()¶
Run printchplenv, or return a cached result of doing so. To get output, CHPL_HOME must have been provided via the constructor; otherwise, the resulting map will be empty.
-
inline owned<ErrorHandler> installErrorHandler(owned<ErrorHandler> substitute)¶
Consume the currently installed error handler. If ‘substitute’ is not nullptr, the context will use the substitute error handler. Otherwise, the context will revert to using the default error handler.
-
inline ErrorHandler *errorHandler()¶
Get a mutable pointer to the currently installed error handler.
-
const char *uniqueCString(const char *s, size_t len)¶
Get or create a unique string and return it as a C string. If the passed string is NULL, this function will return an empty string.
Unique strings are limited to 2**31 bytes.
The returned string will store len bytes, even if there are interior NULL bytes. It will be NULL terminated either way.
Strings returned by this function will always be aligned to 2 bytes.
The function
UniqueString::get
returns such a string with a wrapper type. It should be preferred for type safety and to reduce redundant checks.
-
const char *uniqueCString(const char *s)¶
Calls uniqueCString with len=strlen(s). This simpler call can be used for C strings that don’t contain zero bytes other than the terminator.
-
const char *uniqueCStringConcatLen(const char *s1, size_t len1, const char *s2, size_t len2, const char *s3 = nullptr, size_t len3 = 0, const char *s4 = nullptr, size_t len4 = 0, const char *s5 = nullptr, size_t len5 = 0, const char *s6 = nullptr, size_t len6 = 0, const char *s7 = nullptr, size_t len7 = 0, const char *s8 = nullptr, size_t len8 = 0, const char *s9 = nullptr, size_t len9 = 0)¶
Get or create a unique string by concatenating up to 9 strings with lengths.
-
const char *uniqueCStringConcat(const char *s1, const char *s2, const char *s3 = nullptr, const char *s4 = nullptr, const char *s5 = nullptr, const char *s6 = nullptr, const char *s7 = nullptr, const char *s8 = nullptr, const char *s9 = nullptr)¶
Get or create a unique string by concatenating up to 9 strings.
-
void markUniqueCString(const char *s)¶
When the context is configured to run with garbage collection enabled, unique strings that are reused need to be marked. This function does that for a C string stored in the map. It will cause program crashes if called on a string that is not the result of one of the uniqueCString calls.
-
template<typename T>
inline void markUnownedPointer(const T *ptr)¶ This function can be called by a mark method to perform checking on pointers and any UniqueStrings that they contain when asserts are enabled.
Pointers available to a mark method should have already been returned by previous queries as owned objects and so markOwnedPointer should have been called on them if they have been reused.
-
template<typename T>
inline void markOwnedPointer(const T *ptr)¶ This function can be called by a mark method to mark UniqueStrings within an owned pointer.
-
template<typename T>
inline void markPointer(const owned<T> &ptr)¶ markPointer can be used to mark a pointer, where it is considered owned if the type is owned.
This overload just calls markOwnedPointer.
-
template<typename T>
inline void markPointer(const T *ptr)¶ markPointer can be used to mark a pointer, where it is considered owned if the type is owned.
This overload just calls markPointer.
-
bool filePathForId(ID id, UniqueString &pathOut, UniqueString &parentSymbolPathOut)¶
Return ‘true’ if the filePathForId was found (which can only happen because setFilePathForModuleID was already called for this ID).
Returns the path by setting ‘pathOut’. Returns the parent symbol path (relevant for ‘module include’ by setting ‘parentSymbolPathOut’.
-
void setFilePathForModuleId(ID moduleID, UniqueString path)¶
Sets the file path for the given module ID. This is suitable to call from a parse query.
-
bool pathHasLibrary(const UniqueString &filePath, UniqueString &pathOut)¶
Return ‘true’ if the given file path can be handled by a library file (experimental).
Returns the library’s path by setting ‘pathOut’.
-
void setLibraryForFilePath(const UniqueString &filePath, const UniqueString &libPath)¶
Sets the library path for the given file path.
-
void advanceToNextRevision(bool prepareToGC)¶
This function increments the current revision number stored in the context. After it is called, the setters below can be used to provide the input at that revision.
If the prepareToGC argument is true, when processing queries in that revision, will prepare to garbage collect UniqueStrings (by marking elements appropriately).
-
inline int numQueriesRunThisRevision() const¶
Returns the number of query bodies executed in this revision.
-
void collectGarbage()¶
This function runs garbage collection. It will collect UniqueStrings if the last call to advanceToNextRevision passed prepareToGC=true.
It is an implementation error to call this function while a query is running.
-
void report(owned<ErrorBase> error)¶
Note an error for the currently running query and report it with the error handler set by setErrorHandler.
If no query is currently running, it just reports the error.
-
void error(Location loc, const char *fmt, ...)¶
Note an error for the currently running query. This is a convenience overload. This version takes in a Location and a printf-style format string.
-
void error(ID id, const char *fmt, ...)¶
Note an error for the currently running query. This is a convenience overload. This version takes in an ID and a printf-style format string. The ID is used to compute a Location using parsing::locateId.
-
void error(const uast::AstNode *ast, const char *fmt, ...)¶
Note an error for the currently running query. This is a convenience overload. This version takes in an AST node and a printf-style format string. The AST node is used to compute a Location by using a parsing::locateAst.
-
void error(const resolution::TypedFnSignature *inFn, const uast::AstNode *ast, const char *fmt, ...)¶
Note an error for the currently running query. This is a convenience overload. This version takes in a TypedFnSignature and an AST node and a printf-style format string. The AST node is used to compute a Location by using a parsing::locateAst. The TypedFnSignature is used to print out instantiation information.
-
void setDebugTraceFlag(const bool enable)¶
Sets the enableDebugTrace flag. This was needed because the context in main gets created before the arguments to the compiler are parsed.
-
void setBreakOnHash(const size_t hashVal)¶
-
inline void setQueryTimingFlag(bool enable)¶
Enables/disables timing each query execution
-
void beginQueryTimingTrace(const std::string &outname)¶
Begin query timing trace, sending the trace to outname
-
void endQueryTimingTrace()¶
End query timing trace, closes out stream
-
template<typename ResultType, typename ...ArgTs>
QueryStatus queryStatus(const ResultType &(*queryFunction)(Context *context, ArgTs...), const std::tuple<ArgTs...> &tupleOfArgs)¶ Returns: 0 if the query was not checked or changed in this revision 1 if the query was checked but not changed in this revision 2 if the query was changed in this revision
This is intended only as a debugging aid.
-
template<typename ResultType, typename ...ArgTs>
bool hasCurrentResultForQuery(const ResultType &(*queryFunction)(Context *context, ArgTs...), const std::tuple<ArgTs...> &tupleOfArgs)¶ Returns ‘true’ if the system already has a result for the passed query in the current revision. This can be useful for certain input queries - e.g. one reading a file that can both have the contents set and can also read the data from the filesystem.
-
template<typename ResultType, typename ...ArgTs>
bool isQueryRunning(const ResultType &(*queryFunction)(Context *context, ArgTs...), const std::tuple<ArgTs...> &tupleOfArgs)¶ Returns ‘true’ if the query in question is currently running. This can be useful for avoiding recursion in certain cases.
Public Static Functions
-
static void defaultReportError(Context *context, const ErrorBase *err)¶
Report the error to standard error output.
-
static size_t lengthForUniqueString(const char *s)¶
For a unique string, return the length of the string when it was created. It will cause program crashes if called on a string that is not the result of one of the uniqueCString calls.
-
class ErrorHandler¶
This ErrorHandler class is used by the context to report errors. It can be subclassed to override its behavior. The default subclass used by the context will print the errors.
-
Context(std::string chplHome = "", std::unordered_map<std::string, std::string> chplEnvOverrides = {})¶
-
class chpl::ErrorMessage : public chpl::IdOrLocation¶
This class represents an error/warning message. The message is saved (in the event it needs to be reported again).
Public Types
Public Functions
-
ErrorMessage(Kind kind, IdOrLocation idOrLoc, std::string message)¶
-
void addDetail(ErrorMessage err)¶
Add an ErrorMessage as detail information to this ErrorMessage.
-
inline bool isEmpty() const¶
Returns true is this error message has no message and no details. Even if the error is empty, it may still be meaningful in the case of e.g., a syntax error (where the location offers useful info).
-
inline const std::string &message() const¶
-
inline const std::vector<ErrorMessage> &details() const¶
-
inline bool operator==(const ErrorMessage &other) const¶
-
inline bool operator!=(const ErrorMessage &other) const¶
-
ErrorMessage(Kind kind, IdOrLocation idOrLoc, std::string message)¶
-
enum chpl::ErrorType¶
Enum representing the different types of errors in Dyno.
Values:
-
enumerator General¶
-
enumerator General¶
-
class chpl::ErrorWriterBase¶
ErrorWriterBase is the main way for error messages to output diagnostic information. It abstracts away writing code to output streams (in fact, some instances of ErrorWriterBase do not write to a stream at all), and provides functionality like printing and underlining code. The way data is formatted when fed to the various printing functions like ErrorWriterBase::heading and ErrorWriterBase::message is specified by specializations of the errordetail::Writer class.
The ErrorWriterBase expects that the ErrorWriterBase::heading function be called first by every error message; this function serves the double purpose of printing out the error heading, as well as setting the error message’s location.
Subclassed by chpl::ErrorWriter
Public Types
-
enum OutputFormat¶
The style of error reporting that the ErrorWriterBase should produce.
Values:
-
enumerator DETAILED¶
Specify that all information about the error should be printed.
-
enumerator BRIEF¶
Specify that only key parts of the error should be printed.
-
enumerator DETAILED¶
Public Functions
-
template<typename LocationType, typename ...Ts>
inline void heading(ErrorBase::Kind kind, ErrorType type, LocationType loc, Ts... ts)¶ Write the error heading, possibly with some color and text decoration. The location given to this function and its overloads is considered the error’s main location.
The variable arguments given to this function are automatically converted to strings.
-
template<typename LocationType, typename ...Ts>
inline void headingVerbatim(ErrorBase::Kind kind, ErrorType type, LocationType loc, Ts... ts)¶ Same as ErrorWriter::heading, but doesn’t tweak the resulting error message to remove punctuation.
-
template<typename ...Ts>
inline void message(Ts... ts)¶ Write a note about the error. Unlike messages, notes are printed even in brief mode. Thus, notes can be used to provide information that is useful “in all cases” (e.g., the location of a duplicate definition).
The variable arguments given to this function are automatically converted to strings.
-
template<typename LocationType, typename ...Ts>
inline void note(LocationType loc, Ts... ts)¶ Write a note about the error. Unlike messages, notes are printed even in brief mode. Thus, notes can be used to provide information that is useful “in all cases” (e.g., the location of a duplicate definition).
The variable arguments given to this function are automatically converted to strings.
-
template<typename LocationType, typename ...Ts>
inline void noteVerbatim(ErrorBase::Kind kind, ErrorType type, LocationType loc, Ts... ts)¶ Same as ErrorWriter::note, but doesn’t tweak the resulting error message to remove punctuation.
-
template<typename LocPlace, typename LocHighlight = const uast::AstNode*>
inline void code(const LocPlace &place, const std::vector<LocHighlight> &toHighlight = {})¶ Prints the lines of code associated with the given location. Additional locations provided via
toHighlight
field are underlined when the code is printed.This function accepts any type for which location can be inferred, for both the main location and the highlights.
-
enum OutputFormat¶
-
class chpl::ErrorWriter : public chpl::ErrorWriterBase¶
Implementation of ErrorWriterBase that prints error output to a stream. This class’ output varies depending on if the error message is printed in brief or detailed mode, as well as if the useColor flag is set.
Public Functions
-
inline ErrorWriter(Context *context, std::ostream &oss, ErrorWriterBase::OutputFormat outputFormat, bool useColor)¶
-
void writeNewline()¶
-
inline ErrorWriter(Context *context, std::ostream &oss, ErrorWriterBase::OutputFormat outputFormat, bool useColor)¶
-
class chpl::ErrorBase¶
Parent class for all errors in Dyno.
The most important part of defining a new error is implementing the ErrorBase::write method; see its documentation for the implementation strategy.
Most sub-classes of ErrorBase should be defined by adding them to error-classes-list
Subclassed by chpl::BasicError
Public Types
Public Functions
-
virtual ~ErrorBase() = default¶
-
std::string message() const¶
Extract the error’s summary error message.
-
ErrorMessage toErrorMessage(Context *context) const¶
Convert the error to an ErrorMessage. This is mostly needed for compatibility reasons, since the production compiler currently knows how to print ErrorMessage, and does it differently from our ErrorBase::write methods.
-
virtual void write(ErrorWriterBase &wr) const = 0¶
Write information about this error to the given writer. See the ErrorWriterBase class for the API available to the error messages.
This method should call methods on the ErrorWriterBase class to provide information about the error. All ErrorBase::write implementations must call ErrorWriterBase::heading to provide a concise description of the error message. After this, ErrorWriterBase::note can be used to print notes, which are always shown to the user. ErrorWriterBase::message along with ErrorWriterBase::code can be used to print additional text and code, respectively, which is only shown when the error is printed in detail.
-
virtual ~ErrorBase() = default¶
-
class chpl::BasicError : public chpl::ErrorBase¶
An error without a specific type, and lacking (typed) additional information about what happened.
Subclassed by chpl::GeneralError
Public Functions
-
virtual void write(ErrorWriterBase &eq) const override¶
Write information about this error to the given writer. See the ErrorWriterBase class for the API available to the error messages.
This method should call methods on the ErrorWriterBase class to provide information about the error. All ErrorBase::write implementations must call ErrorWriterBase::heading to provide a concise description of the error message. After this, ErrorWriterBase::note can be used to print notes, which are always shown to the user. ErrorWriterBase::message along with ErrorWriterBase::code can be used to print additional text and code, respectively, which is only shown when the error is printed in detail.
-
virtual void write(ErrorWriterBase &eq) const override¶
-
class chpl::GeneralError : public chpl::BasicError¶
An error without specific information. Used when no error class has yet been specified for the specific error condition.
Public Static Functions
-
static owned<GeneralError> error(Location loc, std::string msg)¶
-
static owned<GeneralError> error(Location loc, std::string msg)¶
-
class chpl::ID¶
This class represents an ID for an AST node. AST element IDs can be helpful for creating maps with AST elements as keys. All AST nodes have IDs.
Public Functions
-
inline ID(UniqueString symbolPath, int postOrderId, int numChildIds)¶
Construct an ID with a symbol path and postorder traversal number
-
inline UniqueString symbolPath() const¶
Return a path to the ID symbol scope. For example, a function ‘foo’ declared in a module M would have symbolPath M.foo.
Functions, class/record/union/enum declarations, and modules create new ID symbol scopes.
-
inline int postOrderId() const¶
Returns the numbering of this node in a postorder traversal of a symbol’s nodes. When the AST node defines a new ID symbol scope, (as with Function or Module) this will return -1.
-
inline int numContainedChildren() const¶
Return the number of ids contained in this node, not including itself. In the postorder traversal numbering, the ids contained appear before the node.
The node with postorder traversal ID postOrderId() - numChildIds() is the first node contained within this node.
E.g. in this notional AST: Node(LeafA LeafB)
LeafA has id 0 and numContainedIds 0 LeafB has id 1 and numContainedIds 0 Node has id 2 and numContainedIds 2
Note that the number of contained children does not include contained IDs with a different symbol scope. So, for example, a module consisting only of a function declaration would have numContainedChildren() == 0.
-
ID parentSymbolId(Context *context) const¶
Returns a new ID for the parent symbol ID.
if postOrderId is >= 0, returns the id with postOrderId == -1 if postOrderId is -1, returns the id from removing the last ‘.bla’ part from the symbolPath.
If this ID has no parent, returns an empty ID.
The returned ID always has numContainedChildren() of 0 and it cannot be used with contains(). However it is suitable for use in looking up an ID in a map.
-
UniqueString symbolName(Context *context) const¶
If the ID represents a symbol, return the name of that symbol. Otherwise, return the name of the symbol that contains the ID.
-
bool contains(const ID &other) const¶
returns ‘true’ if the AST node with this ID contains the AST node with the other ID, including if they refer to the same AST node.
-
int compare(const ID &other) const¶
compare this ID with another ID result < 0 if this < other result == 0 if this == other result > 0 if this > other
-
inline bool isEmpty() const¶
-
inline size_t hash() const¶
-
void stringify(std::ostream &ss, chpl::StringifyKind stringKind) const¶
-
inline void serialize(Serializer &ser) const¶
Public Static Functions
-
static UniqueString parentSymbolPath(Context *context, UniqueString symbolPath)¶
Given a symbol path, return the parent symbol path. Returns an empty string if the symbol path was empty string.
-
static UniqueString innermostSymbolName(Context *context, UniqueString symbolPath)¶
Given a symbol path, return the name of the innermost symbol
-
static std::vector<std::pair<UniqueString, int>> expandSymbolPath(Context *context, UniqueString symbolPath)¶
Given a symbol path, expand it into a vector of pairs, containing the path component and the repeat number.
-
static ID fromString(Context *context, const char *idStr)¶
The inverse of str() converts a string encoding an ID to an ID
-
static inline ID deserialize(Deserializer &des)¶
-
inline ID(UniqueString symbolPath, int postOrderId, int numChildIds)¶
-
class chpl::Location¶
This class represents a source location.
Public Functions
-
Location() = default¶
-
inline explicit Location(UniqueString path, int firstLine = -1, int firstColumn = -1, int lastLine = -1, int lastColumn = -1)¶
-
inline bool isEmpty() const¶
-
inline UniqueString path() const¶
-
inline int firstLine() const¶
-
inline int firstColumn() const¶
-
inline int lastLine() const¶
-
inline int lastColumn() const¶
-
inline int line() const¶
-
inline size_t hash() const¶
-
void stringify(std::ostream &os, StringifyKind stringifyKind) const¶
-
inline void serialize(Serializer &ser) const¶
-
Location() = default¶
-
class chpl::IdOrLocation¶
Subclassed by chpl::ErrorMessage
-
class chpl::UniqueString¶
This class represents a unique’d string. Unique’d strings allow: fast == and != not worrying about freeing them
Public Functions
-
inline UniqueString()¶
create a UniqueString storing the empty string
-
inline UniqueString(detail::PODUniqueString s)¶
create a UniqueString from a PODUniqueString. this constructor intentionally allows implicit conversion.
-
inline const char *c_str() const¶
Return the null-terminated string. The returned pointer may refer to invalid memory if the UniqueString goes out of scope.
-
inline size_t length() const¶
Return the length of the unique string.
-
inline const char *astr(Context *context) const¶
Return the null-terminated string as a pointer to an entry in Context’s string table. This pointer is safe to use after this UniqueString goes out of scope.
-
inline std::string str() const¶
return a std::string containing the string
-
void stringify(std::ostream &ss, chpl::StringifyKind stringKind) const¶
-
void serialize(Serializer &ser) const¶
-
inline bool isEmpty() const¶
-
inline detail::PODUniqueString podUniqueString() const¶
-
inline bool startsWith(const char *prefix) const¶
Checks to see if the string starts with another string.
Note
will not handle prefix strings with embedded
'\0'
bytes
-
inline bool startsWith(const UniqueString prefix) const¶
Checks to see if the string starts with another string.
Note
will not handle prefix strings with embedded
'\0'
bytes
-
inline bool startsWith(const std::string &prefix) const¶
Checks to see if the string starts with another string.
Note
will not handle prefix strings with embedded
'\0'
bytes
-
inline bool endsWith(const char *suffix) const¶
Checks to see if the string ends with another string.
Note
will not handle prefix strings with embedded
'\0'
bytes
-
inline bool endsWith(const UniqueString suffix) const¶
Checks to see if the string ends with another string.
Note
will not handle prefix strings with embedded
'\0'
bytes
-
inline bool endsWith(const std::string &suffix) const¶
Checks to see if the string ends with another string.
Note
will not handle prefix strings with embedded
'\0'
bytes
-
inline bool operator==(const UniqueString other) const¶
-
inline bool operator==(const char *other) const¶
Checks to see if the string contents match a C string.
Note
will only compare up to the first null byte.
-
inline bool operator==(const std::string &other) const¶
Checks to see if the string contents match a C++ std::string.
Note
will only compare up to the first null byte.
-
inline bool operator!=(const UniqueString other) const¶
-
inline bool operator!=(const char *other) const¶
-
inline bool operator!=(const std::string &other) const¶
-
inline int compare(const UniqueString other) const¶
Returns: -1 if this string is less than the passed string 0 if they are the same 1 if this string is greater
Note
will only compare up to the first null byte.
-
inline int compare(const char *other) const¶
-
inline size_t hash() const¶
-
inline void swap(UniqueString &other)¶
Public Static Functions
-
static inline UniqueString get(Context *context, const char *s)¶
Get or create a unique string for a NULL-terminated C string. If NULL is provided, this function will return the UniqueString representing “”.
-
static inline UniqueString getConcat(Context *context, const char *s1, const char *s2, const char *s3 = nullptr, const char *s4 = nullptr, const char *s5 = nullptr, const char *s6 = nullptr, const char *s7 = nullptr, const char *s8 = nullptr, const char *s9 = nullptr)¶
Get or create a unique string by concatenating up to 9 input C strings. These input strings cannot contain null bytes other than the null terminator.
-
static UniqueString get(Context *context, const char *s, size_t len)¶
Get or create a unique string for a string from a pointer and a length. If the length is 0, this function will return the UniqueString representing “”. The length can be passed to truncate a string. The string can contain zero bytes.
-
static inline UniqueString get(Context *context, const std::string &s)¶
Get or create a unique string for a C++ string.
-
static UniqueString deserialize(Deserializer &des)¶
-
static bool update(UniqueString &keep, UniqueString &addin)¶
-
inline UniqueString()¶
-
template<typename C>
class chpl::Iterable¶ Defines a read-only iterator over elements of a container type C
-
class chpl::Bitmap¶
Bitmap just stores a bunch of bits. It’s more or less like vector<bool> but we have a different type to make using it less confusing.
Public Functions
-
inline bool operator[](size_t i) const¶
Returns the value of bit index i
-
inline void setBit(size_t i, bool value)¶
Set the value of bit index i
-
size_t hash() const¶
-
void stringify(std::ostream &s, StringifyKind stringKind) const¶
-
inline bool operator[](size_t i) const¶
-
template<typename T>
using chpl::owned = std::unique_ptr<T>¶ owned<T> is just a synonym for ‘std::unique_ptr<T>’. It is shorter and uses the Chapel term for it.
-
enum chpl::StringifyKind¶
Values:
-
enumerator DEBUG_SUMMARY¶
-
enumerator DEBUG_DETAIL¶
-
enumerator CHPL_SYNTAX¶
-
enumerator DEBUG_SUMMARY¶
-
class chpl::Serializer¶
Public Types
-
using stringCacheType = std::map<const char*, std::pair<int, size_t>>¶
-
using stringCacheType = std::map<const char*, std::pair<int, size_t>>¶
-
class chpl::Deserializer¶
Public Types
-
using stringCacheType = std::vector<std::pair<size_t, const char*>>¶
Public Functions
-
inline Deserializer(Context *context, std::istream &is, const stringCacheType &cache)¶
-
inline Deserializer(Context *context, std::istream &is, Serializer::stringCacheType serCache)¶
-
inline std::istream &is() const¶
-
inline std::pair<size_t, const char*> &getString(int id)¶
-
using stringCacheType = std::vector<std::pair<size_t, const char*>>¶