diff --git a/include/cqasm-annotations.hpp b/include/cqasm-annotations.hpp index 5015dc337..850b6f42c 100644 --- a/include/cqasm-annotations.hpp +++ b/include/cqasm-annotations.hpp @@ -15,48 +15,72 @@ namespace cqasm::annotations { /** * Source location annotation object, containing source file line numbers etc. */ -class SourceLocation { -public: +struct SourceLocation { /** - * The name of the source file. + * An index within a source location. + * An index is defined by a line and a column. */ - std::optional file_name; + struct Index { + std::uint32_t line = 0; + std::uint32_t column = 0; - /** - * The first line of the range, or 0 if unknown. - */ - std::uint32_t first_line; + bool operator==(const Index &other) const = default; + auto operator<=>(const Index &other) const = default; + }; /** - * The first column of the range, or 0 if unknown. + * A range within a source location. + * A range is defined by a first and a last index. */ - std::uint32_t first_column; + struct Range { + Index first; + Index last; + + Range() = default; + Range(const Index &f, const Index &l); + Range(const Range &other) = default; + Range(Range &&other) noexcept = default; + Range& operator=(const Range &other) = default; + Range& operator=(Range &&other) noexcept = default; + + bool operator==(const Range &other) const = default; + auto operator<=>(const Range &other) const = default; + }; /** - * The last line of the range, or 0 if unknown. + * The name of the source file. */ - std::uint32_t last_line; + std::optional file_name; /** - * The last column of the range, or 0 if unknown. + * The source location range. */ - std::uint32_t last_column; + Range range; /** * Constructs a source location object. */ - explicit SourceLocation( - const std::optional &file_name, - std::uint32_t first_line = 0, - std::uint32_t first_column = 0, - std::uint32_t last_line = 0, - std::uint32_t last_column = 0 - ); + SourceLocation() = default; + explicit SourceLocation(const std::optional &file_name, const Range &range); + SourceLocation(const SourceLocation &other) = default; + SourceLocation(SourceLocation &&other) noexcept = default; + SourceLocation& operator=(const SourceLocation &other) = default; + SourceLocation& operator=(SourceLocation &&other) noexcept = default; + + bool operator==(const SourceLocation &other) const = default; + // Some versions of clang still do not implement operator<=> for std::optional + // So they will complain if we try to define a default operator<=> on a struct that contains a std::optional + // This implementation just does not check the optional file_name + // Instead, it just assumes that, when comparing source locations, the file_name will be the same + // This will always be the case if we are just parsing or analyzing a file or a string + auto operator<=>(const SourceLocation &other) const { + return range <=> other.range; + } /** * Expands the location range to contain the given location in the source file. */ - void expand_to_include(std::uint32_t line, std::uint32_t column = 1); + void expand_to_include(const Index &last); }; /** diff --git a/include/cqasm-error.hpp b/include/cqasm-error.hpp index cb4dfe853..6d6b26cd5 100644 --- a/include/cqasm-error.hpp +++ b/include/cqasm-error.hpp @@ -65,10 +65,7 @@ class Error : public std::runtime_error { Error( const std::string &message, const std::optional &file_name, - std::uint32_t first_line, - std::uint32_t first_column, - std::uint32_t last_line, - std::uint32_t last_column); + const annotations::SourceLocation::Range &range); /** * Sets the context of this error to the SourceLocation annotation of the given node, diff --git a/include/cqasm-overload.hpp b/include/cqasm-overload.hpp index 2ff0488d1..16d7ee811 100644 --- a/include/cqasm-overload.hpp +++ b/include/cqasm-overload.hpp @@ -19,6 +19,11 @@ namespace cqasm::overload { struct NameResolutionFailure : public std::exception {}; struct OverloadResolutionFailure : public std::exception {}; + +//----------// +// Overload // +//----------// + /** * Represents a possible overload for the parameter types of a function, gate, or error model. * T is some tag type identifying the overload. @@ -60,6 +65,11 @@ class Overload { } }; + +//------------------// +// OverloadResolver // +//------------------// + /** * Represents a set of possible overloads for the parameter types of a function, gate, or error model. * T is some tag type identifying the overload. @@ -116,6 +126,11 @@ class OverloadResolver { } }; + +//----------------------// +// OverloadNameResolver // +//----------------------// + /** * Table of overloaded callables with case-sensitive identifier matching. * T is the tag type of the callable/overload pair. @@ -141,8 +156,7 @@ class OverloadedNameResolver { * so more specific overloads should always be added last. */ virtual void add_overload(const std::string &name, const T &tag, const Types ¶m_types) { - auto entry = table.find(name); - if (entry == table.end()) { + if (auto entry = table.find(name); entry == table.end()) { auto resolver = OverloadResolver(); resolver.add_overload(tag, param_types); table.insert(std::pair>(name, std::move(resolver))); @@ -159,12 +173,10 @@ class OverloadedNameResolver { * the appropriately promoted vector of value pointers. */ [[nodiscard]] virtual std::pair resolve(const std::string &name, const Values &args) { - auto entry = table.find(name); - if (entry == table.end()) { - throw NameResolutionFailure{}; - } else { + if (auto entry = table.find(name); entry != table.end()) { return entry->second.resolve(args); } + throw NameResolutionFailure{}; } }; diff --git a/include/cqasm-tree.hpp b/include/cqasm-tree.hpp index 982b17bb0..e2b9b9686 100644 --- a/include/cqasm-tree.hpp +++ b/include/cqasm-tree.hpp @@ -7,12 +7,11 @@ #include "tree-annotatable.hpp" #include "tree-base.hpp" -namespace cqasm { /** * Namespace for wrapping tree-gen's support library. */ -namespace tree { +namespace cqasm::tree { using signed_size_t = ::tree::signed_size_t; @@ -45,5 +44,4 @@ One make(Args... args) { return One(std::make_shared(args...)); } -} // namespace tree -} // namespace cqasm +} // namespace cqasm::tree diff --git a/include/v10/qasm_new_to_old.hpp b/include/v10/qasm_new_to_old.hpp index c9c1006d5..b33c9b799 100644 --- a/include/v10/qasm_new_to_old.hpp +++ b/include/v10/qasm_new_to_old.hpp @@ -335,7 +335,7 @@ static void handle_parse_result(QasmRepresentation &qasm, cq1x::parser::ParseRes if (!subcircuit->name.empty()) { int line_number = 0; if (auto loc = subcircuit->get_annotation_ptr()) { - line_number = static_cast(loc->first_line); + line_number = static_cast(loc->range.first.line); } auto subcircuit_sp{ std::make_shared( subcircuit->name.c_str(), @@ -368,7 +368,7 @@ static void handle_parse_result(QasmRepresentation &qasm, cq1x::parser::ParseRes if (!opclus) { int line_number = 0; if (auto loc = instruction->get_annotation_ptr()) { - line_number = static_cast(loc->first_line); + line_number = static_cast(loc->range.first.line); } opclus = std::make_shared(op, line_number); } else { diff --git a/include/v1x/cqasm-analyzer-helper.hpp b/include/v1x/cqasm-analyzer-helper.hpp new file mode 100644 index 000000000..cf3863821 --- /dev/null +++ b/include/v1x/cqasm-analyzer-helper.hpp @@ -0,0 +1,287 @@ +#pragma once + +#include "v1x/cqasm-analysis-result.hpp" +#include "v1x/cqasm-analyzer.hpp" +#include "v1x/cqasm-scope.hpp" + +#include +#include +#include // pair + + +namespace cqasm::v1x::analyzer { + +/** + * Helper class for analyzing a single AST. + * This contains the stateful information that Analyzer can't have (to allow Analyzer to be reused). + */ +class AnalyzerHelper { +public: + /** + * The analyzer associated with this helper. + */ + const Analyzer &analyzer; + + /** + * The analysis result being constructed. + */ + AnalysisResult result; + + /** + * Scope stack. back() is the global scope, front() is the current scope. + */ + std::list scope_stack; + + /** + * List of all goto instructions in the program, for name resolution when all other analysis completes. + */ + std::list, std::string>> gotos; + + /** + * Analyzes the given AST using the given analyzer. + */ + AnalyzerHelper(const Analyzer &analyzer, const ast::Program &ast); + + /** + * Parses the version tag. + * Any semantic errors encountered are pushed into the result error vector. + */ + void analyze_version(const ast::Version &ast); + + /** + * Checks the qubits statement and updates the scope accordingly. + * Any semantic errors encountered are pushed into the result error vector. + */ + void analyze_qubits(const ast::Expression &count); + + /** + * Returns a reference to the subcircuit that's currently being built. + * If there is no subcircuit yet, a default one is created, using the source location annotation on the source node. + */ + tree::Maybe get_current_subcircuit(const tree::Annotatable &source); + + /** + * Returns a reference to the current scope. + */ + Scope &get_current_scope(); + + /** + * Returns a reference to the global scope. + */ + Scope &get_global_scope(); + + /** + * Returns a reference to the block that's currently being built (1.2+). + */ + tree::Maybe get_current_block(const tree::Annotatable &source); + + /** + * Adds an analyzed statement to the current block (1.2+). + */ + void add_to_current_block(const tree::Maybe &stmt); + + /** + * Analyzes the given statement list, + * adding the analyzed statements to the current subcircuit (API 1.0/1.1) or block (API 1.2+). + */ + void analyze_statements(const ast::StatementList &statements); + + /** + * Analyzes a statement list corresponding to a structured control-flow subblock (1.2+). + * Handles the requisite scoping, then defers to analyze_statements(). + */ + tree::Maybe analyze_subblock(const ast::StatementList &statements, bool is_loop); + + /** + * Analyzes the given bundle and, if valid, adds it to the current subcircuit using API version 1.0/1.1. + * If an error occurs, the message is added to the result error vector, and nothing is added to the subcircuit. + */ + void analyze_bundle(const ast::Bundle &bundle); + + /** + * Analyzes the given bundle and, if valid, adds it to the current scope/block using API version 1.2+. + * If an error occurs, the message is added to the result error vector, and nothing is added to the block. + */ + void analyze_bundle_ext(const ast::Bundle &bundle); + + /** + * Analyzes the given instruction. + * If an error occurs, the message is added to the result error vector, and an empty Maybe is returned. + */ + tree::Maybe analyze_instruction(const ast::Instruction &insn); + + /** + * Analyzes the given cQASM 1.2+ set instruction. + * If an error occurs, the message is added to the result error vector, and an empty Maybe is returned. + */ + tree::Maybe analyze_set_instruction(const ast::Instruction &insn); + + /** + * Analyzes the given two operands as lhs and rhs of a set instruction. + * Used for the actual set instruction as well as the assignments in the header of a C-style for loop. + */ + tree::Maybe analyze_set_instruction_operands( + const ast::Expression &lhs_expr, + const ast::Expression &rhs_expr + ); + + /** + * Analyzes the given cQASM 1.2+ goto instruction. + * If an error occurs, the message is added to the result error vector, and an empty Maybe is returned. + */ + tree::Maybe analyze_goto_instruction(const ast::Instruction &insn); + + /** + * Analyzes the error model meta-instruction and, if valid, adds it to the analysis result. + * If an error occurs, the message is added to the result error vector, and nothing is added. + */ + void analyze_error_model(const ast::Instruction &insn); + + /** + * Analyzes the given mapping and, if valid, adds it to the current scope. + * If an error occurs, the message is added to the result error vector, and nothing is added to the scope. + */ + void analyze_mapping(const ast::Mapping &mapping); + + /** + * Analyzes the given declaration of one or more variables and, if valid, adds them to the current scope. + * If an error occurs, the message is added to the result error vector, and nothing is added to the scope. + */ + void analyze_variables(const ast::Variables &variables); + + /** + * Analyzes the given subcircuit header and, if valid, adds it to the subcircuit list. + * If an error occurs, the message is added to the result error vector, and nothing is added to the result. + */ + void analyze_subcircuit(const ast::Subcircuit &subcircuit); + + /** + * Analyzes the given structured control-flow statement and, + * if valid, adds it to the current scope/block using API version 1.2+. + * If an error occurs, the message is added to the result error vector, and nothing is added to the block. + */ + void analyze_structured(const ast::Structured &structured); + + /** + * Analyzes the given if-else chain. + * Only intended for use as a helper function within analyze_structured(). + */ + tree::Maybe analyze_if_else(const ast::IfElse &if_else); + + /** + * Analyzes the given C-style for loop. + * Only intended for use as a helper function within analyze_structured(). + */ + tree::Maybe analyze_for_loop(const ast::ForLoop &for_loop); + + /** + * Analyzes the given static for loop. + * Only intended for use as a helper function within analyze_structured(). + */ + tree::Maybe analyze_foreach_loop(const ast::ForeachLoop &foreach_loop); + + /** + * Analyzes the given while loop. + * Only intended for use as a helper function within analyze_structured(). + */ + tree::Maybe analyze_while_loop(const ast::WhileLoop &while_loop); + + /** + * Analyzes the given repeat-until loop. + * Only intended for use as a helper function within analyze_structured(). + */ + tree::Maybe analyze_repeat_until_loop(const ast::RepeatUntilLoop &repeat_until_loop); + + /** + * Analyzes the given list of annotations. + * Any errors found result in the annotation being skipped and an error being appended to the result error vector. + */ + tree::Any analyze_annotations( + const tree::Any &annotations); + + /** + * Parses any kind of expression. + * Always returns a filled value or throws an exception. + */ + values::Value analyze_expression(const ast::Expression &expression); + + /** + * Shorthand for parsing an expression and promoting it to the given type, + * constructed in-place with the type_args parameter pack. + * Returns empty when the cast fails. + */ + template + values::Value analyze_as(const ast::Expression &expression, TypeArgs... type_args) { + return values::promote(analyze_expression(expression), tree::make(type_args...)); + } + + /** + * Shorthand for parsing an expression to a constant integer. + */ + primitives::Int analyze_as_const_int(const ast::Expression &expression); + + /** + * Parses a matrix. Always returns a filled value or throws an exception. + */ + values::Value analyze_matrix(const ast::MatrixLiteral &matrix_lit); + + /** + * Helper for parsing a matrix. + * Highly templated to avoid repeating the same code for different kinds of matrices, + * but bear in mind that the template parameters are codependent. + * Returns empty on failure. + */ + template + values::Value analyze_matrix_helper( + size_t num_rows, size_t num_cols, + const std::vector &vals + ) { + auto matrix = MatLit(num_rows, num_cols); + for (size_t row = 0; row < num_rows; row++) { + for (size_t col = 0; col < num_cols; col++) { + auto val = values::promote(vals[row * num_cols + col], tree::make()); + if (val.empty()) { + return {}; + } else { + auto val_real = val.template as(); + if (val_real.empty()) { + return {}; + } else { + matrix.at(row + 1, col + 1) = val_real->value; + } + } + } + } + return tree::make(matrix); + } + + /** + * Parses an index operator. Always returns a filled value or throws an + * error. + */ + values::Value analyze_index(const ast::Index &index); + + /** + * Parses an index list. + */ + tree::Many analyze_index_list( + const ast::IndexList &index_list, size_t size); + + /** + * Parses a function. Always returns a filled value or throws an exception. + */ + values::Value analyze_function( + const ast::Identifier &name, + const ast::ExpressionList &args); + + /** + * Parses an operator. Always returns a filled value or throws an exception. + */ + values::Value analyze_operator( + const std::string &name, + const tree::One &a, + const tree::One &b = tree::One(), + const tree::One &c = tree::One()); +}; + +} // namespace cqasm::v1x::analyzer diff --git a/include/v1x/cqasm-functions.hpp b/include/v1x/cqasm-functions.hpp index b5889b033..d6957260e 100644 --- a/include/v1x/cqasm-functions.hpp +++ b/include/v1x/cqasm-functions.hpp @@ -39,7 +39,7 @@ static std::int64_t div_floor(std::int64_t a, std::int64_t b) { return res - corr; } -/* +/** * Function with constant parameters */ template @@ -48,7 +48,7 @@ struct f_cp { using param_type = ParamType; }; -/* +/** * Unary function with constant parameter */ template @@ -60,7 +60,7 @@ struct uf_cp : public f_cp { } }; -/* +/** * Binary function with constant parameters */ template @@ -73,7 +73,7 @@ struct bf_cp : public f_cp { } }; -/* +/** * Ternary function with constant parameters */ template diff --git a/include/v1x/cqasm-instruction.hpp b/include/v1x/cqasm-instruction.hpp index c2bf6cc16..2f912b43f 100644 --- a/include/v1x/cqasm-instruction.hpp +++ b/include/v1x/cqasm-instruction.hpp @@ -9,6 +9,10 @@ #include "cqasm-types.hpp" #include "cqasm-values.hpp" +#include +#include + + namespace cqasm::v1x { /** @@ -18,33 +22,29 @@ namespace cqasm::v1x { namespace instruction { /** - * Representation of an available instruction (also known as gate) in the - * instruction set, without parameters bound to it (note that libqasm cannot - * match instructions based on which qubits are used; you'll need to do that on - * your own). + * Representation of an available instruction (also known as gate) in the instruction set, + * without parameters bound to it + * (note that libqasm cannot match instructions based on which qubits are used; + * you'll need to do that on your own). * - * A number of these can be registered into libqasm by the program or library - * using it through \ref cqasm::analyzer::Analyzer::register_instruction(const instruction::Instruction&) - * "register_instruction()", to inform libqasm of the supported instruction set. - * For each instruction, libqasm needs to know its name, which parameters it - * expects, and a few extra flags in order to be able to resolve the - * instruction and check for errors in the cQASM file. The resolved instruction - * type is part of the cqasm::semantic::Instruction node present in the - * semantic tree returned through the parse result structure. + * A number of these can be registered into libqasm by the program or library using it through + * \ref cqasm::analyzer::Analyzer::register_instruction(const instruction::Instruction&) "register_instruction()", + * to inform libqasm of the supported instruction set. + * For each instruction, libqasm needs to know its name, which parameters it expects, + * and a few extra flags in order to be able to resolve the instruction and check for errors in the cQASM file. + * The resolved instruction type is part of the cqasm::semantic::Instruction node present in the semantic tree + * returned through the parse result structure. * - * Note that it is legal to have multiple instructions with the same name, as - * long as they can be distinguished through their parameter types (i.e. - * instructions can be overloaded). + * Note that it is legal to have multiple instructions with the same name, + * as long as they can be distinguished through their parameter types (i.e. instructions can be overloaded). * * You can add any data you like to these through the - * \ref cqasm::annotatable::Annotatable "Annotatable" interface - * for your own bookkeeping, so you don't have to maintain an additional map - * from this error model structure to your own internal structure if you're - * okay with using this one. + * \ref cqasm::annotatable::Annotatable "Annotatable" interface for your own bookkeeping, + * so you don't have to maintain an additional map from this error model structure to your own internal structure + * if you're okay with using this one. */ class Instruction : public tree::Base { public: - /** * The name of the instruction. Names are matched case insensitively. */ @@ -56,47 +56,47 @@ class Instruction : public tree::Base { types::Types param_types; /** - * Whether this instruction supports conditional execution by means of the - * c- notation. This is normally true. + * Whether this instruction supports conditional execution by means of the c- notation. + * This is normally true. */ bool allow_conditional; /** - * Whether this instruction can be used in a bundle. This is normally true. + * Whether this instruction can be used in a bundle. + * This is normally true. */ bool allow_parallel; /** - * Whether to allow usage of the same qubit in different arguments. This is - * normally false, as this makes no sense in QM, in which case libqasm will - * report an error to the user if a qubit is reused. Setting this to true - * just disables that check. + * Whether to allow usage of the same qubit in different arguments. + * This is normally false, as this makes no sense in QM, + * in which case libqasm will report an error to the user if a qubit is reused. + * Setting this to true just disables that check. */ bool allow_reused_qubits; /** - * Whether different index sizes are allowed. This is normally false, as - * index lists are normally used to designate parallel instructions, and it - * makes no sense for the lists to mismatch in that case. + * Whether different index sizes are allowed. + * This is normally false, as index lists are normally used to designate parallel instructions, + * and it makes no sense for the lists to mismatch in that case. */ bool allow_different_index_sizes; /** - * Creates a new instruction. param_types is a shorthand type specification - * string as parsed by cqasm::types::from_spec(). If you need more control, - * you can also manipulate param_types directly. + * Creates a new instruction. + * param_types is a shorthand type specification string as parsed by cqasm::types::from_spec(). + * If you need more control, you can also manipulate param_types directly. * - * allow_conditional specifies whether the instruction can be made - * conditional with c- notation. allow_parallel specifies whether it may - * appear bundled with other instructions. allow_reused_qubits specifies - * whether it is legal for the instruction to use a qubit more than once in - * its parameter list. allow_different_index_sizes specifies whether it's - * legal to have different "index sizes" for different parameters, for - * instance q[1,2] in one parameter and q[1,2,3,4,5] in another. + * allow_conditional specifies whether the instruction can be made conditional with c- notation. + * allow_parallel specifies whether it may appear bundled with other instructions. + * allow_reused_qubits specifies whether it is legal for the instruction + * to use a qubit more than once in its parameter list. + * allow_different_index_sizes specifies whether it's legal to have different "index sizes" for different parameters, + * for instance q[1,2] in one parameter and q[1,2,3,4,5] in another. */ - explicit Instruction( - const std::string &name, - const std::string ¶m_types = "", + Instruction( + std::string name, + const std::optional ¶m_types, bool allow_conditional = true, bool allow_parallel = true, bool allow_reused_qubits = false, @@ -145,3 +145,8 @@ instruction::InstructionRef deserialize(const ::tree::cbor::MapReader &map); } // namespace primitives } // namespace cqasm::v1x + +/** + * std::ostream support via fmt (uses operator<<). + */ +template <> struct fmt::formatter : ostream_formatter {}; diff --git a/include/v1x/cqasm-parse-helper.hpp b/include/v1x/cqasm-parse-helper.hpp index 7d2d1d1f4..20037560d 100644 --- a/include/v1x/cqasm-parse-helper.hpp +++ b/include/v1x/cqasm-parse-helper.hpp @@ -111,12 +111,7 @@ class ParseHelper { /** * Builds and pushes an error. */ - void push_error( - const std::string &message, - int first_line, - int first_column, - int last_line, - int last_column); + void push_error(const std::string &message, const annotations::SourceLocation::Range &range); }; } // namespace cqasm::v1x::parser diff --git a/include/v1x/cqasm-scope.hpp b/include/v1x/cqasm-scope.hpp new file mode 100644 index 000000000..007bf2b2c --- /dev/null +++ b/include/v1x/cqasm-scope.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include "cqasm-tree.hpp" +#include "v1x/cqasm-resolver.hpp" +#include "v1x/cqasm-semantic-gen.hpp" + + +namespace cqasm::v1x::analyzer { + +/** + * Scope information. + */ +struct Scope { + /** + * The mappings visible within this scope. + */ + resolver::MappingTable mappings; + + /** + * The functions visible within this scope. + */ + resolver::FunctionTable functions; + + /** + * The instruction set visible within this scope. + */ + resolver::InstructionTable instruction_set; + + /** + * The block associated with this scope, if any. + * If this is empty, this is the global scope, and the active block is that of the current subcircuit, + * which is lazily created when needed in case no subcircuit label is explicitly specified, + * and can thus not easily be populated here. + */ + tree::Maybe block; + + /** + * Whether we're within at least one for, foreach, while, or repeat-until loop. + * This is a necessary condition for break and continue statements to be allowed. + */ + bool within_loop; + + /** + * Creates a scope from a table of mappings, functions, and an instruction set. + */ + Scope( + resolver::MappingTable mappings, + resolver::FunctionTable functions, + resolver::InstructionTable instruction_set); +}; + +} // namespace cqasm::v1x::analyzer diff --git a/include/v1x/cqasm-types.hpp b/include/v1x/cqasm-types.hpp index 2ace44626..eda239cf8 100644 --- a/include/v1x/cqasm-types.hpp +++ b/include/v1x/cqasm-types.hpp @@ -16,6 +16,16 @@ */ namespace cqasm::v1x::types { +constexpr const char *qubit_type_name = "qubit"; +constexpr const char *bit_type_name = "bit"; +constexpr const char *axis_type_name = "axis"; +constexpr const char *bool_type_name = "bool"; +constexpr const char *integer_type_name = "int"; +constexpr const char *real_type_name = "real"; +constexpr const char *complex_type_name = "complex"; +constexpr const char *string_type_name = "string"; +constexpr const char *json_type_name = "json"; + /** * A cQASM type. */ diff --git a/include/v3x/AnalyzeTreeGenAstVisitor.hpp b/include/v3x/AnalyzeTreeGenAstVisitor.hpp index de814fa1e..1daff40b0 100644 --- a/include/v3x/AnalyzeTreeGenAstVisitor.hpp +++ b/include/v3x/AnalyzeTreeGenAstVisitor.hpp @@ -5,6 +5,9 @@ #include "v3x/cqasm-semantic-gen.hpp" #include +#include +#include +#include // pair namespace cqasm::v3x::analyzer { @@ -12,7 +15,17 @@ namespace cqasm::v3x::analyzer { using IndexT = values::ConstInt; using IndexListT = tree::Many; +using GlobalBlockReturnT = std::tuple< + tree::One, + const tree::Any &, + const tree::Any &>; + +using LocalBlockReturnT = std::pair< + tree::One, + const tree::Any &>; + class AnalyzeTreeGenAstVisitor : public ast::Visitor { +protected: Analyzer &analyzer_; AnalysisResult result_; @@ -24,12 +37,16 @@ class AnalyzeTreeGenAstVisitor : public ast::Visitor { std::any visit_version(ast::Version &node) override; std::any visit_annotated(ast::Annotated &node) override; std::any visit_annotation_data(ast::AnnotationData &node) override; - std::any visit_statement_list(ast::StatementList &node) override; + std::any visit_global_block(ast::GlobalBlock &node) override; + std::any visit_local_block(ast::LocalBlock &node) override; std::any visit_variable(ast::Variable &node) override; std::any visit_initialization(ast::Initialization &node) override; - std::any visit_assignment_instruction(ast::AssignmentInstruction &node) override; + std::any visit_function(ast::Function &node) override; + std::any visit_assignment_statement(ast::AssignmentStatement &node) override; + std::any visit_return_statement(ast::ReturnStatement &node) override; + std::any visit_expression_statement(ast::ExpressionStatement &node) override; + std::any visit_gate(ast::Gate &node) override; std::any visit_measure_instruction(ast::MeasureInstruction &node) override; - std::any visit_instruction(ast::Instruction &node) override; std::any visit_expression(ast::Expression &node) override; std::any visit_unary_minus_expression(ast::UnaryMinusExpression &node) override; std::any visit_bitwise_not_expression(ast::BitwiseNotExpression &node) override; @@ -67,29 +84,103 @@ class AnalyzeTreeGenAstVisitor : public ast::Visitor { std::any visit_float_literal(ast::FloatLiteral &node) override; private: - /* + bool current_block_has_return_statement(); + void current_block_return_statements_promote_or_error(const tree::Maybe &return_type); + + /** * Build a semantic type - * It can be a simple type T, of size 1, - * or an array type TArray, which size is given by the syntactic type + * It can be a simple type SemanticT, of size 1, + * or an array type SemanticTArray, which size is given by the syntactic type + */ + template + types::Type build_semantic_type(const SyntacticT &type, std::string_view type_name) const { + if (type.size.empty()) { + return tree::make(1); + } else if (type.size->value > 0) { + return tree::make(type.size->value); + } else { + throw error::AnalysisError{ fmt::format("found {} array of size <= 0", type_name) }; + } + } + + /** + * Build a semantic type + */ + template + types::Type build_semantic_type(const SyntacticT &type) const { + assert(!type.empty() && !type->name.empty()); + auto type_name = type->name->name; + if (type_name == types::qubit_type_name) { + return build_semantic_type(*type, types::qubit_type_name); } + if (type_name == types::bit_type_name) { + return build_semantic_type(*type, types::bit_type_name); } + if (type_name == types::axis_type_name) { + return tree::make(3); } + if (type_name == types::bool_type_name) { + return build_semantic_type(*type, types::bool_type_name); } + if (type_name == types::integer_type_name) { + return build_semantic_type(*type, types::integer_type_name); } + if (type_name == types::float_type_name) { + return build_semantic_type(*type, types::float_type_name); } + throw error::AnalysisError("unknown type \"" + type_name + "\""); + } + + /** + * Transform an input array of values into an array of a given Type + * Pre condition: all the values in the input array can be promoted to Type */ - template - [[nodiscard]] types::Type visit_variable_type(const ast::Variable &variable_ast, std::string_view type_name) const; + template + static tree::One build_array_value_from_promoted_values( + const values::Values &values, const types::Type &type) { + + auto ret = tree::make(); + ret->value.get_vec().resize(values.size()); + std::transform(values.begin(), values.end(), ret->value.begin(), + [&type](const auto const_value) { + return values::promote(const_value, type); + }); + return ret; + } - /* + /** + * Transform an input array into a const array of Type + * Pre conditions: + * Type can only be Bool, Int, or Real + * All the values in the input array can be promoted to Type + */ + [[nodiscard]] static values::Value build_value_from_promoted_values( + const values::Values &values, const types::Type &type); + + /** + * Convenience function for visiting a global or a local block + */ + template + void visit_block(Block &block) { + for (const auto &statement_ast : block.statements) { + try { + statement_ast->visit(*this); + } catch (error::AnalysisError &err) { + err.context(block); + result_.errors.push_back(std::move(err)); + } + } + } + + /** * Convenience function for visiting a function call given the function's name and arguments */ values::Value visit_function_call( const tree::One &name, - const tree::One &arguments); + const tree::Maybe &arguments); - /* + /** * Convenience function for visiting unary operators */ std::any visit_unary_operator( const std::string &name, const tree::One &expression); - /* + /** * Convenience function for visiting binary operators */ std::any visit_binary_operator( @@ -97,33 +188,18 @@ class AnalyzeTreeGenAstVisitor : public ast::Visitor { const tree::One &lhs, const tree::One &rhs); - /* - * Transform an input array of values into an array of a given Type - * Pre condition: all the values in the input array can be promoted to Type - */ - template - [[nodiscard]] static tree::One build_array_value_from_promoted_values( - const values::Values &values, const types::Type &type); - - /* - * Transform an input array into a const array of Type - * Pre conditions: - * Type can only be Bool, Int, or Real - * All the values in the input array can be promoted to Type - */ - [[nodiscard]] static values::Value build_value_from_promoted_values( - const values::Values &values, const types::Type &type); - /** * Shorthand for parsing an expression and promoting it to the given type, * constructed in-place with the type_args parameter pack. - * Returns empty when the cast fails. + * Returns empty when the cast fails */ - template - values::Value analyze_as(ast::Expression &expression, TypeArgs... type_args); + template + values::Value visit_as(ast::Expression &expression, TypeArgs... type_args) { + return values::promote(std::any_cast(expression.visit(*this)), tree::make(type_args...)); + } /** - * Shorthand for parsing an expression to a constant integer. + * Shorthand for parsing an expression to a constant integer */ primitives::Int visit_const_int(ast::Expression &expression); }; diff --git a/include/v3x/BuildCustomAstVisitor.hpp b/include/v3x/BuildCustomAstVisitor.hpp index 96ae94748..9beec2a03 100644 --- a/include/v3x/BuildCustomAstVisitor.hpp +++ b/include/v3x/BuildCustomAstVisitor.hpp @@ -17,6 +17,7 @@ class BuildCustomAstVisitor : public CqasmParserVisitor { virtual void addErrorListener(CustomErrorListener *errorListener) = 0; virtual void syntaxError(size_t line, size_t char_position_in_line, const std::string &text) const = 0; virtual void setNodeAnnotation(const ast::One &node, antlr4::Token *token) const = 0; + virtual void expandNodeAnnotation(const ast::One &node, antlr4::Token *token) const = 0; }; } // namespace cqasm::v3x::parser diff --git a/include/v3x/BuildTreeGenAstVisitor.hpp b/include/v3x/BuildTreeGenAstVisitor.hpp index 44a240445..cd4a86bae 100644 --- a/include/v3x/BuildTreeGenAstVisitor.hpp +++ b/include/v3x/BuildTreeGenAstVisitor.hpp @@ -14,7 +14,7 @@ namespace cqasm::v3x::parser { class CustomErrorListener; } namespace cqasm::v3x::parser { -class BuildTreeGenAstVisitor : public BuildCustomAstVisitor { +class BuildTreeGenAstVisitor : public BuildCustomAstVisitor { /** * Name of the file being parsed. */ @@ -32,39 +32,65 @@ class BuildTreeGenAstVisitor : public BuildCustomAstVisitor { std::int64_t get_int_value(antlr4::tree::TerminalNode *node) const ; double get_float_value(antlr4::tree::TerminalNode *node) const; - std::any visitAxisTypeDefinition(CqasmParser::AxisTypeDeclarationContext *context); - std::any visitAxisTypeInitialization(CqasmParser::AxisTypeDeclarationContext *context); - std::any visitBoolTypeDefinition(CqasmParser::BoolTypeDeclarationContext *context); - std::any visitBoolTypeInitialization(CqasmParser::BoolTypeDeclarationContext *context); - std::any visitIntTypeDefinition(CqasmParser::IntTypeDeclarationContext *context); - std::any visitIntTypeInitialization(CqasmParser::IntTypeDeclarationContext *context); - std::any visitFloatTypeDefinition(CqasmParser::FloatTypeDeclarationContext *context); - std::any visitFloatTypeInitialization(CqasmParser::FloatTypeDeclarationContext *context); + tree::Maybe getArraySize(CqasmParser::ArraySizeDeclarationContext *context); + + template + tree::One visitVariable(Context *context) { + auto ret = tree::make( + tree::One{ tree::make(context->IDENTIFIER()->getText()) }, + std::any_cast>(context->type()->accept(this)) + ); + setNodeAnnotation(ret, context->IDENTIFIER()->getSymbol()); + return ret; + } + + template + tree::One visitClassicalVariable(Context *context) { + auto ret = tree::make( + tree::One{ tree::make(context->IDENTIFIER()->getText()) }, + std::any_cast>(context->classicalType()->accept(this)) + ); + setNodeAnnotation(ret, context->IDENTIFIER()->getSymbol()); + return ret; + } template std::any visitBinaryExpression(Context *context, antlr4::Token *token) { auto ret = tree::make( - std::any_cast>(context->expression(0)->accept(this)), - std::any_cast>(context->expression(1)->accept(this)) + std::any_cast>(context->expression(0)->accept(this)), + std::any_cast>(context->expression(1)->accept(this)) ); setNodeAnnotation(ret, token); - return tree::One{ ret }; + return tree::One{ ret }; } public: std::any visitProgram(CqasmParser::ProgramContext *context) override; - std::any visitVersion(CqasmParser::VersionContext *context) override; - std::any visitStatements(CqasmParser::StatementsContext *context) override; std::any visitStatementSeparator(CqasmParser::StatementSeparatorContext *context) override; - std::any visitQubitTypeDeclaration(CqasmParser::QubitTypeDeclarationContext *context) override; - std::any visitBitTypeDeclaration(CqasmParser::BitTypeDeclarationContext *context) override; - std::any visitAxisTypeDeclaration(CqasmParser::AxisTypeDeclarationContext *context) override; - std::any visitBoolTypeDeclaration(CqasmParser::BoolTypeDeclarationContext *context) override; - std::any visitIntTypeDeclaration(CqasmParser::IntTypeDeclarationContext *context) override; - std::any visitFloatTypeDeclaration(CqasmParser::FloatTypeDeclarationContext *context) override; - std::any visitArraySizeDeclaration(CqasmParser::ArraySizeDeclarationContext *context) override; + std::any visitVersion(CqasmParser::VersionContext *context) override; + std::any visitGlobalBlock(CqasmParser::GlobalBlockContext *context) override; + std::any visitLocalBlock(CqasmParser::LocalBlockContext *context) override; + std::any visitGlobalBlockStatement(CqasmParser::GlobalBlockStatementContext *context) override; + std::any visitLocalBlockStatement(CqasmParser::LocalBlockStatementContext *context) override; + std::any visitVariableDeclaration(CqasmParser::VariableDeclarationContext *context) override; + std::any visitVariableDefinition(CqasmParser::VariableDefinitionContext *context) override; + std::any visitVariableInitialization(CqasmParser::VariableInitializationContext *context) override; + std::any visitFunctionDeclaration(CqasmParser::FunctionDeclarationContext *context) override; + std::any visitParameters(CqasmParser::ParametersContext *context) override; + std::any visitAssignmentStatement(CqasmParser::AssignmentStatementContext *context) override; + std::any visitReturnStatement(CqasmParser::ReturnStatementContext *context) override; + std::any visitExpressionStatement(CqasmParser::ExpressionStatementContext *context) override; + std::any visitGate(CqasmParser::GateContext *context) override; std::any visitMeasureInstruction(CqasmParser::MeasureInstructionContext *context) override; - std::any visitInstruction(CqasmParser::InstructionContext *context) override; + std::any visitType(CqasmParser::TypeContext *context) override; + std::any visitQubitType(CqasmParser::QubitTypeContext *context) override; + std::any visitBitType(CqasmParser::BitTypeContext *context) override; + std::any visitAxisType(CqasmParser::AxisTypeContext *context) override; + std::any visitBoolType(CqasmParser::BoolTypeContext *context) override; + std::any visitIntType(CqasmParser::IntTypeContext *context) override; + std::any visitFloatType(CqasmParser::FloatTypeContext *context) override; + std::any visitArraySizeDeclaration(CqasmParser::ArraySizeDeclarationContext *context) override; + std::any visitExpressionList(CqasmParser::ExpressionListContext *context) override; std::any visitIndexList(CqasmParser::IndexListContext *context) override; std::any visitIndexItem(CqasmParser::IndexItemContext *context) override; @@ -99,6 +125,7 @@ class BuildTreeGenAstVisitor : public BuildCustomAstVisitor { void addErrorListener(CustomErrorListener *errorListener) override; void syntaxError(size_t line, size_t char_position_in_line, const std::string &text) const override; void setNodeAnnotation(const ast::One &node, antlr4::Token *token) const override; + void expandNodeAnnotation(const ast::One &node, antlr4::Token *token) const override; }; } // namespace cqasm::v3x::parser diff --git a/include/v3x/cqasm-analyzer.hpp b/include/v3x/cqasm-analyzer.hpp index 1511c1f5f..1d495235d 100644 --- a/include/v3x/cqasm-analyzer.hpp +++ b/include/v3x/cqasm-analyzer.hpp @@ -14,8 +14,10 @@ #include "cqasm-parse-helper.hpp" #include "cqasm-resolver.hpp" #include "cqasm-semantic.hpp" +#include "v3x/cqasm-scope.hpp" #include +#include #include #include @@ -28,46 +30,42 @@ namespace cqasm::v3x::analyzer { /** * Main class used for analyzing cQASM files. * - * Construction of this class is the entry point for libqasm whenever you need - * to modify the default instruction set, have a different set of supported - * error models, or want to add additional initial mappings, operators, or - * functions. The process is simple: + * Construction of this class is the entry point for libqasm + * whenever you need to modify the default instruction set, + * have a different set of supported error models, + * or want to add additional initial mappings, operators, or functions. + * The process is simple: * * - Construct an Analyzer object with the default constructor. - * - Use zero or more of the various `register_*()` methods to configure the - * Analyzer. - * - Use one or more of the `analyze*()` methods to analyze cQASM files or - * string representations thereof. + * - Use zero or more of the various `register_*()` methods to configure the Analyzer. + * - Use one or more of the `analyze*()` methods to analyze cQASM files + * or string representations thereof. * - * Note that the only state maintained by the Analyzer object is its - * configuration, and the `analyze*()` functions never change this state - * (hence they are const). + * Note that the only state maintained by the Analyzer object is its configuration, + * and the `analyze*()` functions never change this state (hence they are const). */ class Analyzer { + friend class AnalyzeTreeGenAstVisitor; + public: /** * The maximum cQASM version that this analyzer supports. */ primitives::Version api_version; -private: - /** - * The set of "mappings" that the parser starts out with. - */ - resolver::MappingTable mappings; +protected: + std::list scope_stack_; - /** - * The functions visible to the analyzer. - */ - resolver::FunctionTable functions; + [[nodiscard]] Scope &global_scope(); + [[nodiscard]] Scope ¤t_scope(); + [[nodiscard]] tree::One current_block(); + [[nodiscard]] tree::Any ¤t_variables(); + [[nodiscard]] tree::Any &global_functions(); - /** - * The supported set of quantum/classical/mixed instructions, - * appearing in the cQASM file as assembly-like commands. - * Instructions have a case-sensitively matched name, and - * a signature for the types of parameters it expects. - */ - resolver::InstructionTable instruction_set; + [[nodiscard]] const Scope &global_scope() const; + [[nodiscard]] const Scope ¤t_scope() const; + [[nodiscard]] const tree::Any ¤t_variables() const; + [[nodiscard]] const tree::Any &global_functions() const; public: /** @@ -123,47 +121,90 @@ class Analyzer { const std::string &data, const std::optional &file_name); /** - * Resolves a mapping. - * Throws NameResolutionFailure if no mapping by the given name exists. + * Pushes a new empty scope to the top of the scope stack. + */ + void push_scope(); + + /** + * Pops a scope from the top of the scope stack. + */ + void pop_scope(); + + /** + * Adds a statement to the current scope. + */ + virtual void add_statement_to_current_scope(const tree::One &statement); + + /** + * Adds a variable to the current scope. + */ + virtual void add_variable_to_current_scope(const tree::One &variable); + + /** + * Adds a function to the global scope. */ - [[nodiscard]] virtual values::Value resolve_mapping(const std::string &name) const; + virtual void add_function_to_global_scope(const tree::One &function); /** - * Registers a mapping. + * Resolves a variable. + * Throws NameResolutionFailure if no variable by the given name exists. */ - virtual void register_mapping(const std::string &name, const values::Value &value); + [[nodiscard]] virtual values::Value resolve_variable(const std::string &name) const; /** - * Calls a function. + * Registers a variable. + */ + virtual void register_variable(const std::string &name, const values::Value &value); + + /** + * Resolves a function implementation. * Throws NameResolutionFailure if no function by the given name exists, - * OverloadResolutionFailure if no overload of the function exists for the given arguments, or otherwise - * returns the value returned by the function. + * OverloadResolutionFailure if no overload of the function exists for the given arguments, + * or otherwise returns the value returned by the function. */ - [[nodiscard]] virtual values::Value call_function(const std::string &name, const values::Values &args) const; + [[nodiscard]] virtual values::Value resolve_function_impl(const std::string &name, const values::Values &args) const; /** - * Registers a function, usable within expressions. + * Resolves a function. + * Tries to call a function implementation first. + * If it doesn't succeed, tries to call a function. + * Throws NameResolutionFailure if no function by the given name exists, + * OverloadResolutionFailure if no overload of the function exists for the given arguments, + * or otherwise returns the value returned by the function. */ - virtual void register_function( + [[nodiscard]] virtual values::Value resolve_function(const std::string &name, const values::Values &args) const; + + /** + * Registers a function implementation, usable within expressions. + */ + virtual void register_function_impl( const std::string &name, const types::Types ¶m_types, const resolver::FunctionImpl &impl); /** - * Convenience method for registering a function. + * Convenience method for registering a function implementation. * The param_types are specified as a string, * converted to types::Types for the other overload using types::from_spec. */ - virtual void register_function( + virtual void register_function_impl( const std::string &name, const std::string ¶m_types, const resolver::FunctionImpl &impl); + /** + * Convenience method for registering a function. + */ + virtual void register_function( + const std::string &name, + const types::Types ¶m_types, + const values::Value &value); + /** * Resolves an instruction. * Throws NameResolutionFailure if no instruction by the given name exists, - * OverloadResolutionFailure if no overload exists for the given arguments, or otherwise - * returns the resolved instruction node. + * OverloadResolutionFailure if no overload exists for the given arguments, + * or otherwise returns the resolved instruction node. * Annotation data, line number information, and the condition still need to be set by the caller. */ [[nodiscard]] virtual tree::One resolve_instruction( @@ -178,7 +219,7 @@ class Analyzer { * Convenience method for registering an instruction type. * The arguments are passed straight to instruction::Instruction's constructor. */ - virtual void register_instruction(const std::string &name, const std::string ¶m_types = ""); + virtual void register_instruction(const std::string &name, const std::optional ¶m_types); }; } // namespace cqasm::v3x::analyzer diff --git a/include/v3x/cqasm-functions.hpp b/include/v3x/cqasm-functions.hpp index 40480955a..bc6818d0a 100644 --- a/include/v3x/cqasm-functions.hpp +++ b/include/v3x/cqasm-functions.hpp @@ -10,7 +10,7 @@ namespace primitives = cqasm::v3x::primitives; -/* +/** * Changes regarding v1: * * - There are not functions operating on complex types yet @@ -25,7 +25,7 @@ namespace primitives = cqasm::v3x::primitives; namespace cqasm::v3x::functions { -/* +/** * Function with constant parameters */ template @@ -34,7 +34,7 @@ struct f_cp { using param_type = ParamType; }; -/* +/** * Unary function with constant parameter */ template @@ -46,7 +46,7 @@ struct uf_cp : public f_cp { } }; -/* +/** * Binary function with constant parameters */ template @@ -59,7 +59,7 @@ struct bf_cp : public f_cp { } }; -/* +/** * Ternary function with constant parameters */ template @@ -73,29 +73,29 @@ struct tf_cp : public f_cp { } }; -constexpr auto op_neg_r = uf_cp{}>{}; +constexpr auto op_neg_f = uf_cp{}>{}; constexpr auto op_neg_i = uf_cp{}; -constexpr auto op_add_rr = bf_cp{}; +constexpr auto op_add_ff = bf_cp{}; constexpr auto op_add_ii = bf_cp{}; -constexpr auto op_sub_rr = bf_cp{}; +constexpr auto op_sub_ff = bf_cp{}; constexpr auto op_sub_ii = bf_cp{}; -constexpr auto op_mul_rr = bf_cp{}; +constexpr auto op_mul_ff = bf_cp{}; constexpr auto op_mul_ii = bf_cp{}; -constexpr auto op_div_rr = bf_cp{}; +constexpr auto op_div_ff = bf_cp{}; constexpr auto op_div_ii = bf_cp{}; constexpr auto op_mod_ii = bf_cp{}; constexpr auto pow = [](auto base, auto exp) { return std::pow(base, exp); }; -constexpr auto op_pow_rr = bf_cp{}; +constexpr auto op_pow_ff = bf_cp{}; -constexpr auto op_eq_rr = bf_cp{}; -constexpr auto op_ne_rr = bf_cp{}; -constexpr auto op_ge_rr = bf_cp{}; -constexpr auto op_gt_rr = bf_cp{}; -constexpr auto op_le_rr = bf_cp{}; -constexpr auto op_lt_rr = bf_cp{}; +constexpr auto op_eq_ff = bf_cp{}; +constexpr auto op_ne_ff = bf_cp{}; +constexpr auto op_ge_ff = bf_cp{}; +constexpr auto op_gt_ff = bf_cp{}; +constexpr auto op_le_ff = bf_cp{}; +constexpr auto op_lt_ff = bf_cp{}; constexpr auto op_eq_ii = bf_cp{}; constexpr auto op_ne_ii = bf_cp{}; @@ -128,47 +128,47 @@ constexpr auto op_lxor_bb = bf_cp{}; constexpr auto op_lor_bb = bf_cp{}; constexpr auto tcnd = [](bool condition, auto if_true, auto if_false) { return condition ? if_true : if_false; }; -constexpr auto op_tcnd_brr = tf_cp{}; +constexpr auto op_tcnd_bff = tf_cp{}; constexpr auto op_tcnd_bii = tf_cp{}; constexpr auto op_tcnd_bbb = tf_cp{}; constexpr auto sqrt = [](auto num) { return std::sqrt(num); }; -constexpr auto fn_sqrt_r = uf_cp{}; +constexpr auto fn_sqrt_f = uf_cp{}; constexpr auto exp = [](auto num) { return std::exp(num); }; -constexpr auto fn_exp_r = uf_cp{}; +constexpr auto fn_exp_f = uf_cp{}; constexpr auto log = [](auto num) { return std::log(num); }; -constexpr auto fn_log_r = uf_cp{}; +constexpr auto fn_log_f = uf_cp{}; constexpr auto sin = [](auto num) { return std::sin(num); }; -constexpr auto fn_sin_r = uf_cp{}; +constexpr auto fn_sin_f = uf_cp{}; constexpr auto cos = [](auto num) { return std::cos(num); }; -constexpr auto fn_cos_r = uf_cp{}; +constexpr auto fn_cos_f = uf_cp{}; constexpr auto tan = [](auto num) { return std::tan(num); }; -constexpr auto fn_tan_r = uf_cp{}; +constexpr auto fn_tan_f = uf_cp{}; constexpr auto sinh = [](auto num) { return std::sinh(num); }; -constexpr auto fn_sinh_r = uf_cp{}; +constexpr auto fn_sinh_f = uf_cp{}; constexpr auto cosh = [](auto num) { return std::cosh(num); }; -constexpr auto fn_cosh_r = uf_cp{}; +constexpr auto fn_cosh_f = uf_cp{}; constexpr auto tanh = [](auto num) { return std::tanh(num); }; -constexpr auto fn_tanh_r = uf_cp{}; +constexpr auto fn_tanh_f = uf_cp{}; constexpr auto asin = [](auto num) { return std::asin(num); }; -constexpr auto fn_asin_r = uf_cp{}; +constexpr auto fn_asin_f = uf_cp{}; constexpr auto acos = [](auto num) { return std::acos(num); }; -constexpr auto fn_acos_r = uf_cp{}; +constexpr auto fn_acos_f = uf_cp{}; constexpr auto atan = [](auto num) { return std::atan(num); }; -constexpr auto fn_atan_r = uf_cp{}; +constexpr auto fn_atan_f = uf_cp{}; constexpr auto asinh = [](auto num) { return std::asinh(num); }; -constexpr auto fn_asinh_r = uf_cp{}; +constexpr auto fn_asinh_f = uf_cp{}; constexpr auto acosh = [](auto num) { return std::acosh(num); }; -constexpr auto fn_acosh_r = uf_cp{}; +constexpr auto fn_acosh_f = uf_cp{}; constexpr auto atanh = [](auto num) { return std::atanh(num); }; -constexpr auto fn_atanh_r = uf_cp{}; +constexpr auto fn_atanh_f = uf_cp{}; constexpr auto abs = [](auto num) { return std::abs(num); }; -constexpr auto fn_abs_r = uf_cp{}; +constexpr auto fn_abs_f = uf_cp{}; constexpr auto fn_abs_i = uf_cp{}; /** - * Registers a bunch of functions usable during constant propagation into the given function table. + * Registers a bunch of functions for which we have a C++ implementation into the given function table. */ -void register_default_functions_into(resolver::FunctionTable &table); +void register_default_function_impls_into(resolver::FunctionImplTable &table); } // namespace functions diff --git a/include/v3x/cqasm-instruction.hpp b/include/v3x/cqasm-instruction.hpp index d17005bd6..042dd6eea 100644 --- a/include/v3x/cqasm-instruction.hpp +++ b/include/v3x/cqasm-instruction.hpp @@ -8,6 +8,9 @@ #include "cqasm-types.hpp" #include "cqasm-values.hpp" +#include +#include + namespace cqasm::v3x { @@ -48,7 +51,7 @@ class Instruction : public tree::Base { * param_types is a shorthand type specification string as parsed by cqasm::types::from_spec(). * If you need more control, you can also manipulate param_types directly. */ - explicit Instruction(const std::string &name, const std::string ¶m_types = ""); + Instruction(std::string name, const std::optional ¶m_types); bool operator==(const Instruction& rhs) const; inline bool operator!=(const Instruction& rhs) const { @@ -65,12 +68,12 @@ using InstructionRef = tree::Maybe; /** * Stream << overload for instructions. */ -std::ostream &operator<<(std::ostream &os, const Instruction &insn); +std::ostream &operator<<(std::ostream &os, const Instruction &instruction); /** * Stream << overload for instruction references. */ -std::ostream &operator<<(std::ostream &os, const InstructionRef &insn); +std::ostream &operator<<(std::ostream &os, const InstructionRef &instruction); } // namespace instruction @@ -85,3 +88,8 @@ instruction::InstructionRef deserialize(const ::tree::cbor::MapReader &map); } // namespace primitives } // namespace cqasm::v3x + +/** + * std::ostream support via fmt (uses operator<<). + */ +template <> struct fmt::formatter : ostream_formatter {}; diff --git a/include/v3x/cqasm-primitives.hpp b/include/v3x/cqasm-primitives.hpp index 0109b898a..d297aa7ec 100644 --- a/include/v3x/cqasm-primitives.hpp +++ b/include/v3x/cqasm-primitives.hpp @@ -55,7 +55,7 @@ Str deserialize(const ::tree::cbor::MapReader &map); * Axis primitive used within the semantic trees. */ struct Axis { - double x = 0.0; + double x = 1.0; double y = 0.0; double z = 0.0; @@ -91,15 +91,15 @@ template <> Int deserialize(const ::tree::cbor::MapReader &map); /** - * Real number primitive used within the AST and semantic trees. + * Float number primitive used within the AST and semantic trees. */ -using Real = double; +using Float = double; template <> -Real initialize(); +Float initialize(); template <> -void serialize(const Real &obj, ::tree::cbor::MapWriter &map); +void serialize(const Float &obj, ::tree::cbor::MapWriter &map); template <> -Real deserialize(const ::tree::cbor::MapReader &map); +Float deserialize(const ::tree::cbor::MapReader &map); /** * Complex number primitive used within the semantic trees. diff --git a/include/v3x/cqasm-resolver.hpp b/include/v3x/cqasm-resolver.hpp index 1c5a892fa..5e0c11cba 100644 --- a/include/v3x/cqasm-resolver.hpp +++ b/include/v3x/cqasm-resolver.hpp @@ -1,6 +1,6 @@ /** \file * Contains \ref cqasm::v3x::resolver::MappingTable "MappingTable", - * \ref cqasm::v3x::resolver::FunctionTable "FunctionTable", and + * \ref cqasm::v3x::resolver::FunctionImplTable "FunctionImplTable", and * \ref cqasm::v3x::resolver::ErrorModelTable "ErrorModelTable", representing the * various cQASM namespaces and their members in scope at some instant. */ @@ -24,6 +24,10 @@ */ namespace cqasm::v3x::resolver { +//-----------------// +// Analysis errors // +//-----------------// + /** * Exception for failed name resolutions. */ @@ -34,17 +38,27 @@ CQASM_ANALYSIS_ERROR(NameResolutionFailure); */ CQASM_ANALYSIS_ERROR(OverloadResolutionFailure); +/** + * Exception for failed resolutions. + */ +CQASM_ANALYSIS_ERROR(ResolutionFailure); + + +//------------------------// +// OverloadedNameResolver // +//------------------------// + template -struct OverloadedNameResolver : public cqasm::overload::OverloadedNameResolver { +struct OverloadedNameResolver : public cqasm::overload::OverloadedNameResolver { virtual ~OverloadedNameResolver() = default; void add_overload(const std::string &name, const T &tag, const types::Types ¶m_types) override { - cqasm::overload::OverloadedNameResolver::add_overload(name, tag, param_types); + cqasm::overload::OverloadedNameResolver::add_overload(name, tag, param_types); } [[nodiscard]] std::pair resolve(const std::string &name, const values::Values &args) override { try { - return cqasm::overload::OverloadedNameResolver::resolve(name, args); + return cqasm::overload::OverloadedNameResolver::resolve(name, args); } catch (const cqasm::overload::NameResolutionFailure &) { throw NameResolutionFailure{ fmt::format("failed to resolve '{}'", name) }; } catch (const cqasm::overload::OverloadResolutionFailure &) { @@ -55,41 +69,89 @@ struct OverloadedNameResolver : public cqasm::overload::OverloadedNameResolver table; public: /** - * Adds a mapping. + * Adds a variable. */ void add(const std::string &name, const values::Value &value); /** - * Resolves a mapping. - * Throws NameResolutionFailure if no mapping by the given name exists. + * Resolves a variable. + * Throws NameResolutionFailure if no variable by the given name exists. */ values::Value resolve(const std::string &name) const; - - /** - * Grants read access to the underlying map. - */ - const std::unordered_map &get_table() const; }; + +//-------------------// +// FunctionImplTable // +//-------------------// + /** - * C++ function representing (one of the overloads of) a function usable in cQASM constant expressions. + * C++ function representing one of the overloads of a function for which we have a C++ implementation. + * This can be a function accepting only constant arguments, or both constant and variable arguments. */ using FunctionImpl = std::function; /** - * Table of all overloads of all constant propagation functions. + * Table of all overloads of all functions for which we have a C++ implementation. */ -class FunctionTable { +class FunctionImplTable { std::unique_ptr> resolver; +public: + FunctionImplTable(); + ~FunctionImplTable(); + FunctionImplTable(const FunctionImplTable& t); + FunctionImplTable(FunctionImplTable&& t) noexcept; + FunctionImplTable& operator=(const FunctionImplTable& t); + FunctionImplTable& operator=(FunctionImplTable&& t) noexcept; + + /** + * Registers a function. + * Matching will be done case-sensitively. + * The param_types variadic specifies the amount and types of the parameters that + * this particular overload of the function expects. + * The C++ implementation of the function can assume that + * the value list it gets is of the right size and the values are of the right types. + * + * This method does not contain any intelligence to override previously added overloads. + * However, the overload resolution engine will always use the last applicable overload it finds, + * so adding does have the effect of overriding. + */ + void add(const std::string &name, const types::Types ¶m_types, const FunctionImpl &impl); + + /** + * Resolves a function. + * Throws NameResolutionFailure if no function by the given name exists, + * OverloadResolutionFailure if no overload of the function exists for the given arguments, or otherwise + * returns the value returned by the function. + */ + [[nodiscard]] values::Value resolve(const std::string &name, const values::Values &args) const; +}; + + +//---------------// +// FunctionTable // +//---------------// + +/** + * Table of all overloads of all functions defined in the cQASM file. + */ +class FunctionTable { + std::unique_ptr> resolver; + public: FunctionTable(); ~FunctionTable(); @@ -102,25 +164,29 @@ class FunctionTable { * Registers a function. * Matching will be done case-sensitively. * The param_types variadic specifies the amount and types of the parameters that - * (this particular overload of) the function expects. - * The C++ implementation of the function can assume that - * the value list it gets is of the right size and the values are of the right types. + * this particular overload of the function expects. + * value should be of type values::FunctionRef. * * This method does not contain any intelligence to override previously added overloads. * However, the overload resolution engine will always use the last applicable overload it finds, * so adding does have the effect of overriding. */ - void add(const std::string &name, const types::Types ¶m_types, const FunctionImpl &impl); + void add(const std::string &name, const types::Types ¶m_types, const values::Value &value); /** - * Calls a function. + * Resolves a function. * Throws NameResolutionFailure if no function by the given name exists, * OverloadResolutionFailure if no overload of the function exists for the given arguments, or otherwise * returns the value returned by the function. */ - [[nodiscard]] values::Value call(const std::string &name, const values::Values &args) const; + [[nodiscard]] values::Value resolve(const std::string &name, const values::Values &args) const; }; + +//------------------// +// InstructionTable // +//------------------// + /** * Table of the supported instructions and their overloads. */ @@ -146,10 +212,7 @@ class InstructionTable { * OverloadResolutionFailure if no overload exists for the given arguments, or otherwise * returns the resolved instruction node. */ - [[nodiscard]] tree::One resolve( - const std::string &name, - const values::Values &args - ) const; + [[nodiscard]] tree::One resolve(const std::string &name, const values::Values &args) const; }; } // namespace cqasm::v3x::resolver diff --git a/include/v3x/cqasm-scope.hpp b/include/v3x/cqasm-scope.hpp new file mode 100644 index 000000000..ab48c9181 --- /dev/null +++ b/include/v3x/cqasm-scope.hpp @@ -0,0 +1,70 @@ +#pragma once + +#include "cqasm-tree.hpp" +#include "v3x/cqasm-resolver.hpp" +#include "v3x/cqasm-semantic-gen.hpp" + + +namespace cqasm::v3x::analyzer { + +/** + * Scope information. + */ +struct Scope { + /** + * The variables visible within this scope. + */ + resolver::VariableTable variable_table; + + /** + * The list of function implementations. + * That is, functions for which we have a C++ implementation. + */ + resolver::FunctionImplTable function_impl_table; + + /** + * The list of functions, other than function implementations. + * That is, functions defined in the cQASM file. + */ + resolver::FunctionTable function_table; + + /** + * The instructions visible within this scope. + * Instructions have a case-sensitively matched name, + * and a signature for the types of parameters they expect. + */ + resolver::InstructionTable instruction_table; + + /** + * The block associated with this scope. + */ + tree::One block; + + /** + * The list of variables declared in this scope. + */ + tree::Any variables; + + /** + * The list of functions defined in the global scope. + */ + tree::Any functions; + + Scope() = default; + Scope(const Scope &other) = default; + Scope(Scope &&other) noexcept = default; + Scope& operator=(const Scope &other) = default; + Scope& operator=(Scope &&other) noexcept = default; + + /** + * Creates a scope from a table of variables, functions, and instructions. + */ + Scope( + resolver::VariableTable variable_table, + resolver::FunctionImplTable function_impl_table, + resolver::FunctionTable function_table, + resolver::InstructionTable instruction_table, + tree::One block); +}; + +} // namespace cqasm::v3x::analyzer diff --git a/include/v3x/cqasm-semantic-helper.hpp b/include/v3x/cqasm-semantic-helper.hpp index c98a3da2d..ab7a01092 100644 --- a/include/v3x/cqasm-semantic-helper.hpp +++ b/include/v3x/cqasm-semantic-helper.hpp @@ -13,5 +13,6 @@ namespace cqasm::v3x::semantic { // It's possible to get rid of this kludge by merging the value (and type) trees into the semantic tree, // as probably should have been done initially, but a lot of refactoring would result. class Variable; +class Function; } // namespace cqasm::v3x::semantic diff --git a/include/v3x/cqasm-types.hpp b/include/v3x/cqasm-types.hpp index 40cc46e2c..7e3c50605 100644 --- a/include/v3x/cqasm-types.hpp +++ b/include/v3x/cqasm-types.hpp @@ -16,6 +16,19 @@ */ namespace cqasm::v3x::types { +constexpr const char *qubit_type_name = "qubit"; +constexpr const char *bit_type_name = "bit"; +constexpr const char *axis_type_name = "axis"; +constexpr const char *bool_type_name = "bool"; +constexpr const char *integer_type_name = "int"; +constexpr const char *float_type_name = "float"; +constexpr const char *complex_type_name = "complex"; +constexpr const char *qubit_array_type_name = "qubit array"; +constexpr const char *bit_array_type_name = "bit array"; +constexpr const char *bool_array_type_name = "bool array"; +constexpr const char *integer_array_type_name = "int array"; +constexpr const char *float_array_type_name = "float array"; + /** * A cQASM type. */ @@ -35,13 +48,13 @@ using Types = tree::Any; * - a = axis (x, y, or z) * - b = bool * - i = int - * - r = real + * - f = float * - c = complex * - V = qubit array * - W = bit array * - X = bool array * - Y = int array - * - Z = real array + * - Z = float array */ Types from_spec(const std::string &spec); diff --git a/include/v3x/cqasm-values.hpp b/include/v3x/cqasm-values.hpp index 4deae51f5..ab8116f9b 100644 --- a/include/v3x/cqasm-values.hpp +++ b/include/v3x/cqasm-values.hpp @@ -24,12 +24,12 @@ namespace cqasm::v3x::values { /** * A cQASM value, either known at compile-time or an expression for something only known at runtime. */ -using Value = tree::One; +using Value = tree::One; /** * Zero or more cQASM values. */ -using Values = tree::Any; +using Values = tree::Any; /** * Promotes a value of array of Type to a value of array of PromotedType. @@ -104,8 +104,8 @@ bool check_all_of_array_values(const Value &value, Pred&& pred) { return std::all_of(const_bool_array->value.begin(), const_bool_array->value.end(), pred); } else if (const auto &const_int_array = value->as_const_int_array()) { return std::all_of(const_int_array->value.begin(), const_int_array->value.end(), pred); - } else if (const auto &const_real_array = value->as_const_real_array()) { - return std::all_of(const_real_array->value.begin(), const_real_array->value.end(), pred); + } else if (const auto &const_float_array = value->as_const_float_array()) { + return std::all_of(const_float_array->value.begin(), const_float_array->value.end(), pred); } else { return false; } diff --git a/res/v1x/parsing/grammar/function/ast.golden.txt b/res/v1x/parsing/grammar/function/ast.golden.txt index 4c6e2475b..a87e4b847 100644 --- a/res/v1x/parsing/grammar/function/ast.golden.txt +++ b/res/v1x/parsing/grammar/function/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:36 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..36 items: [ diff --git a/res/v1x/parsing/grammar/index_positive/ast.golden.txt b/res/v1x/parsing/grammar/index_positive/ast.golden.txt index 67ba38a99..56523163a 100644 --- a/res/v1x/parsing/grammar/index_positive/ast.golden.txt +++ b/res/v1x/parsing/grammar/index_positive/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:59 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..59 items: [ diff --git a/res/v1x/parsing/grammar/instructions/ast.golden.txt b/res/v1x/parsing/grammar/instructions/ast.golden.txt index d3f4788de..59ffe1f5b 100644 --- a/res/v1x/parsing/grammar/instructions/ast.golden.txt +++ b/res/v1x/parsing/grammar/instructions/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..18:1 ) > statements: < - StatementList( # input.cq:2:1..18:60 + StatementList( # input.cq:2:10..18:1 items: [ Bundle( # input.cq:5:1..20 items: [ @@ -311,7 +311,7 @@ Program( # input.cq:1:1..18:1 ) ] ) - Bundle( # input.cq:14:1..17:26 + Bundle( # input.cq:14:1..17:15 items: [ Instruction( # input.cq:15:5..26 name: < diff --git a/res/v1x/parsing/grammar/instructions/semantic.1.0.golden.txt b/res/v1x/parsing/grammar/instructions/semantic.1.0.golden.txt index e9287cba0..fc074976c 100644 --- a/res/v1x/parsing/grammar/instructions/semantic.1.0.golden.txt +++ b/res/v1x/parsing/grammar/instructions/semantic.1.0.golden.txt @@ -159,7 +159,7 @@ Program( # input.cq:1:1..18:1 ) ] ) - Bundle( # input.cq:14:1..17:26 + Bundle( # input.cq:14:1..17:15 items: [ Instruction( # input.cq:15:5..26 instruction: x(qubit reference) diff --git a/res/v1x/parsing/grammar/instructions/semantic.1.1.golden.txt b/res/v1x/parsing/grammar/instructions/semantic.1.1.golden.txt index b6dd834db..2348e6c16 100644 --- a/res/v1x/parsing/grammar/instructions/semantic.1.1.golden.txt +++ b/res/v1x/parsing/grammar/instructions/semantic.1.1.golden.txt @@ -159,7 +159,7 @@ Program( # input.cq:1:1..18:1 ) ] ) - Bundle( # input.cq:14:1..17:26 + Bundle( # input.cq:14:1..17:15 items: [ Instruction( # input.cq:15:5..26 instruction: x(qubit reference) diff --git a/res/v1x/parsing/grammar/instructions/semantic.1.2.golden.txt b/res/v1x/parsing/grammar/instructions/semantic.1.2.golden.txt index 4a678e25b..51b636e7a 100644 --- a/res/v1x/parsing/grammar/instructions/semantic.1.2.golden.txt +++ b/res/v1x/parsing/grammar/instructions/semantic.1.2.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..18:1 bundles: [] annotations: [] body: < - Block( # input.cq:5:1..17:60 + Block( # input.cq:5:1..17:15 statements: [ BundleExt( # input.cq:5:1..20 items: [ @@ -163,7 +163,7 @@ Program( # input.cq:1:1..18:1 ) ] ) - BundleExt( # input.cq:14:1..17:26 + BundleExt( # input.cq:14:1..17:15 items: [ Instruction( # input.cq:15:5..26 instruction: x(qubit reference) diff --git a/res/v1x/parsing/grammar/map/ast.golden.txt b/res/v1x/parsing/grammar/map/ast.golden.txt index 1b5776585..ee6006c68 100644 --- a/res/v1x/parsing/grammar/map/ast.golden.txt +++ b/res/v1x/parsing/grammar/map/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..6:1 ) > statements: < - StatementList( # input.cq:2:1..6:50 + StatementList( # input.cq:2:10..6:1 items: [ Mapping( # input.cq:4:1..26 alias: < diff --git a/res/v1x/parsing/grammar/matrix/ast.golden.txt b/res/v1x/parsing/grammar/matrix/ast.golden.txt index a308a6923..4faf23778 100644 --- a/res/v1x/parsing/grammar/matrix/ast.golden.txt +++ b/res/v1x/parsing/grammar/matrix/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:58 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..58 items: [ diff --git a/res/v1x/parsing/grammar/operator/ast.golden.txt b/res/v1x/parsing/grammar/operator/ast.golden.txt index 5b592e5a5..278b1d0bd 100644 --- a/res/v1x/parsing/grammar/operator/ast.golden.txt +++ b/res/v1x/parsing/grammar/operator/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..11:1 ) > statements: < - StatementList( # input.cq:2:1..11:148 + StatementList( # input.cq:2:10..11:1 items: [ Bundle( # input.cq:4:1..117 items: [ diff --git a/res/v1x/parsing/grammar/operator/semantic.1.2.golden.txt b/res/v1x/parsing/grammar/operator/semantic.1.2.golden.txt index dc1ba9faf..0d7bc8a7e 100644 --- a/res/v1x/parsing/grammar/operator/semantic.1.2.golden.txt +++ b/res/v1x/parsing/grammar/operator/semantic.1.2.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..11:1 bundles: [] annotations: [] body: < - Block( # input.cq:4:1..10:148 + Block( # input.cq:4:1..10:57 statements: [ BundleExt( # input.cq:4:1..117 items: [ diff --git a/res/v1x/parsing/grammar/subcircuit_default/ast.golden.txt b/res/v1x/parsing/grammar/subcircuit_default/ast.golden.txt index f7e21dd32..db51a7f31 100644 --- a/res/v1x/parsing/grammar/subcircuit_default/ast.golden.txt +++ b/res/v1x/parsing/grammar/subcircuit_default/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..15:1 ) > statements: < - StatementList( # input.cq:2:1..15:38 + StatementList( # input.cq:2:10..15:1 items: [ Bundle( # input.cq:4:1..7 items: [ diff --git a/res/v1x/parsing/grammar/subcircuit_default/semantic.1.2.golden.txt b/res/v1x/parsing/grammar/subcircuit_default/semantic.1.2.golden.txt index 57a63250c..0983a0d8a 100644 --- a/res/v1x/parsing/grammar/subcircuit_default/semantic.1.2.golden.txt +++ b/res/v1x/parsing/grammar/subcircuit_default/semantic.1.2.golden.txt @@ -57,7 +57,7 @@ Program( # input.cq:1:1..15:1 ) ] body: < - Block( # input.cq:6:1..8:19 + Block( # input.cq:6:1..8:7 statements: [ BundleExt( # input.cq:8:1..7 items: [ @@ -104,7 +104,7 @@ Program( # input.cq:1:1..15:1 ) ] body: < - Block( # input.cq:10:1..14:38 + Block( # input.cq:10:1..14:7 statements: [ BundleExt( # input.cq:12:1..7 items: [ diff --git a/res/v1x/parsing/grammar/subcircuit_no_default/ast.golden.txt b/res/v1x/parsing/grammar/subcircuit_no_default/ast.golden.txt index 7472124c3..9c845887c 100644 --- a/res/v1x/parsing/grammar/subcircuit_no_default/ast.golden.txt +++ b/res/v1x/parsing/grammar/subcircuit_no_default/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..11:1 ) > statements: < - StatementList( # input.cq:2:1..11:21 + StatementList( # input.cq:2:10..11:1 items: [ Subcircuit( # input.cq:4:1..19 name: < diff --git a/res/v1x/parsing/grammar/subcircuit_no_default/semantic.1.2.golden.txt b/res/v1x/parsing/grammar/subcircuit_no_default/semantic.1.2.golden.txt index 9369b8c3d..15fe759bf 100644 --- a/res/v1x/parsing/grammar/subcircuit_no_default/semantic.1.2.golden.txt +++ b/res/v1x/parsing/grammar/subcircuit_no_default/semantic.1.2.golden.txt @@ -21,7 +21,7 @@ Program( # input.cq:1:1..11:1 ) ] body: < - Block( # input.cq:4:1..6:19 + Block( # input.cq:4:1..6:7 statements: [ BundleExt( # input.cq:6:1..7 items: [ diff --git a/res/v1x/parsing/lexer/comments_positive/ast.golden.txt b/res/v1x/parsing/lexer/comments_positive/ast.golden.txt index 9a93fc5eb..dfff96217 100644 --- a/res/v1x/parsing/lexer/comments_positive/ast.golden.txt +++ b/res/v1x/parsing/lexer/comments_positive/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..11:1 ) > statements: < - StatementList( # input.cq:2:1..11:40 + StatementList( # input.cq:2:10..11:1 items: [ Bundle( # input.cq:5:1..7:6 items: [ @@ -23,7 +23,7 @@ Program( # input.cq:1:1..11:1 > condition: - operands: < - ExpressionList( # input.cq:5:3..7:7 + ExpressionList( # input.cq:5:3..7:6 items: [ Index( # input.cq:5:3..7 expr: < @@ -45,7 +45,7 @@ Program( # input.cq:1:1..11:1 ) > ) - MatrixLiteral( # input.cq:5:1..7:6 + MatrixLiteral( # input.cq:5:9..7:6 rows: [ ExpressionList( # input.cq:6:1..5 items: [ diff --git a/res/v1x/parsing/lexer/comments_positive/semantic.1.0.golden.txt b/res/v1x/parsing/lexer/comments_positive/semantic.1.0.golden.txt index 97844d749..9b1ebd683 100644 --- a/res/v1x/parsing/lexer/comments_positive/semantic.1.0.golden.txt +++ b/res/v1x/parsing/lexer/comments_positive/semantic.1.0.golden.txt @@ -31,7 +31,7 @@ Program( # input.cq:1:1..11:1 ) ] ) - ConstComplexMatrix( # input.cq:5:1..7:6 + ConstComplexMatrix( # input.cq:5:9..7:6 value: [(1,0), (0,0); (2,0), (3,0)] ) ] diff --git a/res/v1x/parsing/lexer/comments_positive/semantic.1.1.golden.txt b/res/v1x/parsing/lexer/comments_positive/semantic.1.1.golden.txt index 77245b69b..2de227a5d 100644 --- a/res/v1x/parsing/lexer/comments_positive/semantic.1.1.golden.txt +++ b/res/v1x/parsing/lexer/comments_positive/semantic.1.1.golden.txt @@ -31,7 +31,7 @@ Program( # input.cq:1:1..11:1 ) ] ) - ConstComplexMatrix( # input.cq:5:1..7:6 + ConstComplexMatrix( # input.cq:5:9..7:6 value: [(1,0), (0,0); (2,0), (3,0)] ) ] diff --git a/res/v1x/parsing/lexer/comments_positive/semantic.1.2.golden.txt b/res/v1x/parsing/lexer/comments_positive/semantic.1.2.golden.txt index 90fe21611..f64de4e71 100644 --- a/res/v1x/parsing/lexer/comments_positive/semantic.1.2.golden.txt +++ b/res/v1x/parsing/lexer/comments_positive/semantic.1.2.golden.txt @@ -35,7 +35,7 @@ Program( # input.cq:1:1..11:1 ) ] ) - ConstComplexMatrix( # input.cq:5:1..7:6 + ConstComplexMatrix( # input.cq:5:9..7:6 value: [(1,0), (0,0); (2,0), (3,0)] ) ] diff --git a/res/v1x/parsing/lexer/json_positive/ast.golden.txt b/res/v1x/parsing/lexer/json_positive/ast.golden.txt index 770009660..f699bd922 100644 --- a/res/v1x/parsing/lexer/json_positive/ast.golden.txt +++ b/res/v1x/parsing/lexer/json_positive/ast.golden.txt @@ -11,11 +11,11 @@ Program( # input.cq:1:1..12:1 ) > statements: < - StatementList( # input.cq:2:1..12:4 + StatementList( # input.cq:2:10..12:1 items: [ Bundle( # input.cq:4:1..11:4 items: [ - Instruction( # input.cq:4:1..11:8 + Instruction( # input.cq:4:1..11:4 name: < Identifier( # input.cq:4:1..8 name: display @@ -28,7 +28,7 @@ Program( # input.cq:1:1..12:1 ) > annotations: [ - AnnotationData( # input.cq:4:10..11:19 + AnnotationData( # input.cq:4:10..11:4 interface: < Identifier( # input.cq:4:10..14 name: test diff --git a/res/v1x/parsing/lexer/json_positive/semantic.1.0.golden.txt b/res/v1x/parsing/lexer/json_positive/semantic.1.0.golden.txt index 70f7b6380..8da0d375e 100644 --- a/res/v1x/parsing/lexer/json_positive/semantic.1.0.golden.txt +++ b/res/v1x/parsing/lexer/json_positive/semantic.1.0.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..12:1 bundles: [ Bundle( # input.cq:4:1..11:4 items: [ - Instruction( # input.cq:4:1..11:8 + Instruction( # input.cq:4:1..11:4 instruction: display() name: display condition: < @@ -25,7 +25,7 @@ Program( # input.cq:1:1..12:1 > operands: [] annotations: [ - AnnotationData( # input.cq:4:10..11:19 + AnnotationData( # input.cq:4:10..11:4 interface: test operation: test operands: [ diff --git a/res/v1x/parsing/lexer/json_positive/semantic.1.1.golden.txt b/res/v1x/parsing/lexer/json_positive/semantic.1.1.golden.txt index fdfecbf1b..0bf99ebc3 100644 --- a/res/v1x/parsing/lexer/json_positive/semantic.1.1.golden.txt +++ b/res/v1x/parsing/lexer/json_positive/semantic.1.1.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..12:1 bundles: [ Bundle( # input.cq:4:1..11:4 items: [ - Instruction( # input.cq:4:1..11:8 + Instruction( # input.cq:4:1..11:4 instruction: display() name: display condition: < @@ -25,7 +25,7 @@ Program( # input.cq:1:1..12:1 > operands: [] annotations: [ - AnnotationData( # input.cq:4:10..11:19 + AnnotationData( # input.cq:4:10..11:4 interface: test operation: test operands: [ diff --git a/res/v1x/parsing/lexer/json_positive/semantic.1.2.golden.txt b/res/v1x/parsing/lexer/json_positive/semantic.1.2.golden.txt index cc4089e00..4fa528e7b 100644 --- a/res/v1x/parsing/lexer/json_positive/semantic.1.2.golden.txt +++ b/res/v1x/parsing/lexer/json_positive/semantic.1.2.golden.txt @@ -19,7 +19,7 @@ Program( # input.cq:1:1..12:1 statements: [ BundleExt( # input.cq:4:1..11:4 items: [ - Instruction( # input.cq:4:1..11:8 + Instruction( # input.cq:4:1..11:4 instruction: display() name: display condition: < @@ -29,7 +29,7 @@ Program( # input.cq:1:1..12:1 > operands: [] annotations: [ - AnnotationData( # input.cq:4:10..11:19 + AnnotationData( # input.cq:4:10..11:4 interface: test operation: test operands: [ diff --git a/res/v1x/parsing/lexer/newlines/ast.golden.txt b/res/v1x/parsing/lexer/newlines/ast.golden.txt index b2cd0c3a6..948b7b9f7 100644 --- a/res/v1x/parsing/lexer/newlines/ast.golden.txt +++ b/res/v1x/parsing/lexer/newlines/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..38:1 ) > statements: < - StatementList( # input.cq:2:1..38:33 + StatementList( # input.cq:2:10..38:1 items: [ Bundle( # input.cq:5:1..7 items: [ @@ -183,7 +183,7 @@ Program( # input.cq:1:1..38:1 > condition: - operands: < - ExpressionList( # input.cq:17:3..20:7 + ExpressionList( # input.cq:17:3..20:2 items: [ Index( # input.cq:17:3..7 expr: < @@ -205,7 +205,7 @@ Program( # input.cq:1:1..38:1 ) > ) - MatrixLiteral( # input.cq:17:5..20:9 + MatrixLiteral( # input.cq:17:9..20:2 rows: [ ExpressionList( # input.cq:18:5..9 items: [ @@ -465,7 +465,7 @@ Program( # input.cq:1:1..38:1 ) Bundle( # input.cq:35:1..37:4 items: [ - Instruction( # input.cq:35:1..37:8 + Instruction( # input.cq:35:1..37:4 name: < Identifier( # input.cq:35:1..8 name: display @@ -478,7 +478,7 @@ Program( # input.cq:1:1..38:1 ) > annotations: [ - AnnotationData( # input.cq:35:10..37:33 + AnnotationData( # input.cq:35:10..37:4 interface: < Identifier( # input.cq:35:10..23 name: an_annotation diff --git a/res/v1x/parsing/lexer/newlines/semantic.1.0.golden.txt b/res/v1x/parsing/lexer/newlines/semantic.1.0.golden.txt index 3dc75733b..64e9c1f47 100644 --- a/res/v1x/parsing/lexer/newlines/semantic.1.0.golden.txt +++ b/res/v1x/parsing/lexer/newlines/semantic.1.0.golden.txt @@ -127,7 +127,7 @@ Program( # input.cq:1:1..38:1 ) ] ) - ConstComplexMatrix( # input.cq:17:5..20:9 + ConstComplexMatrix( # input.cq:17:9..20:2 value: [(0,0), (1,0); (1,0), (0,0)] ) ] @@ -242,7 +242,7 @@ Program( # input.cq:1:1..38:1 ) Bundle( # input.cq:35:1..37:4 items: [ - Instruction( # input.cq:35:1..37:8 + Instruction( # input.cq:35:1..37:4 instruction: display() name: display condition: < @@ -252,7 +252,7 @@ Program( # input.cq:1:1..38:1 > operands: [] annotations: [ - AnnotationData( # input.cq:35:10..37:33 + AnnotationData( # input.cq:35:10..37:4 interface: an_annotation operation: with_json operands: [ diff --git a/res/v1x/parsing/lexer/newlines/semantic.1.1.golden.txt b/res/v1x/parsing/lexer/newlines/semantic.1.1.golden.txt index 8a3ec8b19..f8886f667 100644 --- a/res/v1x/parsing/lexer/newlines/semantic.1.1.golden.txt +++ b/res/v1x/parsing/lexer/newlines/semantic.1.1.golden.txt @@ -127,7 +127,7 @@ Program( # input.cq:1:1..38:1 ) ] ) - ConstComplexMatrix( # input.cq:17:5..20:9 + ConstComplexMatrix( # input.cq:17:9..20:2 value: [(0,0), (1,0); (1,0), (0,0)] ) ] @@ -242,7 +242,7 @@ Program( # input.cq:1:1..38:1 ) Bundle( # input.cq:35:1..37:4 items: [ - Instruction( # input.cq:35:1..37:8 + Instruction( # input.cq:35:1..37:4 instruction: display() name: display condition: < @@ -252,7 +252,7 @@ Program( # input.cq:1:1..38:1 > operands: [] annotations: [ - AnnotationData( # input.cq:35:10..37:33 + AnnotationData( # input.cq:35:10..37:4 interface: an_annotation operation: with_json operands: [ diff --git a/res/v1x/parsing/lexer/newlines/semantic.1.2.golden.txt b/res/v1x/parsing/lexer/newlines/semantic.1.2.golden.txt index 9092b86b2..bf1410adf 100644 --- a/res/v1x/parsing/lexer/newlines/semantic.1.2.golden.txt +++ b/res/v1x/parsing/lexer/newlines/semantic.1.2.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..38:1 bundles: [] annotations: [] body: < - Block( # input.cq:5:1..37:33 + Block( # input.cq:5:1..37:4 statements: [ BundleExt( # input.cq:5:1..7 items: [ @@ -131,7 +131,7 @@ Program( # input.cq:1:1..38:1 ) ] ) - ConstComplexMatrix( # input.cq:17:5..20:9 + ConstComplexMatrix( # input.cq:17:9..20:2 value: [(0,0), (1,0); (1,0), (0,0)] ) ] @@ -246,7 +246,7 @@ Program( # input.cq:1:1..38:1 ) BundleExt( # input.cq:35:1..37:4 items: [ - Instruction( # input.cq:35:1..37:8 + Instruction( # input.cq:35:1..37:4 instruction: display() name: display condition: < @@ -256,7 +256,7 @@ Program( # input.cq:1:1..38:1 > operands: [] annotations: [ - AnnotationData( # input.cq:35:10..37:33 + AnnotationData( # input.cq:35:10..37:4 interface: an_annotation operation: with_json operands: [ diff --git a/res/v1x/parsing/lexer/numbers_positive/ast.golden.txt b/res/v1x/parsing/lexer/numbers_positive/ast.golden.txt index 5ca9f4aa5..5f5c353ef 100644 --- a/res/v1x/parsing/lexer/numbers_positive/ast.golden.txt +++ b/res/v1x/parsing/lexer/numbers_positive/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:68 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..68 items: [ diff --git a/res/v1x/parsing/lexer/string_positive/ast.golden.txt b/res/v1x/parsing/lexer/string_positive/ast.golden.txt index cd7892334..30418f05e 100644 --- a/res/v1x/parsing/lexer/string_positive/ast.golden.txt +++ b/res/v1x/parsing/lexer/string_positive/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..6:1 ) > statements: < - StatementList( # input.cq:2:1..6:11 + StatementList( # input.cq:2:10..6:1 items: [ Bundle( # input.cq:4:1..5:11 items: [ @@ -28,7 +28,7 @@ Program( # input.cq:1:1..6:1 ) > annotations: [ - AnnotationData( # input.cq:4:10..5:19 + AnnotationData( # input.cq:4:10..5:11 interface: < Identifier( # input.cq:4:10..14 name: test @@ -40,7 +40,7 @@ Program( # input.cq:1:1..6:1 ) > operands: < - ExpressionList( # input.cq:4:20..5:46 + ExpressionList( # input.cq:4:20..5:10 items: [ StringLiteral( # input.cq:4:20..26 value: test diff --git a/res/v1x/parsing/lexer/string_positive/semantic.1.0.golden.txt b/res/v1x/parsing/lexer/string_positive/semantic.1.0.golden.txt index ed625c874..d3b521655 100644 --- a/res/v1x/parsing/lexer/string_positive/semantic.1.0.golden.txt +++ b/res/v1x/parsing/lexer/string_positive/semantic.1.0.golden.txt @@ -25,7 +25,7 @@ Program( # input.cq:1:1..6:1 > operands: [] annotations: [ - AnnotationData( # input.cq:4:10..5:19 + AnnotationData( # input.cq:4:10..5:11 interface: test operation: test operands: [ diff --git a/res/v1x/parsing/lexer/string_positive/semantic.1.1.golden.txt b/res/v1x/parsing/lexer/string_positive/semantic.1.1.golden.txt index 14e8cff7a..7099e2901 100644 --- a/res/v1x/parsing/lexer/string_positive/semantic.1.1.golden.txt +++ b/res/v1x/parsing/lexer/string_positive/semantic.1.1.golden.txt @@ -25,7 +25,7 @@ Program( # input.cq:1:1..6:1 > operands: [] annotations: [ - AnnotationData( # input.cq:4:10..5:19 + AnnotationData( # input.cq:4:10..5:11 interface: test operation: test operands: [ diff --git a/res/v1x/parsing/lexer/string_positive/semantic.1.2.golden.txt b/res/v1x/parsing/lexer/string_positive/semantic.1.2.golden.txt index 5eafa7ec6..ff5839147 100644 --- a/res/v1x/parsing/lexer/string_positive/semantic.1.2.golden.txt +++ b/res/v1x/parsing/lexer/string_positive/semantic.1.2.golden.txt @@ -29,7 +29,7 @@ Program( # input.cq:1:1..6:1 > operands: [] annotations: [ - AnnotationData( # input.cq:4:10..5:19 + AnnotationData( # input.cq:4:10..5:11 interface: test operation: test operands: [ diff --git a/res/v1x/parsing/misc/barriers_not_ok_1/ast.golden.txt b/res/v1x/parsing/misc/barriers_not_ok_1/ast.golden.txt index 09e88cf9e..2ef56c732 100644 --- a/res/v1x/parsing/misc/barriers_not_ok_1/ast.golden.txt +++ b/res/v1x/parsing/misc/barriers_not_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:22 + StatementList( # input.cq:2:9..9:1 items: [ Bundle( # input.cq:4:1..7 items: [ diff --git a/res/v1x/parsing/misc/barriers_not_ok_2/ast.golden.txt b/res/v1x/parsing/misc/barriers_not_ok_2/ast.golden.txt index 5d27539e3..18256f1de 100644 --- a/res/v1x/parsing/misc/barriers_not_ok_2/ast.golden.txt +++ b/res/v1x/parsing/misc/barriers_not_ok_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..7:1 ) > statements: < - StatementList( # input.cq:2:1..7:19 + StatementList( # input.cq:2:9..7:1 items: [ Bundle( # input.cq:4:1..7 items: [ diff --git a/res/v1x/parsing/misc/barriers_ok_1/ast.golden.txt b/res/v1x/parsing/misc/barriers_ok_1/ast.golden.txt index 90fa1380a..bb35e2942 100644 --- a/res/v1x/parsing/misc/barriers_ok_1/ast.golden.txt +++ b/res/v1x/parsing/misc/barriers_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..10:1 ) > statements: < - StatementList( # input.cq:2:1..10:15 + StatementList( # input.cq:2:9..10:1 items: [ Bundle( # input.cq:4:1..7 items: [ diff --git a/res/v1x/parsing/misc/barriers_ok_1/semantic.1.2.golden.txt b/res/v1x/parsing/misc/barriers_ok_1/semantic.1.2.golden.txt index 36a29bba6..3fb4fd502 100644 --- a/res/v1x/parsing/misc/barriers_ok_1/semantic.1.2.golden.txt +++ b/res/v1x/parsing/misc/barriers_ok_1/semantic.1.2.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..10:1 bundles: [] annotations: [] body: < - Block( # input.cq:4:1..9:15 + Block( # input.cq:4:1..9:7 statements: [ BundleExt( # input.cq:4:1..7 items: [ diff --git a/res/v1x/parsing/misc/grover/ast.golden.txt b/res/v1x/parsing/misc/grover/ast.golden.txt index 17210bd86..e82687ebc 100644 --- a/res/v1x/parsing/misc/grover/ast.golden.txt +++ b/res/v1x/parsing/misc/grover/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..56:1 ) > statements: < - StatementList( # input.cq:3:1..56:53 + StatementList( # input.cq:3:9..56:1 items: [ Mapping( # input.cq:5:1..16 alias: < diff --git a/res/v1x/parsing/misc/grover/semantic.1.2.golden.txt b/res/v1x/parsing/misc/grover/semantic.1.2.golden.txt index 6d14d5ef9..9d89a8930 100644 --- a/res/v1x/parsing/misc/grover/semantic.1.2.golden.txt +++ b/res/v1x/parsing/misc/grover/semantic.1.2.golden.txt @@ -151,7 +151,7 @@ Program( # input.cq:1:1..56:1 bundles: [] annotations: [] body: < - Block( # input.cq:14:1..47:42 + Block( # input.cq:14:1..47:12 statements: [ BundleExt( # input.cq:20:5..11 items: [ @@ -1193,7 +1193,7 @@ Program( # input.cq:1:1..56:1 bundles: [] annotations: [] body: < - Block( # input.cq:50:1..53:19 + Block( # input.cq:50:1..53:12 statements: [ BundleExt( # input.cq:51:5..13 items: [ diff --git a/res/v1x/parsing/misc/wait_not_ok_1/ast.golden.txt b/res/v1x/parsing/misc/wait_not_ok_1/ast.golden.txt index 96c5aa02d..a02a1b1a9 100644 --- a/res/v1x/parsing/misc/wait_not_ok_1/ast.golden.txt +++ b/res/v1x/parsing/misc/wait_not_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:7 + StatementList( # input.cq:2:9..5:1 items: [ Bundle( # input.cq:4:1..7 items: [ diff --git a/res/v1x/parsing/misc/wait_ok_1/ast.golden.txt b/res/v1x/parsing/misc/wait_ok_1/ast.golden.txt index 5bdb4acbc..455102de7 100644 --- a/res/v1x/parsing/misc/wait_ok_1/ast.golden.txt +++ b/res/v1x/parsing/misc/wait_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..11:1 ) > statements: < - StatementList( # input.cq:2:1..11:20 + StatementList( # input.cq:2:9..11:1 items: [ Mapping( # input.cq:4:1..14 alias: < diff --git a/res/v1x/parsing/paper/example1/ast.golden.txt b/res/v1x/parsing/paper/example1/ast.golden.txt index ca45c8b2f..49b506cc4 100644 --- a/res/v1x/parsing/paper/example1/ast.golden.txt +++ b/res/v1x/parsing/paper/example1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..14:1 ) > statements: < - StatementList( # input.cq:3:1..14:15 + StatementList( # input.cq:3:9..14:1 items: [ Bundle( # input.cq:6:1..7 items: [ diff --git a/res/v1x/parsing/paper/example1/semantic.1.2.golden.txt b/res/v1x/parsing/paper/example1/semantic.1.2.golden.txt index 37cc76464..54c9f240f 100644 --- a/res/v1x/parsing/paper/example1/semantic.1.2.golden.txt +++ b/res/v1x/parsing/paper/example1/semantic.1.2.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..14:1 bundles: [] annotations: [] body: < - Block( # input.cq:6:1..13:15 + Block( # input.cq:6:1..13:13 statements: [ BundleExt( # input.cq:6:1..7 items: [ diff --git a/res/v1x/parsing/paper/example2_fixed/ast.golden.txt b/res/v1x/parsing/paper/example2_fixed/ast.golden.txt index 8fe07bc67..090ecdcca 100644 --- a/res/v1x/parsing/paper/example2_fixed/ast.golden.txt +++ b/res/v1x/parsing/paper/example2_fixed/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..23:1 ) > statements: < - StatementList( # input.cq:3:1..23:24 + StatementList( # input.cq:3:9..23:1 items: [ Mapping( # input.cq:6:1..14 alias: < diff --git a/res/v1x/parsing/paper/example2_original/ast.golden.txt b/res/v1x/parsing/paper/example2_original/ast.golden.txt index bbbedce9d..c108f6de8 100644 --- a/res/v1x/parsing/paper/example2_original/ast.golden.txt +++ b/res/v1x/parsing/paper/example2_original/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..23:1 ) > statements: < - StatementList( # input.cq:3:1..23:24 + StatementList( # input.cq:3:9..23:1 items: [ Mapping( # input.cq:6:1..14 alias: < diff --git a/res/v1x/parsing/paper/example3_actual_syntax/ast.golden.txt b/res/v1x/parsing/paper/example3_actual_syntax/ast.golden.txt index 2281d2766..8f8995929 100644 --- a/res/v1x/parsing/paper/example3_actual_syntax/ast.golden.txt +++ b/res/v1x/parsing/paper/example3_actual_syntax/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..18:1 ) > statements: < - StatementList( # input.cq:2:1..18:18 + StatementList( # input.cq:2:9..18:1 items: [ Bundle( # input.cq:4:1..7 items: [ diff --git a/res/v1x/parsing/paper/example3_actual_syntax/semantic.1.2.golden.txt b/res/v1x/parsing/paper/example3_actual_syntax/semantic.1.2.golden.txt index 29ccfa111..803e10f95 100644 --- a/res/v1x/parsing/paper/example3_actual_syntax/semantic.1.2.golden.txt +++ b/res/v1x/parsing/paper/example3_actual_syntax/semantic.1.2.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..18:1 bundles: [] annotations: [] body: < - Block( # input.cq:4:1..17:18 + Block( # input.cq:4:1..17:9 statements: [ BundleExt( # input.cq:4:1..7 items: [ diff --git a/res/v1x/parsing/paper/example3_original/ast.golden.txt b/res/v1x/parsing/paper/example3_original/ast.golden.txt index 6d7227524..b1d04c684 100644 --- a/res/v1x/parsing/paper/example3_original/ast.golden.txt +++ b/res/v1x/parsing/paper/example3_original/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..18:1 ) > statements: < - StatementList( # input.cq:2:1..18:24 + StatementList( # input.cq:2:9..18:1 items: [ Bundle( # input.cq:4:1..7 items: [ diff --git a/res/v1x/parsing/paper/example4/ast.golden.txt b/res/v1x/parsing/paper/example4/ast.golden.txt index 5fd2e2d33..da11dc6db 100644 --- a/res/v1x/parsing/paper/example4/ast.golden.txt +++ b/res/v1x/parsing/paper/example4/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..18:1 ) > statements: < - StatementList( # input.cq:3:1..18:29 + StatementList( # input.cq:3:9..18:1 items: [ Bundle( # input.cq:6:1..7 items: [ diff --git a/res/v1x/parsing/paper/example5/ast.golden.txt b/res/v1x/parsing/paper/example5/ast.golden.txt index 280edf0b0..1caa66559 100644 --- a/res/v1x/parsing/paper/example5/ast.golden.txt +++ b/res/v1x/parsing/paper/example5/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..11:1 ) > statements: < - StatementList( # input.cq:2:1..11:47 + StatementList( # input.cq:2:9..11:1 items: [ Bundle( # input.cq:4:1..44 items: [ diff --git a/res/v1x/parsing/paper/example5/semantic.1.2.golden.txt b/res/v1x/parsing/paper/example5/semantic.1.2.golden.txt index 79e623b1c..e28a850a8 100644 --- a/res/v1x/parsing/paper/example5/semantic.1.2.golden.txt +++ b/res/v1x/parsing/paper/example5/semantic.1.2.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..11:1 bundles: [] annotations: [] body: < - Block( # input.cq:4:1..10:47 + Block( # input.cq:4:1..10:16 statements: [ BundleExt( # input.cq:4:1..44 items: [ diff --git a/res/v1x/parsing/paper/example6/ast.golden.txt b/res/v1x/parsing/paper/example6/ast.golden.txt index 04d9f46cf..8d81e2b7c 100644 --- a/res/v1x/parsing/paper/example6/ast.golden.txt +++ b/res/v1x/parsing/paper/example6/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..53:1 ) > statements: < - StatementList( # input.cq:4:1..53:54 + StatementList( # input.cq:4:9..53:1 items: [ Mapping( # input.cq:6:1..16 alias: < diff --git a/res/v1x/parsing/paper/example6/semantic.1.2.golden.txt b/res/v1x/parsing/paper/example6/semantic.1.2.golden.txt index 46f7b4655..bb0e4fd33 100644 --- a/res/v1x/parsing/paper/example6/semantic.1.2.golden.txt +++ b/res/v1x/parsing/paper/example6/semantic.1.2.golden.txt @@ -151,7 +151,7 @@ Program( # input.cq:1:1..53:1 bundles: [] annotations: [] body: < - Block( # input.cq:15:2..46:42 + Block( # input.cq:15:2..46:12 statements: [ BundleExt( # input.cq:20:5..11 items: [ @@ -1193,7 +1193,7 @@ Program( # input.cq:1:1..53:1 bundles: [] annotations: [] body: < - Block( # input.cq:49:1..52:19 + Block( # input.cq:49:1..52:12 statements: [ BundleExt( # input.cq:50:5..13 items: [ diff --git a/res/v1x/parsing/paper/example7_actual_syntax/ast.golden.txt b/res/v1x/parsing/paper/example7_actual_syntax/ast.golden.txt index ea64ec0c9..a353bc27d 100644 --- a/res/v1x/parsing/paper/example7_actual_syntax/ast.golden.txt +++ b/res/v1x/parsing/paper/example7_actual_syntax/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..35:1 ) > statements: < - StatementList( # input.cq:3:1..35:47 + StatementList( # input.cq:3:9..35:1 items: [ Bundle( # input.cq:6:1..16 items: [ diff --git a/res/v1x/parsing/paper/example7_actual_syntax/semantic.1.2.golden.txt b/res/v1x/parsing/paper/example7_actual_syntax/semantic.1.2.golden.txt index 2b8c3091e..4a85df696 100644 --- a/res/v1x/parsing/paper/example7_actual_syntax/semantic.1.2.golden.txt +++ b/res/v1x/parsing/paper/example7_actual_syntax/semantic.1.2.golden.txt @@ -43,7 +43,7 @@ Program( # input.cq:1:1..35:1 bundles: [] annotations: [] body: < - Block( # input.cq:10:1..23:47 + Block( # input.cq:10:1..23:33 statements: [ BundleExt( # input.cq:12:5..18 items: [ diff --git a/res/v1x/parsing/semantic/break_not_ok_1/ast.golden.txt b/res/v1x/parsing/semantic/break_not_ok_1/ast.golden.txt index abbca678f..bd34b59e3 100644 --- a/res/v1x/parsing/semantic/break_not_ok_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/break_not_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -44,7 +44,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:10 + StatementList( # input.cq:6:12..8:2 items: [ BreakStatement( # input.cq:7:5..10 annotations: [] diff --git a/res/v1x/parsing/semantic/break_not_ok_2/ast.golden.txt b/res/v1x/parsing/semantic/break_not_ok_2/ast.golden.txt index d87055fb6..f6e31f07c 100644 --- a/res/v1x/parsing/semantic/break_not_ok_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/break_not_ok_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..6:1 ) > statements: < - StatementList( # input.cq:2:1..6:10 + StatementList( # input.cq:2:9..6:1 items: [ Subcircuit( # input.cq:4:1..7 name: < diff --git a/res/v1x/parsing/semantic/break_ok_1/ast.golden.txt b/res/v1x/parsing/semantic/break_ok_1/ast.golden.txt index 9ac836b12..1d93aca86 100644 --- a/res/v1x/parsing/semantic/break_ok_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/break_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -79,7 +79,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:10 + StatementList( # input.cq:6:32..8:2 items: [ BreakStatement( # input.cq:7:5..10 annotations: [] diff --git a/res/v1x/parsing/semantic/break_ok_2/ast.golden.txt b/res/v1x/parsing/semantic/break_ok_2/ast.golden.txt index 44d13f604..ac9d7a515 100644 --- a/res/v1x/parsing/semantic/break_ok_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/break_ok_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..11:1 ) > statements: < - StatementList( # input.cq:2:1..11:11 + StatementList( # input.cq:2:9..11:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -79,7 +79,7 @@ Program( # input.cq:1:1..11:1 ) > body: < - StatementList( # input.cq:6:5..10:6 + StatementList( # input.cq:6:32..10:2 items: [ IfElse( # input.cq:7:5..9:6 branches: [ @@ -99,7 +99,7 @@ Program( # input.cq:1:1..11:1 ) > body: < - StatementList( # input.cq:7:9..9:14 + StatementList( # input.cq:7:16..9:6 items: [ BreakStatement( # input.cq:8:9..14 annotations: [] diff --git a/res/v1x/parsing/semantic/coercion_fail/ast.golden.txt b/res/v1x/parsing/semantic/coercion_fail/ast.golden.txt index 8ac6e7d29..849bff671 100644 --- a/res/v1x/parsing/semantic/coercion_fail/ast.golden.txt +++ b/res/v1x/parsing/semantic/coercion_fail/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..6:1 ) > statements: < - StatementList( # input.cq:2:1..6:29 + StatementList( # input.cq:2:10..6:1 items: [ Bundle( # input.cq:5:1..29 items: [ diff --git a/res/v1x/parsing/semantic/coercion_ok/ast.golden.txt b/res/v1x/parsing/semantic/coercion_ok/ast.golden.txt index 51e51ba9d..057192c3f 100644 --- a/res/v1x/parsing/semantic/coercion_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/coercion_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..12:1 ) > statements: < - StatementList( # input.cq:2:1..12:49 + StatementList( # input.cq:2:10..12:1 items: [ Bundle( # input.cq:5:1..30 items: [ diff --git a/res/v1x/parsing/semantic/constants/ast.golden.txt b/res/v1x/parsing/semantic/constants/ast.golden.txt index 5f4df963e..a95bb7872 100644 --- a/res/v1x/parsing/semantic/constants/ast.golden.txt +++ b/res/v1x/parsing/semantic/constants/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:53 + StatementList( # input.cq:2:9..5:1 items: [ Bundle( # input.cq:4:1..53 items: [ diff --git a/res/v1x/parsing/semantic/continue_not_ok_1/ast.golden.txt b/res/v1x/parsing/semantic/continue_not_ok_1/ast.golden.txt index 939183cde..00b6aa927 100644 --- a/res/v1x/parsing/semantic/continue_not_ok_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/continue_not_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -44,7 +44,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:13 + StatementList( # input.cq:6:12..8:2 items: [ ContinueStatement( # input.cq:7:5..13 annotations: [] diff --git a/res/v1x/parsing/semantic/continue_not_ok_2/ast.golden.txt b/res/v1x/parsing/semantic/continue_not_ok_2/ast.golden.txt index 3ed123089..e66581b20 100644 --- a/res/v1x/parsing/semantic/continue_not_ok_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/continue_not_ok_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..7:1 ) > statements: < - StatementList( # input.cq:2:1..7:13 + StatementList( # input.cq:2:9..7:1 items: [ Subcircuit( # input.cq:4:1..7 name: < diff --git a/res/v1x/parsing/semantic/continue_ok_1/ast.golden.txt b/res/v1x/parsing/semantic/continue_ok_1/ast.golden.txt index 4254784e6..21957d050 100644 --- a/res/v1x/parsing/semantic/continue_ok_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/continue_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -79,7 +79,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:13 + StatementList( # input.cq:6:32..8:2 items: [ ContinueStatement( # input.cq:7:5..13 annotations: [] diff --git a/res/v1x/parsing/semantic/continue_ok_2/ast.golden.txt b/res/v1x/parsing/semantic/continue_ok_2/ast.golden.txt index 93934d259..ff1fbe2c9 100644 --- a/res/v1x/parsing/semantic/continue_ok_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/continue_ok_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..11:1 ) > statements: < - StatementList( # input.cq:2:1..11:11 + StatementList( # input.cq:2:9..11:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -79,7 +79,7 @@ Program( # input.cq:1:1..11:1 ) > body: < - StatementList( # input.cq:6:5..10:6 + StatementList( # input.cq:6:32..10:2 items: [ IfElse( # input.cq:7:5..9:6 branches: [ @@ -99,7 +99,7 @@ Program( # input.cq:1:1..11:1 ) > body: < - StatementList( # input.cq:7:9..9:17 + StatementList( # input.cq:7:16..9:6 items: [ ContinueStatement( # input.cq:8:9..17 annotations: [] diff --git a/res/v1x/parsing/semantic/dyn_func_ok/ast.golden.txt b/res/v1x/parsing/semantic/dyn_func_ok/ast.golden.txt index 4b395753a..9ef622ff4 100644 --- a/res/v1x/parsing/semantic/dyn_func_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/dyn_func_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..8:1 ) > statements: < - StatementList( # input.cq:2:1..8:35 + StatementList( # input.cq:2:10..8:1 items: [ Bundle( # input.cq:4:1..25 items: [ diff --git a/res/v1x/parsing/semantic/error_model_multiple/ast.golden.txt b/res/v1x/parsing/semantic/error_model_multiple/ast.golden.txt index f50454612..f44c08933 100644 --- a/res/v1x/parsing/semantic/error_model_multiple/ast.golden.txt +++ b/res/v1x/parsing/semantic/error_model_multiple/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..6:1 ) > statements: < - StatementList( # input.cq:2:1..6:42 + StatementList( # input.cq:2:10..6:1 items: [ Bundle( # input.cq:4:1..42 items: [ diff --git a/res/v1x/parsing/semantic/error_model_name_missing_1/ast.golden.txt b/res/v1x/parsing/semantic/error_model_name_missing_1/ast.golden.txt index 034ed3136..915279713 100644 --- a/res/v1x/parsing/semantic/error_model_name_missing_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/error_model_name_missing_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:20 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..20 items: [ diff --git a/res/v1x/parsing/semantic/error_model_name_missing_2/ast.golden.txt b/res/v1x/parsing/semantic/error_model_name_missing_2/ast.golden.txt index 47d6e8f65..448d350e4 100644 --- a/res/v1x/parsing/semantic/error_model_name_missing_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/error_model_name_missing_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:12 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..12 items: [ diff --git a/res/v1x/parsing/semantic/error_model_name_unknown/ast.golden.txt b/res/v1x/parsing/semantic/error_model_name_unknown/ast.golden.txt index 9b6b03bbf..23acaeac6 100644 --- a/res/v1x/parsing/semantic/error_model_name_unknown/ast.golden.txt +++ b/res/v1x/parsing/semantic/error_model_name_unknown/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:20 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..20 items: [ diff --git a/res/v1x/parsing/semantic/error_model_ok/ast.golden.txt b/res/v1x/parsing/semantic/error_model_ok/ast.golden.txt index d19110052..68a9fe87d 100644 --- a/res/v1x/parsing/semantic/error_model_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/error_model_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:55 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..55 items: [ diff --git a/res/v1x/parsing/semantic/error_model_overload_unknown/ast.golden.txt b/res/v1x/parsing/semantic/error_model_overload_unknown/ast.golden.txt index a36fa17a7..21fee3f61 100644 --- a/res/v1x/parsing/semantic/error_model_overload_unknown/ast.golden.txt +++ b/res/v1x/parsing/semantic/error_model_overload_unknown/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:41 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..41 items: [ diff --git a/res/v1x/parsing/semantic/for_invalid_condition/ast.golden.txt b/res/v1x/parsing/semantic/for_invalid_condition/ast.golden.txt index 945de9914..3c304e04d 100644 --- a/res/v1x/parsing/semantic/for_invalid_condition/ast.golden.txt +++ b/res/v1x/parsing/semantic/for_invalid_condition/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..6:1 ) > statements: < - StatementList( # input.cq:2:1..6:2 + StatementList( # input.cq:2:9..6:1 items: [ ForLoop( # input.cq:4:1..5:2 initialize: - diff --git a/res/v1x/parsing/semantic/for_ok_1/ast.golden.txt b/res/v1x/parsing/semantic/for_ok_1/ast.golden.txt index 6290e6c61..918e44f9f 100644 --- a/res/v1x/parsing/semantic/for_ok_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/for_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -79,7 +79,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:32..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/for_ok_2/ast.golden.txt b/res/v1x/parsing/semantic/for_ok_2/ast.golden.txt index 67972da1a..322f06c72 100644 --- a/res/v1x/parsing/semantic/for_ok_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/for_ok_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..11:1 ) > statements: < - StatementList( # input.cq:2:1..11:11 + StatementList( # input.cq:2:9..11:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -70,7 +70,7 @@ Program( # input.cq:1:1..11:1 > update: - body: < - StatementList( # input.cq:7:5..10:18 + StatementList( # input.cq:7:17..10:2 items: [ Bundle( # input.cq:8:5..8 items: [ diff --git a/res/v1x/parsing/semantic/for_ok_2/semantic.1.2.golden.txt b/res/v1x/parsing/semantic/for_ok_2/semantic.1.2.golden.txt index 8caf1a83f..32150c659 100644 --- a/res/v1x/parsing/semantic/for_ok_2/semantic.1.2.golden.txt +++ b/res/v1x/parsing/semantic/for_ok_2/semantic.1.2.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..11:1 bundles: [] annotations: [] body: < - Block( # input.cq:6:1..10:10 + Block( # input.cq:6:1..10:2 statements: [ BundleExt( # input.cq:6:1..10 items: [ diff --git a/res/v1x/parsing/semantic/foreach_not_ok_1/ast.golden.txt b/res/v1x/parsing/semantic/foreach_not_ok_1/ast.golden.txt index 782237de7..cba6c1381 100644 --- a/res/v1x/parsing/semantic/foreach_not_ok_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/foreach_not_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -43,7 +43,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:20..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/foreach_not_ok_2/ast.golden.txt b/res/v1x/parsing/semantic/foreach_not_ok_2/ast.golden.txt index e506d37f8..55b267966 100644 --- a/res/v1x/parsing/semantic/foreach_not_ok_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/foreach_not_ok_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:12 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..12 names: [ @@ -43,7 +43,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:20..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/foreach_not_ok_3/ast.golden.txt b/res/v1x/parsing/semantic/foreach_not_ok_3/ast.golden.txt index 104cee03c..7786a19c8 100644 --- a/res/v1x/parsing/semantic/foreach_not_ok_3/ast.golden.txt +++ b/res/v1x/parsing/semantic/foreach_not_ok_3/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -43,7 +43,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:30..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/foreach_ok_1/ast.golden.txt b/res/v1x/parsing/semantic/foreach_ok_1/ast.golden.txt index 11c54ed03..86d41ec9e 100644 --- a/res/v1x/parsing/semantic/foreach_ok_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/foreach_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -43,7 +43,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:20..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/foreach_ok_2/ast.golden.txt b/res/v1x/parsing/semantic/foreach_ok_2/ast.golden.txt index 16418354f..e795fce44 100644 --- a/res/v1x/parsing/semantic/foreach_ok_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/foreach_ok_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -43,7 +43,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:20..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/goto_not_ok/ast.golden.txt b/res/v1x/parsing/semantic/goto_not_ok/ast.golden.txt index a09ab12fb..788067135 100644 --- a/res/v1x/parsing/semantic/goto_not_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/goto_not_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..8:1 ) > statements: < - StatementList( # input.cq:2:1..8:14 + StatementList( # input.cq:2:10..8:1 items: [ Subcircuit( # input.cq:4:1..3 name: < diff --git a/res/v1x/parsing/semantic/goto_ok/ast.golden.txt b/res/v1x/parsing/semantic/goto_ok/ast.golden.txt index d1cf0eab2..cbd36d535 100644 --- a/res/v1x/parsing/semantic/goto_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/goto_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:23 + StatementList( # input.cq:2:10..9:1 items: [ Subcircuit( # input.cq:4:1..3 name: < diff --git a/res/v1x/parsing/semantic/if_else_if_ok/ast.golden.txt b/res/v1x/parsing/semantic/if_else_if_ok/ast.golden.txt index becb7908e..6e8f54543 100644 --- a/res/v1x/parsing/semantic/if_else_if_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/if_else_if_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..14:1 ) > statements: < - StatementList( # input.cq:2:1..14:15 + StatementList( # input.cq:2:10..14:1 items: [ Variables( # input.cq:4:1..15 names: [ @@ -51,7 +51,7 @@ Program( # input.cq:1:1..14:1 ) > body: < - StatementList( # input.cq:7:5..9:8 + StatementList( # input.cq:7:8..9:2 items: [ Bundle( # input.cq:8:5..8 items: [ @@ -87,7 +87,7 @@ Program( # input.cq:1:1..14:1 ) > body: < - StatementList( # input.cq:9:5..11:8 + StatementList( # input.cq:9:15..11:2 items: [ Bundle( # input.cq:10:5..8 items: [ @@ -118,7 +118,7 @@ Program( # input.cq:1:1..14:1 ) ] otherwise: < - StatementList( # input.cq:11:5..13:8 + StatementList( # input.cq:11:8..13:2 items: [ Bundle( # input.cq:12:5..8 items: [ diff --git a/res/v1x/parsing/semantic/if_else_ok/ast.golden.txt b/res/v1x/parsing/semantic/if_else_ok/ast.golden.txt index 747974712..86cb06a78 100644 --- a/res/v1x/parsing/semantic/if_else_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/if_else_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..12:1 ) > statements: < - StatementList( # input.cq:2:1..12:13 + StatementList( # input.cq:2:10..12:1 items: [ Variables( # input.cq:4:1..12 names: [ @@ -48,7 +48,7 @@ Program( # input.cq:1:1..12:1 ) > body: < - StatementList( # input.cq:7:5..9:8 + StatementList( # input.cq:7:8..9:2 items: [ Bundle( # input.cq:8:5..8 items: [ @@ -79,7 +79,7 @@ Program( # input.cq:1:1..12:1 ) ] otherwise: < - StatementList( # input.cq:9:5..11:8 + StatementList( # input.cq:9:8..11:2 items: [ Bundle( # input.cq:10:5..8 items: [ diff --git a/res/v1x/parsing/semantic/if_else_optimize_1/ast.golden.txt b/res/v1x/parsing/semantic/if_else_optimize_1/ast.golden.txt index 6dd11bec8..c71ea4d8d 100644 --- a/res/v1x/parsing/semantic/if_else_optimize_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/if_else_optimize_1/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..11:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..11:13 + StatementList( # input.cq:1:12..11:1 items: [ Variables( # input.cq:3:1..12 names: [ @@ -44,7 +44,7 @@ Program( # input.cq:1:1..11:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:11..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ @@ -75,7 +75,7 @@ Program( # input.cq:1:1..11:1 ) ] otherwise: < - StatementList( # input.cq:8:5..10:8 + StatementList( # input.cq:8:8..10:2 items: [ Bundle( # input.cq:9:5..8 items: [ diff --git a/res/v1x/parsing/semantic/if_else_optimize_2/ast.golden.txt b/res/v1x/parsing/semantic/if_else_optimize_2/ast.golden.txt index 63cc9632f..ed6d2ee49 100644 --- a/res/v1x/parsing/semantic/if_else_optimize_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/if_else_optimize_2/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..11:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..11:13 + StatementList( # input.cq:1:12..11:1 items: [ Variables( # input.cq:3:1..12 names: [ @@ -44,7 +44,7 @@ Program( # input.cq:1:1..11:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:12..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ @@ -75,7 +75,7 @@ Program( # input.cq:1:1..11:1 ) ] otherwise: < - StatementList( # input.cq:8:5..10:8 + StatementList( # input.cq:8:8..10:2 items: [ Bundle( # input.cq:9:5..8 items: [ diff --git a/res/v1x/parsing/semantic/if_else_optimize_3/ast.golden.txt b/res/v1x/parsing/semantic/if_else_optimize_3/ast.golden.txt index da0dabacd..014c1198a 100644 --- a/res/v1x/parsing/semantic/if_else_optimize_3/ast.golden.txt +++ b/res/v1x/parsing/semantic/if_else_optimize_3/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..13:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..13:13 + StatementList( # input.cq:1:12..13:1 items: [ Variables( # input.cq:3:1..12 names: [ @@ -44,7 +44,7 @@ Program( # input.cq:1:1..13:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:8..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ @@ -80,7 +80,7 @@ Program( # input.cq:1:1..13:1 ) > body: < - StatementList( # input.cq:8:5..10:8 + StatementList( # input.cq:8:19..10:2 items: [ Bundle( # input.cq:9:5..8 items: [ @@ -111,7 +111,7 @@ Program( # input.cq:1:1..13:1 ) ] otherwise: < - StatementList( # input.cq:10:5..12:8 + StatementList( # input.cq:10:8..12:2 items: [ Bundle( # input.cq:11:5..8 items: [ diff --git a/res/v1x/parsing/semantic/if_else_optimize_4/ast.golden.txt b/res/v1x/parsing/semantic/if_else_optimize_4/ast.golden.txt index 681c45d34..0020f9539 100644 --- a/res/v1x/parsing/semantic/if_else_optimize_4/ast.golden.txt +++ b/res/v1x/parsing/semantic/if_else_optimize_4/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..15:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..15:13 + StatementList( # input.cq:1:12..15:1 items: [ Variables( # input.cq:3:1..12 names: [ @@ -44,7 +44,7 @@ Program( # input.cq:1:1..15:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:8..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ @@ -80,7 +80,7 @@ Program( # input.cq:1:1..15:1 ) > body: < - StatementList( # input.cq:8:5..10:8 + StatementList( # input.cq:8:19..10:2 items: [ Bundle( # input.cq:9:5..8 items: [ @@ -116,7 +116,7 @@ Program( # input.cq:1:1..15:1 ) > body: < - StatementList( # input.cq:10:5..12:8 + StatementList( # input.cq:10:18..12:2 items: [ Bundle( # input.cq:11:5..8 items: [ @@ -147,7 +147,7 @@ Program( # input.cq:1:1..15:1 ) ] otherwise: < - StatementList( # input.cq:12:5..14:8 + StatementList( # input.cq:12:8..14:2 items: [ Bundle( # input.cq:13:5..8 items: [ diff --git a/res/v1x/parsing/semantic/if_else_optimize_5/ast.golden.txt b/res/v1x/parsing/semantic/if_else_optimize_5/ast.golden.txt index 104cdad72..87574e9bf 100644 --- a/res/v1x/parsing/semantic/if_else_optimize_5/ast.golden.txt +++ b/res/v1x/parsing/semantic/if_else_optimize_5/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..11:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..11:13 + StatementList( # input.cq:1:12..11:1 items: [ Variables( # input.cq:3:1..12 names: [ @@ -67,7 +67,7 @@ Program( # input.cq:1:1..11:1 ) > body: < - StatementList( # input.cq:7:5..9:8 + StatementList( # input.cq:7:12..9:2 items: [ Bundle( # input.cq:8:5..8 items: [ diff --git a/res/v1x/parsing/semantic/if_invalid_condition/ast.golden.txt b/res/v1x/parsing/semantic/if_invalid_condition/ast.golden.txt index b9046934c..d46537b19 100644 --- a/res/v1x/parsing/semantic/if_invalid_condition/ast.golden.txt +++ b/res/v1x/parsing/semantic/if_invalid_condition/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..6:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..6:2 + StatementList( # input.cq:1:12..6:1 items: [ IfElse( # input.cq:3:1..5:2 branches: [ @@ -18,7 +18,7 @@ Program( # input.cq:1:1..6:1 ) > body: < - StatementList( # input.cq:3:5..5:8 + StatementList( # input.cq:3:10..5:2 items: [ Bundle( # input.cq:4:5..8 items: [ diff --git a/res/v1x/parsing/semantic/if_nest_ok/ast.golden.txt b/res/v1x/parsing/semantic/if_nest_ok/ast.golden.txt index c8fd8314c..5669e948d 100644 --- a/res/v1x/parsing/semantic/if_nest_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/if_nest_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..14:1 ) > statements: < - StatementList( # input.cq:2:1..14:15 + StatementList( # input.cq:2:10..14:1 items: [ Variables( # input.cq:4:1..15 names: [ @@ -51,7 +51,7 @@ Program( # input.cq:1:1..14:1 ) > body: < - StatementList( # input.cq:7:5..13:8 + StatementList( # input.cq:7:8..13:2 items: [ Bundle( # input.cq:8:5..8 items: [ @@ -85,7 +85,7 @@ Program( # input.cq:1:1..14:1 ) > body: < - StatementList( # input.cq:9:9..11:12 + StatementList( # input.cq:9:12..11:6 items: [ Bundle( # input.cq:10:9..12 items: [ diff --git a/res/v1x/parsing/semantic/if_ok/ast.golden.txt b/res/v1x/parsing/semantic/if_ok/ast.golden.txt index a795f5a14..9b53b010f 100644 --- a/res/v1x/parsing/semantic/if_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/if_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..10:1 ) > statements: < - StatementList( # input.cq:2:1..10:13 + StatementList( # input.cq:2:10..10:1 items: [ Variables( # input.cq:4:1..12 names: [ @@ -48,7 +48,7 @@ Program( # input.cq:1:1..10:1 ) > body: < - StatementList( # input.cq:7:5..9:8 + StatementList( # input.cq:7:8..9:2 items: [ Bundle( # input.cq:8:5..8 items: [ diff --git a/res/v1x/parsing/semantic/index_not_supported/ast.golden.txt b/res/v1x/parsing/semantic/index_not_supported/ast.golden.txt index 582985a40..b1759421f 100644 --- a/res/v1x/parsing/semantic/index_not_supported/ast.golden.txt +++ b/res/v1x/parsing/semantic/index_not_supported/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:45 + StatementList( # input.cq:2:9..5:1 items: [ Bundle( # input.cq:4:1..45 items: [ diff --git a/res/v1x/parsing/semantic/index_range/ast.golden.txt b/res/v1x/parsing/semantic/index_range/ast.golden.txt index c7065e438..4d72823b7 100644 --- a/res/v1x/parsing/semantic/index_range/ast.golden.txt +++ b/res/v1x/parsing/semantic/index_range/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..19:1 ) > statements: < - StatementList( # input.cq:2:1..19:11 + StatementList( # input.cq:2:9..19:1 items: [ Bundle( # input.cq:4:1..7 items: [ diff --git a/res/v1x/parsing/semantic/insn_condition_const_false/ast.golden.txt b/res/v1x/parsing/semantic/insn_condition_const_false/ast.golden.txt index bf1b44296..c3dcf81c1 100644 --- a/res/v1x/parsing/semantic/insn_condition_const_false/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_condition_const_false/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:16 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..16 items: [ diff --git a/res/v1x/parsing/semantic/insn_condition_const_true/ast.golden.txt b/res/v1x/parsing/semantic/insn_condition_const_true/ast.golden.txt index 232598457..5eb876717 100644 --- a/res/v1x/parsing/semantic/insn_condition_const_true/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_condition_const_true/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:15 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..15 items: [ diff --git a/res/v1x/parsing/semantic/insn_condition_new_ok/ast.golden.txt b/res/v1x/parsing/semantic/insn_condition_new_ok/ast.golden.txt index 765648959..0a08e0472 100644 --- a/res/v1x/parsing/semantic/insn_condition_new_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_condition_new_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..6:1 ) > statements: < - StatementList( # input.cq:2:1..6:23 + StatementList( # input.cq:2:10..6:1 items: [ Bundle( # input.cq:5:1..23 items: [ diff --git a/res/v1x/parsing/semantic/insn_condition_not_bool/ast.golden.txt b/res/v1x/parsing/semantic/insn_condition_not_bool/ast.golden.txt index feec889e8..ed97757b8 100644 --- a/res/v1x/parsing/semantic/insn_condition_not_bool/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_condition_not_bool/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:13 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..13 items: [ diff --git a/res/v1x/parsing/semantic/insn_condition_not_supported/ast.golden.txt b/res/v1x/parsing/semantic/insn_condition_not_supported/ast.golden.txt index 691e468b7..e213a1d55 100644 --- a/res/v1x/parsing/semantic/insn_condition_not_supported/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_condition_not_supported/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:21 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..21 items: [ diff --git a/res/v1x/parsing/semantic/insn_condition_ok/ast.golden.txt b/res/v1x/parsing/semantic/insn_condition_ok/ast.golden.txt index be764f17e..dc5eeee6c 100644 --- a/res/v1x/parsing/semantic/insn_condition_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_condition_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..6:1 ) > statements: < - StatementList( # input.cq:2:1..6:19 + StatementList( # input.cq:2:10..6:1 items: [ Bundle( # input.cq:5:1..19 items: [ diff --git a/res/v1x/parsing/semantic/insn_index_size_mismatch/ast.golden.txt b/res/v1x/parsing/semantic/insn_index_size_mismatch/ast.golden.txt index 215ed1603..0be6ea1bc 100644 --- a/res/v1x/parsing/semantic/insn_index_size_mismatch/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_index_size_mismatch/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..7:1 ) > statements: < - StatementList( # input.cq:2:1..7:20 + StatementList( # input.cq:2:10..7:1 items: [ Bundle( # input.cq:4:1..20 items: [ diff --git a/res/v1x/parsing/semantic/insn_name_unknown/ast.golden.txt b/res/v1x/parsing/semantic/insn_name_unknown/ast.golden.txt index 8743aec54..799d1c3c2 100644 --- a/res/v1x/parsing/semantic/insn_name_unknown/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_name_unknown/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:18 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..18 items: [ diff --git a/res/v1x/parsing/semantic/insn_not_parallelizable/ast.golden.txt b/res/v1x/parsing/semantic/insn_not_parallelizable/ast.golden.txt index 7866b520e..fa7dc3859 100644 --- a/res/v1x/parsing/semantic/insn_not_parallelizable/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_not_parallelizable/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:21 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..21 items: [ diff --git a/res/v1x/parsing/semantic/insn_overload_unknown/ast.golden.txt b/res/v1x/parsing/semantic/insn_overload_unknown/ast.golden.txt index e223ed07b..b1d7746e6 100644 --- a/res/v1x/parsing/semantic/insn_overload_unknown/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_overload_unknown/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:9 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..9 items: [ diff --git a/res/v1x/parsing/semantic/insn_qubit_reuse/ast.golden.txt b/res/v1x/parsing/semantic/insn_qubit_reuse/ast.golden.txt index ec30da08e..ea19d2163 100644 --- a/res/v1x/parsing/semantic/insn_qubit_reuse/ast.golden.txt +++ b/res/v1x/parsing/semantic/insn_qubit_reuse/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..22:1 ) > statements: < - StatementList( # input.cq:2:1..22:20 + StatementList( # input.cq:2:9..22:1 items: [ Bundle( # input.cq:4:1..9 items: [ diff --git a/res/v1x/parsing/semantic/matrix_not_rectangular/ast.golden.txt b/res/v1x/parsing/semantic/matrix_not_rectangular/ast.golden.txt index 6d7bf92b4..f7eb8f128 100644 --- a/res/v1x/parsing/semantic/matrix_not_rectangular/ast.golden.txt +++ b/res/v1x/parsing/semantic/matrix_not_rectangular/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:36 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..36 items: [ diff --git a/res/v1x/parsing/semantic/matrix_not_supported/ast.golden.txt b/res/v1x/parsing/semantic/matrix_not_supported/ast.golden.txt index 45024d2c6..dab1652aa 100644 --- a/res/v1x/parsing/semantic/matrix_not_supported/ast.golden.txt +++ b/res/v1x/parsing/semantic/matrix_not_supported/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:31 + StatementList( # input.cq:2:10..5:1 items: [ Bundle( # input.cq:4:1..31 items: [ diff --git a/res/v1x/parsing/semantic/qubits_variables/ast.golden.txt b/res/v1x/parsing/semantic/qubits_variables/ast.golden.txt index 6a023ccd7..5281f10fd 100644 --- a/res/v1x/parsing/semantic/qubits_variables/ast.golden.txt +++ b/res/v1x/parsing/semantic/qubits_variables/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..6:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..6:25 + StatementList( # input.cq:1:12..6:1 items: [ Variables( # input.cq:3:1..25 names: [ diff --git a/res/v1x/parsing/semantic/repeat_until_invalid_condition/ast.golden.txt b/res/v1x/parsing/semantic/repeat_until_invalid_condition/ast.golden.txt index 0ba0322ee..3d8468a8f 100644 --- a/res/v1x/parsing/semantic/repeat_until_invalid_condition/ast.golden.txt +++ b/res/v1x/parsing/semantic/repeat_until_invalid_condition/ast.golden.txt @@ -11,11 +11,11 @@ Program( # input.cq:1:1..7:1 ) > statements: < - StatementList( # input.cq:2:1..7:18 + StatementList( # input.cq:2:9..7:1 items: [ RepeatUntilLoop( # input.cq:4:1..6:18 body: < - StatementList( # input.cq:4:5..6:8 + StatementList( # input.cq:4:8..6:2 items: [ Bundle( # input.cq:5:5..8 items: [ diff --git a/res/v1x/parsing/semantic/repeat_until_ok_1/ast.golden.txt b/res/v1x/parsing/semantic/repeat_until_ok_1/ast.golden.txt index ea654fb58..b59c15f2a 100644 --- a/res/v1x/parsing/semantic/repeat_until_ok_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/repeat_until_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:17 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -28,7 +28,7 @@ Program( # input.cq:1:1..9:1 ) RepeatUntilLoop( # input.cq:6:1..8:17 body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:8..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/repeat_until_ok_2/ast.golden.txt b/res/v1x/parsing/semantic/repeat_until_ok_2/ast.golden.txt index 97fce202f..9508b82a3 100644 --- a/res/v1x/parsing/semantic/repeat_until_ok_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/repeat_until_ok_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:16 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -28,7 +28,7 @@ Program( # input.cq:1:1..9:1 ) RepeatUntilLoop( # input.cq:6:1..8:16 body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:8..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/repeat_until_ok_3/ast.golden.txt b/res/v1x/parsing/semantic/repeat_until_ok_3/ast.golden.txt index 78cbc76c1..0fd42eeb1 100644 --- a/res/v1x/parsing/semantic/repeat_until_ok_3/ast.golden.txt +++ b/res/v1x/parsing/semantic/repeat_until_ok_3/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:15 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -28,7 +28,7 @@ Program( # input.cq:1:1..9:1 ) RepeatUntilLoop( # input.cq:6:1..8:15 body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:8..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/set_bad/ast.golden.txt b/res/v1x/parsing/semantic/set_bad/ast.golden.txt index 1cfdadbe6..50290d1f0 100644 --- a/res/v1x/parsing/semantic/set_bad/ast.golden.txt +++ b/res/v1x/parsing/semantic/set_bad/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..8:1 ) > statements: < - StatementList( # input.cq:2:1..8:16 + StatementList( # input.cq:2:10..8:1 items: [ Variables( # input.cq:4:1..11 names: [ diff --git a/res/v1x/parsing/semantic/set_ok/ast.golden.txt b/res/v1x/parsing/semantic/set_ok/ast.golden.txt index 6dafee596..5f12eb2c1 100644 --- a/res/v1x/parsing/semantic/set_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/set_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..15:1 ) > statements: < - StatementList( # input.cq:2:1..15:16 + StatementList( # input.cq:2:10..15:1 items: [ Variables( # input.cq:4:1..15 names: [ diff --git a/res/v1x/parsing/semantic/set_ref_coerce/ast.golden.txt b/res/v1x/parsing/semantic/set_ref_coerce/ast.golden.txt index fdaa2ac46..c05915441 100644 --- a/res/v1x/parsing/semantic/set_ref_coerce/ast.golden.txt +++ b/res/v1x/parsing/semantic/set_ref_coerce/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..8:1 ) > statements: < - StatementList( # input.cq:2:1..8:12 + StatementList( # input.cq:2:10..8:1 items: [ Variables( # input.cq:4:1..11 names: [ diff --git a/res/v1x/parsing/semantic/subblock_scope/ast.golden.txt b/res/v1x/parsing/semantic/subblock_scope/ast.golden.txt index a49c9e6b4..105c9dc79 100644 --- a/res/v1x/parsing/semantic/subblock_scope/ast.golden.txt +++ b/res/v1x/parsing/semantic/subblock_scope/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..12:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..12:12 + StatementList( # input.cq:1:12..12:1 items: [ Variables( # input.cq:3:1..12 names: [ @@ -31,7 +31,7 @@ Program( # input.cq:1:1..12:1 ) > body: < - StatementList( # input.cq:5:5..8:17 + StatementList( # input.cq:5:8..8:2 items: [ Variables( # input.cq:6:5..17 names: [ diff --git a/res/v1x/parsing/semantic/subcircuit_iterations_negative/ast.golden.txt b/res/v1x/parsing/semantic/subcircuit_iterations_negative/ast.golden.txt index 01c17990a..86ebeea33 100644 --- a/res/v1x/parsing/semantic/subcircuit_iterations_negative/ast.golden.txt +++ b/res/v1x/parsing/semantic/subcircuit_iterations_negative/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:14 + StatementList( # input.cq:2:10..5:1 items: [ Subcircuit( # input.cq:4:1..14 name: < diff --git a/res/v1x/parsing/semantic/subcircuit_iterations_not_const_int/ast.golden.txt b/res/v1x/parsing/semantic/subcircuit_iterations_not_const_int/ast.golden.txt index 9ed7687e8..b4e2cebc8 100644 --- a/res/v1x/parsing/semantic/subcircuit_iterations_not_const_int/ast.golden.txt +++ b/res/v1x/parsing/semantic/subcircuit_iterations_not_const_int/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:14 + StatementList( # input.cq:2:10..5:1 items: [ Subcircuit( # input.cq:4:1..14 name: < diff --git a/res/v1x/parsing/semantic/subcircuit_iterations_zero/ast.golden.txt b/res/v1x/parsing/semantic/subcircuit_iterations_zero/ast.golden.txt index fe71d7fb6..f60891dcf 100644 --- a/res/v1x/parsing/semantic/subcircuit_iterations_zero/ast.golden.txt +++ b/res/v1x/parsing/semantic/subcircuit_iterations_zero/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:12 + StatementList( # input.cq:2:10..5:1 items: [ Subcircuit( # input.cq:4:1..12 name: < diff --git a/res/v1x/parsing/semantic/subcircuit_name_reuse/ast.golden.txt b/res/v1x/parsing/semantic/subcircuit_name_reuse/ast.golden.txt index 2e63fa9c7..68e672122 100644 --- a/res/v1x/parsing/semantic/subcircuit_name_reuse/ast.golden.txt +++ b/res/v1x/parsing/semantic/subcircuit_name_reuse/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..7:1 ) > statements: < - StatementList( # input.cq:2:1..7:9 + StatementList( # input.cq:2:10..7:1 items: [ Subcircuit( # input.cq:5:1..9 name: < diff --git a/res/v1x/parsing/semantic/subcircuit_name_reuse_1.2/ast.golden.txt b/res/v1x/parsing/semantic/subcircuit_name_reuse_1.2/ast.golden.txt index 63a1969a9..a792d6f74 100644 --- a/res/v1x/parsing/semantic/subcircuit_name_reuse_1.2/ast.golden.txt +++ b/res/v1x/parsing/semantic/subcircuit_name_reuse_1.2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..7:1 ) > statements: < - StatementList( # input.cq:2:1..7:9 + StatementList( # input.cq:2:10..7:1 items: [ Subcircuit( # input.cq:5:1..9 name: < diff --git a/res/v1x/parsing/semantic/subcircuit_ok/ast.golden.txt b/res/v1x/parsing/semantic/subcircuit_ok/ast.golden.txt index ce3beb430..9563b312d 100644 --- a/res/v1x/parsing/semantic/subcircuit_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/subcircuit_ok/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..13:1 ) > statements: < - StatementList( # input.cq:2:1..13:15 + StatementList( # input.cq:2:10..13:1 items: [ Subcircuit( # input.cq:4:1..11 name: < diff --git a/res/v1x/parsing/semantic/subcircuit_ok/semantic.1.2.golden.txt b/res/v1x/parsing/semantic/subcircuit_ok/semantic.1.2.golden.txt index 230e00b54..f59ad85d5 100644 --- a/res/v1x/parsing/semantic/subcircuit_ok/semantic.1.2.golden.txt +++ b/res/v1x/parsing/semantic/subcircuit_ok/semantic.1.2.golden.txt @@ -51,7 +51,7 @@ Program( # input.cq:1:1..13:1 bundles: [] annotations: [] body: < - Block( # input.cq:7:1..9:15 + Block( # input.cq:7:1..9:11 statements: [ BundleExt( # input.cq:8:5..11 items: [ @@ -111,7 +111,7 @@ Program( # input.cq:1:1..13:1 bundles: [] annotations: [] body: < - Block( # input.cq:11:1..12:14 + Block( # input.cq:11:1..12:11 statements: [ BundleExt( # input.cq:12:5..11 items: [ diff --git a/res/v1x/parsing/semantic/var_1.0_missing_qubits/ast.golden.txt b/res/v1x/parsing/semantic/var_1.0_missing_qubits/ast.golden.txt index 15833a115..53f4fdec8 100644 --- a/res/v1x/parsing/semantic/var_1.0_missing_qubits/ast.golden.txt +++ b/res/v1x/parsing/semantic/var_1.0_missing_qubits/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..4:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..4:13 + StatementList( # input.cq:1:12..4:1 items: [ Variables( # input.cq:3:1..13 names: [ diff --git a/res/v1x/parsing/semantic/var_1.0_var_not_supported/ast.golden.txt b/res/v1x/parsing/semantic/var_1.0_var_not_supported/ast.golden.txt index 24be3cbcd..5ac2082d6 100644 --- a/res/v1x/parsing/semantic/var_1.0_var_not_supported/ast.golden.txt +++ b/res/v1x/parsing/semantic/var_1.0_var_not_supported/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..5:1 ) > statements: < - StatementList( # input.cq:2:1..5:13 + StatementList( # input.cq:2:9..5:1 items: [ Variables( # input.cq:4:1..13 names: [ diff --git a/res/v1x/parsing/semantic/var_ok/ast.golden.txt b/res/v1x/parsing/semantic/var_ok/ast.golden.txt index 20183217e..c0c0b50ec 100644 --- a/res/v1x/parsing/semantic/var_ok/ast.golden.txt +++ b/res/v1x/parsing/semantic/var_ok/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..9:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..9:15 + StatementList( # input.cq:1:12..9:1 items: [ Variables( # input.cq:3:1..13 names: [ diff --git a/res/v1x/parsing/semantic/var_shadow/ast.golden.txt b/res/v1x/parsing/semantic/var_shadow/ast.golden.txt index 568969038..0ee115caa 100644 --- a/res/v1x/parsing/semantic/var_shadow/ast.golden.txt +++ b/res/v1x/parsing/semantic/var_shadow/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..8:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..8:13 + StatementList( # input.cq:1:12..8:1 items: [ Variables( # input.cq:3:1..12 names: [ diff --git a/res/v1x/parsing/semantic/var_shadow/semantic.1.2.golden.txt b/res/v1x/parsing/semantic/var_shadow/semantic.1.2.golden.txt index f94521249..419328db6 100644 --- a/res/v1x/parsing/semantic/var_shadow/semantic.1.2.golden.txt +++ b/res/v1x/parsing/semantic/var_shadow/semantic.1.2.golden.txt @@ -15,7 +15,7 @@ Program( # input.cq:1:1..8:1 bundles: [] annotations: [] body: < - Block( # input.cq:4:1..7:6 + Block( # input.cq:4:1..7:4 statements: [ BundleExt( # input.cq:4:1..6 items: [ diff --git a/res/v1x/parsing/semantic/var_unknown_type/ast.golden.txt b/res/v1x/parsing/semantic/var_unknown_type/ast.golden.txt index 86f360400..3e7ba9327 100644 --- a/res/v1x/parsing/semantic/var_unknown_type/ast.golden.txt +++ b/res/v1x/parsing/semantic/var_unknown_type/ast.golden.txt @@ -7,7 +7,7 @@ Program( # input.cq:1:1..4:1 > num_qubits: - statements: < - StatementList( # input.cq:1:1..4:18 + StatementList( # input.cq:1:12..4:1 items: [ Variables( # input.cq:3:1..18 names: [ diff --git a/res/v1x/parsing/semantic/while_invalid_condition/ast.golden.txt b/res/v1x/parsing/semantic/while_invalid_condition/ast.golden.txt index 10767bf58..314c7255f 100644 --- a/res/v1x/parsing/semantic/while_invalid_condition/ast.golden.txt +++ b/res/v1x/parsing/semantic/while_invalid_condition/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..7:1 ) > statements: < - StatementList( # input.cq:2:1..7:2 + StatementList( # input.cq:2:9..7:1 items: [ WhileLoop( # input.cq:4:1..6:2 condition: < @@ -20,7 +20,7 @@ Program( # input.cq:1:1..7:1 ) > body: < - StatementList( # input.cq:4:5..6:8 + StatementList( # input.cq:4:17..6:2 items: [ Bundle( # input.cq:5:5..8 items: [ diff --git a/res/v1x/parsing/semantic/while_ok_1/ast.golden.txt b/res/v1x/parsing/semantic/while_ok_1/ast.golden.txt index 37d2023d1..7fa3136fc 100644 --- a/res/v1x/parsing/semantic/while_ok_1/ast.golden.txt +++ b/res/v1x/parsing/semantic/while_ok_1/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -42,7 +42,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:16..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/while_ok_2/ast.golden.txt b/res/v1x/parsing/semantic/while_ok_2/ast.golden.txt index 192f53c82..f99610bc0 100644 --- a/res/v1x/parsing/semantic/while_ok_2/ast.golden.txt +++ b/res/v1x/parsing/semantic/while_ok_2/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -33,7 +33,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:15..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v1x/parsing/semantic/while_ok_3/ast.golden.txt b/res/v1x/parsing/semantic/while_ok_3/ast.golden.txt index d2a63dffb..1da0f927e 100644 --- a/res/v1x/parsing/semantic/while_ok_3/ast.golden.txt +++ b/res/v1x/parsing/semantic/while_ok_3/ast.golden.txt @@ -11,7 +11,7 @@ Program( # input.cq:1:1..9:1 ) > statements: < - StatementList( # input.cq:2:1..9:11 + StatementList( # input.cq:2:9..9:1 items: [ Variables( # input.cq:4:1..11 names: [ @@ -33,7 +33,7 @@ Program( # input.cq:1:1..9:1 ) > body: < - StatementList( # input.cq:6:5..8:8 + StatementList( # input.cq:6:14..8:2 items: [ Bundle( # input.cq:7:5..8 items: [ diff --git a/res/v3x/parsing/arithmetic_operators/bool_b_equals_1_le_2_eq_3_lt_4/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/bool_b_equals_1_le_2_eq_3_lt_4/ast.golden.txt index 2c9805af9..369bae1a1 100644 --- a/res/v3x/parsing/arithmetic_operators/bool_b_equals_1_le_2_eq_3_lt_4/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/bool_b_equals_1_le_2_eq_3_lt_4/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/bool_b_equals_1_le_2_eq_3_lt_4/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/bool_b_equals_1_le_2_eq_3_lt_4/semantic.3.0.golden.txt index 51d26f9d1..ea8c7fe4a 100644 --- a/res/v3x/parsing/arithmetic_operators/bool_b_equals_1_le_2_eq_3_lt_4/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/bool_b_equals_1_le_2_eq_3_lt_4/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: b - typ: < - Bool( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: b + typ: < + Bool( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstBool( + value: 1 + ) + > + annotations: [] ) - > - rhs: < - ConstBool( - value: 1 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/arithmetic_operators/bool_b_equals_4_ge_3_ne_2_gt_1/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/bool_b_equals_4_ge_3_ne_2_gt_1/ast.golden.txt index d21b09acc..ae266d101 100644 --- a/res/v3x/parsing/arithmetic_operators/bool_b_equals_4_ge_3_ne_2_gt_1/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/bool_b_equals_4_ge_3_ne_2_gt_1/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/bool_b_equals_4_ge_3_ne_2_gt_1/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/bool_b_equals_4_ge_3_ne_2_gt_1/semantic.3.0.golden.txt index 569cb9486..5685c2370 100644 --- a/res/v3x/parsing/arithmetic_operators/bool_b_equals_4_ge_3_ne_2_gt_1/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/bool_b_equals_4_ge_3_ne_2_gt_1/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: b - typ: < - Bool( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: b + typ: < + Bool( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstBool( + value: 0 + ) + > + annotations: [] ) - > - rhs: < - ConstBool( - value: 0 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/arithmetic_operators/float_f_equals_1_div_2_pow_3_times_minus_4_minus_5_times_6/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/float_f_equals_1_div_2_pow_3_times_minus_4_minus_5_times_6/ast.golden.txt index ddc550784..544587e8f 100644 --- a/res/v3x/parsing/arithmetic_operators/float_f_equals_1_div_2_pow_3_times_minus_4_minus_5_times_6/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/float_f_equals_1_div_2_pow_3_times_minus_4_minus_5_times_6/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:7..8 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/float_f_equals_1_div_2_pow_3_times_minus_4_minus_5_times_6/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/float_f_equals_1_div_2_pow_3_times_minus_4_minus_5_times_6/semantic.3.0.golden.txt index 01653a0ab..72ed2aca7 100644 --- a/res/v3x/parsing/arithmetic_operators/float_f_equals_1_div_2_pow_3_times_minus_4_minus_5_times_6/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/float_f_equals_1_div_2_pow_3_times_minus_4_minus_5_times_6/semantic.3.0.golden.txt @@ -6,41 +6,41 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - Real( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstFloat( + value: -30.5 + ) + > + annotations: [] ) - > - rhs: < - ConstReal( - value: -30.5 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: f typ: < - Real( + Float( size: 1 ) > diff --git a/res/v3x/parsing/arithmetic_operators/float_f_equals_2_pow_2_pow_3/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/float_f_equals_2_pow_2_pow_3/ast.golden.txt index 0e0c679d9..aa4128f43 100644 --- a/res/v3x/parsing/arithmetic_operators/float_f_equals_2_pow_2_pow_3/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/float_f_equals_2_pow_2_pow_3/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:7..8 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/float_f_equals_2_pow_2_pow_3/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/float_f_equals_2_pow_2_pow_3/semantic.3.0.golden.txt index 894a6b02a..c05f7baf2 100644 --- a/res/v3x/parsing/arithmetic_operators/float_f_equals_2_pow_2_pow_3/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/float_f_equals_2_pow_2_pow_3/semantic.3.0.golden.txt @@ -6,41 +6,41 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - Real( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstFloat( + value: 256 + ) + > + annotations: [] ) - > - rhs: < - ConstReal( - value: 256 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: f typ: < - Real( + Float( size: 1 ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_or_2_xor_3_and_2/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_or_2_xor_3_and_2/ast.golden.txt index d3ab05202..293c938f2 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_or_2_xor_3_and_2/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_or_2_xor_3_and_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_or_2_xor_3_and_2/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_or_2_xor_3_and_2/semantic.3.0.golden.txt index b0c59b8aa..74af3b16a 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_or_2_xor_3_and_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_or_2_xor_3_and_2/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: 1 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: 1 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_plus_2_minus_4_plus_minus_8_minus_minus_16/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_plus_2_minus_4_plus_minus_8_minus_minus_16/ast.golden.txt index b15bb29a5..770f9ecac 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_plus_2_minus_4_plus_minus_8_minus_minus_16/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_plus_2_minus_4_plus_minus_8_minus_minus_16/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_plus_2_minus_4_plus_minus_8_minus_minus_16/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_plus_2_minus_4_plus_minus_8_minus_minus_16/semantic.3.0.golden.txt index bafaa2e3e..ba2757cd6 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_plus_2_minus_4_plus_minus_8_minus_minus_16/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_plus_2_minus_4_plus_minus_8_minus_minus_16/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: 7 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: 7 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_shl_2/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_shl_2/ast.golden.txt index b1f054b26..a1e2ed9c4 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_shl_2/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_shl_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_shl_2/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_shl_2/semantic.3.0.golden.txt index c06097f5e..f481a6803 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_1_shl_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_1_shl_2/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: 4 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: 4 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_2_times_parens_3_plus_4_parens/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_2_times_parens_3_plus_4_parens/ast.golden.txt index af479bb86..c77aad322 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_2_times_parens_3_plus_4_parens/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_2_times_parens_3_plus_4_parens/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_2_times_parens_3_plus_4_parens/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_2_times_parens_3_plus_4_parens/semantic.3.0.golden.txt index d1b642fa1..b6956b886 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_2_times_parens_3_plus_4_parens/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_2_times_parens_3_plus_4_parens/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: 14 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: 14 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_bitwise_not_minus_2/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_bitwise_not_minus_2/ast.golden.txt index 98293f572..5cc81790d 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_bitwise_not_minus_2/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_bitwise_not_minus_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_bitwise_not_minus_2/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_bitwise_not_minus_2/semantic.3.0.golden.txt index b0c59b8aa..74af3b16a 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_bitwise_not_minus_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_bitwise_not_minus_2/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: 1 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: 1 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_if_false_then_10_else_if_true_then_15_else_20/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_if_false_then_10_else_if_true_then_15_else_20/ast.golden.txt index dd6faa6ec..57fa6c304 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_if_false_then_10_else_if_true_then_15_else_20/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_if_false_then_10_else_if_true_then_15_else_20/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_if_false_then_10_else_if_true_then_15_else_20/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_if_false_then_10_else_if_true_then_15_else_20/semantic.3.0.golden.txt index 850050b2d..fe9f3552d 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_if_false_then_10_else_if_true_then_15_else_20/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_if_false_then_10_else_if_true_then_15_else_20/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: 15 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: 15 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_if_true_or_true_xor_not_false_and_true_then_10_else_20/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_if_true_or_true_xor_not_false_and_true_then_10_else_20/ast.golden.txt index e63a450b2..62d31f477 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_if_true_or_true_xor_not_false_and_true_then_10_else_20/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_if_true_or_true_xor_not_false_and_true_then_10_else_20/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_if_true_or_true_xor_not_false_and_true_then_10_else_20/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_if_true_or_true_xor_not_false_and_true_then_10_else_20/semantic.3.0.golden.txt index ae97e81c7..2e9eaceba 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_if_true_or_true_xor_not_false_and_true_then_10_else_20/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_if_true_or_true_xor_not_false_and_true_then_10_else_20/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: 10 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: 10 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_2_mod_3/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_2_mod_3/ast.golden.txt index a46848d63..6f17bbb28 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_2_mod_3/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_2_mod_3/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_2_mod_3/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_2_mod_3/semantic.3.0.golden.txt index 4db9b5b77..934d476f5 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_2_mod_3/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_2_mod_3/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: -2 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: -2 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_8_shr_2/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_8_shr_2/ast.golden.txt index ff4bb5657..523e0492b 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_8_shr_2/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_8_shr_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_8_shr_2/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_8_shr_2/semantic.3.0.golden.txt index 4db9b5b77..934d476f5 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_8_shr_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_8_shr_2/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: -2 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: -2 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_minus_minus_3/ast.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_minus_minus_3/ast.golden.txt index d5d4b6ef9..63c65db21 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_minus_minus_3/ast.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_minus_minus_3/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_minus_minus_3/semantic.3.0.golden.txt b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_minus_minus_3/semantic.3.0.golden.txt index 5516d910d..9d8cd60af 100644 --- a/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_minus_minus_3/semantic.3.0.golden.txt +++ b/res/v3x/parsing/arithmetic_operators/int_i_equals_minus_minus_minus_3/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: -3 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: -3 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/assignment/1.0_equals_true/ast.golden.txt b/res/v3x/parsing/assignment/1.0_equals_true/ast.golden.txt index 908b62c2e..6c4ad163f 100644 --- a/res/v3x/parsing/assignment/1.0_equals_true/ast.golden.txt +++ b/res/v3x/parsing/assignment/1.0_equals_true/ast.golden.txt @@ -1,2 +1,28 @@ -ERROR -Error at input.cq:3:7..11: missing 'measure' at 'true' +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + AssignmentStatement( # input.cq:3:5..6 + lhs: < + FloatLiteral( # input.cq:3:1..4 + value: 1 + ) + > + rhs: < + BooleanLiteral( # input.cq:3:7..11 + value: 1 + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/assignment/1.0_equals_true/semantic.3.0.golden.txt b/res/v3x/parsing/assignment/1.0_equals_true/semantic.3.0.golden.txt new file mode 100644 index 000000000..b1f7c9403 --- /dev/null +++ b/res/v3x/parsing/assignment/1.0_equals_true/semantic.3.0.golden.txt @@ -0,0 +1,2 @@ +ERROR +Error at input.cq:3:5..6: left-hand side of assignment statement must be assignable diff --git a/res/v3x/parsing/assignment/1_equals_true/ast.golden.txt b/res/v3x/parsing/assignment/1_equals_true/ast.golden.txt index 41b11e066..af9a46f2d 100644 --- a/res/v3x/parsing/assignment/1_equals_true/ast.golden.txt +++ b/res/v3x/parsing/assignment/1_equals_true/ast.golden.txt @@ -1,2 +1,28 @@ -ERROR -Error at input.cq:3:5..9: missing 'measure' at 'true' +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + AssignmentStatement( # input.cq:3:3..4 + lhs: < + IntegerLiteral( # input.cq:3:1..2 + value: 1 + ) + > + rhs: < + BooleanLiteral( # input.cq:3:5..9 + value: 1 + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/assignment/1_equals_true/semantic.3.0.golden.txt b/res/v3x/parsing/assignment/1_equals_true/semantic.3.0.golden.txt new file mode 100644 index 000000000..9457361fd --- /dev/null +++ b/res/v3x/parsing/assignment/1_equals_true/semantic.3.0.golden.txt @@ -0,0 +1,2 @@ +ERROR +Error at input.cq:3:3..4: left-hand side of assignment statement must be assignable diff --git a/res/v3x/parsing/assignment/3.0_equals_3/ast.golden.txt b/res/v3x/parsing/assignment/3.0_equals_3/ast.golden.txt index 51178cc75..d9c20603f 100644 --- a/res/v3x/parsing/assignment/3.0_equals_3/ast.golden.txt +++ b/res/v3x/parsing/assignment/3.0_equals_3/ast.golden.txt @@ -1,2 +1,28 @@ -ERROR -Error at input.cq:3:7..8: missing 'measure' at '3' +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + AssignmentStatement( # input.cq:3:5..6 + lhs: < + FloatLiteral( # input.cq:3:1..4 + value: 3 + ) + > + rhs: < + IntegerLiteral( # input.cq:3:7..8 + value: 3 + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/assignment/3.0_equals_3/semantic.3.0.golden.txt b/res/v3x/parsing/assignment/3.0_equals_3/semantic.3.0.golden.txt new file mode 100644 index 000000000..b1f7c9403 --- /dev/null +++ b/res/v3x/parsing/assignment/3.0_equals_3/semantic.3.0.golden.txt @@ -0,0 +1,2 @@ +ERROR +Error at input.cq:3:5..6: left-hand side of assignment statement must be assignable diff --git a/res/v3x/parsing/assignment/3.14_equals_3.14/ast.golden.txt b/res/v3x/parsing/assignment/3.14_equals_3.14/ast.golden.txt index 19f3ac2bd..4a35aa187 100644 --- a/res/v3x/parsing/assignment/3.14_equals_3.14/ast.golden.txt +++ b/res/v3x/parsing/assignment/3.14_equals_3.14/ast.golden.txt @@ -1,2 +1,28 @@ -ERROR -Error at input.cq:3:8..12: missing 'measure' at '3.14' +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + AssignmentStatement( # input.cq:3:6..7 + lhs: < + FloatLiteral( # input.cq:3:1..5 + value: 3.14 + ) + > + rhs: < + FloatLiteral( # input.cq:3:8..12 + value: 3.14 + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/assignment/3.14_equals_3.14/semantic.3.0.golden.txt b/res/v3x/parsing/assignment/3.14_equals_3.14/semantic.3.0.golden.txt new file mode 100644 index 000000000..6eb08ac49 --- /dev/null +++ b/res/v3x/parsing/assignment/3.14_equals_3.14/semantic.3.0.golden.txt @@ -0,0 +1,2 @@ +ERROR +Error at input.cq:3:6..7: left-hand side of assignment statement must be assignable diff --git a/res/v3x/parsing/assignment/5_equals_5/ast.golden.txt b/res/v3x/parsing/assignment/5_equals_5/ast.golden.txt index 1a0a90518..d2a1affc2 100644 --- a/res/v3x/parsing/assignment/5_equals_5/ast.golden.txt +++ b/res/v3x/parsing/assignment/5_equals_5/ast.golden.txt @@ -1,2 +1,28 @@ -ERROR -Error at input.cq:3:5..6: missing 'measure' at '5' +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + AssignmentStatement( # input.cq:3:3..4 + lhs: < + IntegerLiteral( # input.cq:3:1..2 + value: 5 + ) + > + rhs: < + IntegerLiteral( # input.cq:3:5..6 + value: 5 + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/assignment/5_equals_5/semantic.3.0.golden.txt b/res/v3x/parsing/assignment/5_equals_5/semantic.3.0.golden.txt new file mode 100644 index 000000000..9457361fd --- /dev/null +++ b/res/v3x/parsing/assignment/5_equals_5/semantic.3.0.golden.txt @@ -0,0 +1,2 @@ +ERROR +Error at input.cq:3:3..4: left-hand side of assignment statement must be assignable diff --git a/res/v3x/parsing/assignment/false_equals_false/ast.golden.txt b/res/v3x/parsing/assignment/false_equals_false/ast.golden.txt index 218051bfd..7b133292d 100644 --- a/res/v3x/parsing/assignment/false_equals_false/ast.golden.txt +++ b/res/v3x/parsing/assignment/false_equals_false/ast.golden.txt @@ -1,2 +1,28 @@ -ERROR -Error at input.cq:3:9..14: missing 'measure' at 'false' +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + AssignmentStatement( # input.cq:3:7..8 + lhs: < + BooleanLiteral( # input.cq:3:1..6 + value: 0 + ) + > + rhs: < + BooleanLiteral( # input.cq:3:9..14 + value: 0 + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/assignment/false_equals_false/semantic.3.0.golden.txt b/res/v3x/parsing/assignment/false_equals_false/semantic.3.0.golden.txt new file mode 100644 index 000000000..f589afff9 --- /dev/null +++ b/res/v3x/parsing/assignment/false_equals_false/semantic.3.0.golden.txt @@ -0,0 +1,2 @@ +ERROR +Error at input.cq:3:7..8: left-hand side of assignment statement must be assignable diff --git a/res/v3x/parsing/axis_definition/aaxis_a/ast.golden.txt b/res/v3x/parsing/axis_definition/aaxis_a/ast.golden.txt index 02118b0f3..194b35a9c 100644 --- a/res/v3x/parsing/axis_definition/aaxis_a/ast.golden.txt +++ b/res/v3x/parsing/axis_definition/aaxis_a/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..5 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..5 name: < Identifier( name: Axis ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/axis_definition/aaxis_a/semantic.3.0.golden.txt b/res/v3x/parsing/axis_definition/aaxis_a/semantic.3.0.golden.txt index 304361d32..ba8f63e04 100644 --- a/res/v3x/parsing/axis_definition/aaxis_a/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_definition/aaxis_a/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: failed to resolve mapping 'a' +Error at input.cq:3:6..7: failed to resolve variable 'a' diff --git a/res/v3x/parsing/axis_definition/axis/ast.golden.txt b/res/v3x/parsing/axis_definition/axis/ast.golden.txt index 2a2bbaa12..49ccaaebc 100644 --- a/res/v3x/parsing/axis_definition/axis/ast.golden.txt +++ b/res/v3x/parsing/axis_definition/axis/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..6: missing IDENTIFIER at '\n' +Error at input.cq:3:5..6: no viable alternative at input 'axis\n' diff --git a/res/v3x/parsing/axis_definition/axis_1/ast.golden.txt b/res/v3x/parsing/axis_definition/axis_1/ast.golden.txt index 908f92759..52dcc8c30 100644 --- a/res/v3x/parsing/axis_definition/axis_1/ast.golden.txt +++ b/res/v3x/parsing/axis_definition/axis_1/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: mismatched input '1' expecting IDENTIFIER +Error at input.cq:3:6..7: no viable alternative at input 'axis1' diff --git a/res/v3x/parsing/axis_definition/axis_123abc/ast.golden.txt b/res/v3x/parsing/axis_definition/axis_123abc/ast.golden.txt index 6e40243b6..374276830 100644 --- a/res/v3x/parsing/axis_definition/axis_123abc/ast.golden.txt +++ b/res/v3x/parsing/axis_definition/axis_123abc/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..9: extraneous input '123' expecting IDENTIFIER +Error at input.cq:3:6..9: no viable alternative at input 'axis123' diff --git a/res/v3x/parsing/axis_definition/axis_3.14/ast.golden.txt b/res/v3x/parsing/axis_definition/axis_3.14/ast.golden.txt index e5515387e..a50deb39e 100644 --- a/res/v3x/parsing/axis_definition/axis_3.14/ast.golden.txt +++ b/res/v3x/parsing/axis_definition/axis_3.14/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..10: mismatched input '3.14' expecting IDENTIFIER +Error at input.cq:3:6..10: no viable alternative at input 'axis3.14' diff --git a/res/v3x/parsing/axis_definition/axis_a/ast.golden.txt b/res/v3x/parsing/axis_definition/axis_a/ast.golden.txt index c5ca21b99..6dd473642 100644 --- a/res/v3x/parsing/axis_definition/axis_a/ast.golden.txt +++ b/res/v3x/parsing/axis_definition/axis_a/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:6..7 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_definition/axis_a/semantic.3.0.golden.txt b/res/v3x/parsing/axis_definition/axis_a/semantic.3.0.golden.txt index da04552b4..1a7b2d639 100644 --- a/res/v3x/parsing/axis_definition/axis_a/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_definition/axis_a/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: a diff --git a/res/v3x/parsing/axis_definition/axis_a__axis_a/ast.golden.txt b/res/v3x/parsing/axis_definition/axis_a__axis_a/ast.golden.txt index 36350276b..c12586809 100644 --- a/res/v3x/parsing/axis_definition/axis_a__axis_a/ast.golden.txt +++ b/res/v3x/parsing/axis_definition/axis_a__axis_a/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:6..7 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_definition/axis_a__axis_a/semantic.3.0.golden.txt b/res/v3x/parsing/axis_definition/axis_a__axis_a/semantic.3.0.golden.txt index 16d81ac49..d61a2e7c1 100644 --- a/res/v3x/parsing/axis_definition/axis_a__axis_a/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_definition/axis_a__axis_a/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: a diff --git a/res/v3x/parsing/axis_definition/axis_equal/ast.golden.txt b/res/v3x/parsing/axis_definition/axis_equal/ast.golden.txt index db027a31e..31f11be6d 100644 --- a/res/v3x/parsing/axis_definition/axis_equal/ast.golden.txt +++ b/res/v3x/parsing/axis_definition/axis_equal/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: missing IDENTIFIER at '=' +Error at input.cq:3:6..7: no viable alternative at input 'axis=' diff --git a/res/v3x/parsing/axis_initialization/axis_a1__axis_a2_equals_a1/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a1__axis_a2_equals_a1/ast.golden.txt index 3da7a336a..54fb7bb18 100644 --- a/res/v3x/parsing/axis_initialization/axis_a1__axis_a2_equals_a1/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a1__axis_a2_equals_a1/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:6..8 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a1__axis_a2_equals_a1/semantic.3.0.golden.txt b/res/v3x/parsing/axis_initialization/axis_a1__axis_a2_equals_a1/semantic.3.0.golden.txt index 076cfd3a0..557a8d59a 100644 --- a/res/v3x/parsing/axis_initialization/axis_a1__axis_a2_equals_a1/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a1__axis_a2_equals_a1/semantic.3.0.golden.txt @@ -6,46 +6,46 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: a2 - typ: < - Axis( - size: 3 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: a2 + typ: < + Axis( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - VariableRef( - variable --> < - Variable( - name: a1 - typ: < - Axis( - size: 3 + rhs: < + VariableRef( + variable --> < + Variable( + name: a1 + typ: < + Axis( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > + annotations: [] ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: a1 diff --git a/res/v3x/parsing/axis_initialization/axis_a1_equals_a2/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a1_equals_a2/ast.golden.txt index 0b72627e0..5b09b1be5 100644 --- a/res/v3x/parsing/axis_initialization/axis_a1_equals_a2/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a1_equals_a2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:6..8 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a1_equals_a2/semantic.3.0.golden.txt b/res/v3x/parsing/axis_initialization/axis_a1_equals_a2/semantic.3.0.golden.txt index 1c4e6503c..ac6d1c326 100644 --- a/res/v3x/parsing/axis_initialization/axis_a1_equals_a2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a1_equals_a2/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:11..13: failed to resolve mapping 'a2' +Error at input.cq:3:11..13: failed to resolve variable 'a2' diff --git a/res/v3x/parsing/axis_initialization/axis_a1_equals_list_of_0_0_1__axis_a2_equals_a1/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a1_equals_list_of_0_0_1__axis_a2_equals_a1/ast.golden.txt index dfa39ae17..2b19744b2 100644 --- a/res/v3x/parsing/axis_initialization/axis_a1_equals_list_of_0_0_1__axis_a2_equals_a1/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a1_equals_list_of_0_0_1__axis_a2_equals_a1/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:6..8 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -59,13 +63,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a1_equals_list_of_0_0_1__axis_a2_equals_a1/semantic.3.0.golden.txt b/res/v3x/parsing/axis_initialization/axis_a1_equals_list_of_0_0_1__axis_a2_equals_a1/semantic.3.0.golden.txt index 9c6e56145..e4681e526 100644 --- a/res/v3x/parsing/axis_initialization/axis_a1_equals_list_of_0_0_1__axis_a2_equals_a1/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a1_equals_list_of_0_0_1__axis_a2_equals_a1/semantic.3.0.golden.txt @@ -6,84 +6,79 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: a1 - typ: < - Axis( - size: 3 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: a1 + typ: < + Axis( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstRealArray( - value: [ - ConstReal( - value: 0 - ) - ConstReal( - value: 0 - ) - ConstReal( - value: 1 + rhs: < + ConstFloatArray( + value: [ + ConstFloat( + value: 0 + ) + ConstFloat( + value: 0 + ) + ConstFloat( + value: 1 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] - ) - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: a2 - typ: < - Axis( - size: 3 + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: a2 + typ: < + Axis( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - VariableRef( - variable --> < - Variable( - name: a1 - typ: < - Axis( - size: 3 + rhs: < + VariableRef( + variable --> < + Variable( + name: a1 + typ: < + Axis( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > + annotations: [] ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: a1 diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_3.14/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_3.14/ast.golden.txt index 7ccb47aab..4c466126e 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_3.14/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_3.14/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_42/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_42/ast.golden.txt index 314313534..f4c749b8a 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_42/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_42/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_a/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_a/ast.golden.txt index 437098a4c..f9a87176f 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_a/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_a/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_a/semantic.3.0.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_a/semantic.3.0.golden.txt index deee06cb5..465f6eeb2 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_a/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_a/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..11: failed to resolve mapping 'a' +Error at input.cq:3:10..11: failed to resolve variable 'a' diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0.5_0.5_0.5/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0.5_0.5_0.5/ast.golden.txt index b19e3a112..e4d015035 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0.5_0.5_0.5/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0.5_0.5_0.5/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0.5_0.5_0.5/semantic.3.0.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0.5_0.5_0.5/semantic.3.0.golden.txt index 5a691d7e6..0b35cb95a 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0.5_0.5_0.5/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0.5_0.5_0.5/semantic.3.0.golden.txt @@ -6,46 +6,46 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: a - typ: < - Axis( - size: 3 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: a + typ: < + Axis( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstRealArray( - value: [ - ConstReal( - value: 0.5 - ) - ConstReal( - value: 0.5 - ) - ConstReal( - value: 0.5 + rhs: < + ConstFloatArray( + value: [ + ConstFloat( + value: 0.5 + ) + ConstFloat( + value: 0.5 + ) + ConstFloat( + value: 0.5 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: a diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0_1_2/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0_1_2/ast.golden.txt index e04dc3c01..89f4db548 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0_1_2/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0_1_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0_1_2/semantic.3.0.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0_1_2/semantic.3.0.golden.txt index 372fc8c15..9e5e1ed40 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0_1_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_0_1_2/semantic.3.0.golden.txt @@ -6,46 +6,46 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: a - typ: < - Axis( - size: 3 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: a + typ: < + Axis( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstRealArray( - value: [ - ConstReal( - value: 0 - ) - ConstReal( - value: 1 - ) - ConstReal( - value: 2 + rhs: < + ConstFloatArray( + value: [ + ConstFloat( + value: 0 + ) + ConstFloat( + value: 1 + ) + ConstFloat( + value: 2 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: a diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_false_0_0.0/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_false_0_0.0/ast.golden.txt index 220b50d32..5e222528c 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_false_0_0.0/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_axis_list_of_false_0_0.0/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_false/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_false/ast.golden.txt index 982f52b99..e912cffb6 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_false/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_false/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_list_of_0.5_0.5_0.5/ast.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_list_of_0.5_0.5_0.5/ast.golden.txt index b19e3a112..e4d015035 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_list_of_0.5_0.5_0.5/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_list_of_0.5_0.5_0.5/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/axis_a_equals_list_of_0.5_0.5_0.5/semantic.3.0.golden.txt b/res/v3x/parsing/axis_initialization/axis_a_equals_list_of_0.5_0.5_0.5/semantic.3.0.golden.txt index 5a691d7e6..0b35cb95a 100644 --- a/res/v3x/parsing/axis_initialization/axis_a_equals_list_of_0.5_0.5_0.5/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_initialization/axis_a_equals_list_of_0.5_0.5_0.5/semantic.3.0.golden.txt @@ -6,46 +6,46 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: a - typ: < - Axis( - size: 3 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: a + typ: < + Axis( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstRealArray( - value: [ - ConstReal( - value: 0.5 - ) - ConstReal( - value: 0.5 - ) - ConstReal( - value: 0.5 + rhs: < + ConstFloatArray( + value: [ + ConstFloat( + value: 0.5 + ) + ConstFloat( + value: 0.5 + ) + ConstFloat( + value: 0.5 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: a diff --git a/res/v3x/parsing/axis_initialization/bit_b__axis_a_equals_b/ast.golden.txt b/res/v3x/parsing/axis_initialization/bit_b__axis_a_equals_b/ast.golden.txt index f17d1f150..68748c0fd 100644 --- a/res/v3x/parsing/axis_initialization/bit_b__axis_a_equals_b/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/bit_b__axis_a_equals_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:5..6 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: bit + Type( # input.cq:3:1..4 + name: < + Keyword( + name: bit + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:8..9 @@ -31,13 +35,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/bool_b__axis_a_equals_b/ast.golden.txt b/res/v3x/parsing/axis_initialization/bool_b__axis_a_equals_b/ast.golden.txt index 85d66095b..acaea7afb 100644 --- a/res/v3x/parsing/axis_initialization/bool_b__axis_a_equals_b/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/bool_b__axis_a_equals_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:6..7 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:8..9 @@ -31,13 +35,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/bool_b_equals_true__axis_a_equals_axis_list_of_0_b_1.0/ast.golden.txt b/res/v3x/parsing/axis_initialization/bool_b_equals_true__axis_a_equals_axis_list_of_0_b_1.0/ast.golden.txt index 1b64fd74c..1850f4bc7 100644 --- a/res/v3x/parsing/axis_initialization/bool_b_equals_true__axis_a_equals_axis_list_of_0_b_1.0/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/bool_b_equals_true__axis_a_equals_axis_list_of_0_b_1.0/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > @@ -41,13 +45,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/bool_b_equals_true__axis_a_equals_axis_list_of_0_b_1.0/semantic.3.0.golden.txt b/res/v3x/parsing/axis_initialization/bool_b_equals_true__axis_a_equals_axis_list_of_0_b_1.0/semantic.3.0.golden.txt index 396896909..ba67ddf51 100644 --- a/res/v3x/parsing/axis_initialization/bool_b_equals_true__axis_a_equals_axis_list_of_0_b_1.0/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_initialization/bool_b_equals_true__axis_a_equals_axis_list_of_0_b_1.0/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:8..9: expecting a const bool, const int, or const real value +Error at input.cq:4:8..9: expecting a const bool, const int, or const float value diff --git a/res/v3x/parsing/axis_initialization/float_f__axis_a_equals_f/ast.golden.txt b/res/v3x/parsing/axis_initialization/float_f__axis_a_equals_f/ast.golden.txt index 975664e10..f335efcc0 100644 --- a/res/v3x/parsing/axis_initialization/float_f__axis_a_equals_f/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/float_f__axis_a_equals_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:8..9 @@ -31,13 +35,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/int_i__axis_a_equals_i/ast.golden.txt b/res/v3x/parsing/axis_initialization/int_i__axis_a_equals_i/ast.golden.txt index cb6ef27df..825a7ee15 100644 --- a/res/v3x/parsing/axis_initialization/int_i__axis_a_equals_i/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/int_i__axis_a_equals_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:5..6 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:8..9 @@ -31,13 +35,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/int_i_equals_1__axis_a_equals_axis_list_of_true_i_0.0/ast.golden.txt b/res/v3x/parsing/axis_initialization/int_i_equals_1__axis_a_equals_axis_list_of_true_i_0.0/ast.golden.txt index db15d7421..a59e2530b 100644 --- a/res/v3x/parsing/axis_initialization/int_i_equals_1__axis_a_equals_axis_list_of_true_i_0.0/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/int_i_equals_1__axis_a_equals_axis_list_of_true_i_0.0/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > @@ -41,13 +45,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/axis_initialization/int_i_equals_1__axis_a_equals_axis_list_of_true_i_0.0/semantic.3.0.golden.txt b/res/v3x/parsing/axis_initialization/int_i_equals_1__axis_a_equals_axis_list_of_true_i_0.0/semantic.3.0.golden.txt index 396896909..ba67ddf51 100644 --- a/res/v3x/parsing/axis_initialization/int_i_equals_1__axis_a_equals_axis_list_of_true_i_0.0/semantic.3.0.golden.txt +++ b/res/v3x/parsing/axis_initialization/int_i_equals_1__axis_a_equals_axis_list_of_true_i_0.0/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:8..9: expecting a const bool, const int, or const real value +Error at input.cq:4:8..9: expecting a const bool, const int, or const float value diff --git a/res/v3x/parsing/axis_initialization/qubit_q__axis_a_equals_q/ast.golden.txt b/res/v3x/parsing/axis_initialization/qubit_q__axis_a_equals_q/ast.golden.txt index 4f3619b3c..d9eb80b3d 100644 --- a/res/v3x/parsing/axis_initialization/qubit_q__axis_a_equals_q/ast.golden.txt +++ b/res/v3x/parsing/axis_initialization/qubit_q__axis_a_equals_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:8..9 @@ -31,13 +35,17 @@ Program( ) > typ: < - Keyword( - name: axis - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..5 + name: < + Keyword( + name: axis + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bit_array_definition/bit_array_of_0_b/ast.golden.txt b/res/v3x/parsing/bit_array_definition/bit_array_of_0_b/ast.golden.txt index 93308b65f..7af64613f 100644 --- a/res/v3x/parsing/bit_array_definition/bit_array_of_0_b/ast.golden.txt +++ b/res/v3x/parsing/bit_array_definition/bit_array_of_0_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:8..9 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 0 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 0 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bit_array_definition/bit_array_of_0_b/semantic.3.0.golden.txt b/res/v3x/parsing/bit_array_definition/bit_array_of_0_b/semantic.3.0.golden.txt index 688b15b8c..727b7c702 100644 --- a/res/v3x/parsing/bit_array_definition/bit_array_of_0_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bit_array_definition/bit_array_of_0_b/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:8..9: declaring bit array of size <= 0 +Error at input.cq:3:8..9: found bit array of size <= 0 diff --git a/res/v3x/parsing/bit_array_definition/bit_array_of_17_b/ast.golden.txt b/res/v3x/parsing/bit_array_definition/bit_array_of_17_b/ast.golden.txt index 807d53ac9..df2dc224c 100644 --- a/res/v3x/parsing/bit_array_definition/bit_array_of_17_b/ast.golden.txt +++ b/res/v3x/parsing/bit_array_definition/bit_array_of_17_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:9..10 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bit_array_definition/bit_array_of_17_b/semantic.3.0.golden.txt b/res/v3x/parsing/bit_array_definition/bit_array_of_17_b/semantic.3.0.golden.txt index b4e90d3fb..ead306d82 100644 --- a/res/v3x/parsing/bit_array_definition/bit_array_of_17_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bit_array_definition/bit_array_of_17_b/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/bit_array_definition/bit_array_of_17_b__bit_array_of_17_b/ast.golden.txt b/res/v3x/parsing/bit_array_definition/bit_array_of_17_b__bit_array_of_17_b/ast.golden.txt index 36dbf825f..5205a2906 100644 --- a/res/v3x/parsing/bit_array_definition/bit_array_of_17_b__bit_array_of_17_b/ast.golden.txt +++ b/res/v3x/parsing/bit_array_definition/bit_array_of_17_b__bit_array_of_17_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:9..10 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:4:1..8 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bit_array_definition/bit_array_of_17_b__bit_array_of_17_b/semantic.3.0.golden.txt b/res/v3x/parsing/bit_array_definition/bit_array_of_17_b__bit_array_of_17_b/semantic.3.0.golden.txt index 4ad1af325..8c8de24c8 100644 --- a/res/v3x/parsing/bit_array_definition/bit_array_of_17_b__bit_array_of_17_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bit_array_definition/bit_array_of_17_b__bit_array_of_17_b/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/bit_definition/bbit_b/ast.golden.txt b/res/v3x/parsing/bit_definition/bbit_b/ast.golden.txt index ab7ec5b76..ca1fd75d9 100644 --- a/res/v3x/parsing/bit_definition/bbit_b/ast.golden.txt +++ b/res/v3x/parsing/bit_definition/bbit_b/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..4 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..4 name: < Identifier( name: Bit ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/bit_definition/bbit_b/semantic.3.0.golden.txt b/res/v3x/parsing/bit_definition/bbit_b/semantic.3.0.golden.txt index 8795cf14e..69d4fae00 100644 --- a/res/v3x/parsing/bit_definition/bbit_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bit_definition/bbit_b/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..6: failed to resolve mapping 'b' +Error at input.cq:3:5..6: failed to resolve variable 'b' diff --git a/res/v3x/parsing/bit_definition/bit/ast.golden.txt b/res/v3x/parsing/bit_definition/bit/ast.golden.txt index f260ff0ba..ee42cb07c 100644 --- a/res/v3x/parsing/bit_definition/bit/ast.golden.txt +++ b/res/v3x/parsing/bit_definition/bit/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:4..5: mismatched input '\n' expecting {'[', IDENTIFIER} +Error at input.cq:3:4..5: missing IDENTIFIER at '\n' diff --git a/res/v3x/parsing/bit_definition/bit_1/ast.golden.txt b/res/v3x/parsing/bit_definition/bit_1/ast.golden.txt index 3352ab231..8ce02f5fc 100644 --- a/res/v3x/parsing/bit_definition/bit_1/ast.golden.txt +++ b/res/v3x/parsing/bit_definition/bit_1/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..6: mismatched input '1' expecting {'[', IDENTIFIER} +Error at input.cq:3:5..6: mismatched input '1' expecting IDENTIFIER diff --git a/res/v3x/parsing/bit_definition/bit_123abc/ast.golden.txt b/res/v3x/parsing/bit_definition/bit_123abc/ast.golden.txt index 8b3ecbcb2..b3c60bc43 100644 --- a/res/v3x/parsing/bit_definition/bit_123abc/ast.golden.txt +++ b/res/v3x/parsing/bit_definition/bit_123abc/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..8: extraneous input '123' expecting {'[', IDENTIFIER} +Error at input.cq:3:5..8: extraneous input '123' expecting IDENTIFIER diff --git a/res/v3x/parsing/bit_definition/bit_3.14/ast.golden.txt b/res/v3x/parsing/bit_definition/bit_3.14/ast.golden.txt index 53d860aae..29447b5fe 100644 --- a/res/v3x/parsing/bit_definition/bit_3.14/ast.golden.txt +++ b/res/v3x/parsing/bit_definition/bit_3.14/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..9: mismatched input '3.14' expecting {'[', IDENTIFIER} +Error at input.cq:3:5..9: mismatched input '3.14' expecting IDENTIFIER diff --git a/res/v3x/parsing/bit_definition/bit_b/ast.golden.txt b/res/v3x/parsing/bit_definition/bit_b/ast.golden.txt index 3f3a97789..a84c383dc 100644 --- a/res/v3x/parsing/bit_definition/bit_b/ast.golden.txt +++ b/res/v3x/parsing/bit_definition/bit_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:5..6 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: bit + Type( # input.cq:3:1..4 + name: < + Keyword( + name: bit + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/bit_definition/bit_b/semantic.3.0.golden.txt b/res/v3x/parsing/bit_definition/bit_b/semantic.3.0.golden.txt index 855d8d3d2..3dbc816fc 100644 --- a/res/v3x/parsing/bit_definition/bit_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bit_definition/bit_b/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/bit_definition/bit_b__bit_b/ast.golden.txt b/res/v3x/parsing/bit_definition/bit_b__bit_b/ast.golden.txt index cae1a581d..17c4a971d 100644 --- a/res/v3x/parsing/bit_definition/bit_b__bit_b/ast.golden.txt +++ b/res/v3x/parsing/bit_definition/bit_b__bit_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:5..6 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: bit + Type( # input.cq:3:1..4 + name: < + Keyword( + name: bit + ) + > + size: - ) > - size: - annotations: [] ) Variable( # input.cq:4:5..6 @@ -29,11 +33,15 @@ Program( ) > typ: < - Keyword( - name: bit + Type( # input.cq:4:1..4 + name: < + Keyword( + name: bit + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/bit_definition/bit_b__bit_b/semantic.3.0.golden.txt b/res/v3x/parsing/bit_definition/bit_b__bit_b/semantic.3.0.golden.txt index 55b2d2452..800eb6621 100644 --- a/res/v3x/parsing/bit_definition/bit_b__bit_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bit_definition/bit_b__bit_b/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/bit_definition/bit_equal/ast.golden.txt b/res/v3x/parsing/bit_definition/bit_equal/ast.golden.txt index 56f26b4bf..bdafdaccf 100644 --- a/res/v3x/parsing/bit_definition/bit_equal/ast.golden.txt +++ b/res/v3x/parsing/bit_definition/bit_equal/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..6: mismatched input '=' expecting {'[', IDENTIFIER} +Error at input.cq:3:5..6: mismatched input '=' expecting IDENTIFIER diff --git a/res/v3x/parsing/bool_array_definition/bbool_array_of_17_b/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bbool_array_of_17_b/ast.golden.txt index fa527d1e0..4561e37a7 100644 --- a/res/v3x/parsing/bool_array_definition/bbool_array_of_17_b/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bbool_array_of_17_b/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..11: mismatched input 'b' expecting '=' +Error at input.cq:3:10..11: extraneous input 'b' expecting {, NEW_LINE, ';'} diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_0_b/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_0_b/ast.golden.txt index 0bc26f288..85847b781 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_0_b/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_0_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:9..10 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 0 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 0 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_0_b/semantic.3.0.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_0_b/semantic.3.0.golden.txt index 70bad6158..5a99fd6db 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_0_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_0_b/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:9..10: declaring bool array of size <= 0 +Error at input.cq:3:9..10: found bool array of size <= 0 diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_123abc/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_123abc/ast.golden.txt index 52d1525ac..da602e932 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_123abc/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_123abc/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:9..12: extraneous input 'abc' expecting ']' +Error at input.cq:3:9..12: no viable alternative at input 'bool[123abc' diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_17/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_17/ast.golden.txt index 5c93332fb..43a11adc2 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_17/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_17/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:9..10: missing IDENTIFIER at '\n' +Error at input.cq:3:9..10: no viable alternative at input 'bool[17]\n' diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_17_1/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_17_1/ast.golden.txt index 3c186464d..7b653e03a 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_17_1/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_17_1/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..11: mismatched input '1' expecting IDENTIFIER +Error at input.cq:3:10..11: no viable alternative at input 'bool[17]1' diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_17_3.14/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_17_3.14/ast.golden.txt index 6951be0e7..bb0e769e8 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_17_3.14/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_17_3.14/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..14: mismatched input '3.14' expecting IDENTIFIER +Error at input.cq:3:10..14: no viable alternative at input 'bool[17]3.14' diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_17_b/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_17_b/ast.golden.txt index 44a92b130..e087978ea 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_17_b/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_17_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_17_b/semantic.3.0.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_17_b/semantic.3.0.golden.txt index dabcf0452..ee911fee1 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_17_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_17_b/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_17_b__bool_array_of_17_b/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_17_b__bool_array_of_17_b/ast.golden.txt index 8e0d617ce..ac0bbd4da 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_17_b__bool_array_of_17_b/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_17_b__bool_array_of_17_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:4:1..9 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_17_b__bool_array_of_17_b/semantic.3.0.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_17_b__bool_array_of_17_b/semantic.3.0.golden.txt index 7e148cd8b..14c51a96d 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_17_b__bool_array_of_17_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_17_b__bool_array_of_17_b/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_17_equal/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_17_equal/ast.golden.txt index 8842d5447..859ed04d8 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_17_equal/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_17_equal/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..11: missing IDENTIFIER at '=' +Error at input.cq:3:10..11: no viable alternative at input 'bool[17]=' diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_3.14/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_3.14/ast.golden.txt index e533b3854..b5cd98518 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_3.14/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_3.14/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..10: mismatched input '3.14' expecting INTEGER_LITERAL +Error at input.cq:3:6..10: no viable alternative at input 'bool[3.14' diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_b/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_b/ast.golden.txt index c1a8ba7c2..3d77307e0 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_b/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_b/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: mismatched input 'b' expecting INTEGER_LITERAL +Error at input.cq:3:6..7: no viable alternative at input 'bool[b' diff --git a/res/v3x/parsing/bool_array_definition/bool_array_of_equal/ast.golden.txt b/res/v3x/parsing/bool_array_definition/bool_array_of_equal/ast.golden.txt index c57400413..9917cdf22 100644 --- a/res/v3x/parsing/bool_array_definition/bool_array_of_equal/ast.golden.txt +++ b/res/v3x/parsing/bool_array_definition/bool_array_of_equal/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: mismatched input '=' expecting INTEGER_LITERAL +Error at input.cq:3:6..7: no viable alternative at input 'bool[=' diff --git a/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b1_equals_list_of_false_true__bool_array_of_2_b2_equals_b1/ast.golden.txt b/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b1_equals_list_of_false_true__bool_array_of_2_b2_equals_b1/ast.golden.txt index 5cf4c937d..aaf748038 100644 --- a/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b1_equals_list_of_false_true__bool_array_of_2_b2_equals_b1/ast.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b1_equals_list_of_false_true__bool_array_of_2_b2_equals_b1/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:12..13 var: < Variable( # input.cq:3:9..11 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] @@ -56,13 +60,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:4:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b1_equals_list_of_false_true__bool_array_of_2_b2_equals_b1/semantic.3.0.golden.txt b/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b1_equals_list_of_false_true__bool_array_of_2_b2_equals_b1/semantic.3.0.golden.txt index 22c85989a..1a4f4cd43 100644 --- a/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b1_equals_list_of_false_true__bool_array_of_2_b2_equals_b1/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b1_equals_list_of_false_true__bool_array_of_2_b2_equals_b1/semantic.3.0.golden.txt @@ -6,81 +6,76 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: b1 - typ: < - BoolArray( - size: 2 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: b1 + typ: < + BoolArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstBoolArray( - value: [ - ConstBool( - value: 0 - ) - ConstBool( - value: 1 + rhs: < + ConstBoolArray( + value: [ + ConstBool( + value: 0 + ) + ConstBool( + value: 1 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] - ) - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: b2 - typ: < - BoolArray( - size: 2 + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: b2 + typ: < + BoolArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - VariableRef( - variable --> < - Variable( - name: b1 - typ: < - BoolArray( - size: 2 + rhs: < + VariableRef( + variable --> < + Variable( + name: b1 + typ: < + BoolArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] ) > + annotations: [] ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: b1 diff --git a/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b_equals_list_of_false_true/ast.golden.txt b/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b_equals_list_of_false_true/ast.golden.txt index 30dba0c8e..3d54310c5 100644 --- a/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b_equals_list_of_false_true/ast.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b_equals_list_of_false_true/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:11..12 var: < Variable( # input.cq:3:9..10 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b_equals_list_of_false_true/semantic.3.0.golden.txt b/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b_equals_list_of_false_true/semantic.3.0.golden.txt index 3c14bd8ad..d02ed9c6a 100644 --- a/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b_equals_list_of_false_true/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/bool_array_of_2_b_equals_list_of_false_true/semantic.3.0.golden.txt @@ -6,43 +6,43 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: b - typ: < - BoolArray( - size: 2 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: b + typ: < + BoolArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstBoolArray( - value: [ - ConstBool( - value: 0 - ) - ConstBool( - value: 1 + rhs: < + ConstBoolArray( + value: [ + ConstBool( + value: 0 + ) + ConstBool( + value: 1 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b1_equals_b2/ast.golden.txt b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b1_equals_b2/ast.golden.txt index d06048c23..853baca6e 100644 --- a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b1_equals_b2/ast.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b1_equals_b2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:12..13 var: < Variable( # input.cq:3:9..11 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b1_equals_b2/semantic.3.0.golden.txt b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b1_equals_b2/semantic.3.0.golden.txt index 8b3e195c5..0ff00b0b5 100644 --- a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b1_equals_b2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b1_equals_b2/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:14..16: failed to resolve mapping 'b2' +Error at input.cq:3:14..16: failed to resolve variable 'b2' diff --git a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_b/ast.golden.txt b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_b/ast.golden.txt index 1a1fdf137..d5afb2e07 100644 --- a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_b/ast.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:11..12 var: < Variable( # input.cq:3:9..10 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_b/semantic.3.0.golden.txt b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_b/semantic.3.0.golden.txt index bf208ab1b..46e76b7dc 100644 --- a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_b/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:13..14: failed to resolve mapping 'b' +Error at input.cq:3:13..14: failed to resolve variable 'b' diff --git a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_list_of_false_true/ast.golden.txt b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_list_of_false_true/ast.golden.txt index 9f247ff59..55fbd774a 100644 --- a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_list_of_false_true/ast.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_list_of_false_true/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:11..12 var: < Variable( # input.cq:3:9..10 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_list_of_false_true_0/ast.golden.txt b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_list_of_false_true_0/ast.golden.txt index e1acfb99b..322900444 100644 --- a/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_list_of_false_true_0/ast.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/bool_array_of_3_b_equals_list_of_false_true_0/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:11..12 var: < Variable( # input.cq:3:9..10 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_array_initialization/float_array_of_3_f__bool_array_of_3_b_equals_f/ast.golden.txt b/res/v3x/parsing/bool_array_initialization/float_array_of_3_f__bool_array_of_3_b_equals_f/ast.golden.txt index 756c5e828..42ac3d65b 100644 --- a/res/v3x/parsing/bool_array_initialization/float_array_of_3_f__bool_array_of_3_b_equals_f/ast.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/float_array_of_3_f__bool_array_of_3_b_equals_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_array_initialization/float_array_of_3_f__bool_array_of_3_b_equals_f/semantic.3.0.golden.txt b/res/v3x/parsing/bool_array_initialization/float_array_of_3_f__bool_array_of_3_b_equals_f/semantic.3.0.golden.txt index e7bd8db5f..c3d590236 100644 --- a/res/v3x/parsing/bool_array_initialization/float_array_of_3_f__bool_array_of_3_b_equals_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/float_array_of_3_f__bool_array_of_3_b_equals_f/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:11..12: type of right-hand side (real array) could not be coerced to left-hand side (bool array) +Error at input.cq:4:11..12: type of right-hand side (float array) could not be coerced to left-hand side (bool array) diff --git a/res/v3x/parsing/bool_array_initialization/qubit_array_of_3_q__bool_array_of_3_b_equals_q/ast.golden.txt b/res/v3x/parsing/bool_array_initialization/qubit_array_of_3_q__bool_array_of_3_b_equals_q/ast.golden.txt index 4d4937a41..44e173559 100644 --- a/res/v3x/parsing/bool_array_initialization/qubit_array_of_3_q__bool_array_of_3_b_equals_q/ast.golden.txt +++ b/res/v3x/parsing/bool_array_initialization/qubit_array_of_3_q__bool_array_of_3_b_equals_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/bool_definition/bbool_b/ast.golden.txt b/res/v3x/parsing/bool_definition/bbool_b/ast.golden.txt index 8f54e07c0..a93d0b705 100644 --- a/res/v3x/parsing/bool_definition/bbool_b/ast.golden.txt +++ b/res/v3x/parsing/bool_definition/bbool_b/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..5 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..5 name: < Identifier( name: Bool ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/bool_definition/bbool_b/semantic.3.0.golden.txt b/res/v3x/parsing/bool_definition/bbool_b/semantic.3.0.golden.txt index 0389016bf..8fbfc3be5 100644 --- a/res/v3x/parsing/bool_definition/bbool_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_definition/bbool_b/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: failed to resolve mapping 'b' +Error at input.cq:3:6..7: failed to resolve variable 'b' diff --git a/res/v3x/parsing/bool_definition/bool/ast.golden.txt b/res/v3x/parsing/bool_definition/bool/ast.golden.txt index 532d66eae..f23352071 100644 --- a/res/v3x/parsing/bool_definition/bool/ast.golden.txt +++ b/res/v3x/parsing/bool_definition/bool/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..6: mismatched input '\n' expecting {'[', IDENTIFIER} +Error at input.cq:3:5..6: no viable alternative at input 'bool\n' diff --git a/res/v3x/parsing/bool_definition/bool_1/ast.golden.txt b/res/v3x/parsing/bool_definition/bool_1/ast.golden.txt index a04f88d51..b2d1935a3 100644 --- a/res/v3x/parsing/bool_definition/bool_1/ast.golden.txt +++ b/res/v3x/parsing/bool_definition/bool_1/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: mismatched input '1' expecting {'[', IDENTIFIER} +Error at input.cq:3:6..7: no viable alternative at input 'bool1' diff --git a/res/v3x/parsing/bool_definition/bool_123abc/ast.golden.txt b/res/v3x/parsing/bool_definition/bool_123abc/ast.golden.txt index 6f59c3cff..85b01dba6 100644 --- a/res/v3x/parsing/bool_definition/bool_123abc/ast.golden.txt +++ b/res/v3x/parsing/bool_definition/bool_123abc/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..9: extraneous input '123' expecting {'[', IDENTIFIER} +Error at input.cq:3:6..9: no viable alternative at input 'bool123' diff --git a/res/v3x/parsing/bool_definition/bool_3.14/ast.golden.txt b/res/v3x/parsing/bool_definition/bool_3.14/ast.golden.txt index 39452e392..20e099d0e 100644 --- a/res/v3x/parsing/bool_definition/bool_3.14/ast.golden.txt +++ b/res/v3x/parsing/bool_definition/bool_3.14/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..10: mismatched input '3.14' expecting {'[', IDENTIFIER} +Error at input.cq:3:6..10: no viable alternative at input 'bool3.14' diff --git a/res/v3x/parsing/bool_definition/bool_b/ast.golden.txt b/res/v3x/parsing/bool_definition/bool_b/ast.golden.txt index 11fd306b9..a311a9549 100644 --- a/res/v3x/parsing/bool_definition/bool_b/ast.golden.txt +++ b/res/v3x/parsing/bool_definition/bool_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:6..7 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/bool_definition/bool_b/semantic.3.0.golden.txt b/res/v3x/parsing/bool_definition/bool_b/semantic.3.0.golden.txt index 01811103b..4a30fb987 100644 --- a/res/v3x/parsing/bool_definition/bool_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_definition/bool_b/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/bool_definition/bool_b__bool_b/ast.golden.txt b/res/v3x/parsing/bool_definition/bool_b__bool_b/ast.golden.txt index 527b91e14..1a7219fd0 100644 --- a/res/v3x/parsing/bool_definition/bool_b__bool_b/ast.golden.txt +++ b/res/v3x/parsing/bool_definition/bool_b__bool_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:6..7 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) Variable( # input.cq:4:6..7 @@ -29,11 +33,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:4:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/bool_definition/bool_b__bool_b/semantic.3.0.golden.txt b/res/v3x/parsing/bool_definition/bool_b__bool_b/semantic.3.0.golden.txt index 84e36d42d..bbdbf9ec1 100644 --- a/res/v3x/parsing/bool_definition/bool_b__bool_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_definition/bool_b__bool_b/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/bool_definition/bool_equals/ast.golden.txt b/res/v3x/parsing/bool_definition/bool_equals/ast.golden.txt index 8e418741e..391a0f669 100644 --- a/res/v3x/parsing/bool_definition/bool_equals/ast.golden.txt +++ b/res/v3x/parsing/bool_definition/bool_equals/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: mismatched input '=' expecting {'[', IDENTIFIER} +Error at input.cq:3:6..7: no viable alternative at input 'bool=' diff --git a/res/v3x/parsing/bool_initialization/bool_b1_equals_b2/ast.golden.txt b/res/v3x/parsing/bool_initialization/bool_b1_equals_b2/ast.golden.txt index bb49e3f5f..11ff40ac7 100644 --- a/res/v3x/parsing/bool_initialization/bool_b1_equals_b2/ast.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b1_equals_b2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:6..8 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/bool_initialization/bool_b1_equals_b2/semantic.3.0.golden.txt b/res/v3x/parsing/bool_initialization/bool_b1_equals_b2/semantic.3.0.golden.txt index 8e5ab425d..ba72715b0 100644 --- a/res/v3x/parsing/bool_initialization/bool_b1_equals_b2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b1_equals_b2/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:11..13: failed to resolve mapping 'b2' +Error at input.cq:3:11..13: failed to resolve variable 'b2' diff --git a/res/v3x/parsing/bool_initialization/bool_b1_equals_false__bool_b2_equals_b1/ast.golden.txt b/res/v3x/parsing/bool_initialization/bool_b1_equals_false__bool_b2_equals_b1/ast.golden.txt index 058ddf752..4892af6f2 100644 --- a/res/v3x/parsing/bool_initialization/bool_b1_equals_false__bool_b2_equals_b1/ast.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b1_equals_false__bool_b2_equals_b1/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:6..8 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > @@ -41,11 +45,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:4:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/bool_initialization/bool_b1_equals_false__bool_b2_equals_b1/semantic.3.0.golden.txt b/res/v3x/parsing/bool_initialization/bool_b1_equals_false__bool_b2_equals_b1/semantic.3.0.golden.txt index bf6314c26..0f1ae32da 100644 --- a/res/v3x/parsing/bool_initialization/bool_b1_equals_false__bool_b2_equals_b1/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b1_equals_false__bool_b2_equals_b1/semantic.3.0.golden.txt @@ -6,74 +6,69 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: b1 - typ: < - Bool( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: b1 + typ: < + Bool( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstBool( + value: 0 + ) + > + annotations: [] ) - > - rhs: < - ConstBool( - value: 0 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] - ) - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: b2 - typ: < - Bool( - size: 1 + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: b2 + typ: < + Bool( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - VariableRef( - variable --> < - Variable( - name: b1 - typ: < - Bool( - size: 1 + rhs: < + VariableRef( + variable --> < + Variable( + name: b1 + typ: < + Bool( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + annotations: [] ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: b1 diff --git a/res/v3x/parsing/bool_initialization/bool_b_equals_3.14/ast.golden.txt b/res/v3x/parsing/bool_initialization/bool_b_equals_3.14/ast.golden.txt index a165291d8..b0212a744 100644 --- a/res/v3x/parsing/bool_initialization/bool_b_equals_3.14/ast.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b_equals_3.14/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/bool_initialization/bool_b_equals_3.14/semantic.3.0.golden.txt b/res/v3x/parsing/bool_initialization/bool_b_equals_3.14/semantic.3.0.golden.txt index 9ef667047..116b5a7f8 100644 --- a/res/v3x/parsing/bool_initialization/bool_b_equals_3.14/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b_equals_3.14/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:8..9: type of right-hand side (real) could not be coerced to left-hand side (bool) +Error at input.cq:3:8..9: type of right-hand side (float) could not be coerced to left-hand side (bool) diff --git a/res/v3x/parsing/bool_initialization/bool_b_equals_42/ast.golden.txt b/res/v3x/parsing/bool_initialization/bool_b_equals_42/ast.golden.txt index 277ddeeb6..7a06b049e 100644 --- a/res/v3x/parsing/bool_initialization/bool_b_equals_42/ast.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b_equals_42/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/bool_initialization/bool_b_equals_b/ast.golden.txt b/res/v3x/parsing/bool_initialization/bool_b_equals_b/ast.golden.txt index 231234393..220a48508 100644 --- a/res/v3x/parsing/bool_initialization/bool_b_equals_b/ast.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b_equals_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/bool_initialization/bool_b_equals_b/semantic.3.0.golden.txt b/res/v3x/parsing/bool_initialization/bool_b_equals_b/semantic.3.0.golden.txt index df0e5cf3c..c8b7d73de 100644 --- a/res/v3x/parsing/bool_initialization/bool_b_equals_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b_equals_b/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..11: failed to resolve mapping 'b' +Error at input.cq:3:10..11: failed to resolve variable 'b' diff --git a/res/v3x/parsing/bool_initialization/bool_b_equals_false/ast.golden.txt b/res/v3x/parsing/bool_initialization/bool_b_equals_false/ast.golden.txt index 7b73f074c..9db116fe5 100644 --- a/res/v3x/parsing/bool_initialization/bool_b_equals_false/ast.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b_equals_false/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/bool_initialization/bool_b_equals_false/semantic.3.0.golden.txt b/res/v3x/parsing/bool_initialization/bool_b_equals_false/semantic.3.0.golden.txt index 569cb9486..5685c2370 100644 --- a/res/v3x/parsing/bool_initialization/bool_b_equals_false/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_initialization/bool_b_equals_false/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: b - typ: < - Bool( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: b + typ: < + Bool( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstBool( + value: 0 + ) + > + annotations: [] ) - > - rhs: < - ConstBool( - value: 0 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/bool_initialization/float_f__bool_b_equals_f/ast.golden.txt b/res/v3x/parsing/bool_initialization/float_f__bool_b_equals_f/ast.golden.txt index 5b779b0e5..690cb6951 100644 --- a/res/v3x/parsing/bool_initialization/float_f__bool_b_equals_f/ast.golden.txt +++ b/res/v3x/parsing/bool_initialization/float_f__bool_b_equals_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:8..9 @@ -31,11 +35,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:4:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/bool_initialization/float_f__bool_b_equals_f/semantic.3.0.golden.txt b/res/v3x/parsing/bool_initialization/float_f__bool_b_equals_f/semantic.3.0.golden.txt index cc0a1b7e3..6a9d3c7d6 100644 --- a/res/v3x/parsing/bool_initialization/float_f__bool_b_equals_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/bool_initialization/float_f__bool_b_equals_f/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:8..9: type of right-hand side (real) could not be coerced to left-hand side (bool) +Error at input.cq:4:8..9: type of right-hand side (float) could not be coerced to left-hand side (bool) diff --git a/res/v3x/parsing/bool_initialization/qubit_q__bool_b_equals_q/ast.golden.txt b/res/v3x/parsing/bool_initialization/qubit_q__bool_b_equals_q/ast.golden.txt index 9f6f252ea..72243b98e 100644 --- a/res/v3x/parsing/bool_initialization/qubit_q__bool_b_equals_q/ast.golden.txt +++ b/res/v3x/parsing/bool_initialization/qubit_q__bool_b_equals_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:8..9 @@ -31,11 +35,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:4:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/case_sensitiveness/eu_uppercase/ast.golden.txt b/res/v3x/parsing/case_sensitiveness/eu_uppercase/ast.golden.txt index 5d2b1cc2c..1ba6000c1 100644 --- a/res/v3x/parsing/case_sensitiveness/eu_uppercase/ast.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/eu_uppercase/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:4:1..3 + Gate( # input.cq:4:1..3 name: < Identifier( name: rx ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/case_sensitiveness/eu_uppercase/semantic.3.0.golden.txt b/res/v3x/parsing/case_sensitiveness/eu_uppercase/semantic.3.0.golden.txt index 673f19dc3..fbd25bf2f 100644 --- a/res/v3x/parsing/case_sensitiveness/eu_uppercase/semantic.3.0.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/eu_uppercase/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:7..9: failed to resolve mapping 'EU' +Error at input.cq:4:7..9: failed to resolve variable 'EU' diff --git a/res/v3x/parsing/case_sensitiveness/pi_uppercase/ast.golden.txt b/res/v3x/parsing/case_sensitiveness/pi_uppercase/ast.golden.txt index 64f32fbf9..5e6068db2 100644 --- a/res/v3x/parsing/case_sensitiveness/pi_uppercase/ast.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/pi_uppercase/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:4:1..3 + Gate( # input.cq:4:1..3 name: < Identifier( name: rx ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/case_sensitiveness/pi_uppercase/semantic.3.0.golden.txt b/res/v3x/parsing/case_sensitiveness/pi_uppercase/semantic.3.0.golden.txt index 09a410cc3..25206d694 100644 --- a/res/v3x/parsing/case_sensitiveness/pi_uppercase/semantic.3.0.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/pi_uppercase/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:7..9: failed to resolve mapping 'PI' +Error at input.cq:4:7..9: failed to resolve variable 'PI' diff --git a/res/v3x/parsing/case_sensitiveness/q_uppercase/ast.golden.txt b/res/v3x/parsing/case_sensitiveness/q_uppercase/ast.golden.txt index be7c6c896..ed52d6600 100644 --- a/res/v3x/parsing/case_sensitiveness/q_uppercase/ast.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/q_uppercase/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:4:1..2 + Gate( # input.cq:4:1..2 name: < Identifier( name: x ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/case_sensitiveness/q_uppercase/semantic.3.0.golden.txt b/res/v3x/parsing/case_sensitiveness/q_uppercase/semantic.3.0.golden.txt index 82da6fcd7..2f53ef341 100644 --- a/res/v3x/parsing/case_sensitiveness/q_uppercase/semantic.3.0.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/q_uppercase/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:3..4: failed to resolve mapping 'Q' +Error at input.cq:4:3..4: failed to resolve variable 'Q' diff --git a/res/v3x/parsing/case_sensitiveness/qubit_all_uppercase/ast.golden.txt b/res/v3x/parsing/case_sensitiveness/qubit_all_uppercase/ast.golden.txt index 74b983741..332b2f049 100644 --- a/res/v3x/parsing/case_sensitiveness/qubit_all_uppercase/ast.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/qubit_all_uppercase/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..6 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..6 name: < Identifier( name: QUBIT ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/case_sensitiveness/qubit_all_uppercase/semantic.3.0.golden.txt b/res/v3x/parsing/case_sensitiveness/qubit_all_uppercase/semantic.3.0.golden.txt index cff2186aa..643034f9a 100644 --- a/res/v3x/parsing/case_sensitiveness/qubit_all_uppercase/semantic.3.0.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/qubit_all_uppercase/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..8: failed to resolve mapping 'q' +Error at input.cq:3:7..8: failed to resolve variable 'q' diff --git a/res/v3x/parsing/case_sensitiveness/qubit_camel_case/ast.golden.txt b/res/v3x/parsing/case_sensitiveness/qubit_camel_case/ast.golden.txt index 8b175a599..33c35bdb3 100644 --- a/res/v3x/parsing/case_sensitiveness/qubit_camel_case/ast.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/qubit_camel_case/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..6 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..6 name: < Identifier( name: Qubit ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/case_sensitiveness/qubit_camel_case/semantic.3.0.golden.txt b/res/v3x/parsing/case_sensitiveness/qubit_camel_case/semantic.3.0.golden.txt index cff2186aa..643034f9a 100644 --- a/res/v3x/parsing/case_sensitiveness/qubit_camel_case/semantic.3.0.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/qubit_camel_case/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..8: failed to resolve mapping 'q' +Error at input.cq:3:7..8: failed to resolve variable 'q' diff --git a/res/v3x/parsing/case_sensitiveness/tau_uppercase/ast.golden.txt b/res/v3x/parsing/case_sensitiveness/tau_uppercase/ast.golden.txt index bfdef9cba..3fc3e7c28 100644 --- a/res/v3x/parsing/case_sensitiveness/tau_uppercase/ast.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/tau_uppercase/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:4:1..3 + Gate( # input.cq:4:1..3 name: < Identifier( name: rx ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/case_sensitiveness/tau_uppercase/semantic.3.0.golden.txt b/res/v3x/parsing/case_sensitiveness/tau_uppercase/semantic.3.0.golden.txt index 5c340fe1e..31b4996fb 100644 --- a/res/v3x/parsing/case_sensitiveness/tau_uppercase/semantic.3.0.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/tau_uppercase/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:7..10: failed to resolve mapping 'TAU' +Error at input.cq:4:7..10: failed to resolve variable 'TAU' diff --git a/res/v3x/parsing/case_sensitiveness/x_uppercase/ast.golden.txt b/res/v3x/parsing/case_sensitiveness/x_uppercase/ast.golden.txt index 574c17390..cf94cbdf0 100644 --- a/res/v3x/parsing/case_sensitiveness/x_uppercase/ast.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/x_uppercase/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:4:1..2 + Gate( # input.cq:4:1..2 name: < Identifier( name: X ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/case_sensitiveness/x_uppercase/semantic.3.0.golden.txt b/res/v3x/parsing/case_sensitiveness/x_uppercase/semantic.3.0.golden.txt index c15160b9c..2c328b92c 100644 --- a/res/v3x/parsing/case_sensitiveness/x_uppercase/semantic.3.0.golden.txt +++ b/res/v3x/parsing/case_sensitiveness/x_uppercase/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:1..2: failed to resolve 'X' +Error at input.cq:4:1..2: failed to resolve instruction 'X' with argument pack (qubit) diff --git a/res/v3x/parsing/comments/multi_line/ast.golden.txt b/res/v3x/parsing/comments/multi_line/ast.golden.txt index 986674ffd..9062b4184 100644 --- a/res/v3x/parsing/comments/multi_line/ast.golden.txt +++ b/res/v3x/parsing/comments/multi_line/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/comments/multi_line/semantic.3.0.golden.txt b/res/v3x/parsing/comments/multi_line/semantic.3.0.golden.txt index c67097953..38253ce8e 100644 --- a/res/v3x/parsing/comments/multi_line/semantic.3.0.golden.txt +++ b/res/v3x/parsing/comments/multi_line/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3.0 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/res/v3x/parsing/comments/multi_line_then_error/ast.golden.txt b/res/v3x/parsing/comments/multi_line_then_error/ast.golden.txt index 23c26d878..64fb3f9ba 100644 --- a/res/v3x/parsing/comments/multi_line_then_error/ast.golden.txt +++ b/res/v3x/parsing/comments/multi_line_then_error/ast.golden.txt @@ -1,2 +1,23 @@ -ERROR -Error at input.cq:5:5..6: no viable alternative at input 'blah\n' +SUCCESS +Program( + version: < + Version( # input.cq:1:9..12 + items: 3.0 + ) + > + block: < + GlobalBlock( + statements: [ + ExpressionStatement( + expression: < + Identifier( # input.cq:5:1..5 + name: blah + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/comments/multi_line_then_error/semantic.3.0.golden.txt b/res/v3x/parsing/comments/multi_line_then_error/semantic.3.0.golden.txt new file mode 100644 index 000000000..1741632f5 --- /dev/null +++ b/res/v3x/parsing/comments/multi_line_then_error/semantic.3.0.golden.txt @@ -0,0 +1,2 @@ +ERROR +Error at input.cq:5:1..5: expression statement is not of function call type diff --git a/res/v3x/parsing/comments/multi_line_within_single_line/ast.golden.txt b/res/v3x/parsing/comments/multi_line_within_single_line/ast.golden.txt index 986674ffd..9062b4184 100644 --- a/res/v3x/parsing/comments/multi_line_within_single_line/ast.golden.txt +++ b/res/v3x/parsing/comments/multi_line_within_single_line/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/comments/multi_line_within_single_line/semantic.3.0.golden.txt b/res/v3x/parsing/comments/multi_line_within_single_line/semantic.3.0.golden.txt index c67097953..38253ce8e 100644 --- a/res/v3x/parsing/comments/multi_line_within_single_line/semantic.3.0.golden.txt +++ b/res/v3x/parsing/comments/multi_line_within_single_line/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3.0 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/res/v3x/parsing/comments/open_multi_line_within_single_line/ast.golden.txt b/res/v3x/parsing/comments/open_multi_line_within_single_line/ast.golden.txt index 986674ffd..9062b4184 100644 --- a/res/v3x/parsing/comments/open_multi_line_within_single_line/ast.golden.txt +++ b/res/v3x/parsing/comments/open_multi_line_within_single_line/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/comments/open_multi_line_within_single_line/semantic.3.0.golden.txt b/res/v3x/parsing/comments/open_multi_line_within_single_line/semantic.3.0.golden.txt index c67097953..38253ce8e 100644 --- a/res/v3x/parsing/comments/open_multi_line_within_single_line/semantic.3.0.golden.txt +++ b/res/v3x/parsing/comments/open_multi_line_within_single_line/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3.0 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/res/v3x/parsing/comments/single_line/ast.golden.txt b/res/v3x/parsing/comments/single_line/ast.golden.txt index 986674ffd..9062b4184 100644 --- a/res/v3x/parsing/comments/single_line/ast.golden.txt +++ b/res/v3x/parsing/comments/single_line/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/comments/single_line/semantic.3.0.golden.txt b/res/v3x/parsing/comments/single_line/semantic.3.0.golden.txt index c67097953..38253ce8e 100644 --- a/res/v3x/parsing/comments/single_line/semantic.3.0.golden.txt +++ b/res/v3x/parsing/comments/single_line/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3.0 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/res/v3x/parsing/comments/single_line_and_multi_line_before_version/ast.golden.txt b/res/v3x/parsing/comments/single_line_and_multi_line_before_version/ast.golden.txt index 1bad993e5..e11173c0f 100644 --- a/res/v3x/parsing/comments/single_line_and_multi_line_before_version/ast.golden.txt +++ b/res/v3x/parsing/comments/single_line_and_multi_line_before_version/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/comments/single_line_and_multi_line_before_version/semantic.3.0.golden.txt b/res/v3x/parsing/comments/single_line_and_multi_line_before_version/semantic.3.0.golden.txt index c67097953..38253ce8e 100644 --- a/res/v3x/parsing/comments/single_line_and_multi_line_before_version/semantic.3.0.golden.txt +++ b/res/v3x/parsing/comments/single_line_and_multi_line_before_version/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3.0 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/res/v3x/parsing/comments/single_line_then_error/ast.golden.txt b/res/v3x/parsing/comments/single_line_then_error/ast.golden.txt index 3b6b66baf..df55bdc2c 100644 --- a/res/v3x/parsing/comments/single_line_then_error/ast.golden.txt +++ b/res/v3x/parsing/comments/single_line_then_error/ast.golden.txt @@ -1,2 +1,23 @@ -ERROR -Error at input.cq:4:5..10: no viable alternative at input 'blah' +SUCCESS +Program( + version: < + Version( # input.cq:1:9..12 + items: 3.0 + ) + > + block: < + GlobalBlock( + statements: [ + ExpressionStatement( + expression: < + Identifier( # input.cq:4:1..5 + name: blah + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/comments/single_line_then_error/semantic.3.0.golden.txt b/res/v3x/parsing/comments/single_line_then_error/semantic.3.0.golden.txt new file mode 100644 index 000000000..b0402e3bd --- /dev/null +++ b/res/v3x/parsing/comments/single_line_then_error/semantic.3.0.golden.txt @@ -0,0 +1,2 @@ +ERROR +Error at input.cq:4:1..5: expression statement is not of function call type diff --git a/res/v3x/parsing/comments/single_line_within_multi_line/ast.golden.txt b/res/v3x/parsing/comments/single_line_within_multi_line/ast.golden.txt index 986674ffd..9062b4184 100644 --- a/res/v3x/parsing/comments/single_line_within_multi_line/ast.golden.txt +++ b/res/v3x/parsing/comments/single_line_within_multi_line/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/comments/single_line_within_multi_line/semantic.3.0.golden.txt b/res/v3x/parsing/comments/single_line_within_multi_line/semantic.3.0.golden.txt index c67097953..38253ce8e 100644 --- a/res/v3x/parsing/comments/single_line_within_multi_line/semantic.3.0.golden.txt +++ b/res/v3x/parsing/comments/single_line_within_multi_line/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3.0 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/res/v3x/parsing/expression/out_of_bounds_index/ast.golden.txt b/res/v3x/parsing/expression/out_of_bounds_index/ast.golden.txt index bce67c2c6..b36e2a492 100644 --- a/res/v3x/parsing/expression/out_of_bounds_index/ast.golden.txt +++ b/res/v3x/parsing/expression/out_of_bounds_index/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,24 +15,27 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] ) - Instruction( # input.cq:4:1..2 + Gate( # input.cq:4:1..2 name: < Identifier( name: x ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/float_array_definition/ffloat_array_of_17_f/ast.golden.txt b/res/v3x/parsing/float_array_definition/ffloat_array_of_17_f/ast.golden.txt index fed3a790b..6d055b385 100644 --- a/res/v3x/parsing/float_array_definition/ffloat_array_of_17_f/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/ffloat_array_of_17_f/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:11..12: mismatched input 'f' expecting '=' +Error at input.cq:3:11..12: extraneous input 'f' expecting {, NEW_LINE, ';'} diff --git a/res/v3x/parsing/float_array_definition/float_array_of_0_f/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_0_f/ast.golden.txt index b24a9b918..779c23f65 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_0_f/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_0_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 0 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 0 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_definition/float_array_of_0_f/semantic.3.0.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_0_f/semantic.3.0.golden.txt index 7dd856c14..9a114400c 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_0_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_0_f/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..11: declaring real array of size <= 0 +Error at input.cq:3:10..11: found float array of size <= 0 diff --git a/res/v3x/parsing/float_array_definition/float_array_of_123abc/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_123abc/ast.golden.txt index 20376017b..f9cd9e985 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_123abc/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_123abc/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..13: extraneous input 'abc' expecting ']' +Error at input.cq:3:10..13: no viable alternative at input 'float[123abc' diff --git a/res/v3x/parsing/float_array_definition/float_array_of_17/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_17/ast.golden.txt index 1f82cb608..e4e7e327e 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_17/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_17/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..11: missing IDENTIFIER at '\n' +Error at input.cq:3:10..11: no viable alternative at input 'float[17]\n' diff --git a/res/v3x/parsing/float_array_definition/float_array_of_17_1/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_17_1/ast.golden.txt index bc95ae090..e0dfcb0bf 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_17_1/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_17_1/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:11..12: mismatched input '1' expecting IDENTIFIER +Error at input.cq:3:11..12: no viable alternative at input 'float[17]1' diff --git a/res/v3x/parsing/float_array_definition/float_array_of_17_3.14/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_17_3.14/ast.golden.txt index 789fb047e..6c6b81bff 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_17_3.14/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_17_3.14/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:11..15: mismatched input '3.14' expecting IDENTIFIER +Error at input.cq:3:11..15: no viable alternative at input 'float[17]3.14' diff --git a/res/v3x/parsing/float_array_definition/float_array_of_17_equal/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_17_equal/ast.golden.txt index 42fa248d6..6a6ebc019 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_17_equal/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_17_equal/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:11..12: missing IDENTIFIER at '=' +Error at input.cq:3:11..12: no viable alternative at input 'float[17]=' diff --git a/res/v3x/parsing/float_array_definition/float_array_of_17_f/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_17_f/ast.golden.txt index 88a6ef738..d46b51b53 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_17_f/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_17_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:11..12 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:3:1..10 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_definition/float_array_of_17_f/semantic.3.0.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_17_f/semantic.3.0.golden.txt index fe8892379..41cd82e8c 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_17_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_17_f/semantic.3.0.golden.txt @@ -6,12 +6,17 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: f typ: < - RealArray( + FloatArray( size: 17 ) > diff --git a/res/v3x/parsing/float_array_definition/float_array_of_17_f__float_array_of_17_f/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_17_f__float_array_of_17_f/ast.golden.txt index 3607e594a..09b4a57f1 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_17_f__float_array_of_17_f/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_17_f__float_array_of_17_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:11..12 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:3:1..10 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:4:1..10 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_definition/float_array_of_17_f__float_array_of_17_f/semantic.3.0.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_17_f__float_array_of_17_f/semantic.3.0.golden.txt index e10c3e5e1..31d82fc54 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_17_f__float_array_of_17_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_17_f__float_array_of_17_f/semantic.3.0.golden.txt @@ -6,12 +6,17 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: f typ: < - RealArray( + FloatArray( size: 17 ) > @@ -20,7 +25,7 @@ Program( Variable( name: f typ: < - RealArray( + FloatArray( size: 17 ) > diff --git a/res/v3x/parsing/float_array_definition/float_array_of_3.14/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_3.14/ast.golden.txt index efab8ef43..22ffb7ffd 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_3.14/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_3.14/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..11: mismatched input '3.14' expecting INTEGER_LITERAL +Error at input.cq:3:7..11: no viable alternative at input 'float[3.14' diff --git a/res/v3x/parsing/float_array_definition/float_array_of_equal/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_equal/ast.golden.txt index 16b4ec8e5..c8ef4b121 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_equal/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_equal/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..8: mismatched input '=' expecting INTEGER_LITERAL +Error at input.cq:3:7..8: no viable alternative at input 'float[=' diff --git a/res/v3x/parsing/float_array_definition/float_array_of_f/ast.golden.txt b/res/v3x/parsing/float_array_definition/float_array_of_f/ast.golden.txt index bd842ae3c..7071eac4b 100644 --- a/res/v3x/parsing/float_array_definition/float_array_of_f/ast.golden.txt +++ b/res/v3x/parsing/float_array_definition/float_array_of_f/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..8: mismatched input 'f' expecting INTEGER_LITERAL +Error at input.cq:3:7..8: no viable alternative at input 'float[f' diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2/ast.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2/ast.golden.txt index eb40de8e8..086303da0 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2/ast.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:12..13 var: < Variable( # input.cq:3:10..11 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2/semantic.3.0.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2/semantic.3.0.golden.txt index e90302cf0..cfe915a27 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2/semantic.3.0.golden.txt @@ -6,48 +6,48 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - RealArray( - size: 2 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + FloatArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstRealArray( - value: [ - ConstReal( - value: 1.1 - ) - ConstReal( - value: 2.2 + rhs: < + ConstFloatArray( + value: [ + ConstFloat( + value: 1.1 + ) + ConstFloat( + value: 2.2 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: f typ: < - RealArray( + FloatArray( size: 2 ) > diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2__float_array_of_2_g_equals_f/ast.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2__float_array_of_2_g_equals_f/ast.golden.txt index 8cd505ea9..0855c4869 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2__float_array_of_2_g_equals_f/ast.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2__float_array_of_2_g_equals_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:12..13 var: < Variable( # input.cq:3:10..11 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] @@ -56,13 +60,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:4:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2__float_array_of_2_g_equals_f/semantic.3.0.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2__float_array_of_2_g_equals_f/semantic.3.0.golden.txt index 662e36f27..f93996815 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2__float_array_of_2_g_equals_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_2_f_equals_list_of_1.1_2.2__float_array_of_2_g_equals_f/semantic.3.0.golden.txt @@ -6,86 +6,81 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - RealArray( - size: 2 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + FloatArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstRealArray( - value: [ - ConstReal( - value: 1.1 - ) - ConstReal( - value: 2.2 + rhs: < + ConstFloatArray( + value: [ + ConstFloat( + value: 1.1 + ) + ConstFloat( + value: 2.2 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] - ) - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: g - typ: < - RealArray( - size: 2 + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: g + typ: < + FloatArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - RealArray( - size: 2 + rhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + FloatArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] ) > + annotations: [] ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: f typ: < - RealArray( + FloatArray( size: 2 ) > @@ -94,7 +89,7 @@ Program( Variable( name: g typ: < - RealArray( + FloatArray( size: 2 ) > diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_f/ast.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_f/ast.golden.txt index 96e3abc05..14821da26 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_f/ast.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:12..13 var: < Variable( # input.cq:3:10..11 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_f/semantic.3.0.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_f/semantic.3.0.golden.txt index fe5064556..f1c8aa9e7 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_f/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:14..15: failed to resolve mapping 'f' +Error at input.cq:3:14..15: failed to resolve variable 'f' diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_g/ast.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_g/ast.golden.txt index af624c33c..d944149b3 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_g/ast.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_g/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:12..13 var: < Variable( # input.cq:3:10..11 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_g/semantic.3.0.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_g/semantic.3.0.golden.txt index 01cc86a35..a595595fc 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_g/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_g/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:14..15: failed to resolve mapping 'g' +Error at input.cq:3:14..15: failed to resolve variable 'g' diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_1.1_2.2/ast.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_1.1_2.2/ast.golden.txt index 16b2cc20e..95ec03f93 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_1.1_2.2/ast.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_1.1_2.2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:12..13 var: < Variable( # input.cq:3:10..11 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_false_1.1_2.2/ast.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_false_1.1_2.2/ast.golden.txt index 916550a80..d2acbb134 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_false_1.1_2.2/ast.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_false_1.1_2.2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:12..13 var: < Variable( # input.cq:3:10..11 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_false_1.1_2.2/semantic.3.0.golden.txt b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_false_1.1_2.2/semantic.3.0.golden.txt index dfd73fc92..afafd204a 100644 --- a/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_false_1.1_2.2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_array_initialization/float_array_of_3_f_equals_list_of_false_1.1_2.2/semantic.3.0.golden.txt @@ -6,51 +6,51 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - RealArray( - size: 3 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + FloatArray( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstRealArray( - value: [ - ConstReal( - value: 0 - ) - ConstReal( - value: 1.1 - ) - ConstReal( - value: 2.2 + rhs: < + ConstFloatArray( + value: [ + ConstFloat( + value: 0 + ) + ConstFloat( + value: 1.1 + ) + ConstFloat( + value: 2.2 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: f typ: < - RealArray( + FloatArray( size: 3 ) > diff --git a/res/v3x/parsing/float_array_initialization/int_array_of_3_i__float_array_of_3_f_equals_i/ast.golden.txt b/res/v3x/parsing/float_array_initialization/int_array_of_3_i__float_array_of_3_f_equals_i/ast.golden.txt index 6fe7566ea..d68572efa 100644 --- a/res/v3x/parsing/float_array_initialization/int_array_of_3_i__float_array_of_3_f_equals_i/ast.golden.txt +++ b/res/v3x/parsing/float_array_initialization/int_array_of_3_i__float_array_of_3_f_equals_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:8..9 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_initialization/int_array_of_3_i__float_array_of_3_f_equals_i/semantic.3.0.golden.txt b/res/v3x/parsing/float_array_initialization/int_array_of_3_i__float_array_of_3_f_equals_i/semantic.3.0.golden.txt index 43fc77fc5..f85ebb91c 100644 --- a/res/v3x/parsing/float_array_initialization/int_array_of_3_i__float_array_of_3_f_equals_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_array_initialization/int_array_of_3_i__float_array_of_3_f_equals_i/semantic.3.0.golden.txt @@ -6,46 +6,46 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - RealArray( - size: 3 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + FloatArray( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - IntArray( - size: 3 + rhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + IntArray( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > + annotations: [] ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i @@ -59,7 +59,7 @@ Program( Variable( name: f typ: < - RealArray( + FloatArray( size: 3 ) > diff --git a/res/v3x/parsing/float_array_initialization/qubit_array_of_3_q__float_array_of_3_f_equals_q/ast.golden.txt b/res/v3x/parsing/float_array_initialization/qubit_array_of_3_q__float_array_of_3_f_equals_q/ast.golden.txt index 28e253a97..db75d72db 100644 --- a/res/v3x/parsing/float_array_initialization/qubit_array_of_3_q__float_array_of_3_f_equals_q/ast.golden.txt +++ b/res/v3x/parsing/float_array_initialization/qubit_array_of_3_q__float_array_of_3_f_equals_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/float_array_initialization/qubit_array_of_3_q__float_array_of_3_f_equals_q/semantic.3.0.golden.txt b/res/v3x/parsing/float_array_initialization/qubit_array_of_3_q__float_array_of_3_f_equals_q/semantic.3.0.golden.txt index 16382b446..bc09f3db5 100644 --- a/res/v3x/parsing/float_array_initialization/qubit_array_of_3_q__float_array_of_3_f_equals_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_array_initialization/qubit_array_of_3_q__float_array_of_3_f_equals_q/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:12..13: type of right-hand side (qubit array) could not be coerced to left-hand side (real array) +Error at input.cq:4:12..13: type of right-hand side (qubit array) could not be coerced to left-hand side (float array) diff --git a/res/v3x/parsing/float_definition/ffloat_f/ast.golden.txt b/res/v3x/parsing/float_definition/ffloat_f/ast.golden.txt index ebc4ddf7f..0bab8a23f 100644 --- a/res/v3x/parsing/float_definition/ffloat_f/ast.golden.txt +++ b/res/v3x/parsing/float_definition/ffloat_f/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..6 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..6 name: < Identifier( name: Float ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/float_definition/ffloat_f/semantic.3.0.golden.txt b/res/v3x/parsing/float_definition/ffloat_f/semantic.3.0.golden.txt index b5cd82396..b156d3ecb 100644 --- a/res/v3x/parsing/float_definition/ffloat_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_definition/ffloat_f/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..8: failed to resolve mapping 'f' +Error at input.cq:3:7..8: failed to resolve variable 'f' diff --git a/res/v3x/parsing/float_definition/float/ast.golden.txt b/res/v3x/parsing/float_definition/float/ast.golden.txt index 6034f8e53..563007766 100644 --- a/res/v3x/parsing/float_definition/float/ast.golden.txt +++ b/res/v3x/parsing/float_definition/float/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: mismatched input '\n' expecting {'[', IDENTIFIER} +Error at input.cq:3:6..7: no viable alternative at input 'float\n' diff --git a/res/v3x/parsing/float_definition/float_1/ast.golden.txt b/res/v3x/parsing/float_definition/float_1/ast.golden.txt index b62134a23..8bf59b137 100644 --- a/res/v3x/parsing/float_definition/float_1/ast.golden.txt +++ b/res/v3x/parsing/float_definition/float_1/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..8: mismatched input '1' expecting {'[', IDENTIFIER} +Error at input.cq:3:7..8: no viable alternative at input 'float1' diff --git a/res/v3x/parsing/float_definition/float_123abc/ast.golden.txt b/res/v3x/parsing/float_definition/float_123abc/ast.golden.txt index 716cc6c75..ffa226fa1 100644 --- a/res/v3x/parsing/float_definition/float_123abc/ast.golden.txt +++ b/res/v3x/parsing/float_definition/float_123abc/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..10: extraneous input '123' expecting {'[', IDENTIFIER} +Error at input.cq:3:7..10: no viable alternative at input 'float123' diff --git a/res/v3x/parsing/float_definition/float_3.14/ast.golden.txt b/res/v3x/parsing/float_definition/float_3.14/ast.golden.txt index 45082ad50..96892f124 100644 --- a/res/v3x/parsing/float_definition/float_3.14/ast.golden.txt +++ b/res/v3x/parsing/float_definition/float_3.14/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..11: mismatched input '3.14' expecting {'[', IDENTIFIER} +Error at input.cq:3:7..11: no viable alternative at input 'float3.14' diff --git a/res/v3x/parsing/float_definition/float_equals/ast.golden.txt b/res/v3x/parsing/float_definition/float_equals/ast.golden.txt index a4c0560c1..2500de30d 100644 --- a/res/v3x/parsing/float_definition/float_equals/ast.golden.txt +++ b/res/v3x/parsing/float_definition/float_equals/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..8: mismatched input '=' expecting {'[', IDENTIFIER} +Error at input.cq:3:7..8: no viable alternative at input 'float=' diff --git a/res/v3x/parsing/float_definition/float_f/ast.golden.txt b/res/v3x/parsing/float_definition/float_f/ast.golden.txt index 04b33a632..cbb3ffa0f 100644 --- a/res/v3x/parsing/float_definition/float_f/ast.golden.txt +++ b/res/v3x/parsing/float_definition/float_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/float_definition/float_f/semantic.3.0.golden.txt b/res/v3x/parsing/float_definition/float_f/semantic.3.0.golden.txt index 75b51a6a1..b6b822fe5 100644 --- a/res/v3x/parsing/float_definition/float_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_definition/float_f/semantic.3.0.golden.txt @@ -6,12 +6,17 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: f typ: < - Real( + Float( size: 1 ) > diff --git a/res/v3x/parsing/float_definition/float_f__float_f/ast.golden.txt b/res/v3x/parsing/float_definition/float_f__float_f/ast.golden.txt index 600528b4c..abd144e84 100644 --- a/res/v3x/parsing/float_definition/float_f__float_f/ast.golden.txt +++ b/res/v3x/parsing/float_definition/float_f__float_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) Variable( # input.cq:4:7..8 @@ -29,11 +33,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:4:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/float_definition/float_f__float_f/semantic.3.0.golden.txt b/res/v3x/parsing/float_definition/float_f__float_f/semantic.3.0.golden.txt index 06fff0a00..310d5edad 100644 --- a/res/v3x/parsing/float_definition/float_f__float_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_definition/float_f__float_f/semantic.3.0.golden.txt @@ -6,12 +6,17 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: f typ: < - Real( + Float( size: 1 ) > @@ -20,7 +25,7 @@ Program( Variable( name: f typ: < - Real( + Float( size: 1 ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_3.14/ast.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_3.14/ast.golden.txt index fcc7bbbc1..2b22c3320 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_3.14/ast.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_3.14/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:7..8 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_3.14/semantic.3.0.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_3.14/semantic.3.0.golden.txt index b718b2d30..213bfccd8 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_3.14/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_3.14/semantic.3.0.golden.txt @@ -6,41 +6,41 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - Real( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstFloat( + value: 3.14 + ) + > + annotations: [] ) - > - rhs: < - ConstReal( - value: 3.14 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: f typ: < - Real( + Float( size: 1 ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_3.14_float_g_equals_f/ast.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_3.14_float_g_equals_f/ast.golden.txt index 3d08b7d85..d46d55352 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_3.14_float_g_equals_f/ast.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_3.14_float_g_equals_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:7..8 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > @@ -41,11 +45,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:4:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_3.14_float_g_equals_f/semantic.3.0.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_3.14_float_g_equals_f/semantic.3.0.golden.txt index 95b810c70..78c40dcd4 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_3.14_float_g_equals_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_3.14_float_g_equals_f/semantic.3.0.golden.txt @@ -6,79 +6,74 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - Real( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstFloat( + value: 3.14 + ) + > + annotations: [] ) - > - rhs: < - ConstReal( - value: 3.14 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] - ) - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: g - typ: < - Real( - size: 1 + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: g + typ: < + Float( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - Real( - size: 1 + rhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + annotations: [] ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: f typ: < - Real( + Float( size: 1 ) > @@ -87,7 +82,7 @@ Program( Variable( name: g typ: < - Real( + Float( size: 1 ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_42/ast.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_42/ast.golden.txt index 685667d20..dea42cdb4 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_42/ast.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_42/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:7..8 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_42/semantic.3.0.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_42/semantic.3.0.golden.txt index 2d14e04e2..61546af45 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_42/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_42/semantic.3.0.golden.txt @@ -6,41 +6,41 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - Real( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstFloat( + value: 42 + ) + > + annotations: [] ) - > - rhs: < - ConstReal( - value: 42 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: f typ: < - Real( + Float( size: 1 ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_f/ast.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_f/ast.golden.txt index ae9ab624d..cec7964e0 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_f/ast.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:7..8 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_f/semantic.3.0.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_f/semantic.3.0.golden.txt index dc1c23e83..62cfe207f 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_f/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:11..12: failed to resolve mapping 'f' +Error at input.cq:3:11..12: failed to resolve variable 'f' diff --git a/res/v3x/parsing/float_initialization/float_f_equals_false/ast.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_false/ast.golden.txt index d72537b90..695c02b9c 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_false/ast.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_false/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:7..8 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_false/semantic.3.0.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_false/semantic.3.0.golden.txt index d93786f79..58b77c773 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_false/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_false/semantic.3.0.golden.txt @@ -6,41 +6,41 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - Real( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstFloat( + value: 0 + ) + > + annotations: [] ) - > - rhs: < - ConstReal( - value: 0 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: f typ: < - Real( + Float( size: 1 ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_g/ast.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_g/ast.golden.txt index 766d15b74..e1dd3e288 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_g/ast.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_g/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:9..10 var: < Variable( # input.cq:3:7..8 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/float_initialization/float_f_equals_g/semantic.3.0.golden.txt b/res/v3x/parsing/float_initialization/float_f_equals_g/semantic.3.0.golden.txt index 91cbc95f2..2a65cf498 100644 --- a/res/v3x/parsing/float_initialization/float_f_equals_g/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_initialization/float_f_equals_g/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:11..12: failed to resolve mapping 'g' +Error at input.cq:3:11..12: failed to resolve variable 'g' diff --git a/res/v3x/parsing/float_initialization/int_i__float_f_equals_i/ast.golden.txt b/res/v3x/parsing/float_initialization/int_i__float_f_equals_i/ast.golden.txt index 246d030a6..4de08e34e 100644 --- a/res/v3x/parsing/float_initialization/int_i__float_f_equals_i/ast.golden.txt +++ b/res/v3x/parsing/float_initialization/int_i__float_f_equals_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:5..6 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:9..10 @@ -31,11 +35,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:4:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/float_initialization/int_i__float_f_equals_i/semantic.3.0.golden.txt b/res/v3x/parsing/float_initialization/int_i__float_f_equals_i/semantic.3.0.golden.txt index 57b1f6726..d7b10c029 100644 --- a/res/v3x/parsing/float_initialization/int_i__float_f_equals_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_initialization/int_i__float_f_equals_i/semantic.3.0.golden.txt @@ -6,46 +6,46 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: f - typ: < - Real( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + rhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + annotations: [] ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i @@ -59,7 +59,7 @@ Program( Variable( name: f typ: < - Real( + Float( size: 1 ) > diff --git a/res/v3x/parsing/float_initialization/qubit_q__float_f_equals_q/ast.golden.txt b/res/v3x/parsing/float_initialization/qubit_q__float_f_equals_q/ast.golden.txt index 846fbc6bd..390198de4 100644 --- a/res/v3x/parsing/float_initialization/qubit_q__float_f_equals_q/ast.golden.txt +++ b/res/v3x/parsing/float_initialization/qubit_q__float_f_equals_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:9..10 @@ -31,11 +35,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:4:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/float_initialization/qubit_q__float_f_equals_q/semantic.3.0.golden.txt b/res/v3x/parsing/float_initialization/qubit_q__float_f_equals_q/semantic.3.0.golden.txt index 73152675a..37c48f2a3 100644 --- a/res/v3x/parsing/float_initialization/qubit_q__float_f_equals_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/float_initialization/qubit_q__float_f_equals_q/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:9..10: type of right-hand side (qubit) could not be coerced to left-hand side (real) +Error at input.cq:4:9..10: type of right-hand side (qubit) could not be coerced to left-hand side (float) diff --git a/res/v3x/parsing/function/area__float_f__float/ast.golden.txt b/res/v3x/parsing/function/area__float_f__float/ast.golden.txt new file mode 100644 index 000000000..46f1ed602 --- /dev/null +++ b/res/v3x/parsing/function/area__float_f__float/ast.golden.txt @@ -0,0 +1,130 @@ +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + Function( # input.cq:3:5..9 + name: < + Identifier( + name: area + ) + > + parameters: < + LocalBlock( + statements: [ + Variable( # input.cq:3:16..17 + name: < + Identifier( + name: r + ) + > + typ: < + Type( # input.cq:3:10..15 + name: < + Keyword( + name: float + ) + > + size: - + ) + > + annotations: [] + ) + ] + ) + > + return_type: < + Type( # input.cq:3:22..27 + name: < + Keyword( + name: float + ) + > + size: - + ) + > + block: < + LocalBlock( + statements: [ + ReturnStatement( # input.cq:7:5..11 + return_value: < + ProductExpression( # input.cq:7:19..20 + lhs: < + ProductExpression( # input.cq:7:14..15 + lhs: < + IntegerLiteral( # input.cq:7:12..13 + value: 2 + ) + > + rhs: < + Identifier( # input.cq:7:16..18 + name: pi + ) + > + ) + > + rhs: < + FloatLiteral( # input.cq:7:21..24 + value: 1 + ) + > + ) + > + annotations: [] + ) + ] + ) + > + annotations: [] + ) + Initialization( # input.cq:10:9..10 + var: < + Variable( # input.cq:10:7..8 + name: < + Identifier( + name: f + ) + > + typ: < + Type( # input.cq:10:1..6 + name: < + Keyword( + name: float + ) + > + size: - + ) + > + annotations: [] + ) + > + rhs: < + FunctionCall( # input.cq:10:11..15 + name: < + Identifier( + name: area + ) + > + arguments: < + ExpressionList( + items: [ + FloatLiteral( # input.cq:10:16..18 + value: 1 + ) + ] + ) + > + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/function/area__float_f__float/input.cq b/res/v3x/parsing/function/area__float_f__float/input.cq new file mode 100644 index 000000000..c29750ab7 --- /dev/null +++ b/res/v3x/parsing/function/area__float_f__float/input.cq @@ -0,0 +1,10 @@ +version 3 + +def area(float r) -> float { + // TODO: this test requires that the product arithmetic operator works on variables + // return 2 * pi * r + // So, at the moment, just work on constant values + return 2 * pi * 1.0 +} + +float f = area(1.) diff --git a/res/v3x/parsing/function/area__float_f__float/semantic.3.0.golden.txt b/res/v3x/parsing/function/area__float_f__float/semantic.3.0.golden.txt new file mode 100644 index 000000000..1d0889428 --- /dev/null +++ b/res/v3x/parsing/function/area__float_f__float/semantic.3.0.golden.txt @@ -0,0 +1,130 @@ +SUCCESS +Program( + api_version: 3.0 + version: < + Version( + items: 3 + ) + > + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] + ) + > + ) + > + rhs: < + FunctionCall( + function: < + FunctionRef( + function --> < + Function( + name: area + return_type: < + Float( + size: 1 + ) + > + block: < + Block( + statements: [ + ReturnStatement( + return_value: < + ConstFloat( + value: 6.28319 + ) + > + annotations: [] + ) + ] + ) + > + variables: [ + Variable( + name: r + typ: < + Float( + size: 1 + ) + > + annotations: [] + ) + ] + annotations: [] + ) + > + ) + > + arguments: [ + ConstFloat( + value: 1 + ) + ] + ) + > + annotations: [] + ) + ] + ) + > + functions: [ + Function( + name: area + return_type: < + Float( + size: 1 + ) + > + block: < + Block( + statements: [ + ReturnStatement( + return_value: < + ConstFloat( + value: 6.28319 + ) + > + annotations: [] + ) + ] + ) + > + variables: [ + Variable( + name: r + typ: < + Float( + size: 1 + ) + > + annotations: [] + ) + ] + annotations: [] + ) + ] + variables: [ + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] + ) + ] +) + diff --git a/res/v3x/parsing/function/bell__qubit_array_of_2_q/ast.golden.txt b/res/v3x/parsing/function/bell__qubit_array_of_2_q/ast.golden.txt new file mode 100644 index 000000000..59d2af6ff --- /dev/null +++ b/res/v3x/parsing/function/bell__qubit_array_of_2_q/ast.golden.txt @@ -0,0 +1,189 @@ +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + Function( # input.cq:3:5..9 + name: < + Identifier( + name: bell + ) + > + parameters: < + LocalBlock( + statements: [ + Variable( # input.cq:3:19..20 + name: < + Identifier( + name: q + ) + > + typ: < + Type( # input.cq:3:10..18 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > + ) + > + annotations: [] + ) + ] + ) + > + return_type: - + block: < + LocalBlock( + statements: [ + Gate( # input.cq:4:5..6 + name: < + Identifier( + name: h + ) + > + operands: < + ExpressionList( + items: [ + Index( # input.cq:4:7..8 + expr: < + Identifier( + name: q + ) + > + indices: < + IndexList( + items: [ + IndexItem( + index: < + IntegerLiteral( # input.cq:4:9..10 + value: 0 + ) + > + ) + ] + ) + > + ) + ] + ) + > + annotations: [] + ) + Gate( # input.cq:5:5..9 + name: < + Identifier( + name: cnot + ) + > + operands: < + ExpressionList( + items: [ + Index( # input.cq:5:10..11 + expr: < + Identifier( + name: q + ) + > + indices: < + IndexList( + items: [ + IndexItem( + index: < + IntegerLiteral( # input.cq:5:12..13 + value: 0 + ) + > + ) + ] + ) + > + ) + Index( # input.cq:5:16..17 + expr: < + Identifier( + name: q + ) + > + indices: < + IndexList( + items: [ + IndexItem( + index: < + IntegerLiteral( # input.cq:5:18..19 + value: 1 + ) + > + ) + ] + ) + > + ) + ] + ) + > + annotations: [] + ) + ] + ) + > + annotations: [] + ) + Variable( # input.cq:8:10..11 + name: < + Identifier( + name: q + ) + > + typ: < + Type( # input.cq:8:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > + ) + > + annotations: [] + ) + ExpressionStatement( + expression: < + FunctionCall( # input.cq:9:1..5 + name: < + Identifier( + name: bell + ) + > + arguments: < + ExpressionList( + items: [ + Identifier( # input.cq:9:6..7 + name: q + ) + ] + ) + > + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/function/bell__qubit_array_of_2_q/input.cq b/res/v3x/parsing/function/bell__qubit_array_of_2_q/input.cq new file mode 100644 index 000000000..02aef21ac --- /dev/null +++ b/res/v3x/parsing/function/bell__qubit_array_of_2_q/input.cq @@ -0,0 +1,9 @@ +version 3 + +def bell(qubit[2] q) { + h q[0] + cnot q[0], q[1] +} + +qubit[2] q +bell(q) diff --git a/res/v3x/parsing/function/bell__qubit_array_of_2_q/semantic.3.0.golden.txt b/res/v3x/parsing/function/bell__qubit_array_of_2_q/semantic.3.0.golden.txt new file mode 100644 index 000000000..e882112ab --- /dev/null +++ b/res/v3x/parsing/function/bell__qubit_array_of_2_q/semantic.3.0.golden.txt @@ -0,0 +1,237 @@ +SUCCESS +Program( + api_version: 3.0 + version: < + Version( + items: 3 + ) + > + block: < + Block( + statements: [ + FunctionCallStatement( + return_value: < + FunctionCall( + function: < + FunctionRef( + function --> < + Function( + name: bell + return_type: - + block: < + Block( + statements: [ + Instruction( + instruction: h(qubit) + name: h + operands: [ + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] + ) + > + indices: [ + ConstInt( + value: 0 + ) + ] + ) + ] + annotations: [] + ) + Instruction( + instruction: cnot(qubit, qubit) + name: cnot + operands: [ + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] + ) + > + indices: [ + ConstInt( + value: 0 + ) + ] + ) + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] + ) + > + indices: [ + ConstInt( + value: 1 + ) + ] + ) + ] + annotations: [] + ) + ] + ) + > + variables: [ + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] + ) + ] + annotations: [] + ) + > + ) + > + arguments: [ + VariableRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] + ) + > + ) + ] + ) + > + annotations: [] + ) + ] + ) + > + functions: [ + Function( + name: bell + return_type: - + block: < + Block( + statements: [ + Instruction( + instruction: h(qubit) + name: h + operands: [ + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] + ) + > + indices: [ + ConstInt( + value: 0 + ) + ] + ) + ] + annotations: [] + ) + Instruction( + instruction: cnot(qubit, qubit) + name: cnot + operands: [ + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] + ) + > + indices: [ + ConstInt( + value: 0 + ) + ] + ) + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] + ) + > + indices: [ + ConstInt( + value: 1 + ) + ] + ) + ] + annotations: [] + ) + ] + ) + > + variables: [ + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] + ) + ] + annotations: [] + ) + ] + variables: [ + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] + ) + ] +) + diff --git a/res/v3x/parsing/function/f__j__cos_pi/ast.golden.txt b/res/v3x/parsing/function/f__j__cos_pi/ast.golden.txt new file mode 100644 index 000000000..e041b9939 --- /dev/null +++ b/res/v3x/parsing/function/f__j__cos_pi/ast.golden.txt @@ -0,0 +1,224 @@ +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + Function( # input.cq:7:5..6 + name: < + Identifier( + name: f + ) + > + parameters: < + LocalBlock( + statements: [ + Variable( # input.cq:7:11..12 + name: < + Identifier( + name: i + ) + > + typ: < + Type( # input.cq:7:7..10 + name: < + Keyword( + name: int + ) + > + size: - + ) + > + annotations: [] + ) + Variable( # input.cq:7:20..21 + name: < + Identifier( + name: f + ) + > + typ: < + Type( # input.cq:7:14..19 + name: < + Keyword( + name: float + ) + > + size: - + ) + > + annotations: [] + ) + ] + ) + > + return_type: < + Type( # input.cq:7:26..31 + name: < + Keyword( + name: float + ) + > + size: - + ) + > + block: < + LocalBlock( + statements: [ + ReturnStatement( # input.cq:11:5..11 + return_value: < + ProductExpression( # input.cq:11:14..15 + lhs: < + IntegerLiteral( # input.cq:11:12..13 + value: 2 + ) + > + rhs: < + FloatLiteral( # input.cq:11:16..19 + value: 3 + ) + > + ) + > + annotations: [] + ) + ] + ) + > + annotations: [] + ) + Initialization( # input.cq:14:7..8 + var: < + Variable( # input.cq:14:5..6 + name: < + Identifier( + name: i + ) + > + typ: < + Type( # input.cq:14:1..4 + name: < + Keyword( + name: int + ) + > + size: - + ) + > + annotations: [] + ) + > + rhs: < + IntegerLiteral( # input.cq:14:9..10 + value: 3 + ) + > + annotations: [] + ) + Initialization( # input.cq:15:7..8 + var: < + Variable( # input.cq:15:5..6 + name: < + Identifier( + name: j + ) + > + typ: < + Type( # input.cq:15:1..4 + name: < + Keyword( + name: int + ) + > + size: - + ) + > + annotations: [] + ) + > + rhs: < + Identifier( # input.cq:15:9..10 + name: i + ) + > + annotations: [] + ) + AssignmentStatement( # input.cq:18:3..4 + lhs: < + Identifier( # input.cq:18:1..2 + name: i + ) + > + rhs: < + IntegerLiteral( # input.cq:18:5..6 + value: 5 + ) + > + annotations: [] + ) + Initialization( # input.cq:24:9..10 + var: < + Variable( # input.cq:24:7..8 + name: < + Identifier( + name: f + ) + > + typ: < + Type( # input.cq:24:1..6 + name: < + Keyword( + name: float + ) + > + size: - + ) + > + annotations: [] + ) + > + rhs: < + FunctionCall( # input.cq:24:11..12 + name: < + Identifier( + name: f + ) + > + arguments: < + ExpressionList( + items: [ + Identifier( # input.cq:24:13..14 + name: j + ) + FunctionCall( # input.cq:24:16..19 + name: < + Identifier( + name: cos + ) + > + arguments: < + ExpressionList( + items: [ + Identifier( # input.cq:24:20..22 + name: pi + ) + ] + ) + > + ) + ] + ) + > + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/function/f__j__cos_pi/input.cq b/res/v3x/parsing/function/f__j__cos_pi/input.cq new file mode 100644 index 000000000..2548d2def --- /dev/null +++ b/res/v3x/parsing/function/f__j__cos_pi/input.cq @@ -0,0 +1,24 @@ +version 3 + +// Parameter i shadows global variable i +// Parameter f shadows global variable f +// Parameter f is called like function f +// i should have a value of 3 at this point +def f(int i, float f) -> float { + // TODO: this test requires that the product arithmetic operator works on variables + // return i * f + // So, at the moment, just work on constant values + return 2 * 3.0 +} + +int i = 3 +int j = i + +// Assignment to i should not modify value of j +i = 5 + +// Variable f is called like function f +// pi is a constant registered by default in the analyzer +// cos is a function registered by default in the analyzer +// cos(pi) is a function call value +float f = f(j, cos(pi)) diff --git a/res/v3x/parsing/function/f__j__cos_pi/semantic.3.0.golden.txt b/res/v3x/parsing/function/f__j__cos_pi/semantic.3.0.golden.txt new file mode 100644 index 000000000..76603f0a3 --- /dev/null +++ b/res/v3x/parsing/function/f__j__cos_pi/semantic.3.0.golden.txt @@ -0,0 +1,258 @@ +SUCCESS +Program( + api_version: 3.0 + version: < + Version( + items: 3 + ) + > + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] + ) + > + ) + > + rhs: < + ConstInt( + value: 3 + ) + > + annotations: [] + ) + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: j + typ: < + Int( + size: 1 + ) + > + annotations: [] + ) + > + ) + > + rhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] + ) + > + ) + > + annotations: [] + ) + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] + ) + > + ) + > + rhs: < + ConstInt( + value: 5 + ) + > + annotations: [] + ) + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] + ) + > + ) + > + rhs: < + FunctionCall( + function: < + FunctionRef( + function --> < + Function( + name: f + return_type: < + Float( + size: 1 + ) + > + block: < + Block( + statements: [ + ReturnStatement( + return_value: < + ConstFloat( + value: 6 + ) + > + annotations: [] + ) + ] + ) + > + variables: [ + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] + ) + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] + ) + ] + annotations: [] + ) + > + ) + > + arguments: [ + VariableRef( + variable --> < + Variable( + name: j + typ: < + Int( + size: 1 + ) + > + annotations: [] + ) + > + ) + ConstFloat( + value: -1 + ) + ] + ) + > + annotations: [] + ) + ] + ) + > + functions: [ + Function( + name: f + return_type: < + Float( + size: 1 + ) + > + block: < + Block( + statements: [ + ReturnStatement( + return_value: < + ConstFloat( + value: 6 + ) + > + annotations: [] + ) + ] + ) + > + variables: [ + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] + ) + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] + ) + ] + annotations: [] + ) + ] + variables: [ + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] + ) + Variable( + name: j + typ: < + Int( + size: 1 + ) + > + annotations: [] + ) + Variable( + name: f + typ: < + Float( + size: 1 + ) + > + annotations: [] + ) + ] +) + diff --git a/res/v3x/parsing/function/f__no_params/ast.golden.txt b/res/v3x/parsing/function/f__no_params/ast.golden.txt new file mode 100644 index 000000000..cca5096c7 --- /dev/null +++ b/res/v3x/parsing/function/f__no_params/ast.golden.txt @@ -0,0 +1,47 @@ +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + Function( # input.cq:3:5..6 + name: < + Identifier( + name: f + ) + > + parameters: < + LocalBlock( + statements: [] + ) + > + return_type: - + block: < + LocalBlock( + statements: [] + ) + > + annotations: [] + ) + ExpressionStatement( + expression: < + FunctionCall( # input.cq:5:1..2 + name: < + Identifier( + name: f + ) + > + arguments: - + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/function/f__no_params/input.cq b/res/v3x/parsing/function/f__no_params/input.cq new file mode 100644 index 000000000..a51b4c1b8 --- /dev/null +++ b/res/v3x/parsing/function/f__no_params/input.cq @@ -0,0 +1,5 @@ +version 3 + +def f() {} + +f() diff --git a/res/v3x/parsing/function/f__no_params/semantic.3.0.golden.txt b/res/v3x/parsing/function/f__no_params/semantic.3.0.golden.txt new file mode 100644 index 000000000..6bcff341a --- /dev/null +++ b/res/v3x/parsing/function/f__no_params/semantic.3.0.golden.txt @@ -0,0 +1,55 @@ +SUCCESS +Program( + api_version: 3.0 + version: < + Version( + items: 3 + ) + > + block: < + Block( + statements: [ + FunctionCallStatement( + return_value: < + FunctionCall( + function: < + FunctionRef( + function --> < + Function( + name: f + return_type: - + block: < + Block( + statements: [] + ) + > + variables: [] + annotations: [] + ) + > + ) + > + arguments: [] + ) + > + annotations: [] + ) + ] + ) + > + functions: [ + Function( + name: f + return_type: - + block: < + Block( + statements: [] + ) + > + variables: [] + annotations: [] + ) + ] + variables: [] +) + diff --git a/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi/ast.golden.txt b/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi/ast.golden.txt index d7924eef8..1fd9addd5 100644 --- a/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi/ast.golden.txt +++ b/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:8..10 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:4:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi/semantic.3.0.golden.txt b/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi/semantic.3.0.golden.txt index 79b1c5538..4c57fc4ad 100644 --- a/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi/semantic.3.0.golden.txt +++ b/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:12..13: expecting a const bool, const int, or const real value +Error at input.cq:4:12..13: expecting a const bool, const int, or const float value diff --git a/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi_at_1/ast.golden.txt b/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi_at_1/ast.golden.txt index 54fe0364d..d332034d0 100644 --- a/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi_at_1/ast.golden.txt +++ b/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi_at_1/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:8..10 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: bool - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:4:1..8 + name: < + Keyword( + name: bool + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi_at_1/semantic.3.0.golden.txt b/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi_at_1/semantic.3.0.golden.txt index 79b1c5538..4c57fc4ad 100644 --- a/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi_at_1/semantic.3.0.golden.txt +++ b/res/v3x/parsing/initialization_list/bit_array_of_2_bi__bool_array_of_2_bo_equals_list_of_false_bi_at_1/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:12..13: expecting a const bool, const int, or const real value +Error at input.cq:4:12..13: expecting a const bool, const int, or const float value diff --git a/res/v3x/parsing/initialization_list/int_array_of_1_i_equals_list_of_list_of_0_1_2/ast.golden.txt b/res/v3x/parsing/initialization_list/int_array_of_1_i_equals_list_of_list_of_0_1_2/ast.golden.txt index 73ecd087b..0b30613df 100644 --- a/res/v3x/parsing/initialization_list/int_array_of_1_i_equals_list_of_list_of_0_1_2/ast.golden.txt +++ b/res/v3x/parsing/initialization_list/int_array_of_1_i_equals_list_of_list_of_0_1_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:10..11 var: < Variable( # input.cq:3:8..9 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 1 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 1 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/initialization_list/int_array_of_1_i_equals_list_of_list_of_0_1_2/semantic.3.0.golden.txt b/res/v3x/parsing/initialization_list/int_array_of_1_i_equals_list_of_list_of_0_1_2/semantic.3.0.golden.txt index 7361550aa..cc28a72d1 100644 --- a/res/v3x/parsing/initialization_list/int_array_of_1_i_equals_list_of_list_of_0_1_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/initialization_list/int_array_of_1_i_equals_list_of_list_of_0_1_2/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..11: expecting a const bool, const int, or const real value +Error at input.cq:3:10..11: expecting a const bool, const int, or const float value diff --git a/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q/ast.golden.txt b/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q/ast.golden.txt index 60815e74a..b7984ac86 100644 --- a/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q/ast.golden.txt +++ b/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q/semantic.3.0.golden.txt b/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q/semantic.3.0.golden.txt index a0de9a483..51d2ab6e7 100644 --- a/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:10..11: expecting a const bool, const int, or const real value +Error at input.cq:4:10..11: expecting a const bool, const int, or const float value diff --git a/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q_at_2/ast.golden.txt b/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q_at_2/ast.golden.txt index 77e1458ce..648bdd974 100644 --- a/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q_at_2/ast.golden.txt +++ b/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q_at_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q_at_2/semantic.3.0.golden.txt b/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q_at_2/semantic.3.0.golden.txt index a0de9a483..51d2ab6e7 100644 --- a/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q_at_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/initialization_list/qubit_array_of_3_q__int_array_of_3_i_equals_list_of_0_1_q_at_2/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:10..11: expecting a const bool, const int, or const real value +Error at input.cq:4:10..11: expecting a const bool, const int, or const float value diff --git a/res/v3x/parsing/instruction/qubit_2__h_q_0__h_q_1__cnot_q_0_q_1/ast.golden.txt b/res/v3x/parsing/instruction/qubit_2__h_q_0__h_q_1__cnot_q_0_q_1/ast.golden.txt index 307602bf5..70a46eb8a 100644 --- a/res/v3x/parsing/instruction/qubit_2__h_q_0__h_q_1__cnot_q_0_q_1/ast.golden.txt +++ b/res/v3x/parsing/instruction/qubit_2__h_q_0__h_q_1__cnot_q_0_q_1/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,24 +15,27 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 2 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 2 + ) + > ) > annotations: [] ) - Instruction( # input.cq:5:1..2 + Gate( # input.cq:5:1..2 name: < Identifier( name: h ) > - condition: - operands: < ExpressionList( items: [ @@ -61,13 +64,12 @@ Program( > annotations: [] ) - Instruction( # input.cq:6:1..2 + Gate( # input.cq:6:1..2 name: < Identifier( name: h ) > - condition: - operands: < ExpressionList( items: [ @@ -96,13 +98,12 @@ Program( > annotations: [] ) - Instruction( # input.cq:7:1..5 + Gate( # input.cq:7:1..5 name: < Identifier( name: cnot ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/instruction/qubit_2__h_q_0__h_q_1__cnot_q_0_q_1/semantic.3.0.golden.txt b/res/v3x/parsing/instruction/qubit_2__h_q_0__h_q_1__cnot_q_0_q_1/semantic.3.0.golden.txt index 3053f2821..292ba785a 100644 --- a/res/v3x/parsing/instruction/qubit_2__h_q_0__h_q_1__cnot_q_0_q_1/semantic.3.0.golden.txt +++ b/res/v3x/parsing/instruction/qubit_2__h_q_0__h_q_1__cnot_q_0_q_1/semantic.3.0.golden.txt @@ -6,116 +6,106 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: h(qubit) - name: h - operands: [ - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 2 + block: < + Block( + statements: [ + Instruction( + instruction: h(qubit) + name: h + operands: [ + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 0 + indices: [ + ConstInt( + value: 0 + ) + ] ) ] + annotations: [] ) - ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] - ) - Instruction( - instruction: h(qubit) - name: h - operands: [ - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 2 + Instruction( + instruction: h(qubit) + name: h + operands: [ + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 1 + indices: [ + ConstInt( + value: 1 + ) + ] ) ] + annotations: [] ) - ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] - ) - Instruction( - instruction: cnot(qubit, qubit) - name: cnot - operands: [ - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 2 + Instruction( + instruction: cnot(qubit, qubit) + name: cnot + operands: [ + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 0 + indices: [ + ConstInt( + value: 0 + ) + ] ) - ] - ) - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 2 + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 2 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 1 + indices: [ + ConstInt( + value: 1 + ) + ] ) ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/instruction/qubit_q__x_q/ast.golden.txt b/res/v3x/parsing/instruction/qubit_q__x_q/ast.golden.txt index af1357554..15bfb7b03 100644 --- a/res/v3x/parsing/instruction/qubit_q__x_q/ast.golden.txt +++ b/res/v3x/parsing/instruction/qubit_q__x_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:5:1..2 + Gate( # input.cq:5:1..2 name: < Identifier( name: x ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/instruction/qubit_q__x_q/semantic.3.0.golden.txt b/res/v3x/parsing/instruction/qubit_q__x_q/semantic.3.0.golden.txt index a700bcffb..5d3617ecd 100644 --- a/res/v3x/parsing/instruction/qubit_q__x_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/instruction/qubit_q__x_q/semantic.3.0.golden.txt @@ -6,33 +6,33 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: x(qubit) - name: x - operands: [ - VariableRef( - variable --> < - Variable( - name: q - typ: < - Qubit( - size: 1 + block: < + Block( + statements: [ + Instruction( + instruction: x(qubit) + name: x + operands: [ + VariableRef( + variable --> < + Variable( + name: q + typ: < + Qubit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/instruction/v_1/ast.golden.txt b/res/v3x/parsing/instruction/v_1/ast.golden.txt index 0eab650c1..4d658a6d3 100644 --- a/res/v3x/parsing/instruction/v_1/ast.golden.txt +++ b/res/v3x/parsing/instruction/v_1/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..2 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..2 name: < Identifier( name: v ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/instruction/v_1/semantic.3.0.golden.txt b/res/v3x/parsing/instruction/v_1/semantic.3.0.golden.txt index b273b794d..3d33ea029 100644 --- a/res/v3x/parsing/instruction/v_1/semantic.3.0.golden.txt +++ b/res/v3x/parsing/instruction/v_1/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:1..2: failed to resolve 'v' +Error at input.cq:3:1..2: failed to resolve instruction 'v' with argument pack (int) diff --git a/res/v3x/parsing/instruction/x/ast.golden.txt b/res/v3x/parsing/instruction/x/ast.golden.txt index 1cdf9ea48..f4759fa69 100644 --- a/res/v3x/parsing/instruction/x/ast.golden.txt +++ b/res/v3x/parsing/instruction/x/ast.golden.txt @@ -1,2 +1,23 @@ -ERROR -Error at input.cq:3:2..3: no viable alternative at input 'x\n' +SUCCESS +Program( + version: < + Version( # input.cq:1:9..10 + items: 3 + ) + > + block: < + GlobalBlock( + statements: [ + ExpressionStatement( + expression: < + Identifier( # input.cq:3:1..2 + name: x + ) + > + annotations: [] + ) + ] + ) + > +) + diff --git a/res/v3x/parsing/instruction/x/semantic.3.0.golden.txt b/res/v3x/parsing/instruction/x/semantic.3.0.golden.txt new file mode 100644 index 000000000..eff497a1d --- /dev/null +++ b/res/v3x/parsing/instruction/x/semantic.3.0.golden.txt @@ -0,0 +1,2 @@ +ERROR +Error at input.cq:3:1..2: expression statement is not of function call type diff --git a/res/v3x/parsing/instruction/x_1/ast.golden.txt b/res/v3x/parsing/instruction/x_1/ast.golden.txt index c9bf54035..9f2e023c9 100644 --- a/res/v3x/parsing/instruction/x_1/ast.golden.txt +++ b/res/v3x/parsing/instruction/x_1/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..2 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..2 name: < Identifier( name: x ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/instruction/x_1/semantic.3.0.golden.txt b/res/v3x/parsing/instruction/x_1/semantic.3.0.golden.txt index 56711bcd8..d69e99a9e 100644 --- a/res/v3x/parsing/instruction/x_1/semantic.3.0.golden.txt +++ b/res/v3x/parsing/instruction/x_1/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:1..2: failed to resolve overload for 'x' with argument pack (int) +Error at input.cq:3:1..2: failed to resolve instruction 'x' with argument pack (int) diff --git a/res/v3x/parsing/instruction/x_q0/ast.golden.txt b/res/v3x/parsing/instruction/x_q0/ast.golden.txt index a3de79c0b..13d2fedf9 100644 --- a/res/v3x/parsing/instruction/x_q0/ast.golden.txt +++ b/res/v3x/parsing/instruction/x_q0/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..2 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..2 name: < Identifier( name: x ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/instruction/x_q0/semantic.3.0.golden.txt b/res/v3x/parsing/instruction/x_q0/semantic.3.0.golden.txt index 5d19674df..03a6d6713 100644 --- a/res/v3x/parsing/instruction/x_q0/semantic.3.0.golden.txt +++ b/res/v3x/parsing/instruction/x_q0/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:3..4: failed to resolve mapping 'q' +Error at input.cq:3:3..4: failed to resolve variable 'q' diff --git a/res/v3x/parsing/instruction/x_v/ast.golden.txt b/res/v3x/parsing/instruction/x_v/ast.golden.txt index 88c0055a1..d1798acd4 100644 --- a/res/v3x/parsing/instruction/x_v/ast.golden.txt +++ b/res/v3x/parsing/instruction/x_v/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..2 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..2 name: < Identifier( name: x ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/instruction/x_v/semantic.3.0.golden.txt b/res/v3x/parsing/instruction/x_v/semantic.3.0.golden.txt index fa92c91c0..8dea1b552 100644 --- a/res/v3x/parsing/instruction/x_v/semantic.3.0.golden.txt +++ b/res/v3x/parsing/instruction/x_v/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:3..4: failed to resolve mapping 'v' +Error at input.cq:3:3..4: failed to resolve variable 'v' diff --git a/res/v3x/parsing/int_array_definition/iint_array_of_17_i/ast.golden.txt b/res/v3x/parsing/int_array_definition/iint_array_of_17_i/ast.golden.txt index 9326630b1..a009d9307 100644 --- a/res/v3x/parsing/int_array_definition/iint_array_of_17_i/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/iint_array_of_17_i/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:9..10: mismatched input 'i' expecting '=' +Error at input.cq:3:9..10: extraneous input 'i' expecting {, NEW_LINE, ';'} diff --git a/res/v3x/parsing/int_array_definition/int_array_of_0_i/ast.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_0_i/ast.golden.txt index 892dd48fe..85c461f7b 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_0_i/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_0_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:8..9 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 0 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 0 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/int_array_definition/int_array_of_0_i/semantic.3.0.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_0_i/semantic.3.0.golden.txt index 41d75e1f8..784efd95f 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_0_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_0_i/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:8..9: declaring int array of size <= 0 +Error at input.cq:3:8..9: found int array of size <= 0 diff --git a/res/v3x/parsing/int_array_definition/int_array_of_123abc/ast.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_123abc/ast.golden.txt index 3a53d2e81..5c99f3dfe 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_123abc/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_123abc/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:8..11: extraneous input 'abc' expecting ']' +Error at input.cq:3:8..11: no viable alternative at input 'int[123abc' diff --git a/res/v3x/parsing/int_array_definition/int_array_of_17/ast.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_17/ast.golden.txt index 99ed747f6..bbccf6090 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_17/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_17/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:8..9: missing IDENTIFIER at '\n' +Error at input.cq:3:8..9: no viable alternative at input 'int[17]\n' diff --git a/res/v3x/parsing/int_array_definition/int_array_of_17_1/ast.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_17_1/ast.golden.txt index 66696ca45..804c32c10 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_17_1/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_17_1/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:9..10: mismatched input '1' expecting IDENTIFIER +Error at input.cq:3:9..10: no viable alternative at input 'int[17]1' diff --git a/res/v3x/parsing/int_array_definition/int_array_of_17_equal/ast.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_17_equal/ast.golden.txt index 4fec36e83..6cd1a30cb 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_17_equal/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_17_equal/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:9..10: missing IDENTIFIER at '=' +Error at input.cq:3:9..10: no viable alternative at input 'int[17]=' diff --git a/res/v3x/parsing/int_array_definition/int_array_of_17_i/ast.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_17_i/ast.golden.txt index 0f8c3ecd1..dcc7492b6 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_17_i/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_17_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:9..10 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/int_array_definition/int_array_of_17_i/semantic.3.0.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_17_i/semantic.3.0.golden.txt index 2e5bcc2fc..f29d9d399 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_17_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_17_i/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/int_array_definition/int_array_of_17_i__int_array_of_17_i/ast.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_17_i__int_array_of_17_i/ast.golden.txt index 1afdd3c9b..4acc6dc52 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_17_i__int_array_of_17_i/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_17_i__int_array_of_17_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:9..10 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:3:1..8 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:4:1..8 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/int_array_definition/int_array_of_17_i__int_array_of_17_i/semantic.3.0.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_17_i__int_array_of_17_i/semantic.3.0.golden.txt index d04895b4a..e5dc4f0cb 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_17_i__int_array_of_17_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_17_i__int_array_of_17_i/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/int_array_definition/int_array_of_3.14/ast.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_3.14/ast.golden.txt index a7bcdba54..f26701adb 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_3.14/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_3.14/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..9: mismatched input '3.14' expecting INTEGER_LITERAL +Error at input.cq:3:5..9: no viable alternative at input 'int[3.14' diff --git a/res/v3x/parsing/int_array_definition/int_array_of_equal/ast.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_equal/ast.golden.txt index 8baf9b3dc..1ea9d2356 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_equal/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_equal/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..6: mismatched input '=' expecting INTEGER_LITERAL +Error at input.cq:3:5..6: no viable alternative at input 'int[=' diff --git a/res/v3x/parsing/int_array_definition/int_array_of_i/ast.golden.txt b/res/v3x/parsing/int_array_definition/int_array_of_i/ast.golden.txt index f6029b6c8..6abaeb5c0 100644 --- a/res/v3x/parsing/int_array_definition/int_array_of_i/ast.golden.txt +++ b/res/v3x/parsing/int_array_definition/int_array_of_i/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..6: mismatched input 'i' expecting INTEGER_LITERAL +Error at input.cq:3:5..6: no viable alternative at input 'int[i' diff --git a/res/v3x/parsing/int_array_initialization/float_array_of_3_f__int_array_of_3_i_equals_f/ast.golden.txt b/res/v3x/parsing/int_array_initialization/float_array_of_3_f__int_array_of_3_i_equals_f/ast.golden.txt index 489cfe679..64fc55aba 100644 --- a/res/v3x/parsing/int_array_initialization/float_array_of_3_f__int_array_of_3_i_equals_f/ast.golden.txt +++ b/res/v3x/parsing/int_array_initialization/float_array_of_3_f__int_array_of_3_i_equals_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: float - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: float + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/int_array_initialization/float_array_of_3_f__int_array_of_3_i_equals_f/semantic.3.0.golden.txt b/res/v3x/parsing/int_array_initialization/float_array_of_3_f__int_array_of_3_i_equals_f/semantic.3.0.golden.txt index c29bb49be..4b376042a 100644 --- a/res/v3x/parsing/int_array_initialization/float_array_of_3_f__int_array_of_3_i_equals_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_array_initialization/float_array_of_3_f__int_array_of_3_i_equals_f/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:10..11: type of right-hand side (real array) could not be coerced to left-hand side (int array) +Error at input.cq:4:10..11: type of right-hand side (float array) could not be coerced to left-hand side (int array) diff --git a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_i/ast.golden.txt b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_i/ast.golden.txt index 5b80e21d7..2bc4af7c7 100644 --- a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_i/ast.golden.txt +++ b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:10..11 var: < Variable( # input.cq:3:8..9 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_i/semantic.3.0.golden.txt b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_i/semantic.3.0.golden.txt index 6273994fe..37975c1cf 100644 --- a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_i/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:12..13: failed to resolve mapping 'i' +Error at input.cq:3:12..13: failed to resolve variable 'i' diff --git a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_j/ast.golden.txt b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_j/ast.golden.txt index fbf7f108a..565532389 100644 --- a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_j/ast.golden.txt +++ b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_j/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:10..11 var: < Variable( # input.cq:3:8..9 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_j/semantic.3.0.golden.txt b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_j/semantic.3.0.golden.txt index a729857a7..7abeca420 100644 --- a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_j/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_j/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:12..13: failed to resolve mapping 'j' +Error at input.cq:3:12..13: failed to resolve variable 'j' diff --git a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1/ast.golden.txt b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1/ast.golden.txt index b3d5599a2..290ee2c87 100644 --- a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1/ast.golden.txt +++ b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:10..11 var: < Variable( # input.cq:3:8..9 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1_2/ast.golden.txt b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1_2/ast.golden.txt index 544f8ea3b..2f824b5d5 100644 --- a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1_2/ast.golden.txt +++ b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:10..11 var: < Variable( # input.cq:3:8..9 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1_2/semantic.3.0.golden.txt b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1_2/semantic.3.0.golden.txt index 054cdc516..6b9db8106 100644 --- a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_0_1_2/semantic.3.0.golden.txt @@ -6,46 +6,46 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - IntArray( - size: 3 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + IntArray( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstIntArray( - value: [ - ConstInt( - value: 0 - ) - ConstInt( - value: 1 - ) - ConstInt( - value: 2 + rhs: < + ConstIntArray( + value: [ + ConstInt( + value: 0 + ) + ConstInt( + value: 1 + ) + ConstInt( + value: 2 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_false_1_2/ast.golden.txt b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_false_1_2/ast.golden.txt index 11be78992..97102366f 100644 --- a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_false_1_2/ast.golden.txt +++ b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_false_1_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:10..11 var: < Variable( # input.cq:3:8..9 @@ -17,13 +17,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_false_1_2/semantic.3.0.golden.txt b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_false_1_2/semantic.3.0.golden.txt index 054cdc516..6b9db8106 100644 --- a/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_false_1_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_array_initialization/int_array_of_3_i_equals_list_of_false_1_2/semantic.3.0.golden.txt @@ -6,46 +6,46 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - IntArray( - size: 3 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + IntArray( + size: 3 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - ConstIntArray( - value: [ - ConstInt( - value: 0 - ) - ConstInt( - value: 1 - ) - ConstInt( - value: 2 + rhs: < + ConstIntArray( + value: [ + ConstInt( + value: 0 + ) + ConstInt( + value: 1 + ) + ConstInt( + value: 2 + ) + ] ) - ] - ) - > - condition: < - ConstBool( - value: 1 + > + annotations: [] ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/int_array_initialization/qubit_array_of_3_q__int_array_of_3_i_equals_q/ast.golden.txt b/res/v3x/parsing/int_array_initialization/qubit_array_of_3_q__int_array_of_3_i_equals_q/ast.golden.txt index b6da6789a..cd4a050c0 100644 --- a/res/v3x/parsing/int_array_initialization/qubit_array_of_3_q__int_array_of_3_i_equals_q/ast.golden.txt +++ b/res/v3x/parsing/int_array_initialization/qubit_array_of_3_q__int_array_of_3_i_equals_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -35,13 +39,17 @@ Program( ) > typ: < - Keyword( - name: int - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: int + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/int_definition/iint_i/ast.golden.txt b/res/v3x/parsing/int_definition/iint_i/ast.golden.txt index ad6030399..cd83bf4ef 100644 --- a/res/v3x/parsing/int_definition/iint_i/ast.golden.txt +++ b/res/v3x/parsing/int_definition/iint_i/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..4 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..4 name: < Identifier( name: Int ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/int_definition/iint_i/semantic.3.0.golden.txt b/res/v3x/parsing/int_definition/iint_i/semantic.3.0.golden.txt index a1cb94231..0c968fe77 100644 --- a/res/v3x/parsing/int_definition/iint_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_definition/iint_i/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..6: failed to resolve mapping 'i' +Error at input.cq:3:5..6: failed to resolve variable 'i' diff --git a/res/v3x/parsing/int_definition/int/ast.golden.txt b/res/v3x/parsing/int_definition/int/ast.golden.txt index f260ff0ba..9b0d337b9 100644 --- a/res/v3x/parsing/int_definition/int/ast.golden.txt +++ b/res/v3x/parsing/int_definition/int/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:4..5: mismatched input '\n' expecting {'[', IDENTIFIER} +Error at input.cq:3:4..5: no viable alternative at input 'int\n' diff --git a/res/v3x/parsing/int_definition/int_1/ast.golden.txt b/res/v3x/parsing/int_definition/int_1/ast.golden.txt index 3352ab231..d30997b48 100644 --- a/res/v3x/parsing/int_definition/int_1/ast.golden.txt +++ b/res/v3x/parsing/int_definition/int_1/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..6: mismatched input '1' expecting {'[', IDENTIFIER} +Error at input.cq:3:5..6: no viable alternative at input 'int1' diff --git a/res/v3x/parsing/int_definition/int_123abc/ast.golden.txt b/res/v3x/parsing/int_definition/int_123abc/ast.golden.txt index 8b3ecbcb2..795ee2235 100644 --- a/res/v3x/parsing/int_definition/int_123abc/ast.golden.txt +++ b/res/v3x/parsing/int_definition/int_123abc/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..8: extraneous input '123' expecting {'[', IDENTIFIER} +Error at input.cq:3:5..8: no viable alternative at input 'int123' diff --git a/res/v3x/parsing/int_definition/int_equals/ast.golden.txt b/res/v3x/parsing/int_definition/int_equals/ast.golden.txt index 56f26b4bf..2184d2166 100644 --- a/res/v3x/parsing/int_definition/int_equals/ast.golden.txt +++ b/res/v3x/parsing/int_definition/int_equals/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:5..6: mismatched input '=' expecting {'[', IDENTIFIER} +Error at input.cq:3:5..6: no viable alternative at input 'int=' diff --git a/res/v3x/parsing/int_definition/int_i/ast.golden.txt b/res/v3x/parsing/int_definition/int_i/ast.golden.txt index 9442b22c1..4239b4ef1 100644 --- a/res/v3x/parsing/int_definition/int_i/ast.golden.txt +++ b/res/v3x/parsing/int_definition/int_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:5..6 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/int_definition/int_i/semantic.3.0.golden.txt b/res/v3x/parsing/int_definition/int_i/semantic.3.0.golden.txt index 4962b7c8b..6c152bfbd 100644 --- a/res/v3x/parsing/int_definition/int_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_definition/int_i/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/int_definition/int_i__int_i/ast.golden.txt b/res/v3x/parsing/int_definition/int_i__int_i/ast.golden.txt index f84b8a1a3..98c4bd68f 100644 --- a/res/v3x/parsing/int_definition/int_i__int_i/ast.golden.txt +++ b/res/v3x/parsing/int_definition/int_i__int_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:5..6 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) Variable( # input.cq:4:5..6 @@ -29,11 +33,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:4:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/int_definition/int_i__int_i/semantic.3.0.golden.txt b/res/v3x/parsing/int_definition/int_i__int_i/semantic.3.0.golden.txt index a1db1237e..08dca9a8c 100644 --- a/res/v3x/parsing/int_definition/int_i__int_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_definition/int_i__int_i/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/int_initialization/bool_b_equals_true__int_i_equals_b/ast.golden.txt b/res/v3x/parsing/int_initialization/bool_b_equals_true__int_i_equals_b/ast.golden.txt index fb66c391b..498cdedd2 100644 --- a/res/v3x/parsing/int_initialization/bool_b_equals_true__int_i_equals_b/ast.golden.txt +++ b/res/v3x/parsing/int_initialization/bool_b_equals_true__int_i_equals_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:8..9 var: < Variable( # input.cq:3:6..7 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: bool + Type( # input.cq:3:1..5 + name: < + Keyword( + name: bool + ) + > + size: - ) > - size: - annotations: [] ) > @@ -41,11 +45,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:4:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/int_initialization/bool_b_equals_true__int_i_equals_b/semantic.3.0.golden.txt b/res/v3x/parsing/int_initialization/bool_b_equals_true__int_i_equals_b/semantic.3.0.golden.txt index 7c49c6546..490110ef0 100644 --- a/res/v3x/parsing/int_initialization/bool_b_equals_true__int_i_equals_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_initialization/bool_b_equals_true__int_i_equals_b/semantic.3.0.golden.txt @@ -6,74 +6,69 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: b - typ: < - Bool( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: b + typ: < + Bool( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstBool( + value: 1 + ) + > + annotations: [] ) - > - rhs: < - ConstBool( - value: 1 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] - ) - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - VariableRef( - variable --> < - Variable( - name: b - typ: < - Bool( - size: 1 + rhs: < + VariableRef( + variable --> < + Variable( + name: b + typ: < + Bool( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + annotations: [] ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: b diff --git a/res/v3x/parsing/int_initialization/float_f__int_i_equals_f/ast.golden.txt b/res/v3x/parsing/int_initialization/float_f__int_i_equals_f/ast.golden.txt index 3256e3006..4507732be 100644 --- a/res/v3x/parsing/int_initialization/float_f__int_i_equals_f/ast.golden.txt +++ b/res/v3x/parsing/int_initialization/float_f__int_i_equals_f/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: float + Type( # input.cq:3:1..6 + name: < + Keyword( + name: float + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:7..8 @@ -31,11 +35,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:4:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/int_initialization/float_f__int_i_equals_f/semantic.3.0.golden.txt b/res/v3x/parsing/int_initialization/float_f__int_i_equals_f/semantic.3.0.golden.txt index 2ee572104..872c1fe38 100644 --- a/res/v3x/parsing/int_initialization/float_f__int_i_equals_f/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_initialization/float_f__int_i_equals_f/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:4:7..8: type of right-hand side (real) could not be coerced to left-hand side (int) +Error at input.cq:4:7..8: type of right-hand side (float) could not be coerced to left-hand side (int) diff --git a/res/v3x/parsing/int_initialization/int_i_equals_42/ast.golden.txt b/res/v3x/parsing/int_initialization/int_i_equals_42/ast.golden.txt index b454e24a9..4230943a3 100644 --- a/res/v3x/parsing/int_initialization/int_i_equals_42/ast.golden.txt +++ b/res/v3x/parsing/int_initialization/int_i_equals_42/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/int_initialization/int_i_equals_42/semantic.3.0.golden.txt b/res/v3x/parsing/int_initialization/int_i_equals_42/semantic.3.0.golden.txt index fe9f4603d..2a9dbee88 100644 --- a/res/v3x/parsing/int_initialization/int_i_equals_42/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_initialization/int_i_equals_42/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: 42 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: 42 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/int_initialization/int_i_equals_42__int_j_equals_i/ast.golden.txt b/res/v3x/parsing/int_initialization/int_i_equals_42__int_j_equals_i/ast.golden.txt index d9fbc8820..6439f9826 100644 --- a/res/v3x/parsing/int_initialization/int_i_equals_42__int_j_equals_i/ast.golden.txt +++ b/res/v3x/parsing/int_initialization/int_i_equals_42__int_j_equals_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > @@ -41,11 +45,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:4:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/int_initialization/int_i_equals_42__int_j_equals_i/semantic.3.0.golden.txt b/res/v3x/parsing/int_initialization/int_i_equals_42__int_j_equals_i/semantic.3.0.golden.txt index 9a2eb398d..f35f5c3c7 100644 --- a/res/v3x/parsing/int_initialization/int_i_equals_42__int_j_equals_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_initialization/int_i_equals_42__int_j_equals_i/semantic.3.0.golden.txt @@ -6,74 +6,69 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: 42 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: 42 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] - ) - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: j - typ: < - Int( - size: 1 + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: j + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > - ) - > - rhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + rhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + annotations: [] ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/int_initialization/int_i_equals_false/ast.golden.txt b/res/v3x/parsing/int_initialization/int_i_equals_false/ast.golden.txt index f5b9f1fb1..e30a293b1 100644 --- a/res/v3x/parsing/int_initialization/int_i_equals_false/ast.golden.txt +++ b/res/v3x/parsing/int_initialization/int_i_equals_false/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/int_initialization/int_i_equals_false/semantic.3.0.golden.txt b/res/v3x/parsing/int_initialization/int_i_equals_false/semantic.3.0.golden.txt index bec9acccf..c52ec2053 100644 --- a/res/v3x/parsing/int_initialization/int_i_equals_false/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_initialization/int_i_equals_false/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - AssignmentInstruction( - lhs: < - VariableRef( - variable --> < - Variable( - name: i - typ: < - Int( - size: 1 + block: < + Block( + statements: [ + AssignmentStatement( + lhs: < + VariableRef( + variable --> < + Variable( + name: i + typ: < + Int( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) > + rhs: < + ConstInt( + value: 0 + ) + > + annotations: [] ) - > - rhs: < - ConstInt( - value: 0 - ) - > - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] + ] ) - ] + > + functions: [] variables: [ Variable( name: i diff --git a/res/v3x/parsing/int_initialization/int_i_equals_i/ast.golden.txt b/res/v3x/parsing/int_initialization/int_i_equals_i/ast.golden.txt index 02525849b..d41e6d6d5 100644 --- a/res/v3x/parsing/int_initialization/int_i_equals_i/ast.golden.txt +++ b/res/v3x/parsing/int_initialization/int_i_equals_i/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/int_initialization/int_i_equals_i/semantic.3.0.golden.txt b/res/v3x/parsing/int_initialization/int_i_equals_i/semantic.3.0.golden.txt index a09997d23..7eddb0254 100644 --- a/res/v3x/parsing/int_initialization/int_i_equals_i/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_initialization/int_i_equals_i/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:9..10: failed to resolve mapping 'i' +Error at input.cq:3:9..10: failed to resolve variable 'i' diff --git a/res/v3x/parsing/int_initialization/int_i_equals_j/ast.golden.txt b/res/v3x/parsing/int_initialization/int_i_equals_j/ast.golden.txt index fa7d55cb8..b25038ced 100644 --- a/res/v3x/parsing/int_initialization/int_i_equals_j/ast.golden.txt +++ b/res/v3x/parsing/int_initialization/int_i_equals_j/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Initialization( # input.cq:3:7..8 var: < Variable( # input.cq:3:5..6 @@ -17,11 +17,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:3:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/int_initialization/int_i_equals_j/semantic.3.0.golden.txt b/res/v3x/parsing/int_initialization/int_i_equals_j/semantic.3.0.golden.txt index 972168483..c431eca3c 100644 --- a/res/v3x/parsing/int_initialization/int_i_equals_j/semantic.3.0.golden.txt +++ b/res/v3x/parsing/int_initialization/int_i_equals_j/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:9..10: failed to resolve mapping 'j' +Error at input.cq:3:9..10: failed to resolve variable 'j' diff --git a/res/v3x/parsing/int_initialization/qubit_q__int_i_equals_q/ast.golden.txt b/res/v3x/parsing/int_initialization/qubit_q__int_i_equals_q/ast.golden.txt index d82119ef8..48fb0e27d 100644 --- a/res/v3x/parsing/int_initialization/qubit_q__int_i_equals_q/ast.golden.txt +++ b/res/v3x/parsing/int_initialization/qubit_q__int_i_equals_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) Initialization( # input.cq:4:7..8 @@ -31,11 +35,15 @@ Program( ) > typ: < - Keyword( - name: int + Type( # input.cq:4:1..4 + name: < + Keyword( + name: int + ) + > + size: - ) > - size: - annotations: [] ) > diff --git a/res/v3x/parsing/measure_instruction/array_of_3_q_to_b0/ast.golden.txt b/res/v3x/parsing/measure_instruction/array_of_3_q_to_b0/ast.golden.txt index 0a0f0b627..caac5e48d 100644 --- a/res/v3x/parsing/measure_instruction/array_of_3_q_to_b0/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/array_of_3_q_to_b0/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -33,11 +37,15 @@ Program( ) > typ: < - Keyword( - name: bit + Type( # input.cq:4:1..4 + name: < + Keyword( + name: bit + ) + > + size: - ) > - size: - annotations: [] ) MeasureInstruction( # input.cq:6:6..13 @@ -46,7 +54,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..3 name: b0 diff --git a/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_5_b/ast.golden.txt b/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_5_b/ast.golden.txt index 2bf177b35..a7666dd5e 100644 --- a/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_5_b/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_5_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..2 name: b diff --git a/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_5_b/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_5_b/semantic.3.0.golden.txt index 81ded3374..2864857e4 100644 --- a/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_5_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_5_b/semantic.3.0.golden.txt @@ -6,46 +6,46 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit array, qubit array) - name: measure - operands: [ - VariableRef( - variable --> < - Variable( - name: b - typ: < - BitArray( - size: 5 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit array, qubit array) + name: measure + operands: [ + VariableRef( + variable --> < + Variable( + name: b + typ: < + BitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] ) - > - ) - VariableRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 5 + VariableRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] ) - > + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_9_b/ast.golden.txt b/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_9_b/ast.golden.txt index a6dab0deb..be97db2d2 100644 --- a/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_9_b/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/array_of_5_q_to_array_of_9_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 9 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 9 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..2 name: b diff --git a/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_0_4/ast.golden.txt b/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_0_4/ast.golden.txt index e87d8fdec..e136dc334 100644 --- a/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_0_4/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_0_4/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 9 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 9 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Index( # input.cq:6:1..2 expr: < diff --git a/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_0_4/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_0_4/semantic.3.0.golden.txt index 03cec52e3..66b5bc9a8 100644 --- a/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_0_4/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_0_4/semantic.3.0.golden.txt @@ -6,63 +6,63 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit array, qubit array) - name: measure - operands: [ - IndexRef( - variable --> < - Variable( - name: b - typ: < - BitArray( - size: 9 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit array, qubit array) + name: measure + operands: [ + IndexRef( + variable --> < + Variable( + name: b + typ: < + BitArray( + size: 9 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 0 - ) - ConstInt( - value: 1 - ) - ConstInt( - value: 2 - ) - ConstInt( - value: 3 - ) - ConstInt( - value: 4 + indices: [ + ConstInt( + value: 0 + ) + ConstInt( + value: 1 + ) + ConstInt( + value: 2 + ) + ConstInt( + value: 3 + ) + ConstInt( + value: 4 + ) + ] ) - ] - ) - VariableRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 5 + VariableRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] ) - > + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_2_6/ast.golden.txt b/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_2_6/ast.golden.txt index e97476700..bcacc4cc5 100644 --- a/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_2_6/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_2_6/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 9 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 9 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Index( # input.cq:6:1..2 expr: < diff --git a/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_2_6/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_2_6/semantic.3.0.golden.txt index 0e62c99e3..7ee499e50 100644 --- a/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_2_6/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/array_of_5_q_to_b_range_2_6/semantic.3.0.golden.txt @@ -6,63 +6,63 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit array, qubit array) - name: measure - operands: [ - IndexRef( - variable --> < - Variable( - name: b - typ: < - BitArray( - size: 9 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit array, qubit array) + name: measure + operands: [ + IndexRef( + variable --> < + Variable( + name: b + typ: < + BitArray( + size: 9 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 2 - ) - ConstInt( - value: 3 - ) - ConstInt( - value: 4 - ) - ConstInt( - value: 5 - ) - ConstInt( - value: 6 + indices: [ + ConstInt( + value: 2 + ) + ConstInt( + value: 3 + ) + ConstInt( + value: 4 + ) + ConstInt( + value: 5 + ) + ConstInt( + value: 6 + ) + ] ) - ] - ) - VariableRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 5 + VariableRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] ) - > + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/array_of_9_q_to_array_of_5_b/ast.golden.txt b/res/v3x/parsing/measure_instruction/array_of_9_q_to_array_of_5_b/ast.golden.txt index a6dab0deb..be97db2d2 100644 --- a/res/v3x/parsing/measure_instruction/array_of_9_q_to_array_of_5_b/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/array_of_9_q_to_array_of_5_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 9 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 9 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..2 name: b diff --git a/res/v3x/parsing/measure_instruction/b_to_b/ast.golden.txt b/res/v3x/parsing/measure_instruction/b_to_b/ast.golden.txt index a090b3ce6..65ff9d579 100644 --- a/res/v3x/parsing/measure_instruction/b_to_b/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/b_to_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:5..6 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: bit + Type( # input.cq:3:1..4 + name: < + Keyword( + name: bit + ) + > + size: - ) > - size: - annotations: [] ) MeasureInstruction( # input.cq:5:5..12 @@ -28,7 +32,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:5:1..2 name: b diff --git a/res/v3x/parsing/measure_instruction/b_to_b/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/b_to_b/semantic.3.0.golden.txt index 8d622392e..1ba2367ba 100644 --- a/res/v3x/parsing/measure_instruction/b_to_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/b_to_b/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:5:5..12: failed to resolve overload for 'measure' with argument pack (bit, bit) +Error at input.cq:5:5..12: failed to resolve instruction 'measure' with argument pack (bit, bit) diff --git a/res/v3x/parsing/measure_instruction/b_to_q/ast.golden.txt b/res/v3x/parsing/measure_instruction/b_to_q/ast.golden.txt index 1b476072f..7d8667293 100644 --- a/res/v3x/parsing/measure_instruction/b_to_q/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/b_to_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) Variable( # input.cq:4:5..6 @@ -29,11 +33,15 @@ Program( ) > typ: < - Keyword( - name: bit + Type( # input.cq:4:1..4 + name: < + Keyword( + name: bit + ) + > + size: - ) > - size: - annotations: [] ) MeasureInstruction( # input.cq:6:5..12 @@ -42,7 +50,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..2 name: q diff --git a/res/v3x/parsing/measure_instruction/b_to_q/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/b_to_q/semantic.3.0.golden.txt index 9d33092a2..d41cbf097 100644 --- a/res/v3x/parsing/measure_instruction/b_to_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/b_to_q/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:6:5..12: failed to resolve overload for 'measure' with argument pack (qubit, bit) +Error at input.cq:6:5..12: failed to resolve instruction 'measure' with argument pack (qubit, bit) diff --git a/res/v3x/parsing/measure_instruction/bit_and_qubit/ast.golden.txt b/res/v3x/parsing/measure_instruction/bit_and_qubit/ast.golden.txt index f3b0eb804..c4464593b 100644 --- a/res/v3x/parsing/measure_instruction/bit_and_qubit/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/bit_and_qubit/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) Variable( # input.cq:4:5..6 @@ -29,11 +33,15 @@ Program( ) > typ: < - Keyword( - name: bit + Type( # input.cq:4:1..4 + name: < + Keyword( + name: bit + ) + > + size: - ) > - size: - annotations: [] ) MeasureInstruction( # input.cq:6:5..12 @@ -42,7 +50,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..2 name: b diff --git a/res/v3x/parsing/measure_instruction/bit_and_qubit/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/bit_and_qubit/semantic.3.0.golden.txt index eff25bdf6..1520ccfa6 100644 --- a/res/v3x/parsing/measure_instruction/bit_and_qubit/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/bit_and_qubit/semantic.3.0.golden.txt @@ -6,46 +6,46 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit, qubit) - name: measure - operands: [ - VariableRef( - variable --> < - Variable( - name: b - typ: < - Bit( - size: 1 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit, qubit) + name: measure + operands: [ + VariableRef( + variable --> < + Variable( + name: b + typ: < + Bit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > - ) - VariableRef( - variable --> < - Variable( - name: q - typ: < - Qubit( - size: 1 + VariableRef( + variable --> < + Variable( + name: q + typ: < + Qubit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/no_bit_no_qubit/ast.golden.txt b/res/v3x/parsing/measure_instruction/no_bit_no_qubit/ast.golden.txt index 18817f273..dc5c82a8d 100644 --- a/res/v3x/parsing/measure_instruction/no_bit_no_qubit/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/no_bit_no_qubit/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:1..8: extraneous input 'measure' expecting {, NEW_LINE, ';'} +Error at input.cq:3:1..8: no viable alternative at input '\n\nmeasure' diff --git a/res/v3x/parsing/measure_instruction/q0_to_array_of_3_b/ast.golden.txt b/res/v3x/parsing/measure_instruction/q0_to_array_of_3_b/ast.golden.txt index e89c126b3..684a5fe48 100644 --- a/res/v3x/parsing/measure_instruction/q0_to_array_of_3_b/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q0_to_array_of_3_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..9 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) Variable( # input.cq:4:8..9 @@ -29,13 +33,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -46,7 +54,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..2 name: b diff --git a/res/v3x/parsing/measure_instruction/q0_to_b_0/ast.golden.txt b/res/v3x/parsing/measure_instruction/q0_to_b_0/ast.golden.txt index 6ce6dca20..12b8c8746 100644 --- a/res/v3x/parsing/measure_instruction/q0_to_b_0/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q0_to_b_0/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..9 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) Variable( # input.cq:4:8..9 @@ -29,13 +33,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -46,7 +54,6 @@ Program( name: measure ) > - condition: - lhs: < Index( # input.cq:6:1..2 expr: < diff --git a/res/v3x/parsing/measure_instruction/q0_to_b_0/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/q0_to_b_0/semantic.3.0.golden.txt index 4137e0d31..e9b0b6f1e 100644 --- a/res/v3x/parsing/measure_instruction/q0_to_b_0/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/q0_to_b_0/semantic.3.0.golden.txt @@ -6,51 +6,51 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit, qubit) - name: measure - operands: [ - IndexRef( - variable --> < - Variable( - name: b - typ: < - BitArray( - size: 3 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit, qubit) + name: measure + operands: [ + IndexRef( + variable --> < + Variable( + name: b + typ: < + BitArray( + size: 3 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 0 + indices: [ + ConstInt( + value: 0 + ) + ] ) - ] - ) - VariableRef( - variable --> < - Variable( - name: q0 - typ: < - Qubit( - size: 1 + VariableRef( + variable --> < + Variable( + name: q0 + typ: < + Qubit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q0 diff --git a/res/v3x/parsing/measure_instruction/q_0_to_b0/ast.golden.txt b/res/v3x/parsing/measure_instruction/q_0_to_b0/ast.golden.txt index 12fc92d85..4c5332d4f 100644 --- a/res/v3x/parsing/measure_instruction/q_0_to_b0/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_0_to_b0/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 3 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 3 + ) + > ) > annotations: [] @@ -33,11 +37,15 @@ Program( ) > typ: < - Keyword( - name: bit + Type( # input.cq:4:1..4 + name: < + Keyword( + name: bit + ) + > + size: - ) > - size: - annotations: [] ) MeasureInstruction( # input.cq:6:6..13 @@ -46,7 +54,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..3 name: b0 diff --git a/res/v3x/parsing/measure_instruction/q_0_to_b0/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/q_0_to_b0/semantic.3.0.golden.txt index f799ac633..8ff3e3b82 100644 --- a/res/v3x/parsing/measure_instruction/q_0_to_b0/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_0_to_b0/semantic.3.0.golden.txt @@ -6,51 +6,51 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit, qubit) - name: measure - operands: [ - VariableRef( - variable --> < - Variable( - name: b0 - typ: < - Bit( - size: 1 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit, qubit) + name: measure + operands: [ + VariableRef( + variable --> < + Variable( + name: b0 + typ: < + Bit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > - ) - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 3 + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 3 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 0 + indices: [ + ConstInt( + value: 0 + ) + ] ) ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/q_1_3_4_5_7_to_array_of_5_b/ast.golden.txt b/res/v3x/parsing/measure_instruction/q_1_3_4_5_7_to_array_of_5_b/ast.golden.txt index cc17d0b0c..4ae6af684 100644 --- a/res/v3x/parsing/measure_instruction/q_1_3_4_5_7_to_array_of_5_b/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_1_3_4_5_7_to_array_of_5_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 9 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 9 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..2 name: b diff --git a/res/v3x/parsing/measure_instruction/q_1_3_4_5_7_to_array_of_5_b/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/q_1_3_4_5_7_to_array_of_5_b/semantic.3.0.golden.txt index 245f12eb3..2d44dd888 100644 --- a/res/v3x/parsing/measure_instruction/q_1_3_4_5_7_to_array_of_5_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_1_3_4_5_7_to_array_of_5_b/semantic.3.0.golden.txt @@ -6,63 +6,63 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit array, qubit array) - name: measure - operands: [ - VariableRef( - variable --> < - Variable( - name: b - typ: < - BitArray( - size: 5 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit array, qubit array) + name: measure + operands: [ + VariableRef( + variable --> < + Variable( + name: b + typ: < + BitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] ) - > - ) - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 9 + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 9 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 1 - ) - ConstInt( - value: 3 - ) - ConstInt( - value: 4 - ) - ConstInt( - value: 5 - ) - ConstInt( - value: 7 + indices: [ + ConstInt( + value: 1 + ) + ConstInt( + value: 3 + ) + ConstInt( + value: 4 + ) + ConstInt( + value: 5 + ) + ConstInt( + value: 7 + ) + ] ) ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/q_2_4_to_b_1_3/ast.golden.txt b/res/v3x/parsing/measure_instruction/q_2_4_to_b_1_3/ast.golden.txt index fe82971a9..1c3b72531 100644 --- a/res/v3x/parsing/measure_instruction/q_2_4_to_b_1_3/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_2_4_to_b_1_3/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Index( # input.cq:6:1..2 expr: < diff --git a/res/v3x/parsing/measure_instruction/q_2_4_to_b_1_3/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/q_2_4_to_b_1_3/semantic.3.0.golden.txt index b81140818..ecd47cbf6 100644 --- a/res/v3x/parsing/measure_instruction/q_2_4_to_b_1_3/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_2_4_to_b_1_3/semantic.3.0.golden.txt @@ -6,62 +6,62 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit array, qubit array) - name: measure - operands: [ - IndexRef( - variable --> < - Variable( - name: b - typ: < - BitArray( - size: 5 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit array, qubit array) + name: measure + operands: [ + IndexRef( + variable --> < + Variable( + name: b + typ: < + BitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 1 - ) - ConstInt( - value: 3 + indices: [ + ConstInt( + value: 1 + ) + ConstInt( + value: 3 + ) + ] ) - ] - ) - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 5 + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 2 - ) - ConstInt( - value: 4 + indices: [ + ConstInt( + value: 2 + ) + ConstInt( + value: 4 + ) + ] ) ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/ast.actual.txt b/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/ast.actual.txt index ab3c4584f..b05054f03 100644 --- a/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/ast.actual.txt +++ b/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/ast.actual.txt @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/ast.golden.txt b/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/ast.golden.txt index ab3c4584f..892df8bec 100644 --- a/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Index( # input.cq:6:1..2 expr: < diff --git a/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/semantic.3.0.golden.txt index d0fe868c0..7361235d0 100644 --- a/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_2_4_to_b_range_1_2/semantic.3.0.golden.txt @@ -6,62 +6,62 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit array, qubit array) - name: measure - operands: [ - IndexRef( - variable --> < - Variable( - name: b - typ: < - BitArray( - size: 5 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit array, qubit array) + name: measure + operands: [ + IndexRef( + variable --> < + Variable( + name: b + typ: < + BitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 1 - ) - ConstInt( - value: 2 + indices: [ + ConstInt( + value: 1 + ) + ConstInt( + value: 2 + ) + ] ) - ] - ) - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 5 + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 2 - ) - ConstInt( - value: 4 + indices: [ + ConstInt( + value: 2 + ) + ConstInt( + value: 4 + ) + ] ) ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/q_range_0_4_to_array_of_5_b/ast.golden.txt b/res/v3x/parsing/measure_instruction/q_range_0_4_to_array_of_5_b/ast.golden.txt index ddd7657c7..dd96ab461 100644 --- a/res/v3x/parsing/measure_instruction/q_range_0_4_to_array_of_5_b/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_range_0_4_to_array_of_5_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 9 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 9 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..2 name: b diff --git a/res/v3x/parsing/measure_instruction/q_range_0_4_to_array_of_5_b/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/q_range_0_4_to_array_of_5_b/semantic.3.0.golden.txt index 8fa078ea7..12bb3b35c 100644 --- a/res/v3x/parsing/measure_instruction/q_range_0_4_to_array_of_5_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_range_0_4_to_array_of_5_b/semantic.3.0.golden.txt @@ -6,63 +6,63 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit array, qubit array) - name: measure - operands: [ - VariableRef( - variable --> < - Variable( - name: b - typ: < - BitArray( - size: 5 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit array, qubit array) + name: measure + operands: [ + VariableRef( + variable --> < + Variable( + name: b + typ: < + BitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] ) - > - ) - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 9 + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 9 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 0 - ) - ConstInt( - value: 1 - ) - ConstInt( - value: 2 - ) - ConstInt( - value: 3 - ) - ConstInt( - value: 4 + indices: [ + ConstInt( + value: 0 + ) + ConstInt( + value: 1 + ) + ConstInt( + value: 2 + ) + ConstInt( + value: 3 + ) + ConstInt( + value: 4 + ) + ] ) ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/q_range_2_6_to_array_of_5_b/ast.golden.txt b/res/v3x/parsing/measure_instruction/q_range_2_6_to_array_of_5_b/ast.golden.txt index 203d08cbe..5e5752249 100644 --- a/res/v3x/parsing/measure_instruction/q_range_2_6_to_array_of_5_b/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_range_2_6_to_array_of_5_b/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 9 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 9 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:6:1..2 name: b diff --git a/res/v3x/parsing/measure_instruction/q_range_2_6_to_array_of_5_b/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/q_range_2_6_to_array_of_5_b/semantic.3.0.golden.txt index c11972d77..27a9fd89d 100644 --- a/res/v3x/parsing/measure_instruction/q_range_2_6_to_array_of_5_b/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_range_2_6_to_array_of_5_b/semantic.3.0.golden.txt @@ -6,63 +6,63 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit array, qubit array) - name: measure - operands: [ - VariableRef( - variable --> < - Variable( - name: b - typ: < - BitArray( - size: 5 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit array, qubit array) + name: measure + operands: [ + VariableRef( + variable --> < + Variable( + name: b + typ: < + BitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] ) - > - ) - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 9 + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 9 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 2 - ) - ConstInt( - value: 3 - ) - ConstInt( - value: 4 - ) - ConstInt( - value: 5 - ) - ConstInt( - value: 6 + indices: [ + ConstInt( + value: 2 + ) + ConstInt( + value: 3 + ) + ConstInt( + value: 4 + ) + ConstInt( + value: 5 + ) + ConstInt( + value: 6 + ) + ] ) ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/q_range_3_4_to_b_1_3/ast.golden.txt b/res/v3x/parsing/measure_instruction/q_range_3_4_to_b_1_3/ast.golden.txt index 7416253b5..38f974b88 100644 --- a/res/v3x/parsing/measure_instruction/q_range_3_4_to_b_1_3/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_range_3_4_to_b_1_3/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: bit - ) - > - size: < - IntegerLiteral( - value: 5 + Type( # input.cq:4:1..7 + name: < + Keyword( + name: bit + ) + > + size: < + IntegerLiteral( + value: 5 + ) + > ) > annotations: [] @@ -50,7 +58,6 @@ Program( name: measure ) > - condition: - lhs: < Index( # input.cq:6:1..2 expr: < diff --git a/res/v3x/parsing/measure_instruction/q_range_3_4_to_b_1_3/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/q_range_3_4_to_b_1_3/semantic.3.0.golden.txt index 96194aa7c..7f4864045 100644 --- a/res/v3x/parsing/measure_instruction/q_range_3_4_to_b_1_3/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_range_3_4_to_b_1_3/semantic.3.0.golden.txt @@ -6,62 +6,62 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: measure(bit array, qubit array) - name: measure - operands: [ - IndexRef( - variable --> < - Variable( - name: b - typ: < - BitArray( - size: 5 + block: < + Block( + statements: [ + Instruction( + instruction: measure(bit array, qubit array) + name: measure + operands: [ + IndexRef( + variable --> < + Variable( + name: b + typ: < + BitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 1 - ) - ConstInt( - value: 3 + indices: [ + ConstInt( + value: 1 + ) + ConstInt( + value: 3 + ) + ] ) - ] - ) - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 5 + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 5 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 3 - ) - ConstInt( - value: 4 + indices: [ + ConstInt( + value: 3 + ) + ConstInt( + value: 4 + ) + ] ) ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/measure_instruction/q_to_5/ast.golden.txt b/res/v3x/parsing/measure_instruction/q_to_5/ast.golden.txt index cbaa516e4..5d8293088 100644 --- a/res/v3x/parsing/measure_instruction/q_to_5/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_to_5/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) MeasureInstruction( # input.cq:5:5..12 @@ -28,7 +32,6 @@ Program( name: measure ) > - condition: - lhs: < IntegerLiteral( # input.cq:5:1..2 value: 5 diff --git a/res/v3x/parsing/measure_instruction/q_to_5/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/q_to_5/semantic.3.0.golden.txt index 9d149a620..79d884b4d 100644 --- a/res/v3x/parsing/measure_instruction/q_to_5/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_to_5/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:5:5..12: failed to resolve overload for 'measure' with argument pack (int, qubit) +Error at input.cq:5:5..12: failed to resolve instruction 'measure' with argument pack (int, qubit) diff --git a/res/v3x/parsing/measure_instruction/q_to_q/ast.golden.txt b/res/v3x/parsing/measure_instruction/q_to_q/ast.golden.txt index f55e665b1..01806b5f8 100644 --- a/res/v3x/parsing/measure_instruction/q_to_q/ast.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_to_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) MeasureInstruction( # input.cq:5:5..12 @@ -28,7 +32,6 @@ Program( name: measure ) > - condition: - lhs: < Identifier( # input.cq:5:1..2 name: q diff --git a/res/v3x/parsing/measure_instruction/q_to_q/semantic.3.0.golden.txt b/res/v3x/parsing/measure_instruction/q_to_q/semantic.3.0.golden.txt index 5052dc961..f48b30b3c 100644 --- a/res/v3x/parsing/measure_instruction/q_to_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/measure_instruction/q_to_q/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:5:5..12: failed to resolve overload for 'measure' with argument pack (qubit, qubit) +Error at input.cq:5:5..12: failed to resolve instruction 'measure' with argument pack (qubit, qubit) diff --git a/res/v3x/parsing/newline_or_semicolon/qubit_newline_q/ast.golden.txt b/res/v3x/parsing/newline_or_semicolon/qubit_newline_q/ast.golden.txt index b686b4213..64a360da7 100644 --- a/res/v3x/parsing/newline_or_semicolon/qubit_newline_q/ast.golden.txt +++ b/res/v3x/parsing/newline_or_semicolon/qubit_newline_q/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: extraneous input '\n' expecting {'[', IDENTIFIER} +Error at input.cq:3:6..7: extraneous input '\n' expecting IDENTIFIER diff --git a/res/v3x/parsing/newline_or_semicolon/version_3_newline_qubit_q/ast.golden.txt b/res/v3x/parsing/newline_or_semicolon/version_3_newline_qubit_q/ast.golden.txt index ce938a805..2dc90a8b3 100644 --- a/res/v3x/parsing/newline_or_semicolon/version_3_newline_qubit_q/ast.golden.txt +++ b/res/v3x/parsing/newline_or_semicolon/version_3_newline_qubit_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/newline_or_semicolon/version_3_newline_qubit_q/semantic.3.0.golden.txt b/res/v3x/parsing/newline_or_semicolon/version_3_newline_qubit_q/semantic.3.0.golden.txt index e93ebf2b0..c51d6a845 100644 --- a/res/v3x/parsing/newline_or_semicolon/version_3_newline_qubit_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/newline_or_semicolon/version_3_newline_qubit_q/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/newline_or_semicolon/version_3_semicolon_qubit_q/ast.golden.txt b/res/v3x/parsing/newline_or_semicolon/version_3_semicolon_qubit_q/ast.golden.txt index fecb1bfe4..5453b5983 100644 --- a/res/v3x/parsing/newline_or_semicolon/version_3_semicolon_qubit_q/ast.golden.txt +++ b/res/v3x/parsing/newline_or_semicolon/version_3_semicolon_qubit_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:1:18..19 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:1:12..17 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/newline_or_semicolon/version_3_semicolon_qubit_q/semantic.3.0.golden.txt b/res/v3x/parsing/newline_or_semicolon/version_3_semicolon_qubit_q/semantic.3.0.golden.txt index e93ebf2b0..c51d6a845 100644 --- a/res/v3x/parsing/newline_or_semicolon/version_3_semicolon_qubit_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/newline_or_semicolon/version_3_semicolon_qubit_q/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_eu/ast.golden.txt b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_eu/ast.golden.txt index 5069d515f..520452990 100644 --- a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_eu/ast.golden.txt +++ b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_eu/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:4:1..3 + Gate( # input.cq:4:1..3 name: < Identifier( name: rx ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_eu/semantic.3.0.golden.txt b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_eu/semantic.3.0.golden.txt index b09c082aa..9c8a56977 100644 --- a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_eu/semantic.3.0.golden.txt +++ b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_eu/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: rx(qubit, real) - name: rx - operands: [ - VariableRef( - variable --> < - Variable( - name: q - typ: < - Qubit( - size: 1 + block: < + Block( + statements: [ + Instruction( + instruction: rx(qubit, float) + name: rx + operands: [ + VariableRef( + variable --> < + Variable( + name: q + typ: < + Qubit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > - ) - ConstReal( - value: 2.71828 + ConstFloat( + value: 2.71828 + ) + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_pi/ast.golden.txt b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_pi/ast.golden.txt index 0d25306e1..cb86971f5 100644 --- a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_pi/ast.golden.txt +++ b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_pi/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:4:1..3 + Gate( # input.cq:4:1..3 name: < Identifier( name: rx ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_pi/semantic.3.0.golden.txt b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_pi/semantic.3.0.golden.txt index c1712abf8..de488a9e9 100644 --- a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_pi/semantic.3.0.golden.txt +++ b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_pi/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: rx(qubit, real) - name: rx - operands: [ - VariableRef( - variable --> < - Variable( - name: q - typ: < - Qubit( - size: 1 + block: < + Block( + statements: [ + Instruction( + instruction: rx(qubit, float) + name: rx + operands: [ + VariableRef( + variable --> < + Variable( + name: q + typ: < + Qubit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > - ) - ConstReal( - value: 3.14159 + ConstFloat( + value: 3.14159 + ) + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_tau/ast.golden.txt b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_tau/ast.golden.txt index 7ff5830c4..6177be1c7 100644 --- a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_tau/ast.golden.txt +++ b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_tau/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:4:1..3 + Gate( # input.cq:4:1..3 name: < Identifier( name: rx ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_tau/semantic.3.0.golden.txt b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_tau/semantic.3.0.golden.txt index 25d584968..8503f367f 100644 --- a/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_tau/semantic.3.0.golden.txt +++ b/res/v3x/parsing/pi_im_eu_tau/qubit_q__rx_q_tau/semantic.3.0.golden.txt @@ -6,36 +6,36 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: rx(qubit, real) - name: rx - operands: [ - VariableRef( - variable --> < - Variable( - name: q - typ: < - Qubit( - size: 1 + block: < + Block( + statements: [ + Instruction( + instruction: rx(qubit, float) + name: rx + operands: [ + VariableRef( + variable --> < + Variable( + name: q + typ: < + Qubit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > - ) - ConstReal( - value: 6.28319 + ConstFloat( + value: 6.28319 + ) + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/program/bad_token_after_version/ast.golden.txt b/res/v3x/parsing/program/bad_token_after_version/ast.golden.txt index 09b5f7465..b13a41627 100644 --- a/res/v3x/parsing/program/bad_token_after_version/ast.golden.txt +++ b/res/v3x/parsing/program/bad_token_after_version/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:4..7: mismatched input 'abc' expecting '=' +Error at input.cq:3:4..7: extraneous input 'abc' expecting {, NEW_LINE, ';'} diff --git a/res/v3x/parsing/program/newlines_before_version/ast.golden.txt b/res/v3x/parsing/program/newlines_before_version/ast.golden.txt index eea988cfb..be3758d1a 100644 --- a/res/v3x/parsing/program/newlines_before_version/ast.golden.txt +++ b/res/v3x/parsing/program/newlines_before_version/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/program/newlines_before_version/semantic.3.0.golden.txt b/res/v3x/parsing/program/newlines_before_version/semantic.3.0.golden.txt index c67097953..38253ce8e 100644 --- a/res/v3x/parsing/program/newlines_before_version/semantic.3.0.golden.txt +++ b/res/v3x/parsing/program/newlines_before_version/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3.0 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/res/v3x/parsing/program/no_statement_separators_after_last_statement/ast.golden.txt b/res/v3x/parsing/program/no_statement_separators_after_last_statement/ast.golden.txt index 419622db1..95d6f21c5 100644 --- a/res/v3x/parsing/program/no_statement_separators_after_last_statement/ast.golden.txt +++ b/res/v3x/parsing/program/no_statement_separators_after_last_statement/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:2:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:2:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:3:1..2 + Gate( # input.cq:3:1..2 name: < Identifier( name: x ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/program/no_statement_separators_after_last_statement/semantic.3.0.golden.txt b/res/v3x/parsing/program/no_statement_separators_after_last_statement/semantic.3.0.golden.txt index 5eb2f69cd..e5bc7350b 100644 --- a/res/v3x/parsing/program/no_statement_separators_after_last_statement/semantic.3.0.golden.txt +++ b/res/v3x/parsing/program/no_statement_separators_after_last_statement/semantic.3.0.golden.txt @@ -6,33 +6,33 @@ Program( items: 3.0 ) > - statements: [ - Instruction( - instruction: x(qubit) - name: x - operands: [ - VariableRef( - variable --> < - Variable( - name: q - typ: < - Qubit( - size: 1 + block: < + Block( + statements: [ + Instruction( + instruction: x(qubit) + name: x + operands: [ + VariableRef( + variable --> < + Variable( + name: q + typ: < + Qubit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/program/no_statement_separators_after_version/ast.golden.txt b/res/v3x/parsing/program/no_statement_separators_after_version/ast.golden.txt index 986674ffd..9062b4184 100644 --- a/res/v3x/parsing/program/no_statement_separators_after_version/ast.golden.txt +++ b/res/v3x/parsing/program/no_statement_separators_after_version/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/program/no_statement_separators_after_version/semantic.3.0.golden.txt b/res/v3x/parsing/program/no_statement_separators_after_version/semantic.3.0.golden.txt index c67097953..38253ce8e 100644 --- a/res/v3x/parsing/program/no_statement_separators_after_version/semantic.3.0.golden.txt +++ b/res/v3x/parsing/program/no_statement_separators_after_version/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3.0 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/res/v3x/parsing/program/statement_separators_after_statements/ast.golden.txt b/res/v3x/parsing/program/statement_separators_after_statements/ast.golden.txt index 419622db1..95d6f21c5 100644 --- a/res/v3x/parsing/program/statement_separators_after_statements/ast.golden.txt +++ b/res/v3x/parsing/program/statement_separators_after_statements/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:2:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:2:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:3:1..2 + Gate( # input.cq:3:1..2 name: < Identifier( name: x ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/program/statement_separators_after_statements/semantic.3.0.golden.txt b/res/v3x/parsing/program/statement_separators_after_statements/semantic.3.0.golden.txt index 5eb2f69cd..e5bc7350b 100644 --- a/res/v3x/parsing/program/statement_separators_after_statements/semantic.3.0.golden.txt +++ b/res/v3x/parsing/program/statement_separators_after_statements/semantic.3.0.golden.txt @@ -6,33 +6,33 @@ Program( items: 3.0 ) > - statements: [ - Instruction( - instruction: x(qubit) - name: x - operands: [ - VariableRef( - variable --> < - Variable( - name: q - typ: < - Qubit( - size: 1 + block: < + Block( + statements: [ + Instruction( + instruction: x(qubit) + name: x + operands: [ + VariableRef( + variable --> < + Variable( + name: q + typ: < + Qubit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/program/statement_separators_before_eof/ast.golden.txt b/res/v3x/parsing/program/statement_separators_before_eof/ast.golden.txt index 986674ffd..9062b4184 100644 --- a/res/v3x/parsing/program/statement_separators_before_eof/ast.golden.txt +++ b/res/v3x/parsing/program/statement_separators_before_eof/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/program/statement_separators_before_eof/semantic.3.0.golden.txt b/res/v3x/parsing/program/statement_separators_before_eof/semantic.3.0.golden.txt index c67097953..38253ce8e 100644 --- a/res/v3x/parsing/program/statement_separators_before_eof/semantic.3.0.golden.txt +++ b/res/v3x/parsing/program/statement_separators_before_eof/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3.0 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/res/v3x/parsing/program/statement_separators_between_statements/ast.golden.txt b/res/v3x/parsing/program/statement_separators_between_statements/ast.golden.txt index 2e85ff665..626a6810d 100644 --- a/res/v3x/parsing/program/statement_separators_between_statements/ast.golden.txt +++ b/res/v3x/parsing/program/statement_separators_between_statements/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:2:7..8 name: < Identifier( @@ -15,20 +15,23 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:2:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) - Instruction( # input.cq:4:1..2 + Gate( # input.cq:4:1..2 name: < Identifier( name: x ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/program/statement_separators_between_statements/semantic.3.0.golden.txt b/res/v3x/parsing/program/statement_separators_between_statements/semantic.3.0.golden.txt index 5eb2f69cd..e5bc7350b 100644 --- a/res/v3x/parsing/program/statement_separators_between_statements/semantic.3.0.golden.txt +++ b/res/v3x/parsing/program/statement_separators_between_statements/semantic.3.0.golden.txt @@ -6,33 +6,33 @@ Program( items: 3.0 ) > - statements: [ - Instruction( - instruction: x(qubit) - name: x - operands: [ - VariableRef( - variable --> < - Variable( - name: q - typ: < - Qubit( - size: 1 + block: < + Block( + statements: [ + Instruction( + instruction: x(qubit) + name: x + operands: [ + VariableRef( + variable --> < + Variable( + name: q + typ: < + Qubit( + size: 1 + ) + > + annotations: [] ) > - annotations: [] ) - > + ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/qubit_array_definition/qubit_array_of_0_q/ast.golden.txt b/res/v3x/parsing/qubit_array_definition/qubit_array_of_0_q/ast.golden.txt index 768b84ae2..3e862d5b1 100644 --- a/res/v3x/parsing/qubit_array_definition/qubit_array_of_0_q/ast.golden.txt +++ b/res/v3x/parsing/qubit_array_definition/qubit_array_of_0_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 0 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 0 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/qubit_array_definition/qubit_array_of_0_q/semantic.3.0.golden.txt b/res/v3x/parsing/qubit_array_definition/qubit_array_of_0_q/semantic.3.0.golden.txt index 0272aa644..2addfdcf0 100644 --- a/res/v3x/parsing/qubit_array_definition/qubit_array_of_0_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/qubit_array_definition/qubit_array_of_0_q/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:10..11: declaring qubit array of size <= 0 +Error at input.cq:3:10..11: found qubit array of size <= 0 diff --git a/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q/ast.golden.txt b/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q/ast.golden.txt index 270d9249b..cb5d2eb5c 100644 --- a/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q/ast.golden.txt +++ b/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:11..12 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:3:1..10 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q/semantic.3.0.golden.txt b/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q/semantic.3.0.golden.txt index d35d9bd54..bd9c4e7d5 100644 --- a/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q__qubit_array_of_17_q/ast.golden.txt b/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q__qubit_array_of_17_q/ast.golden.txt index 6ccfcfe43..bf9c02152 100644 --- a/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q__qubit_array_of_17_q/ast.golden.txt +++ b/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q__qubit_array_of_17_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:11..12 name: < Identifier( @@ -15,13 +15,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:3:1..10 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] @@ -33,13 +37,17 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 17 + Type( # input.cq:4:1..10 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 17 + ) + > ) > annotations: [] diff --git a/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q__qubit_array_of_17_q/semantic.3.0.golden.txt b/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q__qubit_array_of_17_q/semantic.3.0.golden.txt index 45b231b63..89d3fa675 100644 --- a/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q__qubit_array_of_17_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/qubit_array_definition/qubit_array_of_17_q__qubit_array_of_17_q/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/qubit_definition/qqubit_q/ast.golden.txt b/res/v3x/parsing/qubit_definition/qqubit_q/ast.golden.txt index 8b175a599..33c35bdb3 100644 --- a/res/v3x/parsing/qubit_definition/qqubit_q/ast.golden.txt +++ b/res/v3x/parsing/qubit_definition/qqubit_q/ast.golden.txt @@ -5,16 +5,15 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ - Instruction( # input.cq:3:1..6 + block: < + GlobalBlock( + statements: [ + Gate( # input.cq:3:1..6 name: < Identifier( name: Qubit ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/qubit_definition/qqubit_q/semantic.3.0.golden.txt b/res/v3x/parsing/qubit_definition/qqubit_q/semantic.3.0.golden.txt index cff2186aa..643034f9a 100644 --- a/res/v3x/parsing/qubit_definition/qqubit_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/qubit_definition/qqubit_q/semantic.3.0.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..8: failed to resolve mapping 'q' +Error at input.cq:3:7..8: failed to resolve variable 'q' diff --git a/res/v3x/parsing/qubit_definition/qubit/ast.golden.txt b/res/v3x/parsing/qubit_definition/qubit/ast.golden.txt index 6034f8e53..c587c2ee3 100644 --- a/res/v3x/parsing/qubit_definition/qubit/ast.golden.txt +++ b/res/v3x/parsing/qubit_definition/qubit/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:6..7: mismatched input '\n' expecting {'[', IDENTIFIER} +Error at input.cq:3:6..7: missing IDENTIFIER at '\n' diff --git a/res/v3x/parsing/qubit_definition/qubit_1/ast.golden.txt b/res/v3x/parsing/qubit_definition/qubit_1/ast.golden.txt index b62134a23..581902b6c 100644 --- a/res/v3x/parsing/qubit_definition/qubit_1/ast.golden.txt +++ b/res/v3x/parsing/qubit_definition/qubit_1/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..8: mismatched input '1' expecting {'[', IDENTIFIER} +Error at input.cq:3:7..8: mismatched input '1' expecting IDENTIFIER diff --git a/res/v3x/parsing/qubit_definition/qubit_123abc/ast.golden.txt b/res/v3x/parsing/qubit_definition/qubit_123abc/ast.golden.txt index 716cc6c75..ecead5df2 100644 --- a/res/v3x/parsing/qubit_definition/qubit_123abc/ast.golden.txt +++ b/res/v3x/parsing/qubit_definition/qubit_123abc/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..10: extraneous input '123' expecting {'[', IDENTIFIER} +Error at input.cq:3:7..10: extraneous input '123' expecting IDENTIFIER diff --git a/res/v3x/parsing/qubit_definition/qubit_equal/ast.golden.txt b/res/v3x/parsing/qubit_definition/qubit_equal/ast.golden.txt index a4c0560c1..997a4f267 100644 --- a/res/v3x/parsing/qubit_definition/qubit_equal/ast.golden.txt +++ b/res/v3x/parsing/qubit_definition/qubit_equal/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:3:7..8: mismatched input '=' expecting {'[', IDENTIFIER} +Error at input.cq:3:7..8: mismatched input '=' expecting IDENTIFIER diff --git a/res/v3x/parsing/qubit_definition/qubit_q/ast.golden.txt b/res/v3x/parsing/qubit_definition/qubit_q/ast.golden.txt index ce938a805..2dc90a8b3 100644 --- a/res/v3x/parsing/qubit_definition/qubit_q/ast.golden.txt +++ b/res/v3x/parsing/qubit_definition/qubit_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/qubit_definition/qubit_q/semantic.3.0.golden.txt b/res/v3x/parsing/qubit_definition/qubit_q/semantic.3.0.golden.txt index e93ebf2b0..c51d6a845 100644 --- a/res/v3x/parsing/qubit_definition/qubit_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/qubit_definition/qubit_q/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/qubit_definition/qubit_q__qubit_q/ast.golden.txt b/res/v3x/parsing/qubit_definition/qubit_q__qubit_q/ast.golden.txt index 5314950f8..94ac15dad 100644 --- a/res/v3x/parsing/qubit_definition/qubit_q__qubit_q/ast.golden.txt +++ b/res/v3x/parsing/qubit_definition/qubit_q__qubit_q/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:7..8 name: < Identifier( @@ -15,11 +15,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:3:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) Variable( # input.cq:4:7..8 @@ -29,11 +33,15 @@ Program( ) > typ: < - Keyword( - name: qubit + Type( # input.cq:4:1..6 + name: < + Keyword( + name: qubit + ) + > + size: - ) > - size: - annotations: [] ) ] diff --git a/res/v3x/parsing/qubit_definition/qubit_q__qubit_q/semantic.3.0.golden.txt b/res/v3x/parsing/qubit_definition/qubit_q__qubit_q/semantic.3.0.golden.txt index 81246bebc..7a18a6aee 100644 --- a/res/v3x/parsing/qubit_definition/qubit_q__qubit_q/semantic.3.0.golden.txt +++ b/res/v3x/parsing/qubit_definition/qubit_q__qubit_q/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.actual.json b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.actual.json index 590f1ce97..23bb0eadc 100644 --- a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.actual.json +++ b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.actual.json @@ -1 +1 @@ -{"Program":{"version":{"Version":{"items":"3","source_location":"input.cq:1:9..10"}},"statements":{"StatementList":{"items":[{"Variable":{"name":{"Identifier":{"name":"q"}},"typ":{"Keyword":{"name":"qubit"}},"size":{"IntegerLiteral":{"value":"4"}},"annotations":"[]","source_location":"input.cq:3:10..11"}},{"Instruction":{"name":{"Identifier":{"name":"cnot"}},"condition":"-","operands":{"ExpressionList":{"items":[{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexItem":{"index":{"IntegerLiteral":{"value":"0","source_location":"input.cq:5:8..9"}}}},{"IndexItem":{"index":{"IntegerLiteral":{"value":"1","source_location":"input.cq:5:11..12"}}}}]}},"source_location":"input.cq:5:6..7"}},{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexItem":{"index":{"IntegerLiteral":{"value":"3","source_location":"input.cq:5:17..18"}}}},{"IndexItem":{"index":{"IntegerLiteral":{"value":"2","source_location":"input.cq:5:20..21"}}}}]}},"source_location":"input.cq:5:15..16"}}]}},"annotations":"[]","source_location":"input.cq:5:1..5"}}]}}}} \ No newline at end of file +{"Program":{"version":{"Version":{"items":"3","source_location":"input.cq:1:9..10"}},"statements":{"StatementList":{"items":[{"Variable":{"name":{"Identifier":{"name":"q"}},"typ":{"Type":{"name":{"Keyword":{"name":"qubit"}},"size":{"IntegerLiteral":{"value":"4"}}}},"annotations":"[]","source_location":"input.cq:3:10..11"}},{"Gate":{"name":{"Identifier":{"name":"cnot"}},"condition":"-","operands":{"ExpressionList":{"items":[{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexItem":{"index":{"IntegerLiteral":{"value":"0","source_location":"input.cq:5:8..9"}}}},{"IndexItem":{"index":{"IntegerLiteral":{"value":"1","source_location":"input.cq:5:11..12"}}}}]}},"source_location":"input.cq:5:6..7"}},{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexItem":{"index":{"IntegerLiteral":{"value":"3","source_location":"input.cq:5:17..18"}}}},{"IndexItem":{"index":{"IntegerLiteral":{"value":"2","source_location":"input.cq:5:20..21"}}}}]}},"source_location":"input.cq:5:15..16"}}]}},"annotations":"[]","source_location":"input.cq:5:1..5"}}]}}}} \ No newline at end of file diff --git a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.actual.txt b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.actual.txt index 669c543b8..47b0eaff9 100644 --- a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.actual.txt +++ b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.actual.txt @@ -15,18 +15,22 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 4 + Type( + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 4 + ) + > ) > annotations: [] ) - Instruction( # input.cq:5:1..5 + Gate( # input.cq:5:1..5 name: < Identifier( name: cnot diff --git a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.golden.json b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.golden.json index 590f1ce97..e5981fc93 100644 --- a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.golden.json +++ b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.golden.json @@ -1 +1 @@ -{"Program":{"version":{"Version":{"items":"3","source_location":"input.cq:1:9..10"}},"statements":{"StatementList":{"items":[{"Variable":{"name":{"Identifier":{"name":"q"}},"typ":{"Keyword":{"name":"qubit"}},"size":{"IntegerLiteral":{"value":"4"}},"annotations":"[]","source_location":"input.cq:3:10..11"}},{"Instruction":{"name":{"Identifier":{"name":"cnot"}},"condition":"-","operands":{"ExpressionList":{"items":[{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexItem":{"index":{"IntegerLiteral":{"value":"0","source_location":"input.cq:5:8..9"}}}},{"IndexItem":{"index":{"IntegerLiteral":{"value":"1","source_location":"input.cq:5:11..12"}}}}]}},"source_location":"input.cq:5:6..7"}},{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexItem":{"index":{"IntegerLiteral":{"value":"3","source_location":"input.cq:5:17..18"}}}},{"IndexItem":{"index":{"IntegerLiteral":{"value":"2","source_location":"input.cq:5:20..21"}}}}]}},"source_location":"input.cq:5:15..16"}}]}},"annotations":"[]","source_location":"input.cq:5:1..5"}}]}}}} \ No newline at end of file +{"Program":{"version":{"Version":{"items":"3","source_location":"input.cq:1:9..10"}},"block":{"GlobalBlock":{"statements":[{"Variable":{"name":{"Identifier":{"name":"q"}},"typ":{"Type":{"name":{"Keyword":{"name":"qubit"}},"size":{"IntegerLiteral":{"value":"4"}},"source_location":"input.cq:3:1..9"}},"annotations":"[]","source_location":"input.cq:3:10..11"}},{"Gate":{"name":{"Identifier":{"name":"cnot"}},"operands":{"ExpressionList":{"items":[{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexItem":{"index":{"IntegerLiteral":{"value":"0","source_location":"input.cq:5:8..9"}}}},{"IndexItem":{"index":{"IntegerLiteral":{"value":"1","source_location":"input.cq:5:11..12"}}}}]}},"source_location":"input.cq:5:6..7"}},{"Index":{"expr":{"Identifier":{"name":"q"}},"indices":{"IndexList":{"items":[{"IndexItem":{"index":{"IntegerLiteral":{"value":"3","source_location":"input.cq:5:17..18"}}}},{"IndexItem":{"index":{"IntegerLiteral":{"value":"2","source_location":"input.cq:5:20..21"}}}}]}},"source_location":"input.cq:5:15..16"}}]}},"annotations":"[]","source_location":"input.cq:5:1..5"}}]}}}} \ No newline at end of file diff --git a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.golden.txt b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.golden.txt index 669c543b8..0014f658e 100644 --- a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.golden.txt +++ b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [ + block: < + GlobalBlock( + statements: [ Variable( # input.cq:3:10..11 name: < Identifier( @@ -15,24 +15,27 @@ Program( ) > typ: < - Keyword( - name: qubit - ) - > - size: < - IntegerLiteral( - value: 4 + Type( # input.cq:3:1..9 + name: < + Keyword( + name: qubit + ) + > + size: < + IntegerLiteral( + value: 4 + ) + > ) > annotations: [] ) - Instruction( # input.cq:5:1..5 + Gate( # input.cq:5:1..5 name: < Identifier( name: cnot ) > - condition: - operands: < ExpressionList( items: [ diff --git a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/semantic.3.0.golden.json b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/semantic.3.0.golden.json index 41fafc05c..f265e87d7 100644 --- a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/semantic.3.0.golden.json +++ b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/semantic.3.0.golden.json @@ -1 +1 @@ -{"Program":{"api_version":"3.0","version":{"Version":{"items":"3"}},"statements":[{"Instruction":{"instruction":"cnot(qubit array, qubit array)","name":"cnot","operands":[{"IndexRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"4"}},"annotations":"[]"}},"indices":[{"ConstInt":{"value":"0"}},{"ConstInt":{"value":"1"}}]}},{"IndexRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"4"}},"annotations":"[]"}},"indices":[{"ConstInt":{"value":"3"}},{"ConstInt":{"value":"2"}}]}}],"condition":{"ConstBool":{"value":"1"}},"annotations":"[]"}}],"variables":[{"Variable":{"name":"q","typ":{"QubitArray":{"size":"4"}},"annotations":"[]"}}]}} \ No newline at end of file +{"Program":{"api_version":"3.0","version":{"Version":{"items":"3"}},"block":{"Block":{"statements":[{"Instruction":{"instruction":"cnot(qubit array, qubit array)","name":"cnot","operands":[{"IndexRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"4"}},"annotations":"[]"}},"indices":[{"ConstInt":{"value":"0"}},{"ConstInt":{"value":"1"}}]}},{"IndexRef":{"variable":{"Variable":{"name":"q","typ":{"QubitArray":{"size":"4"}},"annotations":"[]"}},"indices":[{"ConstInt":{"value":"3"}},{"ConstInt":{"value":"2"}}]}}],"annotations":"[]"}}]}},"functions":"[]","variables":[{"Variable":{"name":"q","typ":{"QubitArray":{"size":"4"}},"annotations":"[]"}}]}} \ No newline at end of file diff --git a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/semantic.3.0.golden.txt b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/semantic.3.0.golden.txt index e90ad8485..3c7b6124f 100644 --- a/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/semantic.3.0.golden.txt +++ b/res/v3x/parsing/sgmq/cnot_q_0_1_q_3_2/semantic.3.0.golden.txt @@ -6,62 +6,62 @@ Program( items: 3 ) > - statements: [ - Instruction( - instruction: cnot(qubit array, qubit array) - name: cnot - operands: [ - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 4 + block: < + Block( + statements: [ + Instruction( + instruction: cnot(qubit array, qubit array) + name: cnot + operands: [ + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 4 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 0 - ) - ConstInt( - value: 1 + indices: [ + ConstInt( + value: 0 + ) + ConstInt( + value: 1 + ) + ] ) - ] - ) - IndexRef( - variable --> < - Variable( - name: q - typ: < - QubitArray( - size: 4 + IndexRef( + variable --> < + Variable( + name: q + typ: < + QubitArray( + size: 4 + ) + > + annotations: [] ) > - annotations: [] - ) - > - indices: [ - ConstInt( - value: 3 - ) - ConstInt( - value: 2 + indices: [ + ConstInt( + value: 3 + ) + ConstInt( + value: 2 + ) + ] ) ] + annotations: [] ) ] - condition: < - ConstBool( - value: 1 - ) - > - annotations: [] ) - ] + > + functions: [] variables: [ Variable( name: q diff --git a/res/v3x/parsing/version/version_3/ast.golden.txt b/res/v3x/parsing/version/version_3/ast.golden.txt index 01c61033a..fb5958a39 100644 --- a/res/v3x/parsing/version/version_3/ast.golden.txt +++ b/res/v3x/parsing/version/version_3/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/version/version_3/semantic.3.0.golden.txt b/res/v3x/parsing/version/version_3/semantic.3.0.golden.txt index 109d4fdee..6e3f392cd 100644 --- a/res/v3x/parsing/version/version_3/semantic.3.0.golden.txt +++ b/res/v3x/parsing/version/version_3/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/res/v3x/parsing/version/version_30_dot_20/ast.golden.txt b/res/v3x/parsing/version/version_30_dot_20/ast.golden.txt index de6845910..b317b9c17 100644 --- a/res/v3x/parsing/version/version_30_dot_20/ast.golden.txt +++ b/res/v3x/parsing/version/version_30_dot_20/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 30.20 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/version/version_3__version_3__qubit_q/ast.golden.txt b/res/v3x/parsing/version/version_3__version_3__qubit_q/ast.golden.txt index e7ea844fa..bb6e74308 100644 --- a/res/v3x/parsing/version/version_3__version_3__qubit_q/ast.golden.txt +++ b/res/v3x/parsing/version/version_3__version_3__qubit_q/ast.golden.txt @@ -1,2 +1,2 @@ ERROR -Error at input.cq:2:1..8: extraneous input 'version' expecting {, NEW_LINE, ';'} +Error at input.cq:2:1..8: no viable alternative at input '\nversion' diff --git a/res/v3x/parsing/version/version_3_dot_0/ast.golden.txt b/res/v3x/parsing/version/version_3_dot_0/ast.golden.txt index 986674ffd..9062b4184 100644 --- a/res/v3x/parsing/version/version_3_dot_0/ast.golden.txt +++ b/res/v3x/parsing/version/version_3_dot_0/ast.golden.txt @@ -5,9 +5,9 @@ Program( items: 3.0 ) > - statements: < - StatementList( - items: [] + block: < + GlobalBlock( + statements: [] ) > ) diff --git a/res/v3x/parsing/version/version_3_dot_0/semantic.3.0.golden.txt b/res/v3x/parsing/version/version_3_dot_0/semantic.3.0.golden.txt index c67097953..38253ce8e 100644 --- a/res/v3x/parsing/version/version_3_dot_0/semantic.3.0.golden.txt +++ b/res/v3x/parsing/version/version_3_dot_0/semantic.3.0.golden.txt @@ -6,7 +6,12 @@ Program( items: 3.0 ) > - statements: [] + block: < + Block( + statements: [] + ) + > + functions: [] variables: [] ) diff --git a/src/cqasm-annotations.cpp b/src/cqasm-annotations.cpp index 9b287d2bf..95e4ef7e2 100644 --- a/src/cqasm-annotations.cpp +++ b/src/cqasm-annotations.cpp @@ -5,53 +5,34 @@ #include "cqasm-annotations.hpp" #include "cqasm-annotations-constants.hpp" +#include // min, max #include namespace cqasm::annotations { +SourceLocation::Range::Range(const Index &f, const Index &l) +: first{ f } , last{ l } { + last = std::max(last, first); +} + /** * Constructs a source location object. */ -SourceLocation::SourceLocation( - const std::optional &file_name_, - std::uint32_t first_line_, - std::uint32_t first_column_, - std::uint32_t last_line_, - std::uint32_t last_column_) +SourceLocation::SourceLocation(const std::optional &file_name_, const Range &range_) : file_name{ file_name_ } -, first_line{ first_line_ } -, first_column{ first_column_ } -, last_line{ last_line_ } -, last_column{ last_column_ } { - +, range{ range_ } { if (file_name.has_value() && file_name.value().empty()) { file_name = std::nullopt; } - if (last_line < first_line) { - last_line = first_line; - } - if (last_line == first_line && last_column < first_column) { - last_column = first_column; - } } /** * Expands the location range to contain the given location in the source file. */ -void SourceLocation::expand_to_include(std::uint32_t line, std::uint32_t column) { - if (line < first_line) { - first_line = line; - } - if (line == first_line && column < first_column) { - first_column = column; - } - if (line > last_line) { - last_line = line; - } - if (line == last_line && column > last_column) { - last_column = column; - } +void SourceLocation::expand_to_include(const Index &index) { + range.first = std::min(range.first, index); + range.last = std::max(range.last, index); } /** @@ -62,33 +43,33 @@ std::ostream &operator<<(std::ostream &os, const SourceLocation &object) { os << object.file_name.value_or(unknown_file_name); // Special case for when only the source file name is known. - if (!object.first_line) { + if (!object.range.first.line) { return os; } // Print line number. - os << ":" << object.first_line; + os << ":" << object.range.first.line; // Special case for when only line numbers are known. - if (!object.first_column) { + if (!object.range.first.column) { // Print last line too, if greater. - if (object.last_line > object.first_line) { - os << ".." << object.last_line; + if (object.range.last.line > object.range.first.line) { + os << ".." << object.range.last.line; } return os; } // Print column. - os << ":" << object.first_column; + os << ":" << object.range.first.column; - if (object.last_line == object.first_line) { + if (object.range.last.line == object.range.first.line) { // Range is on a single line. Only repeat the column number. - if (object.last_column > object.first_column) { - os << ".." << object.last_column; + if (object.range.last.column > object.range.first.column) { + os << ".." << object.range.last.column; } - } else if (object.last_line > object.first_line) { + } else if (object.range.last.line > object.range.first.line) { // Range is on multiple lines. Repeat both line and column number. - os << ".." << object.last_line << ":" << object.last_column; + os << ".." << object.range.last.line << ":" << object.range.last.column; } return os; diff --git a/src/cqasm-error.cpp b/src/cqasm-error.cpp index f151a0344..6b0d006db 100644 --- a/src/cqasm-error.cpp +++ b/src/cqasm-error.cpp @@ -38,18 +38,10 @@ Error::Error(const std::string &message, std::shared_ptr &file_name, - std::uint32_t first_line, - std::uint32_t first_column, - std::uint32_t last_line, - std::uint32_t last_column) + const annotations::SourceLocation::Range &range) : std::runtime_error{ !message.empty() ? message.c_str() : unknown_error_message } , message_{ !message.empty() ? message : unknown_error_message } -, location_{ std::make_shared( - file_name, - first_line, - first_column, - last_line, - last_column) } +, location_{ std::make_shared(file_name, range) } {} /** @@ -128,10 +120,10 @@ std::string Error::to_json() const { R"(,"severity":{5})" R"({6})" R"(}})", - location_ ? location_->first_line : 0, - location_ ? location_->first_column : 0, - location_ ? location_->last_line : 0, - location_ ? location_->last_column : 0, + location_ ? location_->range.first.line : 0, + location_ ? location_->range.first.column : 0, + location_ ? location_->range.last.line : 0, + location_ ? location_->range.last.column : 0, cqasm::utils::json_encode(message_), 1, related_information diff --git a/src/cqasm-version-parser.y b/src/cqasm-version-parser.y index 13b8a1314..3515459be 100644 --- a/src/cqasm-version-parser.y +++ b/src/cqasm-version-parser.y @@ -11,6 +11,7 @@ #include #include #include + #include "cqasm-annotations.hpp" #include "cqasm-error.hpp" #include "cqasm-version.hpp" using namespace cqasm::version; @@ -67,9 +68,7 @@ void yyerror(YYLTYPE* yyllocp, yyscan_t unused, const std::string &file_name, cq throw cqasm::error::ParseError( std::string(msg), file_name, - yyllocp->first_line, - yyllocp->first_column, - yyllocp->last_line, - yyllocp->last_column + { { static_cast(yyllocp->first_line), static_cast(yyllocp->first_column) }, + { static_cast(yyllocp->last_line), static_cast(yyllocp->last_column) } } ); } diff --git a/src/v1x/CMakeLists.txt b/src/v1x/CMakeLists.txt index 5afd443fd..38aa1adb0 100644 --- a/src/v1x/CMakeLists.txt +++ b/src/v1x/CMakeLists.txt @@ -2,6 +2,7 @@ set(CQASM_V1X_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-analysis-result.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-analyzer.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-analyzer-helper.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-error-model.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-functions.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-instruction.cpp" @@ -10,6 +11,7 @@ set(CQASM_V1X_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-primitives.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-py.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-resolver.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-scope.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-types.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-values.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm.cpp" diff --git a/src/v1x/cqasm-analyzer-helper.cpp b/src/v1x/cqasm-analyzer-helper.cpp new file mode 100644 index 000000000..af3c59f1a --- /dev/null +++ b/src/v1x/cqasm-analyzer-helper.cpp @@ -0,0 +1,1445 @@ +#include "cqasm-utils.hpp" +#include "v1x/cqasm-analyzer-helper.hpp" +#include "v1x/cqasm-values.hpp" + +#include +#include +#include + + +namespace cqasm::v1x::analyzer { + +/** + * Analyzes the given AST using the given analyzer. + */ +AnalyzerHelper::AnalyzerHelper(const Analyzer &analyzer, const ast::Program &ast) +: analyzer(analyzer) +, result() +, scope_stack( { Scope(analyzer.mappings, analyzer.functions, analyzer.instruction_set) } ) +{ + try { + // Construct the program node. + result.root.set(tree::make()); + result.root->copy_annotation(ast); + result.root->api_version = analyzer.api_version; + + // Check and set the version. + analyze_version(*ast.version); + + // Handle the qubits statement. + // Qubit variables can be used instead of the qubits keyword, + // in which case num_qubits is set to 0 to indicate that it's not being used. + if (!ast.num_qubits.empty()) { + analyze_qubits(*ast.num_qubits); + } else if (ast.version->items < "1.1") { + throw error::AnalysisError{ "missing qubits statement (required until version 1.1)" }; + } else { + result.root->num_qubits = 0; + } + + // Read the statements. + analyze_statements(*ast.statements); + + // Resolve goto targets. + if (ast.version->items >= "1.2") { + + // Figure out all the subcircuit names and check for duplicates. + std::map> subcircuits; + for (const auto &subcircuit : result.root->subcircuits) { + try { + auto insert_result = subcircuits.insert({subcircuit->name, subcircuit}); + if (!insert_result.second) { + std::ostringstream ss; + ss << "duplicate subcircuit name \"" << subcircuit->name << "\""; + if (auto loc = insert_result.first->second->get_annotation_ptr()) { + ss << "; previous definition was at " << *loc; + } + throw error::AnalysisError{ ss.str() }; + } + } catch (error::AnalysisError &err) { + err.context(*subcircuit); + result.errors.push_back(std::move(err)); + } + } + + // Resolve the goto instruction targets. + for (const auto &it : gotos) { + try { + auto it2 = subcircuits.find(it.second); + if (it2 == subcircuits.end()) { + throw error::AnalysisError{ + fmt::format("failed to resolve subcircuit \"{}\"", it.second) }; + } + it.first->target = it2->second; + } catch (error::AnalysisError &err) { + err.context(*it.first); + result.errors.push_back(std::move(err)); + } + } + + } + + // Save the list of final mappings. + for (const auto &it : get_current_scope().mappings.get_table()) { + const auto &name = it.first; + const auto &value = it.second.first; + const auto &ast_node = it.second.second; + + // Ignore predefined and implicit mappings. + if (ast_node.empty()) { + continue; + } + + // Analyze any annotations attached to the mapping. + auto annotations = analyze_annotations(ast_node->annotations); + + // Construct the mapping object and copy the source location. + auto mapping = tree::make( + name, value, + analyze_annotations(ast_node->annotations) + ); + mapping->copy_annotation(*ast_node); + result.root->mappings.add(mapping); + + } + + // The iteration order over the mapping table is undefined, + // because it's backed by an unordered_map. + // To get a deterministic tree, sort by source location. + std::sort( + result.root->mappings.begin(), result.root->mappings.end(), + [](const tree::One &lhs, const tree::One &rhs) -> bool { + auto lhs_source_location = lhs->get_annotation_ptr(); + auto rhs_source_location = rhs->get_annotation_ptr(); + return lhs_source_location && rhs_source_location && *lhs_source_location < *rhs_source_location; + }); + + } catch (error::AnalysisError &err) { + result.errors.push_back(std::move(err)); + } +} + +/** + * Checks the AST version node and puts it into the semantic tree. + */ +void AnalyzerHelper::analyze_version(const ast::Version &ast) { + try { + // Default to API version in case the version in the AST is broken. + result.root->version = tree::make(); + result.root->version->items = analyzer.api_version; + + // Check API version. + for (const auto &item : ast.items) { + if (item < 0) { + throw error::AnalysisError{ "invalid version component" }; + } + } + if (ast.items > analyzer.api_version) { + throw error::AnalysisError{ fmt::format( + "the maximum cQASM version supported is {}, but the cQASM file is version {}", + analyzer.api_version, ast.items) }; + } + + // Save the file version. + result.root->version->items = ast.items; + + } catch (error::AnalysisError &err) { + err.context(ast); + result.errors.push_back(std::move(err)); + } + result.root->version->copy_annotation(ast); +} + +/** + * Checks the qubits statement and updates the scope accordingly. + * Any semantic errors encountered are pushed into the result error vector. + */ +void AnalyzerHelper::analyze_qubits(const ast::Expression &count) { + try { + // Default to 0 qubits in case we get an exception or no qubit count is defined. + result.root->num_qubits = 0; + + // Try to load the number of qubits from the expression. + result.root->num_qubits = analyze_as_const_int(count); + if (result.root->num_qubits < 1) { + // Number of qubits must be positive if specified. + throw error::AnalysisError{ "invalid number of qubits" }; + } + + // Construct the special q and b mappings, that map to the whole qubit and measurement register respectively. + tree::Many all_qubits; + for (primitives::Int i = 0; i < result.root->num_qubits; i++) { + auto vi = tree::make(i); + vi->copy_annotation(count); + all_qubits.add(vi); + } + get_current_scope().mappings.add("q", tree::make(all_qubits)); + get_current_scope().mappings.add("b", tree::make(all_qubits)); + + } catch (error::AnalysisError &err) { + err.context(count); + result.errors.push_back(std::move(err)); + } +} + +/** + * Returns a reference to the subcircuit that's currently being built. + * If there is no subcircuit yet, a default one is created, + * using the source location annotation on the source node. + */ +tree::Maybe AnalyzerHelper::get_current_subcircuit(const tree::Annotatable &source) { + // If we don't have a subcircuit yet, add a default one. + // Note that the original libqasm always had this default subcircuit (even if it was empty) + // and used the name "default" vs. the otherwise invalid empty string. + if (result.root->subcircuits.empty()) { + auto subcircuit_node = tree::make("", 1); + subcircuit_node->copy_annotation(source); + if (analyzer.api_version >= "1.2") { + subcircuit_node->body = tree::make(); + } + result.root->subcircuits.add(subcircuit_node); + } + + // Add the node to the last subcircuit. + return result.root->subcircuits.back(); +} + +/** + * Returns a reference to the current scope. + */ +Scope &AnalyzerHelper::get_current_scope() { + return scope_stack.back(); +} + +/** + * Returns a reference to the global scope. + */ +Scope &AnalyzerHelper::get_global_scope() { + return scope_stack.front(); +} + +/** + * Returns a reference to the block that's currently being built. + */ +tree::Maybe AnalyzerHelper::get_current_block( + const tree::Annotatable &source +) { + // If we're in a local scope/block, return that block. + const auto &scope = get_current_scope(); + if (!scope.block.empty()) { + return scope.block; + } + + // Otherwise return the block belonging to the current subcircuit. + return get_current_subcircuit(source)->body; +} + +/** + * Adds an analyzed statement to the current block (1.2+). + */ +void AnalyzerHelper::add_to_current_block(const tree::Maybe &statement) { + // Add the statement to the current block. + auto block = get_current_block(*statement); + block->statements.add(statement); + + // Expand the source location annotation of the block to include the statement. + if (auto statement_loc = statement->get_annotation_ptr()) { + if (auto block_loc = block->get_annotation_ptr()) { + block_loc->expand_to_include(statement_loc->range.first); + block_loc->expand_to_include(statement_loc->range.last); + } else { + block->set_annotation(*statement_loc); + } + } +} + +/** + * Analyzes the given statement list, + * adding the analyzed statements to the current subcircuit (API 1.0/1.1) or block (API 1.2+). + */ +void AnalyzerHelper::analyze_statements(const ast::StatementList &statements) { + for (const auto &statement : statements.items) { + try { + if (auto bundle = statement->as_bundle()) { + if (analyzer.api_version >= "1.2") { + analyze_bundle_ext(*bundle); + } else { + analyze_bundle(*bundle); + } + } else if (auto mapping = statement->as_mapping()) { + analyze_mapping(*mapping); + } else if (auto variables = statement->as_variables()) { + analyze_variables(*variables); + } else if (auto subcircuit = statement->as_subcircuit()) { + analyze_subcircuit(*subcircuit); + } else if (auto structured = statement->as_structured()) { + if (result.root->version->items < "1.2") { + throw error::AnalysisError{ "structured control-flow is not supported (need version 1.2+)" }; + } + analyze_structured(*structured); + } else { + throw std::runtime_error("unexpected statement node"); + } + } catch (error::AnalysisError &err) { + err.context(*statement); + result.errors.push_back(std::move(err)); + } + } +} + +/** + * Analyzes a statement list corresponding to a structured control-flow subblock (1.2+). + * Handles the requisite scoping, then defers to analyze_statements(). + */ +tree::Maybe AnalyzerHelper::analyze_subblock( + const ast::StatementList &statements, + bool is_loop +) { + // Create the block. + tree::Maybe block; + block.emplace(); + + // Create a scope for the block. + scope_stack.emplace_back(get_current_scope()); + get_current_scope().block = block; + get_current_scope().within_loop |= is_loop; + + // Analyze the statements within the block. + // The statements will be added to the current scope, which we just updated. + analyze_statements(statements); + + // Pop the scope from the stack. + scope_stack.pop_back(); + + return block; +} + +/** + * Analyzes the given bundle and, if valid, adds it to the current subcircuit using API version 1.0/1.1. + * If an error occurs, the message is added to the result error vector, and nothing is added to the subcircuit. + */ +void AnalyzerHelper::analyze_bundle(const ast::Bundle &bundle) { + try { + // The error model statement from the original cQASM grammar is a bit of a pain, + // because it conflicts with gates/instructions, so we have to special-case it here. + // Technically we could also have made it a keyword, + // but the less random keywords there are, the better. + if (bundle.items.size() == 1) { + if (utils::equal_case_insensitive(bundle.items[0]->name->name, "error_model")) { + analyze_error_model(*bundle.items[0]); + return; + } + } + + // Analyze and add the instructions. + auto node = tree::make(); + for (const auto &insn : bundle.items) { + node->items.add(analyze_instruction(*insn)); + } + + // If we have more than two instructions, ensure that all instructions are parallelizable. + if (node->items.size() > 1) { + for (const auto &insn : node->items) { + try { + if (!insn->instruction.empty()) { + if (!insn->instruction->allow_parallel) { + std::ostringstream ss; + ss << "instruction "; + ss << insn->instruction->name; + ss << " with parameter pack "; + ss << insn->instruction->param_types; + ss << " is not parallelizable, but is bundled with "; + ss << (node->items.size() - 1); + ss << " other instruction"; + if (node->items.size() != 2) { + ss << "s"; + } + throw error::AnalysisError{ ss.str() }; + } + } + } catch (error::AnalysisError &err) { + err.context(*insn); + result.errors.push_back(std::move(err)); + } + } + } + + // It's possible that no instructions end up being added, + // due to all condition codes resolving to constant false. + // In that case the entire bundle is removed. + if (node->items.empty()) { + return; + } + + // Copy annotation data. + node->annotations = analyze_annotations(bundle.annotations); + node->copy_annotation(bundle); + + // Add the node to the last subcircuit. + get_current_subcircuit(bundle)->bundles.add(node); + + } catch (error::AnalysisError &err) { + err.context(bundle); + result.errors.push_back(std::move(err)); + } +} + +/** + * Analyzes the given bundle and, if valid, adds it to the current + * subcircuit using API version 1.2+. If an error occurs, the message is + * added to the result error vector, and nothing is added to the subcircuit. + */ +void AnalyzerHelper::analyze_bundle_ext(const ast::Bundle &bundle) { + try { + // The error model statement from the original cQASM grammar is a bit of a pain, + // because it conflicts with gates/instructions, so we have to special-case it here. + // Technically we could also have made it a keyword, + // but the less random keywords there are, the better. + if (bundle.items.size() == 1) { + if (utils::equal_case_insensitive(bundle.items[0]->name->name, "error_model")) { + analyze_error_model(*bundle.items[0]); + return; + } + } + + // Analyze and add the instructions + auto node = tree::make(); + for (const auto &insn : bundle.items) { + if (utils::equal_case_insensitive(insn->name->name, "set")) { + node->items.add(analyze_set_instruction(*insn)); + } else if (utils::equal_case_insensitive(insn->name->name, "goto")) { + node->items.add(analyze_goto_instruction(*insn)); + } else { + node->items.add(analyze_instruction(*insn)); + } + } + + // If we have more than two instructions, ensure that all instructions can be executed in parallel + if (node->items.size() > 1) { + for (const auto &insn_base : node->items) { + try { + if (auto insn = insn_base->as_instruction()) { + if (!insn->instruction.empty()) { + if (!insn->instruction->allow_parallel) { + std::ostringstream ss; + ss << "instruction "; + ss << insn->instruction->name; + ss << " with parameter pack "; + ss << insn->instruction->param_types; + ss << " is not parallelizable, but is bundled with "; + ss << (node->items.size() - 1); + ss << " other instruction"; + if (node->items.size() != 2) { + ss << "s"; + } + throw error::AnalysisError{ ss.str() }; + } + } + } + } catch (error::AnalysisError &err) { + err.context(*insn_base); + result.errors.push_back(std::move(err)); + } + } + } + + // It's possible that no instructions end up being added, + // due to all condition codes resolving to constant false. + // In that case the entire bundle is removed. + if (node->items.empty()) { + return; + } + + // Copy annotation data. + node->annotations = analyze_annotations(bundle.annotations); + node->copy_annotation(bundle); + + // Add the node to the last subcircuit. + add_to_current_block(node.as()); + + } catch (error::AnalysisError &err) { + err.context(bundle); + result.errors.push_back(std::move(err)); + } +} + +/** + * Analyzes the given instruction. + * If an error occurs, the message is added to the result error vector, and an empty Maybe is returned. + * It's also possible that an empty Maybe is returned without an error, + * when the condition code statically resolves to false. + */ +tree::Maybe AnalyzerHelper::analyze_instruction(const ast::Instruction &insn) { + try { + // Figure out the operand list. + auto operands = values::Values(); + for (const auto &operand_expr : insn.operands->items) { + operands.add(analyze_expression(*operand_expr)); + } + + // Resolve the instruction and/or make the instruction node. + tree::Maybe node; + if (analyzer.resolve_instructions) { + node.set(get_current_scope().instruction_set.resolve(insn.name->name, operands)); + } else { + node.set(tree::make( + tree::Maybe(), + insn.name->name, values::Value(), operands, + tree::Any())); + } + + // Resolve the condition code. + if (!insn.condition.empty()) { + if (!node->instruction.empty() && !node->instruction->allow_conditional) { + throw error::AnalysisError{ + "conditional execution is not supported for this instruction" }; + } + auto condition_val = analyze_expression(*insn.condition); + node->condition = values::promote(condition_val, tree::make()); + if (node->condition.empty()) { + throw error::AnalysisError{ "condition must be a boolean" }; + } + + // If the condition is constant false, optimize the instruction + // away. + if (auto x = node->condition->as_const_bool()) { + if (!x->value) { + return {}; + } + } + + } else { + node->condition.set(tree::make(true)); + } + + // Enforce qubit uniqueness if the instruction requires us to. + if (!node->instruction.empty() && !node->instruction->allow_reused_qubits) { + std::unordered_set qubits_used; + for (const auto &operand : operands) { + if (auto x = operand->as_qubit_refs()) { + for (const auto &index : x->index) { + if (!qubits_used.insert(index->value).second) { + throw error::AnalysisError{ + fmt::format("qubit with index {} is used more than once", index->value) }; + } + } + } + } + } + + // Enforce that all qubit and bit references have the same length if + // the instruction requires us to. Note that historically the condition + // is NOT split across the resulting parallel instructions but is + // instead copied and reduced using boolean and at runtime, so its + // length does NOT have to match. + if (!node->instruction.empty() && !node->instruction->allow_different_index_sizes) { + size_t num_refs = 0; + const parser::SourceLocation *num_refs_loc = nullptr; + for (const auto &operand : operands) { + const tree::Many *indices = nullptr; + if (auto qr = operand->as_qubit_refs()) { + indices = &qr->index; + } else if (auto br = operand->as_bit_refs()) { + indices = &br->index; + } + if (indices) { + if (!num_refs) { + num_refs = indices->size(); + } else if (num_refs != indices->size()) { + std::ostringstream ss; + ss << "the number of indices (" << indices->size() << ") "; + ss << "doesn't match previously found number of indices "; + ss << "(" << num_refs << ")"; + if (num_refs_loc) { + ss << " at " << *num_refs_loc; + } + throw error::AnalysisError{ ss.str(), &*operand }; + } + if (!num_refs_loc) { + num_refs_loc = operand->get_annotation_ptr(); + } + } + } + } + + // Copy annotation data. + node->annotations = analyze_annotations(insn.annotations); + node->copy_annotation(insn); + + return node; + } catch (error::AnalysisError &err) { + err.context(insn); + result.errors.push_back(std::move(err)); + } + return {}; +} + +/** + * Analyzes the given cQASM 1.2+ set instruction. + * If an error occurs, the message is added to the result error vector, + * and an empty Maybe is returned. + */ +tree::Maybe AnalyzerHelper::analyze_set_instruction( + const ast::Instruction &insn +) { + try { + // Figure out the operand list. + if (insn.operands->items.size() != 2) { + throw error::AnalysisError{ "set instruction must have two operands" }; + } + + // Analyze the operands. + auto node = analyze_set_instruction_operands( + *insn.operands->items[0], + *insn.operands->items[1] + ); + + // Resolve the condition code. + if (!insn.condition.empty()) { + auto condition_val = analyze_expression(*insn.condition); + node->condition = values::promote(condition_val, tree::make()); + if (node->condition.empty()) { + throw error::AnalysisError{ "condition must be a boolean" }; + } + + // If the condition is constant false, optimize the instruction + // away. + if (auto x = node->condition->as_const_bool()) { + if (!x->value) { + return {}; + } + } + } else { + node->condition.set(tree::make(true)); + } + + // Copy annotation data. + node->annotations = analyze_annotations(insn.annotations); + node->copy_annotation(insn); + + return node; + } catch (error::AnalysisError &err) { + err.context(insn); + result.errors.push_back(std::move(err)); + } + return {}; +} + +/** + * Analyzes the given two operands as lhs and rhs of a set instruction. + * Used for the actual set instruction as well as the assignments in the header of a C-style for loop. + */ +tree::Maybe AnalyzerHelper::analyze_set_instruction_operands( + const ast::Expression &lhs_expr, + const ast::Expression &rhs_expr +) { + // Analyze the expressions. + auto lhs = analyze_expression(lhs_expr); + auto rhs = analyze_expression(rhs_expr); + + // Check assignability of the left-hand side. + bool assignable = lhs->as_reference(); + if (auto fn = lhs->as_function()) { + assignable |= fn->return_type->as_type_base()->assignable; + } + if (!assignable) { + throw error::AnalysisError{ "left-hand side of assignment statement must be assignable" }; + } + + // Type-check/promote the right-hand side. + auto target_type = values::type_of(lhs).clone(); + target_type->assignable = false; + auto rhs_promoted = values::promote(rhs, target_type); + if (rhs_promoted.empty()) { + throw error::AnalysisError{ fmt::format( + "type of right-hand side ({}) could not be coerced to left-hand side ({})", + values::type_of(rhs), values::type_of(lhs)) }; + } + + // Create the node. + tree::Maybe node; + node.emplace(lhs, rhs_promoted); + return node; +} + +/** + * Analyzes the given cQASM 1.2+ goto instruction. + * If an error occurs, the message is added to the result error vector, + * and an empty Maybe is returned. + */ +tree::Maybe AnalyzerHelper::analyze_goto_instruction( + const ast::Instruction &insn +) { + try { + // Parse the operands. + if (insn.operands->items.size() != 1) { + throw error::AnalysisError{ "goto instruction must have a single operand" }; + } + std::string target; + if (auto identifier = insn.operands->items[0]->as_identifier()) { + target = identifier->name; + } else { + throw error::AnalysisError{ "goto instruction operand must be a subcircuit identifier" }; + } + + // Create the node. + tree::Maybe node; + node.set(tree::make()); + + // We can't resolve the target subcircuit yet, because goto instructions + // may refer forward. Instead, we maintain a list of yet-to-be resolved + // goto instructions. + gotos.emplace_back(node, target); + + // Resolve the condition code. + if (!insn.condition.empty()) { + auto condition_val = analyze_expression(*insn.condition); + node->condition = values::promote(condition_val, tree::make()); + if (node->condition.empty()) { + throw error::AnalysisError{ "condition must be a boolean" }; + } + + // If the condition is constant false, optimize the instruction + // away. + if (auto x = node->condition->as_const_bool()) { + if (!x->value) { + return {}; + } + } + } else { + node->condition.set(tree::make(true)); + } + + // Copy annotation data. + node->annotations = analyze_annotations(insn.annotations); + node->copy_annotation(insn); + + return node; + } catch (error::AnalysisError &err) { + err.context(insn); + result.errors.push_back(std::move(err)); + } + return {}; +} + +/** + * Analyzes the error model meta-instruction and, if valid, adds it to the analysis result. + * If an error occurs, the message is added to the result error vector, and nothing is added. + */ +void AnalyzerHelper::analyze_error_model(const ast::Instruction &insn) { + try { + // Only one error model should be specified, so throw an error + // if we already have one. + if (!result.root->error_model.empty()) { + auto ss = std::ostringstream(); + ss << "error model can only be specified once"; + if (auto loc = result.root->error_model->get_annotation_ptr()) { + ss << ", previous specification was at " << *loc; + } + throw error::AnalysisError{ ss.str() }; + } + + // Figure out the name of the error model. + const auto &arg_exprs = insn.operands->items; + if (arg_exprs.empty()) { + throw error::AnalysisError{ "missing error model name" }; + } + std::string name; + if (auto name_ident = arg_exprs[0]->as_identifier()) { + name = name_ident->name; + } else { + throw error::AnalysisError{ "first argument of an error model must be its name as an identifier" }; + } + + // Figure out the argument list. + auto arg_values = values::Values(); + for (auto arg_expr_it = arg_exprs.begin() + 1; arg_expr_it < arg_exprs.end(); arg_expr_it++) { + arg_values.add(analyze_expression(**arg_expr_it)); + } + + // Resolve the error model to one of the known models if + // requested. If resolving is disabled, just make a node with + // the name and values directly (without promotion/implicit + // casts). + if (analyzer.resolve_error_model) { + result.root->error_model.set( + analyzer.error_models.resolve( + name, arg_values)); + } else { + result.root->error_model.set( + tree::make( + tree::Maybe(), + name, arg_values, + tree::Any())); + } + + // Copy annotation data. + result.root->error_model->annotations = analyze_annotations(insn.annotations); + result.root->error_model->copy_annotation(insn); + + } catch (error::AnalysisError &err) { + err.context(insn); + result.errors.push_back(std::move(err)); + } +} + +/** + * Analyzes the given mapping and, if valid, adds it to the current scope. + * If an error occurs, the message is added to the result error vector, and nothing is added to the scope. + */ +void AnalyzerHelper::analyze_mapping(const ast::Mapping &mapping) { + try { + get_current_scope().mappings.add( + mapping.alias->name, + analyze_expression(*mapping.expr), + tree::make(mapping) + ); + } catch (error::AnalysisError &err) { + err.context(mapping); + result.errors.push_back(std::move(err)); + } +} + +/** + * Analyzes the given declaration of one or more variables and, if valid, adds them to the current scope. + * If an error occurs, the message is added to the result error vector, and nothing is added to the scope. + */ +void AnalyzerHelper::analyze_variables(const ast::Variables &variables) { + try { + // Check version compatibility. + if (result.root->version->items < "1.1") { + throw error::AnalysisError{ "variables are only supported from cQASM 1.1 onwards" }; + } + + // Figure out what type the variables should have. + auto type_name = utils::to_lowercase(variables.typ->name); + types::Type type{}; + if (type_name == types::qubit_type_name) { + type = tree::make(); + } else if (type_name == types::bit_type_name || type_name == types::bool_type_name) { + type = tree::make(); + } else if (type_name == types::integer_type_name) { + type = tree::make(); + } else if (type_name == types::real_type_name) { + type = tree::make(); + } else if (type_name == types::complex_type_name) { + type = tree::make(); + } else { + throw error::AnalysisError{ fmt::format("unknown type \"{}\"", type_name) }; + } + type->assignable = true; + + // Construct the variables and add mappings for them. + for (const auto &identifier : variables.names) { + // Construct variable. + // Use the location tag of the identifier to record where the variable was defined. + auto var = tree::make(identifier->name, type.clone()); + var->copy_annotation(*identifier); + var->annotations = analyze_annotations(variables.annotations); + result.root->variables.add(var); + + // Add a mapping for the variable. + get_current_scope().mappings.add( + identifier->name, + tree::make(var), + tree::Maybe() + ); + } + + } catch (error::AnalysisError &err) { + err.context(variables); + result.errors.push_back(std::move(err)); + } +} + +/** + * Analyzes the given subcircuit header and, if valid, adds it to the subcircuit list. + * If an error occurs, the message is added to the result error vector, and nothing is added to the result. + */ +void AnalyzerHelper::analyze_subcircuit(const ast::Subcircuit &subcircuit) { + try { + if (scope_stack.size() > 1) { + throw error::AnalysisError{ "cannot open subcircuit within subblock" }; + } + primitives::Int iterations = 1; + if (!subcircuit.iterations.empty()) { + iterations = analyze_as_const_int(*subcircuit.iterations); + if (iterations < 1) { + throw error::AnalysisError{ + fmt::format("subcircuit iteration count must be positive, but is {}", iterations), + &*subcircuit.iterations }; + } + } + auto node = tree::make( + subcircuit.name->name, + iterations, + tree::Any(), + analyze_annotations(subcircuit.annotations)); + node->copy_annotation(subcircuit); + if (analyzer.api_version >= "1.2") { + node->body = tree::make(); + node->body->copy_annotation(subcircuit); + } + result.root->subcircuits.add(node); + } catch (error::AnalysisError &err) { + err.context(subcircuit); + result.errors.push_back(std::move(err)); + } +} + +/** + * Analyzes the given structured control-flow statement and, + * if valid, adds it to the current scope/block using API version 1.2+. + * If an error occurs, the message is added to the result error vector, + * and nothing is added to the block. + */ +void AnalyzerHelper::analyze_structured(const ast::Structured &structured) { + try { + tree::Maybe node; + + // Switch based on statement type. + if (auto if_else = structured.as_if_else()) { + node = analyze_if_else(*if_else); + } else if (auto for_loop = structured.as_for_loop()) { + node = analyze_for_loop(*for_loop); + } else if (auto foreach_loop = structured.as_foreach_loop()) { + node = analyze_foreach_loop(*foreach_loop); + } else if (auto while_loop = structured.as_while_loop()) { + node = analyze_while_loop(*while_loop); + } else if (auto repeat_until_loop = structured.as_repeat_until_loop()) { + node = analyze_repeat_until_loop(*repeat_until_loop); + } else if (structured.as_break_statement()) { + // Handle break statement. + if (!get_current_scope().within_loop) { + throw error::AnalysisError{ "cannot use break outside of a structured loop" }; + } + node.emplace(); + } else if (structured.as_continue_statement()) { + // Handle continue statement. + if (!get_current_scope().within_loop) { + throw error::AnalysisError{ "cannot use continue outside of a structured loop" }; + } + node.emplace(); + } else { + throw std::runtime_error("unexpected statement node"); + } + + // Stop if the node was optimized away. + if (node.empty()) { + return; + } + + // Copy annotation data. + node->annotations = analyze_annotations(structured.annotations); + node->copy_annotation(structured); + + // Add the node to the current block. + add_to_current_block(node.as()); + + } catch (error::AnalysisError &err) { + err.context(structured); + result.errors.push_back(std::move(err)); + } +} + +/** + * Analyzes the given if-else chain. + * Only intended for use as a helper function within analyze_structured(). + */ +tree::Maybe AnalyzerHelper::analyze_if_else( + const ast::IfElse &if_else +) { + // Create the if-else node. + tree::Maybe node; + node.emplace(); + + // Analyze the branches. + for (const auto &branch : if_else.branches) { + // Analyze the condition. + auto condition = analyze_expression(*branch->condition); + condition = values::promote(condition, tree::make()); + if (condition.empty()) { + throw error::AnalysisError{ "if/else condition must be a boolean" }; + } + + // Analyze the block. + auto body = analyze_subblock(*branch->body, false); + + // Add the branch. + node->branches.emplace(condition, body); + } + + // Analyze the otherwise block, if any. + if (!if_else.otherwise.empty()) { + node->otherwise = analyze_subblock(*if_else.otherwise, false); + } + + // Remove branches that are never taken due to constant-propagated + // conditions. + for (size_t idx = 0; idx < node->branches.size(); ) { + if (auto val = node->branches[idx]->condition->as_const_bool()) { + if (val->value) { + + // Constant true: optimize away all subsequent branches and + // replace the otherwise block with this one. + node->otherwise = node->branches[idx]->body; + while (node->branches.size() > idx) { + node->branches.remove(); + } + } else { + // Constant false: remove this condition/block. + node->branches.remove(static_cast(idx)); + } + } else { + idx++; + } + } + + // If no branches remain, optimize the entire statement away. + if (node->branches.empty()) { + if (!node->otherwise.empty()) { + for (const auto &statement : node->otherwise->statements) { + add_to_current_block(statement); + } + } + return {}; + } + + return node; +} + +/** + * Analyzes the given C-style for loop. + * Only intended for use as a helper function within analyze_structured(). + */ +tree::Maybe AnalyzerHelper::analyze_for_loop( + const ast::ForLoop &for_loop +) { + // Create the for-loop node. + tree::Maybe node; + node.emplace(); + + // Analyze the initialization assignment. + if (!for_loop.initialize.empty()) { + node->initialize = analyze_set_instruction_operands( + *for_loop.initialize->lhs, + *for_loop.initialize->rhs + ); + node->initialize->condition.emplace(true); + } + + // Analyze the condition. + auto condition = analyze_expression(*for_loop.condition); + node->condition = values::promote(condition, tree::make()); + if (node->condition.empty()) { + throw error::AnalysisError{ "loop condition must be a boolean" }; + } + + // Analyze the update assignment. + if (!for_loop.update.empty()) { + node->update = analyze_set_instruction_operands( + *for_loop.update->lhs, + *for_loop.update->rhs + ); + node->update->condition.emplace(true); + } + + // Analyze the body. + node->body = analyze_subblock(*for_loop.body, true); + + return node; +} + +/** + * Analyzes the given static for loop. + * Only intended for use as a helper function within analyze_structured(). + */ +tree::Maybe AnalyzerHelper::analyze_foreach_loop( + const ast::ForeachLoop &foreach_loop +) { + // Create the foreach loop node. + tree::Maybe node; + node.emplace(); + + // Analyze the loop variable. + node->lhs = values::promote(analyze_expression(*foreach_loop.lhs), tree::make(true)); + if (node->lhs.empty()) { + throw error::AnalysisError{ "foreach loop variable must be an assignable integer" }; + } + + // Analyze the boundaries. + node->frm = analyze_as_const_int(*foreach_loop.frm); + node->to = analyze_as_const_int(*foreach_loop.to); + + // Analyze the body. + node->body = analyze_subblock(*foreach_loop.body, true); + + return node; +} + +/** + * Analyzes the given while loop. + * Only intended for use as a helper function within analyze_structured(). + */ +tree::Maybe AnalyzerHelper::analyze_while_loop( + const ast::WhileLoop &while_loop +) { + // Create the while-loop node. + tree::Maybe node; + node.emplace(); + + // Analyze the condition. + auto condition = analyze_expression(*while_loop.condition); + node->condition = values::promote(condition, tree::make()); + if (node->condition.empty()) { + throw error::AnalysisError{ "loop condition must be a boolean" }; + } + + // Analyze the body. + node->body = analyze_subblock(*while_loop.body, true); + + // If the condition is constant false, optimize away. + if (auto cond = node->condition->as_const_bool(); cond && !cond->value) { + return {}; + } + + return node; +} + +/** + * Analyzes the given repeat-until loop. + * Only intended for use as a helper function within analyze_structured(). + */ +tree::Maybe AnalyzerHelper::analyze_repeat_until_loop( + const ast::RepeatUntilLoop &repeat_until_loop +) { + // Create the repeat-until-loop node. + tree::Maybe node; + node.emplace(); + + // Analyze the body. + node->body = analyze_subblock(*repeat_until_loop.body, true); + + // Analyze the condition. + auto condition = analyze_expression(*repeat_until_loop.condition); + node->condition = values::promote(condition, tree::make()); + if (node->condition.empty()) { + throw error::AnalysisError{ "loop condition must be a boolean" }; + } + + // If the condition is constant true, optimize away. + if (auto cond = node->condition->as_const_bool()) { + if (cond->value) { + for (const auto &statement : node->body->statements) { + add_to_current_block(statement); + } + return {}; + } + } + + return node; +} + +/** + * Analyzes the given list of annotations. Any errors found result in the + * annotation being skipped and an error being appended to the result error + * vector. + */ +tree::Any AnalyzerHelper::analyze_annotations( + const tree::Any &annotations +) { + auto retval = tree::Any(); + for (const auto &annotation_ast : annotations) { + try { + auto annotation = tree::make(); + annotation->interface = annotation_ast->interface->name; + annotation->operation = annotation_ast->operation->name; + for (const auto &expression_ast : annotation_ast->operands->items) { + try { + annotation->operands.add(analyze_expression(*expression_ast)); + } catch (error::AnalysisError &err) { + err.context(*annotation_ast); + result.errors.push_back(std::move(err)); + } + } + annotation->copy_annotation(*annotation_ast); + retval.add(annotation); + } catch (error::AnalysisError &err) { + err.context(*annotation_ast); + result.errors.push_back(std::move(err)); + } + } + return retval; +} + +/** + * Parses any kind of expression. Always returns a filled value or throws + * an exception. + */ +values::Value AnalyzerHelper::analyze_expression(const ast::Expression &expression) { + values::Value retval; + try { + if (auto int_lit = expression.as_integer_literal()) { + retval.set(tree::make(int_lit->value)); + } else if (auto float_lit = expression.as_float_literal()) { + retval.set(tree::make(float_lit->value)); + } else if (auto string_lit = expression.as_string_literal()) { + retval.set(tree::make(string_lit->value)); + } else if (auto json_lit = expression.as_json_literal()) { + retval.set(tree::make(json_lit->value)); + } else if (auto matrix_lit = expression.as_matrix_literal()) { + retval.set(analyze_matrix(*matrix_lit)); + } else if (auto ident = expression.as_identifier()) { + retval.set(get_current_scope().mappings.resolve(ident->name)); + } else if (auto index = expression.as_index()) { + retval.set(analyze_index(*index)); + } else if (auto func = expression.as_function_call()) { + retval.set(analyze_function(func->name->name, *func->arguments)); + } else if (auto negate = expression.as_negate()) { + retval.set(analyze_operator("-", negate->expr)); + } else if (auto bit_not = expression.as_bitwise_not()) { + retval.set(analyze_operator("~", bit_not->expr)); + } else if (auto log_not = expression.as_logical_not()) { + retval.set(analyze_operator("!", log_not->expr)); + } else if (auto power = expression.as_power()) { + retval.set(analyze_operator("**", power->lhs, power->rhs)); + } else if (auto mult = expression.as_multiply()) { + retval.set(analyze_operator("*", mult->lhs, mult->rhs)); + } else if (auto div = expression.as_divide()) { + retval.set(analyze_operator("/", div->lhs, div->rhs)); + } else if (auto idiv = expression.as_int_divide()) { + retval.set(analyze_operator("//", idiv->lhs, idiv->rhs)); + } else if (auto mod = expression.as_modulo()) { + retval.set(analyze_operator("%", mod->lhs, mod->rhs)); + } else if (auto add = expression.as_add()) { + retval.set(analyze_operator("+", add->lhs, add->rhs)); + } else if (auto sub = expression.as_subtract()) { + retval.set(analyze_operator("-", sub->lhs, sub->rhs)); + } else if (auto shl = expression.as_shift_left()) { + retval.set(analyze_operator("<<", shl->lhs, shl->rhs)); + } else if (auto sra = expression.as_shift_right_arith()) { + retval.set(analyze_operator(">>", sra->lhs, sra->rhs)); + } else if (auto srl = expression.as_shift_right_logic()) { + retval.set(analyze_operator(">>>", srl->lhs, srl->rhs)); + } else if (auto cmpeq = expression.as_cmp_eq()) { + retval.set(analyze_operator("==", cmpeq->lhs, cmpeq->rhs)); + } else if (auto cmpne = expression.as_cmp_ne()) { + retval.set(analyze_operator("!=", cmpne->lhs, cmpne->rhs)); + } else if (auto cmpgt = expression.as_cmp_gt()) { + retval.set(analyze_operator(">", cmpgt->lhs, cmpgt->rhs)); + } else if (auto cmpge = expression.as_cmp_ge()) { + retval.set(analyze_operator(">=", cmpge->lhs, cmpge->rhs)); + } else if (auto cmplt = expression.as_cmp_lt()) { + retval.set(analyze_operator("<", cmplt->lhs, cmplt->rhs)); + } else if (auto cmple = expression.as_cmp_le()) { + retval.set(analyze_operator("<=", cmple->lhs, cmple->rhs)); + } else if (auto band = expression.as_bitwise_and()) { + retval.set(analyze_operator("&", band->lhs, band->rhs)); + } else if (auto bxor = expression.as_bitwise_xor()) { + retval.set(analyze_operator("^", bxor->lhs, bxor->rhs)); + } else if (auto bor = expression.as_bitwise_or()) { + retval.set(analyze_operator("|", bor->lhs, bor->rhs)); + } else if (auto land = expression.as_logical_and()) { + retval.set(analyze_operator("&&", land->lhs, land->rhs)); + } else if (auto lxor = expression.as_logical_xor()) { + retval.set(analyze_operator("^^", lxor->lhs, lxor->rhs)); + } else if (auto lor = expression.as_logical_or()) { + retval.set(analyze_operator("||", lor->lhs, lor->rhs)); + } else if (auto tcond = expression.as_ternary_cond()) { + retval.set(analyze_operator("?:", tcond->cond, tcond->if_true, tcond->if_false)); + } else { + throw std::runtime_error("unexpected expression node"); + } + if ((analyzer.api_version < "1.1") && + !retval.empty() && + (retval->as_function() || retval->as_variable_ref())) { + throw error::AnalysisError{ "dynamic expressions are only supported from cQASM 1.1 onwards" }; + } + } catch (error::AnalysisError &err) { + err.context(expression); + throw; + } + if (retval.empty()) { + throw std::runtime_error( + "analyze_expression returned nonsense, this should never happen"); + } + retval->copy_annotation(expression); + return retval; +} + +/** + * Shorthand for parsing an expression to a constant integer. + */ +primitives::Int AnalyzerHelper::analyze_as_const_int(const ast::Expression &expression) { + try { + auto value = analyze_as(expression); + if (value.empty()) { + throw error::AnalysisError{ "expected an integer" }; + } + if (auto int_value = value->as_const_int()) { + return int_value->value; + } else { + throw error::AnalysisError{ "integer must be constant" }; + } + } catch (error::AnalysisError &err) { + err.context(expression); + throw; + } +} + +/** + * Parses a matrix. Always returns a filled value or throws an exception. + */ +values::Value AnalyzerHelper::analyze_matrix(const ast::MatrixLiteral &matrix_lit) { + // Figure out the size of the matrix and parse the subexpressions. + // Note that the number of rows is always at least 1 (Many vs Any) so the number of cols line is well-behaved. + size_t num_rows = matrix_lit.rows.size(); + size_t num_cols = matrix_lit.rows[0]->items.size(); + for (const auto &row : matrix_lit.rows) { + if (row->items.size() != num_cols) { + throw error::AnalysisError{ "matrix is not rectangular" }; + } + } + std::vector vals; + for (size_t row = 0; row < num_rows; row++) { + for (size_t col = 0; col < num_cols; col++) { + vals.push_back(analyze_expression(*matrix_lit.rows[row]->items[col])); + } + } + + // Try building a matrix of constant real numbers. + auto value = analyze_matrix_helper< + types::Real, values::ConstReal, + primitives::RMatrix, values::ConstRealMatrix + >(num_rows, num_cols, vals); + if (!value.empty()) { + return value; + } + + // Try building a matrix of constant complex numbers. + value = analyze_matrix_helper< + types::Complex, values::ConstComplex, + primitives::CMatrix, values::ConstComplexMatrix + >(num_rows, num_cols, vals); + if (!value.empty()) { + return value; + } + + // Only real and complex are supported right now. If more is to be + // added in the future, this should probably be written a little + // neater. + throw error::AnalysisError{ + "only matrices of constant real or complex numbers are currently supported" }; +} + +/** + * Parses an index operator. Always returns a filled value or throws an error. + */ +values::Value AnalyzerHelper::analyze_index(const ast::Index &index) { + auto expr = analyze_expression(*index.expr); + if (auto qubit_refs = expr->as_qubit_refs()) { + + // Qubit refs. + auto indices = analyze_index_list(*index.indices, qubit_refs->index.size()); + for (const auto &idx : indices) { + idx->value = qubit_refs->index[idx->value]->value; + } + return tree::make(indices); + + } else if (auto bit_refs = expr->as_bit_refs()) { + + // Measurement bit refs. + auto indices = analyze_index_list(*index.indices, bit_refs->index.size()); + for (const auto &idx : indices) { + idx->value = bit_refs->index[idx->value]->value; + } + return tree::make(indices); + + } else { + + // While matrices could conceivably be indexed, this is not supported right now. + throw error::AnalysisError{ fmt::format( + "indexation is not supported for value of type {}", values::type_of(expr)) }; + } +} + +/** + * Parses an index list. + */ +tree::Many AnalyzerHelper::analyze_index_list(const ast::IndexList &index_list, size_t size) { + tree::Many retval; + for (const auto &entry : index_list.items) { + if (auto item = entry->as_index_item()) { + + // Single index. + auto index = analyze_as_const_int(*item->index); + if (index < 0 || static_cast(index) >= size) { + throw error::AnalysisError{ + fmt::format("index {} out of range (size {})", index, size), item }; + } + auto index_val = tree::make(index); + index_val->copy_annotation(*item); + retval.add(index_val); + + } else if (auto range = entry->as_index_range()) { + + // Range notation. + auto first = analyze_as_const_int(*range->first); + if (first < 0 || static_cast(first) >= size) { + throw error::AnalysisError{ + fmt::format("index {} out of range (size {})", first, size), &*range->first }; + } + auto last = analyze_as_const_int(*range->last); + if (last < 0 || static_cast(last) >= size) { + throw error::AnalysisError{ + fmt::format("index {} out of range (size {})", last, size), &*range->first }; + } + if (first > last) { + throw error::AnalysisError{ "last index is lower than first index", range }; + } + for (auto index = first; index <= last; index++) { + auto index_val = tree::make(index); + index_val->copy_annotation(*range); + retval.add(index_val); + } + + } else { + throw std::runtime_error{ "unknown IndexEntry AST node" }; + } + } + return retval; +} + +/** + * Parses a function. Always returns a filled value or throws an exception. + */ +values::Value AnalyzerHelper::analyze_function(const ast::Identifier &name, const ast::ExpressionList &args) { + auto arg_values = values::Values(); + for (const auto &arg : args.items) { + arg_values.add(analyze_expression(*arg)); + } + auto retval = get_current_scope().functions.call(name.name, arg_values); + if (retval.empty()) { + throw std::runtime_error("function implementation returned empty value"); + } + return retval; +} + +/** + * Parses an operator. Always returns a filled value or throws an exception. + */ +values::Value AnalyzerHelper::analyze_operator( + const std::string &name, + const tree::One &a, + const tree::One &b, + const tree::One &c +) { + auto identifier = ast::Identifier("operator" + name); + auto args = ast::ExpressionList(); + args.items.add(a); + args.items.add(b); + args.items.add(c); + return analyze_function(identifier, args); +} + +} // namespace cqasm::v1x::analyzer diff --git a/src/v1x/cqasm-analyzer.cpp b/src/v1x/cqasm-analyzer.cpp index fedd2e01e..8ee877dbb 100644 --- a/src/v1x/cqasm-analyzer.cpp +++ b/src/v1x/cqasm-analyzer.cpp @@ -7,14 +7,13 @@ #include "cqasm-tree.hpp" // signed_size_t #include "cqasm-utils.hpp" #include "v1x/cqasm-analyzer.hpp" +#include "v1x/cqasm-analyzer-helper.hpp" #include "v1x/cqasm-functions.hpp" #include "v1x/cqasm-parse-helper.hpp" +#include "v1x/cqasm-scope.hpp" #include #include -#include -#include -#include #include @@ -145,330 +144,6 @@ void Analyzer::register_error_model( register_error_model(error_model::ErrorModel(name, param_types)); } -/** - * Scope information. - */ -class Scope { -public: - /** - * The mappings visible within this scope. - */ - resolver::MappingTable mappings; - - /** - * The functions visible within this scope. - */ - resolver::FunctionTable functions; - - /** - * The instruction set visible within this scope. - */ - resolver::InstructionTable instruction_set; - - /** - * The block associated with this scope, if any. If this is empty, this is - * the global scope, and the active block is that of the current subcircuit, - * which is lazily created when needed in case no subcircuit label is - * explicitly specified, and can thus not easily be populated here. - */ - tree::Maybe block; - - /** - * Whether we're within at least one for, foreach, while, or repeat-until - * loop. This is a necessary condition for break and continue statements to - * be allowed. - */ - bool within_loop; - - /** - * Creates the global scope. - */ - Scope( - const resolver::MappingTable &mappings, - const resolver::FunctionTable &functions, - const resolver::InstructionTable &instruction_set - ) : - mappings(mappings), - functions(functions), - instruction_set(instruction_set), - block(), - within_loop(false) - {} -}; - -/** - * Helper class for analyzing a single AST. This contains the stateful - * information that Analyzer can't have (to allow Analyzer to be reused). - */ -class AnalyzerHelper { -public: - /** - * The analyzer associated with this helper. - */ - const Analyzer &analyzer; - - /** - * The analysis result being constructed. - */ - AnalysisResult result; - - /** - * Scope stack. back() is the global scope, front() is the current scope. - */ - std::list scope_stack; - - /** - * List of all goto instructions in the program, for name resolution when - * all other analysis completes. - */ - std::list, std::string>> gotos; - - /** - * Analyzes the given AST using the given analyzer. - */ - AnalyzerHelper(const Analyzer &analyzer, const ast::Program &ast); - - /** - * Parses the version tag. Any semantic errors encountered are pushed into - * the result error vector. - */ - void analyze_version(const ast::Version &ast); - - /** - * Checks the qubits statement and updates the scope accordingly. Any - * semantic errors encountered are pushed into the result error vector. - */ - void analyze_qubits(const ast::Expression &count); - - /** - * Returns a reference to the subcircuit that's currently being built. If there - * is no subcircuit yet, a default one is created, using the source location - * annotation on the source node. - */ - tree::Maybe get_current_subcircuit(const tree::Annotatable &source); - - /** - * Returns a reference to the current scope. - */ - Scope &get_current_scope(); - - /** - * Returns a reference to the global scope. - */ - Scope &get_global_scope(); - - /** - * Returns a reference to the block that's currently being built (1.2+). - */ - tree::Maybe get_current_block(const tree::Annotatable &source); - - /** - * Adds an analyzed statement to the current block (1.2+). - */ - void add_to_current_block(const tree::Maybe &stmt); - - /** - * Analyzes the given statement list, adding the analyzed statements to the - * current subcircuit (API 1.0/1.1) or block (API 1.2+). - */ - void analyze_statements(const ast::StatementList &statements); - - /** - * Analyzes a statement list corresponding to a structured control-flow - * subblock (1.2+). Handles the requisite scoping, then defers to - * analyze_statements(). - */ - tree::Maybe analyze_subblock(const ast::StatementList &statements, bool is_loop); - - /** - * Analyzes the given bundle and, if valid, adds it to the current - * subcircuit using API version 1.0/1.1. If an error occurs, the message is - * added to the result error vector, and nothing is added to the subcircuit. - */ - void analyze_bundle(const ast::Bundle &bundle); - - /** - * Analyzes the given bundle and, if valid, adds it to the current - * scope/block using API version 1.2+. If an error occurs, the message is - * added to the result error vector, and nothing is added to the block. - */ - void analyze_bundle_ext(const ast::Bundle &bundle); - - /** - * Analyzes the given instruction. If an error occurs, the message is added to - * the result error vector, and an empty Maybe is returned. - */ - tree::Maybe analyze_instruction(const ast::Instruction &insn); - - /** - * Analyzes the given cQASM 1.2+ set instruction. If an error occurs, the - * message is added to the result error vector, and an empty Maybe is - * returned. - */ - tree::Maybe analyze_set_instruction(const ast::Instruction &insn); - - /** - * Analyzes the given two operands as lhs and rhs of a set instruction. Used for - * the actual set instruction as well as the assignments in the header of a - * C-style for loop. - */ - tree::Maybe analyze_set_instruction_operands( - const ast::Expression &lhs_expr, - const ast::Expression &rhs_expr - ); - - /** - * Analyzes the given cQASM 1.2+ goto instruction. If an error occurs, the - * message is added to the result error vector, and an empty Maybe is - * returned. - */ - tree::Maybe analyze_goto_instruction(const ast::Instruction &insn); - - /** - * Analyzes the error model meta-instruction and, if valid, adds it to the - * analysis result. If an error occurs, the message is added to the result - * error vector, and nothing is added. - */ - void analyze_error_model(const ast::Instruction &insn); - - /** - * Analyzes the given mapping and, if valid, adds it to the current - * scope. If an error occurs, the message is added to the result - * error vector, and nothing is added to the scope. - */ - void analyze_mapping(const ast::Mapping &mapping); - - /** - * Analyzes the given declaration of one or more variables and, if valid, - * adds them to the current scope. If an error occurs, the message is added - * to the result error vector, and nothing is added to the scope. - */ - void analyze_variables(const ast::Variables &variables); - - /** - * Analyzes the given subcircuit header and, if valid, adds it to the - * subcircuit list. If an error occurs, the message is added to the result - * error vector, and nothing is added to the result. - */ - void analyze_subcircuit(const ast::Subcircuit &subcircuit); - - /** - * Analyzes the given structured control-flow statement and, if valid, adds - * it to the current scope/block using API version 1.2+. If an error occurs, - * the message is added to the result error vector, and nothing is added to - * the block. - */ - void analyze_structured(const ast::Structured &structured); - - /** - * Analyzes the given if-else chain. Only intended for use as a helper - * function within analyze_structured(). - */ - tree::Maybe analyze_if_else(const ast::IfElse &if_else); - - /** - * Analyzes the given C-style for loop. Only intended for use as a helper - * function within analyze_structured(). - */ - tree::Maybe analyze_for_loop(const ast::ForLoop &for_loop); - - /** - * Analyzes the given static for loop. Only intended for use as a helper - * function within analyze_structured(). - */ - tree::Maybe analyze_foreach_loop(const ast::ForeachLoop &foreach_loop); - - /** - * Analyzes the given while loop. Only intended for use as a helper function - * within analyze_structured(). - */ - tree::Maybe analyze_while_loop(const ast::WhileLoop &while_loop); - - /** - * Analyzes the given repeat-until loop. Only intended for use as a helper - * function within analyze_structured(). - */ - tree::Maybe analyze_repeat_until_loop(const ast::RepeatUntilLoop &repeat_until_loop); - - /** - * Analyzes the given list of annotations. Any errors found result in the - * annotation being skipped and an error being appended to the result error - * vector. - */ - tree::Any analyze_annotations( - const tree::Any &annotations - ); - - /** - * Parses any kind of expression. Always returns a filled value or throws - * an exception. - */ - values::Value analyze_expression(const ast::Expression &expression); - - /** - * Shorthand for parsing an expression and promoting it to the given type, - * constructed in-place with the type_args parameter pack. Returns empty - * when the cast fails. - */ - template - values::Value analyze_as( - const ast::Expression &expression, - TypeArgs... type_args - ); - - /** - * Shorthand for parsing an expression to a constant integer. - */ - primitives::Int analyze_as_const_int(const ast::Expression &expression); - - /** - * Parses a matrix. Always returns a filled value or throws an exception. - */ - values::Value analyze_matrix(const ast::MatrixLiteral &matrix_lit); - - /** - * Helper for parsing a matrix. Highly templated to avoid repeating the - * same code for different kinds of matrices, but bear in mind that the - * template parameters are codependent. Returns empty on failure. - */ - template - values::Value analyze_matrix_helper( - size_t nrows, size_t ncols, - const std::vector &vals - ); - - /** - * Parses an index operator. Always returns a filled value or throws an - * error. - */ - values::Value analyze_index(const ast::Index &index); - - /** - * Parses an index list. - */ - tree::Many analyze_index_list( - const ast::IndexList &index_list, size_t size - ); - - /** - * Parses a function. Always returns a filled value or throws an exception. - */ - values::Value analyze_function( - const ast::Identifier &name, - const ast::ExpressionList &args - ); - - /** - * Parses an operator. Always returns a filled value or throws an exception. - */ - values::Value analyze_operator( - const std::string &name, - const tree::One &a, - const tree::One &b = tree::One(), - const tree::One &c = tree::One() - ); -}; - /** * Analyzes the given AST. */ @@ -549,1526 +224,4 @@ AnalysisResult Analyzer::analyze_string(const std::string &data, const std::opti ); } -/** - * Analyzes the given AST using the given analyzer. - */ -AnalyzerHelper::AnalyzerHelper(const Analyzer &analyzer, const ast::Program &ast) -: analyzer(analyzer) -, result() -, scope_stack( { Scope(analyzer.mappings, analyzer.functions, analyzer.instruction_set) } ) -{ - try { - // Construct the program node. - result.root.set(tree::make()); - result.root->copy_annotation(ast); - result.root->api_version = analyzer.api_version; - - // Check and set the version. - analyze_version(*ast.version); - - // Handle the qubits statement. Qubit variables can be used instead of - // the qubits keyword, in which case num_qubits is set to 0 to indicate - // that it's not being used. - if (!ast.num_qubits.empty()) { - analyze_qubits(*ast.num_qubits); - } else if (ast.version->items < "1.1") { - throw error::AnalysisError("missing qubits statement (required until version 1.1)"); - } else { - result.root->num_qubits = 0; - } - - // Read the statements. - analyze_statements(*ast.statements); - - // Resolve goto targets. - if (ast.version->items >= "1.2") { - - // Figure out all the subcircuit names and check for duplicates. - std::map> subcircuits; - for (const auto &subcircuit : result.root->subcircuits) { - try { - auto insert_result = subcircuits.insert({subcircuit->name, subcircuit}); - if (!insert_result.second) { - std::ostringstream ss; - ss << "duplicate subcircuit name \"" << subcircuit->name << "\""; - if (auto loc = insert_result.first->second->get_annotation_ptr()) { - ss << "; previous definition was at " << *loc; - } - throw error::AnalysisError(ss.str()); - } - } catch (error::AnalysisError &err) { - err.context(*subcircuit); - result.errors.push_back(std::move(err)); - } - } - - // Resolve the goto instruction targets. - for (const auto &it : gotos) { - try { - auto it2 = subcircuits.find(it.second); - if (it2 == subcircuits.end()) { - throw error::AnalysisError( - "failed to resolve subcircuit \"" + it.second + "\"" - ); - } - it.first->target = it2->second; - } catch (error::AnalysisError &err) { - err.context(*it.first); - result.errors.push_back(std::move(err)); - } - } - - } - - // Save the list of final mappings. - for (const auto &it : get_current_scope().mappings.get_table()) { - const auto &name = it.first; - const auto &value = it.second.first; - const auto &ast_node = it.second.second; - - // Ignore predefined and implicit mappings. - if (ast_node.empty()) { - continue; - } - - // Analyze any annotations attached to the mapping. - auto annotations = analyze_annotations(ast_node->annotations); - - // Construct the mapping object and copy the source location. - auto mapping = tree::make( - name, value, - analyze_annotations(ast_node->annotations) - ); - mapping->copy_annotation(*ast_node); - result.root->mappings.add(mapping); - - } - - // The iteration order over the mapping table is undefined, because it's - // backed by an unordered_map. To get a deterministic tree, sort by - // source location. - std::sort( - result.root->mappings.begin(), result.root->mappings.end(), - [](const tree::One &lhs, const tree::One &rhs) -> bool { - if (auto lhsa = lhs->get_annotation_ptr()) { - if (auto rhsa = rhs->get_annotation_ptr()) { - if (lhsa->file_name < rhsa->file_name) return true; - if (rhsa->file_name < lhsa->file_name) return false; - if (lhsa->first_line < rhsa->first_line) return true; - if (rhsa->first_line < lhsa->first_line) return false; - return lhsa->first_column < rhsa->first_column; - } - } - return false; - }); - - } catch (error::AnalysisError &err) { - result.errors.push_back(std::move(err)); - } -} - -/** - * Checks the AST version node and puts it into the semantic tree. - */ -void AnalyzerHelper::analyze_version(const ast::Version &ast) { - try { - // Default to API version in case the version in the AST is broken. - result.root->version = tree::make(); - result.root->version->items = analyzer.api_version; - - // Check API version. - for (const auto &item : ast.items) { - if (item < 0) { - throw error::AnalysisError("invalid version component"); - } - } - if (ast.items > analyzer.api_version) { - std::ostringstream ss{}; - ss << "the maximum cQASM version supported is " << analyzer.api_version; - ss << ", but the cQASM file is version " << ast.items; - throw error::AnalysisError(ss.str()); - } - - // Save the file version. - result.root->version->items = ast.items; - - } catch (error::AnalysisError &err) { - err.context(ast); - result.errors.push_back(std::move(err)); - } - result.root->version->copy_annotation(ast); -} - -/** - * Checks the qubits statement and updates the scope accordingly. Any - * semantic errors encountered are pushed into the result error vector. - */ -void AnalyzerHelper::analyze_qubits(const ast::Expression &count) { - try { - // Default to 0 qubits in case we get an exception or no qubit count is - // defined. - result.root->num_qubits = 0; - - // Try to load the number of qubits from the expression. - result.root->num_qubits = analyze_as_const_int(count); - if (result.root->num_qubits < 1) { - // Number of qubits must be positive if specified. - throw error::AnalysisError("invalid number of qubits"); - } - - // Construct the special q and b mappings, that map to the whole qubit - // and measurement register respectively. - tree::Many all_qubits; - for (primitives::Int i = 0; i < result.root->num_qubits; i++) { - auto vi = tree::make(i); - vi->copy_annotation(count); - all_qubits.add(vi); - } - get_current_scope().mappings.add("q", tree::make(all_qubits)); - get_current_scope().mappings.add("b", tree::make(all_qubits)); - - } catch (error::AnalysisError &err) { - err.context(count); - result.errors.push_back(std::move(err)); - } -} - -/** - * Returns a reference to the subcircuit that's currently being built. If there - * is no subcircuit yet, a default one is created, using the source location - * annotation on the source node. - */ -tree::Maybe AnalyzerHelper::get_current_subcircuit( - const tree::Annotatable &source -) { - // If we don't have a subcircuit yet, add a default one. Note that the - // original libqasm always had this default subcircuit (even if it was - // empty) and used the name "default" vs. the otherwise invalid empty - // string. - if (result.root->subcircuits.empty()) { - auto subcircuit_node = tree::make("", 1); - subcircuit_node->copy_annotation(source); - if (analyzer.api_version >= "1.2") { - subcircuit_node->body = tree::make(); - } - result.root->subcircuits.add(subcircuit_node); - } - - // Add the node to the last subcircuit. - return result.root->subcircuits.back(); -} - -/** - * Returns a reference to the current scope. - */ -Scope &AnalyzerHelper::get_current_scope() { - return scope_stack.back(); -} - -/** - * Returns a reference to the global scope. - */ -Scope &AnalyzerHelper::get_global_scope() { - return scope_stack.front(); -} - -/** - * Returns a reference to the block that's currently being built. - */ -tree::Maybe AnalyzerHelper::get_current_block( - const tree::Annotatable &source -) { - // If we're in a local scope/block, return that block. - const auto &scope = get_current_scope(); - if (!scope.block.empty()) { - return scope.block; - } - - // Otherwise return the block belonging to the current subcircuit. - return get_current_subcircuit(source)->body; -} - -/** - * Adds an analyzed statement to the current block (1.2+). - */ -void AnalyzerHelper::add_to_current_block(const tree::Maybe &stmt) { - // Add the statement to the current block. - auto block = get_current_block(*stmt); - block->statements.add(stmt); - - // Expand the source location annotation of the block to include the - // statement. - if (auto stmt_loc = stmt->get_annotation_ptr()) { - if (auto block_loc = block->get_annotation_ptr()) { - block_loc->expand_to_include(stmt_loc->first_line, stmt_loc->first_column); - block_loc->expand_to_include(stmt_loc->last_line, stmt_loc->last_column); - } else { - block->set_annotation(*stmt_loc); - } - } -} - -/** - * Analyzes the given statement list, adding the analyzed statements to the - * current subcircuit (API 1.0/1.1) or block (API 1.2+). - */ -void AnalyzerHelper::analyze_statements(const ast::StatementList &statements) { - for (const auto &stmt : statements.items) { - try { - if (auto bundle = stmt->as_bundle()) { - if (analyzer.api_version >= "1.2") { - analyze_bundle_ext(*bundle); - } else { - analyze_bundle(*bundle); - } - } else if (auto mapping = stmt->as_mapping()) { - analyze_mapping(*mapping); - } else if (auto variables = stmt->as_variables()) { - analyze_variables(*variables); - } else if (auto subcircuit = stmt->as_subcircuit()) { - analyze_subcircuit(*subcircuit); - } else if (auto structured = stmt->as_structured()) { - if (result.root->version->items < "1.2") { - throw error::AnalysisError("structured control-flow is not supported (need version 1.2+)"); - } - analyze_structured(*structured); - } else { - throw std::runtime_error("unexpected statement node"); - } - } catch (error::AnalysisError &err) { - err.context(*stmt); - result.errors.push_back(std::move(err)); - } - } -} - -/** - * Analyzes a statement list corresponding to a structured control-flow - * subblock (1.2+). Handles the requisite scoping, then defers to - * analyze_statements(). - */ -tree::Maybe AnalyzerHelper::analyze_subblock( - const ast::StatementList &statements, - bool is_loop -) { - // Create the block. - tree::Maybe block; - block.emplace(); - - // Create a scope for the block. - scope_stack.emplace_back(get_current_scope()); - get_current_scope().block = block; - get_current_scope().within_loop |= is_loop; - - // Analyze the statements within the block. The statements will be added - // to the current scope, which we just updated. - analyze_statements(statements); - - // Pop the scope from the stack. - scope_stack.pop_back(); - - return block; -} - -/** - * Analyzes the given bundle and, if valid, adds it to the current - * subcircuit using API version 1.0/1.1. If an error occurs, the message is - * added to the result error vector, and nothing is added to the subcircuit. - */ -void AnalyzerHelper::analyze_bundle(const ast::Bundle &bundle) { - try { - // The error model statement from the original cQASM grammar is a bit - // of a pain, because it conflicts with gates/instructions, so we have - // to special-case it here. Technically we could also have made it a - // keyword, but the less random keywords there are, the better. - if (bundle.items.size() == 1) { - if (utils::equal_case_insensitive(bundle.items[0]->name->name, "error_model")) { - analyze_error_model(*bundle.items[0]); - return; - } - } - - // Analyze and add the instructions. - auto node = tree::make(); - for (const auto &insn : bundle.items) { - node->items.add(analyze_instruction(*insn)); - } - - // If we have more than two instructions, ensure that all instructions are parallelizable. - if (node->items.size() > 1) { - for (const auto &insn : node->items) { - try { - if (!insn->instruction.empty()) { - if (!insn->instruction->allow_parallel) { - std::ostringstream ss; - ss << "instruction "; - ss << insn->instruction->name; - ss << " with parameter pack "; - ss << insn->instruction->param_types; - ss << " is not parallelizable, but is bundled with "; - ss << (node->items.size() - 1); - ss << " other instruction"; - if (node->items.size() != 2) { - ss << "s"; - } - throw error::AnalysisError(ss.str()); - } - } - } catch (error::AnalysisError &err) { - err.context(*insn); - result.errors.push_back(std::move(err)); - } - } - } - - // It's possible that no instructions end up being added, due to all - // condition codes resolving to constant false. In that case the entire - // bundle is removed. - if (node->items.empty()) { - return; - } - - // Copy annotation data. - node->annotations = analyze_annotations(bundle.annotations); - node->copy_annotation(bundle); - - // Add the node to the last subcircuit. - get_current_subcircuit(bundle)->bundles.add(node); - - } catch (error::AnalysisError &err) { - err.context(bundle); - result.errors.push_back(std::move(err)); - } -} - -/** - * Analyzes the given bundle and, if valid, adds it to the current - * subcircuit using API version 1.2+. If an error occurs, the message is - * added to the result error vector, and nothing is added to the subcircuit. - */ -void AnalyzerHelper::analyze_bundle_ext(const ast::Bundle &bundle) { - try { - // The error model statement from the original cQASM grammar is a bit - // of a pain, because it conflicts with gates/instructions, so we have - // to special-case it here. Technically we could also have made it a - // keyword, but the less random keywords there are, the better. - if (bundle.items.size() == 1) { - if (utils::equal_case_insensitive(bundle.items[0]->name->name, "error_model")) { - analyze_error_model(*bundle.items[0]); - return; - } - } - - // Analyze and add the instructions - auto node = tree::make(); - for (const auto &insn : bundle.items) { - if (utils::equal_case_insensitive(insn->name->name, "set")) { - node->items.add(analyze_set_instruction(*insn)); - } else if (utils::equal_case_insensitive(insn->name->name, "goto")) { - node->items.add(analyze_goto_instruction(*insn)); - } else { - node->items.add(analyze_instruction(*insn)); - } - } - - // If we have more than two instructions, ensure that all instructions can be executed in parallel - if (node->items.size() > 1) { - for (const auto &insn_base : node->items) { - try { - if (auto insn = insn_base->as_instruction()) { - if (!insn->instruction.empty()) { - if (!insn->instruction->allow_parallel) { - std::ostringstream ss; - ss << "instruction "; - ss << insn->instruction->name; - ss << " with parameter pack "; - ss << insn->instruction->param_types; - ss << " is not parallelizable, but is bundled with "; - ss << (node->items.size() - 1); - ss << " other instruction"; - if (node->items.size() != 2) { - ss << "s"; - } - throw error::AnalysisError(ss.str()); - } - } - } - } catch (error::AnalysisError &err) { - err.context(*insn_base); - result.errors.push_back(std::move(err)); - } - } - } - - // It's possible that no instructions end up being added, due to all - // condition codes resolving to constant false. In that case the entire - // bundle is removed. - if (node->items.empty()) { - return; - } - - // Copy annotation data. - node->annotations = analyze_annotations(bundle.annotations); - node->copy_annotation(bundle); - - // Add the node to the last subcircuit. - add_to_current_block(node.as()); - - } catch (error::AnalysisError &err) { - err.context(bundle); - result.errors.push_back(std::move(err)); - } -} - -/** - * Analyzes the given instruction. If an error occurs, the message is added to - * the result error vector, and an empty Maybe is returned. It's also possible - * that an empty Maybe is returned without an error, when the condition code - * statically resolves to false. - */ -tree::Maybe AnalyzerHelper::analyze_instruction(const ast::Instruction &insn) { - try { - // Figure out the operand list. - auto operands = values::Values(); - for (const auto &operand_expr : insn.operands->items) { - operands.add(analyze_expression(*operand_expr)); - } - - // Resolve the instruction and/or make the instruction node. - tree::Maybe node; - if (analyzer.resolve_instructions) { - node.set(get_current_scope().instruction_set.resolve(insn.name->name, operands)); - } else { - node.set(tree::make( - tree::Maybe(), - insn.name->name, values::Value(), operands, - tree::Any())); - } - - // Resolve the condition code. - if (!insn.condition.empty()) { - if (!node->instruction.empty() && !node->instruction->allow_conditional) { - throw error::AnalysisError( - "conditional execution is not supported for this instruction"); - } - auto condition_val = analyze_expression(*insn.condition); - node->condition = values::promote(condition_val, tree::make()); - if (node->condition.empty()) { - throw error::AnalysisError("condition must be a boolean"); - } - - // If the condition is constant false, optimize the instruction - // away. - if (auto x = node->condition->as_const_bool()) { - if (!x->value) { - return {}; - } - } - - } else { - node->condition.set(tree::make(true)); - } - - // Enforce qubit uniqueness if the instruction requires us to. - if (!node->instruction.empty() && !node->instruction->allow_reused_qubits) { - std::unordered_set qubits_used; - for (const auto &operand : operands) { - if (auto x = operand->as_qubit_refs()) { - for (const auto &index : x->index) { - if (!qubits_used.insert(index->value).second) { - throw error::AnalysisError( - "qubit with index " + std::to_string(index->value) - + " is used more than once"); - } - } - } - } - } - - // Enforce that all qubit and bit references have the same length if - // the instruction requires us to. Note that historically the condition - // is NOT split across the resulting parallel instructions but is - // instead copied and reduced using boolean and at runtime, so its - // length does NOT have to match. - if (!node->instruction.empty() && !node->instruction->allow_different_index_sizes) { - size_t num_refs = 0; - const parser::SourceLocation *num_refs_loc = nullptr; - for (const auto &operand : operands) { - const tree::Many *indices = nullptr; - if (auto qr = operand->as_qubit_refs()) { - indices = &qr->index; - } else if (auto br = operand->as_bit_refs()) { - indices = &br->index; - } - if (indices) { - if (!num_refs) { - num_refs = indices->size(); - } else if (num_refs != indices->size()) { - std::ostringstream ss; - ss << "the number of indices (" << indices->size() << ") "; - ss << "doesn't match previously found number of indices "; - ss << "(" << num_refs << ")"; - if (num_refs_loc) { - ss << " at " << *num_refs_loc; - } - throw error::AnalysisError(ss.str(), &*operand); - } - if (!num_refs_loc) { - num_refs_loc = operand->get_annotation_ptr(); - } - } - } - } - - // Copy annotation data. - node->annotations = analyze_annotations(insn.annotations); - node->copy_annotation(insn); - - return node; - } catch (error::AnalysisError &err) { - err.context(insn); - result.errors.push_back(std::move(err)); - } - return {}; -} - -/** - * Analyzes the given cQASM 1.2+ set instruction. If an error occurs, the - * message is added to the result error vector, and an empty Maybe is - * returned. - */ -tree::Maybe AnalyzerHelper::analyze_set_instruction( - const ast::Instruction &insn -) { - try { - // Figure out the operand list. - if (insn.operands->items.size() != 2) { - throw error::AnalysisError("set instruction must have two operands"); - } - - // Analyze the operands. - auto node = analyze_set_instruction_operands( - *insn.operands->items[0], - *insn.operands->items[1] - ); - - // Resolve the condition code. - if (!insn.condition.empty()) { - auto condition_val = analyze_expression(*insn.condition); - node->condition = values::promote(condition_val, tree::make()); - if (node->condition.empty()) { - throw error::AnalysisError("condition must be a boolean"); - } - - // If the condition is constant false, optimize the instruction - // away. - if (auto x = node->condition->as_const_bool()) { - if (!x->value) { - return {}; - } - } - } else { - node->condition.set(tree::make(true)); - } - - // Copy annotation data. - node->annotations = analyze_annotations(insn.annotations); - node->copy_annotation(insn); - - return node; - } catch (error::AnalysisError &err) { - err.context(insn); - result.errors.push_back(std::move(err)); - } - return {}; -} - -/** - * Analyzes the given two operands as lhs and rhs of a set instruction. Used for - * the actual set instruction as well as the assignments in the header of a - * C-style for loop. - */ -tree::Maybe AnalyzerHelper::analyze_set_instruction_operands( - const ast::Expression &lhs_expr, - const ast::Expression &rhs_expr -) { - // Analyze the expressions. - auto lhs = analyze_expression(lhs_expr); - auto rhs = analyze_expression(rhs_expr); - - // Check assignability of the left-hand side. - bool assignable = lhs->as_reference(); - if (auto fn = lhs->as_function()) { - assignable |= fn->return_type->as_type_base()->assignable; - } - if (!assignable) { - throw error::AnalysisError( - "left-hand side of assignment statement must be assignable" - ); - } - - // Type-check/promote the right-hand side. - auto target_type = values::type_of(lhs).clone(); - target_type->assignable = false; - auto rhs_promoted = values::promote(rhs, target_type); - if (rhs_promoted.empty()) { - std::ostringstream ss; - ss << "type of right-hand side (" << values::type_of(rhs) << ") "; - ss << "could not be coerced to left-hand side (" << values::type_of(lhs) << ")"; - throw error::AnalysisError(ss.str()); - } - - // Create the node. - tree::Maybe node; - node.emplace(lhs, rhs_promoted); - return node; -} - -/** - * Analyzes the given cQASM 1.2+ goto instruction. If an error occurs, the - * message is added to the result error vector, and an empty Maybe is - * returned. - */ -tree::Maybe AnalyzerHelper::analyze_goto_instruction( - const ast::Instruction &insn -) { - try { - // Parse the operands. - if (insn.operands->items.size() != 1) { - throw error::AnalysisError( - "goto instruction must have a single operand" - ); - } - std::string target; - if (auto identifier = insn.operands->items[0]->as_identifier()) { - target = identifier->name; - } else { - throw error::AnalysisError( - "goto instruction operand must be a subcircuit identifier" - ); - } - - // Create the node. - tree::Maybe node; - node.set(tree::make()); - - // We can't resolve the target subcircuit yet, because goto instructions - // may refer forward. Instead, we maintain a list of yet-to-be resolved - // goto instructions. - gotos.emplace_back(node, target); - - // Resolve the condition code. - if (!insn.condition.empty()) { - auto condition_val = analyze_expression(*insn.condition); - node->condition = values::promote(condition_val, tree::make()); - if (node->condition.empty()) { - throw error::AnalysisError("condition must be a boolean"); - } - - // If the condition is constant false, optimize the instruction - // away. - if (auto x = node->condition->as_const_bool()) { - if (!x->value) { - return {}; - } - } - } else { - node->condition.set(tree::make(true)); - } - - // Copy annotation data. - node->annotations = analyze_annotations(insn.annotations); - node->copy_annotation(insn); - - return node; - } catch (error::AnalysisError &err) { - err.context(insn); - result.errors.push_back(std::move(err)); - } - return {}; -} - -/** - * Analyzes the error model meta-instruction and, if valid, adds it to the - * analysis result. If an error occurs, the message is added to the result - * error vector, and nothing is added. - */ -void AnalyzerHelper::analyze_error_model(const ast::Instruction &insn) { - try { - // Only one error model should be specified, so throw an error - // if we already have one. - if (!result.root->error_model.empty()) { - auto ss = std::ostringstream(); - ss << "error model can only be specified once"; - if (auto loc = result.root->error_model->get_annotation_ptr()) { - ss << ", previous specification was at " << *loc; - } - throw error::AnalysisError(ss.str()); - } - - // Figure out the name of the error model. - const auto &arg_exprs = insn.operands->items; - if (arg_exprs.empty()) { - throw error::AnalysisError("missing error model name"); - } - std::string name; - if (auto name_ident = arg_exprs[0]->as_identifier()) { - name = name_ident->name; - } else { - throw error::AnalysisError( - "first argument of an error model must be its name as an identifier"); - } - - // Figure out the argument list. - auto arg_values = values::Values(); - for (auto arg_expr_it = arg_exprs.begin() + 1; arg_expr_it < arg_exprs.end(); arg_expr_it++) { - arg_values.add(analyze_expression(**arg_expr_it)); - } - - // Resolve the error model to one of the known models if - // requested. If resolving is disabled, just make a node with - // the name and values directly (without promotion/implicit - // casts). - if (analyzer.resolve_error_model) { - result.root->error_model.set( - analyzer.error_models.resolve( - name, arg_values)); - } else { - result.root->error_model.set( - tree::make( - tree::Maybe(), - name, arg_values, - tree::Any())); - } - - // Copy annotation data. - result.root->error_model->annotations = analyze_annotations(insn.annotations); - result.root->error_model->copy_annotation(insn); - - } catch (error::AnalysisError &err) { - err.context(insn); - result.errors.push_back(std::move(err)); - } -} - -/** - * Analyzes the given mapping and, if valid, adds it to the current - * scope. If an error occurs, the message is added to the result - * error vector, and nothing is added to the scope. - */ -void AnalyzerHelper::analyze_mapping(const ast::Mapping &mapping) { - try { - get_current_scope().mappings.add( - mapping.alias->name, - analyze_expression(*mapping.expr), - tree::make(mapping) - ); - } catch (error::AnalysisError &err) { - err.context(mapping); - result.errors.push_back(std::move(err)); - } -} - -/** - * Analyzes the given declaration of one or more variables and, - * if valid, adds them to the current scope. - * If an error occurs, the message is added to the result error vector, and nothing is added to the scope. - */ -void AnalyzerHelper::analyze_variables(const ast::Variables &variables) { - try { - // Check version compatibility. - if (result.root->version->items < "1.1") { - throw error::AnalysisError("variables are only supported from cQASM 1.1 onwards"); - } - - // Figure out what type the variables should have. - auto type_name = utils::to_lowercase(variables.typ->name); - types::Type type{}; - if (type_name == "qubit") { - type = tree::make(); - } else if (type_name == "bool" || type_name == "bit") { - type = tree::make(); - } else if (type_name == "int") { - type = tree::make(); - } else if (type_name == "real") { - type = tree::make(); - } else if (type_name == "complex") { - type = tree::make(); - } else { - throw error::AnalysisError("unknown type \"" + type_name + "\""); - } - type->assignable = true; - - // Construct the variables and add mappings for them. - for (const auto &identifier : variables.names) { - // Construct variable. - // Use the location tag of the identifier to record where the variable was defined. - auto var = tree::make(identifier->name, type.clone()); - var->copy_annotation(*identifier); - var->annotations = analyze_annotations(variables.annotations); - result.root->variables.add(var); - - // Add a mapping for the variable. - get_current_scope().mappings.add( - identifier->name, - tree::make(var), - tree::Maybe() - ); - } - - } catch (error::AnalysisError &err) { - err.context(variables); - result.errors.push_back(std::move(err)); - } -} - -/** - * Analyzes the given subcircuit header and, if valid, adds it to the - * subcircuit list. If an error occurs, the message is added to the result - * error vector, and nothing is added to the result. - */ -void AnalyzerHelper::analyze_subcircuit(const ast::Subcircuit &subcircuit) { - try { - if (scope_stack.size() > 1) { - throw error::AnalysisError("cannot open subcircuit within subblock"); - } - primitives::Int iterations = 1; - if (!subcircuit.iterations.empty()) { - iterations = analyze_as_const_int(*subcircuit.iterations); - if (iterations < 1) { - throw error::AnalysisError( - "subcircuit iteration count must be positive, but is " - + std::to_string(iterations), &*subcircuit.iterations); - } - } - auto node = tree::make( - subcircuit.name->name, - iterations, - tree::Any(), - analyze_annotations(subcircuit.annotations)); - node->copy_annotation(subcircuit); - if (analyzer.api_version >= "1.2") { - node->body = tree::make(); - node->body->copy_annotation(subcircuit); - } - result.root->subcircuits.add(node); - } catch (error::AnalysisError &err) { - err.context(subcircuit); - result.errors.push_back(std::move(err)); - } -} - -/** - * Analyzes the given structured control-flow statement and, if valid, adds - * it to the current scope/block using API version 1.2+. If an error occurs, - * the message is added to the result error vector, and nothing is added to - * the block. - */ -void AnalyzerHelper::analyze_structured(const ast::Structured &structured) { - try { - tree::Maybe node; - - // Switch based on statement type. - if (auto if_else = structured.as_if_else()) { - node = analyze_if_else(*if_else); - } else if (auto for_loop = structured.as_for_loop()) { - node = analyze_for_loop(*for_loop); - } else if (auto foreach_loop = structured.as_foreach_loop()) { - node = analyze_foreach_loop(*foreach_loop); - } else if (auto while_loop = structured.as_while_loop()) { - node = analyze_while_loop(*while_loop); - } else if (auto repeat_until_loop = structured.as_repeat_until_loop()) { - node = analyze_repeat_until_loop(*repeat_until_loop); - } else if (structured.as_break_statement()) { - - // Handle break statement. - if (!get_current_scope().within_loop) { - throw error::AnalysisError( - "cannot use break outside of a structured loop" - ); - } - node.emplace(); - - } else if (structured.as_continue_statement()) { - - // Handle continue statement. - if (!get_current_scope().within_loop) { - throw error::AnalysisError( - "cannot use continue outside of a structured loop" - ); - } - node.emplace(); - - } else { - throw std::runtime_error("unexpected statement node"); - } - - // Stop if the node was optimized away. - if (node.empty()) { - return; - } - - // Copy annotation data. - node->annotations = analyze_annotations(structured.annotations); - node->copy_annotation(structured); - - // Add the node to the current block. - add_to_current_block(node.as()); - - } catch (error::AnalysisError &err) { - err.context(structured); - result.errors.push_back(std::move(err)); - } -} - -/** - * Analyzes the given if-else chain. Only intended for use as a helper - * function within analyze_structured(). - */ -tree::Maybe AnalyzerHelper::analyze_if_else( - const ast::IfElse &if_else -) { - // Create the if-else node. - tree::Maybe node; - node.emplace(); - - // Analyze the branches. - for (const auto &branch : if_else.branches) { - // Analyze the condition. - auto condition = analyze_expression(*branch->condition); - condition = values::promote(condition, tree::make()); - if (condition.empty()) { - throw error::AnalysisError("if/else condition must be a boolean"); - } - - // Analyze the block. - auto body = analyze_subblock(*branch->body, false); - - // Add the branch. - node->branches.emplace(condition, body); - } - - // Analyze the otherwise block, if any. - if (!if_else.otherwise.empty()) { - node->otherwise = analyze_subblock(*if_else.otherwise, false); - } - - // Remove branches that are never taken due to constant-propagated - // conditions. - for (size_t idx = 0; idx < node->branches.size(); ) { - if (auto val = node->branches[idx]->condition->as_const_bool()) { - if (val->value) { - - // Constant true: optimize away all subsequent branches and - // replace the otherwise block with this one. - node->otherwise = node->branches[idx]->body; - while (node->branches.size() > idx) { - node->branches.remove(); - } - } else { - // Constant false: remove this condition/block. - node->branches.remove(static_cast(idx)); - } - } else { - idx++; - } - } - - // If no branches remain, optimize the entire statement away. - if (node->branches.empty()) { - if (!node->otherwise.empty()) { - for (const auto &stmt : node->otherwise->statements) { - add_to_current_block(stmt); - } - } - return {}; - } - - return node; -} - -/** - * Analyzes the given C-style for loop. Only intended for use as a helper - * function within analyze_structured(). - */ -tree::Maybe AnalyzerHelper::analyze_for_loop( - const ast::ForLoop &for_loop -) { - // Create the for-loop node. - tree::Maybe node; - node.emplace(); - - // Analyze the initialization assignment. - if (!for_loop.initialize.empty()) { - node->initialize = analyze_set_instruction_operands( - *for_loop.initialize->lhs, - *for_loop.initialize->rhs - ); - node->initialize->condition.emplace(true); - } - - // Analyze the condition. - auto condition = analyze_expression(*for_loop.condition); - node->condition = values::promote(condition, tree::make()); - if (node->condition.empty()) { - throw error::AnalysisError("loop condition must be a boolean"); - } - - // Analyze the update assignment. - if (!for_loop.update.empty()) { - node->update = analyze_set_instruction_operands( - *for_loop.update->lhs, - *for_loop.update->rhs - ); - node->update->condition.emplace(true); - } - - // Analyze the body. - node->body = analyze_subblock(*for_loop.body, true); - - return node; -} - -/** - * Analyzes the given static for loop. Only intended for use as a helper - * function within analyze_structured(). - */ -tree::Maybe AnalyzerHelper::analyze_foreach_loop( - const ast::ForeachLoop &foreach_loop -) { - - // Create the foreach loop node. - tree::Maybe node; - node.emplace(); - - // Analyze the loop variable. - node->lhs = values::promote(analyze_expression(*foreach_loop.lhs), tree::make(true)); - if (node->lhs.empty()) { - throw error::AnalysisError("foreach loop variable must be an assignable integer"); - } - - // Analyze the boundaries. - node->frm = analyze_as_const_int(*foreach_loop.frm); - node->to = analyze_as_const_int(*foreach_loop.to); - - // Analyze the body. - node->body = analyze_subblock(*foreach_loop.body, true); - - return node; -} - -/** - * Analyzes the given while loop. Only intended for use as a helper function - * within analyze_structured(). - */ -tree::Maybe AnalyzerHelper::analyze_while_loop( - const ast::WhileLoop &while_loop -) { - // Create the while-loop node. - tree::Maybe node; - node.emplace(); - - // Analyze the condition. - auto condition = analyze_expression(*while_loop.condition); - node->condition = values::promote(condition, tree::make()); - if (node->condition.empty()) { - throw error::AnalysisError("loop condition must be a boolean"); - } - - // Analyze the body. - node->body = analyze_subblock(*while_loop.body, true); - - // If the condition is constant false, optimize away. - if (auto cond = node->condition->as_const_bool()) { - if (!cond->value) { - return {}; - } - } - - return node; -} - -/** - * Analyzes the given repeat-until loop. Only intended for use as a helper - * function within analyze_structured(). - */ -tree::Maybe AnalyzerHelper::analyze_repeat_until_loop( - const ast::RepeatUntilLoop &repeat_until_loop -) { - // Create the repeat-until-loop node. - tree::Maybe node; - node.emplace(); - - // Analyze the body. - node->body = analyze_subblock(*repeat_until_loop.body, true); - - // Analyze the condition. - auto condition = analyze_expression(*repeat_until_loop.condition); - node->condition = values::promote(condition, tree::make()); - if (node->condition.empty()) { - throw error::AnalysisError("loop condition must be a boolean"); - } - - // If the condition is constant true, optimize away. - if (auto cond = node->condition->as_const_bool()) { - if (cond->value) { - for (const auto &stmt : node->body->statements) { - add_to_current_block(stmt); - } - return {}; - } - } - - return node; -} - -/** - * Analyzes the given list of annotations. Any errors found result in the - * annotation being skipped and an error being appended to the result error - * vector. - */ -tree::Any AnalyzerHelper::analyze_annotations( - const tree::Any &annotations -) { - auto retval = tree::Any(); - for (const auto &annotation_ast : annotations) { - try { - auto annotation = tree::make(); - annotation->interface = annotation_ast->interface->name; - annotation->operation = annotation_ast->operation->name; - for (const auto &expression_ast : annotation_ast->operands->items) { - try { - annotation->operands.add(analyze_expression(*expression_ast)); - } catch (error::AnalysisError &err) { - err.context(*annotation_ast); - result.errors.push_back(std::move(err)); - } - } - annotation->copy_annotation(*annotation_ast); - retval.add(annotation); - } catch (error::AnalysisError &err) { - err.context(*annotation_ast); - result.errors.push_back(std::move(err)); - } - } - return retval; -} - -/** - * Parses any kind of expression. Always returns a filled value or throws - * an exception. - */ -values::Value AnalyzerHelper::analyze_expression(const ast::Expression &expression) { - values::Value retval; - try { - if (auto int_lit = expression.as_integer_literal()) { - retval.set(tree::make(int_lit->value)); - } else if (auto float_lit = expression.as_float_literal()) { - retval.set(tree::make(float_lit->value)); - } else if (auto string_lit = expression.as_string_literal()) { - retval.set(tree::make(string_lit->value)); - } else if (auto json_lit = expression.as_json_literal()) { - retval.set(tree::make(json_lit->value)); - } else if (auto matrix_lit = expression.as_matrix_literal()) { - retval.set(analyze_matrix(*matrix_lit)); - } else if (auto ident = expression.as_identifier()) { - retval.set(get_current_scope().mappings.resolve(ident->name)); - } else if (auto index = expression.as_index()) { - retval.set(analyze_index(*index)); - } else if (auto func = expression.as_function_call()) { - retval.set(analyze_function(func->name->name, *func->arguments)); - } else if (auto negate = expression.as_negate()) { - retval.set(analyze_operator("-", negate->expr)); - } else if (auto bit_not = expression.as_bitwise_not()) { - retval.set(analyze_operator("~", bit_not->expr)); - } else if (auto log_not = expression.as_logical_not()) { - retval.set(analyze_operator("!", log_not->expr)); - } else if (auto power = expression.as_power()) { - retval.set(analyze_operator("**", power->lhs, power->rhs)); - } else if (auto mult = expression.as_multiply()) { - retval.set(analyze_operator("*", mult->lhs, mult->rhs)); - } else if (auto div = expression.as_divide()) { - retval.set(analyze_operator("/", div->lhs, div->rhs)); - } else if (auto idiv = expression.as_int_divide()) { - retval.set(analyze_operator("//", idiv->lhs, idiv->rhs)); - } else if (auto mod = expression.as_modulo()) { - retval.set(analyze_operator("%", mod->lhs, mod->rhs)); - } else if (auto add = expression.as_add()) { - retval.set(analyze_operator("+", add->lhs, add->rhs)); - } else if (auto sub = expression.as_subtract()) { - retval.set(analyze_operator("-", sub->lhs, sub->rhs)); - } else if (auto shl = expression.as_shift_left()) { - retval.set(analyze_operator("<<", shl->lhs, shl->rhs)); - } else if (auto sra = expression.as_shift_right_arith()) { - retval.set(analyze_operator(">>", sra->lhs, sra->rhs)); - } else if (auto srl = expression.as_shift_right_logic()) { - retval.set(analyze_operator(">>>", srl->lhs, srl->rhs)); - } else if (auto cmpeq = expression.as_cmp_eq()) { - retval.set(analyze_operator("==", cmpeq->lhs, cmpeq->rhs)); - } else if (auto cmpne = expression.as_cmp_ne()) { - retval.set(analyze_operator("!=", cmpne->lhs, cmpne->rhs)); - } else if (auto cmpgt = expression.as_cmp_gt()) { - retval.set(analyze_operator(">", cmpgt->lhs, cmpgt->rhs)); - } else if (auto cmpge = expression.as_cmp_ge()) { - retval.set(analyze_operator(">=", cmpge->lhs, cmpge->rhs)); - } else if (auto cmplt = expression.as_cmp_lt()) { - retval.set(analyze_operator("<", cmplt->lhs, cmplt->rhs)); - } else if (auto cmple = expression.as_cmp_le()) { - retval.set(analyze_operator("<=", cmple->lhs, cmple->rhs)); - } else if (auto band = expression.as_bitwise_and()) { - retval.set(analyze_operator("&", band->lhs, band->rhs)); - } else if (auto bxor = expression.as_bitwise_xor()) { - retval.set(analyze_operator("^", bxor->lhs, bxor->rhs)); - } else if (auto bor = expression.as_bitwise_or()) { - retval.set(analyze_operator("|", bor->lhs, bor->rhs)); - } else if (auto land = expression.as_logical_and()) { - retval.set(analyze_operator("&&", land->lhs, land->rhs)); - } else if (auto lxor = expression.as_logical_xor()) { - retval.set(analyze_operator("^^", lxor->lhs, lxor->rhs)); - } else if (auto lor = expression.as_logical_or()) { - retval.set(analyze_operator("||", lor->lhs, lor->rhs)); - } else if (auto tcond = expression.as_ternary_cond()) { - retval.set(analyze_operator("?:", tcond->cond, tcond->if_true, tcond->if_false)); - } else { - throw std::runtime_error("unexpected expression node"); - } - if ((analyzer.api_version < "1.1") && - !retval.empty() && - (retval->as_function() || retval->as_variable_ref())) { - throw error::AnalysisError("dynamic expressions are only supported from cQASM 1.1 onwards"); - } - } catch (error::AnalysisError &err) { - err.context(expression); - throw; - } - if (retval.empty()) { - throw std::runtime_error( - "analyze_expression returned nonsense, this should never happen"); - } - retval->copy_annotation(expression); - return retval; -} - -/** - * Shorthand for parsing an expression and promoting it to the given type, - * constructed in-place with the type_args parameter pack. Returns empty - * when the cast fails. - */ -template -values::Value AnalyzerHelper::analyze_as(const ast::Expression &expression, TypeArgs... type_args) { - return values::promote(analyze_expression(expression), tree::make(type_args...)); -} - -/** - * Shorthand for parsing an expression to a constant integer. - */ -primitives::Int AnalyzerHelper::analyze_as_const_int(const ast::Expression &expression) { - try { - auto value = analyze_as(expression); - if (value.empty()) { - throw error::AnalysisError("expected an integer"); - } - if (auto int_value = value->as_const_int()) { - return int_value->value; - } else { - throw error::AnalysisError("integer must be constant"); - } - } catch (error::AnalysisError &err) { - err.context(expression); - throw; - } -} - -/** - * Parses a matrix. Always returns a filled value or throws an exception. - */ -values::Value AnalyzerHelper::analyze_matrix(const ast::MatrixLiteral &matrix_lit) { - // Figure out the size of the matrix and parse the subexpressions. - // Note that the number of rows is always at least 1 (Many vs Any) so - // the ncols line is well-behaved. - size_t nrows = matrix_lit.rows.size(); - size_t ncols = matrix_lit.rows[0]->items.size(); - for (const auto &row : matrix_lit.rows) { - if (row->items.size() != ncols) { - throw error::AnalysisError("matrix is not rectangular"); - } - } - std::vector vals; - for (size_t row = 0; row < nrows; row++) { - for (size_t col = 0; col < ncols; col++) { - vals.push_back(analyze_expression(*matrix_lit.rows[row]->items[col])); - } - } - - // Try building a matrix of constant real numbers. - auto value = analyze_matrix_helper< - types::Real, values::ConstReal, - primitives::RMatrix, values::ConstRealMatrix - >(nrows, ncols, vals); - if (!value.empty()) { - return value; - } - - // Try building a matrix of constant complex numbers. - value = analyze_matrix_helper< - types::Complex, values::ConstComplex, - primitives::CMatrix, values::ConstComplexMatrix - >(nrows, ncols, vals); - if (!value.empty()) { - return value; - } - - // Only real and complex are supported right now. If more is to be - // added in the future, this should probably be written a little - // neater. - throw error::AnalysisError("only matrices of constant real or complex numbers are currently supported"); -} - -/** - * Helper for parsing a matrix. Highly templated to avoid repeating the - * same code for different kinds of matrices, but bear in mind that the - * template parameters are codependent. Returns empty on failure. - */ -template -values::Value AnalyzerHelper::analyze_matrix_helper( - size_t nrows, size_t ncols, - const std::vector &vals -) { - auto matrix = MatLit(nrows, ncols); - for (size_t row = 0; row < nrows; row++) { - for (size_t col = 0; col < ncols; col++) { - auto val = values::promote(vals[row * ncols + col], tree::make()); - if (val.empty()) { - return {}; - } else { - auto val_real = val.template as(); - if (val_real.empty()) { - return {}; - } else { - matrix.at(row + 1, col + 1) = val_real->value; - } - } - } - } - return tree::make(matrix); -} - -/** - * Parses an index operator. Always returns a filled value or throws an error. - */ -values::Value AnalyzerHelper::analyze_index(const ast::Index &index) { - auto expr = analyze_expression(*index.expr); - if (auto qubit_refs = expr->as_qubit_refs()) { - - // Qubit refs. - auto indices = analyze_index_list(*index.indices, qubit_refs->index.size()); - for (const auto &idx : indices) { - idx->value = qubit_refs->index[idx->value]->value; - } - return tree::make(indices); - - } else if (auto bit_refs = expr->as_bit_refs()) { - - // Measurement bit refs. - auto indices = analyze_index_list(*index.indices, bit_refs->index.size()); - for (const auto &idx : indices) { - idx->value = bit_refs->index[idx->value]->value; - } - return tree::make(indices); - - } else { - - // While matrices could conceivably be indexed, this is not supported - // right now. - std::ostringstream ss; - ss << "indexation is not supported for value of type " << values::type_of(expr); - throw error::AnalysisError(ss.str()); - } -} - -/** - * Parses an index list. - */ -tree::Many AnalyzerHelper::analyze_index_list(const ast::IndexList &index_list, size_t size) { - tree::Many retval; - for (const auto &entry : index_list.items) { - if (auto item = entry->as_index_item()) { - - // Single index. - auto index = analyze_as_const_int(*item->index); - if (index < 0 || (unsigned long)index >= size) { - throw error::AnalysisError( - "index " + std::to_string(index) - + " out of range (size " + std::to_string(size) + ")", - item); - } - auto index_val = tree::make(index); - index_val->copy_annotation(*item); - retval.add(index_val); - - } else if (auto range = entry->as_index_range()) { - - // Range notation. - auto first = analyze_as_const_int(*range->first); - if (first < 0 || (unsigned long)first >= size) { - throw error::AnalysisError( - "index " + std::to_string(first) - + " out of range (size " + std::to_string(size) + ")", - &*range->first); - } - auto last = analyze_as_const_int(*range->last); - if (last < 0 || (unsigned long)last >= size) { - throw error::AnalysisError( - "index " + std::to_string(last) - + " out of range (size " + std::to_string(size) + ")", - &*range->first); - } - if (first > last) { - throw error::AnalysisError("last index is lower than first index", range); - } - for (auto index = first; index <= last; index++) { - auto index_val = tree::make(index); - index_val->copy_annotation(*range); - retval.add(index_val); - } - - } else { - throw std::runtime_error("unknown IndexEntry AST node"); - } - } - return retval; -} - -/** - * Parses a function. Always returns a filled value or throws an exception. - */ -values::Value AnalyzerHelper::analyze_function(const ast::Identifier &name, const ast::ExpressionList &args) { - auto arg_values = values::Values(); - for (const auto &arg : args.items) { - arg_values.add(analyze_expression(*arg)); - } - auto retval = get_current_scope().functions.call(name.name, arg_values); - if (retval.empty()) { - throw std::runtime_error("function implementation returned empty value"); - } - return retval; -} - -/** - * Parses an operator. Always returns a filled value or throws an exception. - */ -values::Value AnalyzerHelper::analyze_operator( - const std::string &name, - const tree::One &a, - const tree::One &b, - const tree::One &c -) { - auto identifier = ast::Identifier("operator" + name); - auto args = ast::ExpressionList(); - args.items.add(a); - args.items.add(b); - args.items.add(c); - return analyze_function(identifier, args); -} - } // namespace cqasm::v1x::analyzer diff --git a/src/v1x/cqasm-instruction.cpp b/src/v1x/cqasm-instruction.cpp index 468ca0847..3829cf784 100644 --- a/src/v1x/cqasm-instruction.cpp +++ b/src/v1x/cqasm-instruction.cpp @@ -11,32 +11,31 @@ namespace cqasm::v1x { namespace instruction { /** - * Creates a new instruction. param_types is a shorthand type specification - * string as parsed by cqasm::types::from_spec(). If you need more control, - * you can also manipulate param_types directly. + * Creates a new instruction. + * param_types is a shorthand type specification string as parsed by cqasm::types::from_spec(). + * If you need more control, you can also manipulate param_types directly. * - * allow_conditional specifies whether the instruction can be made - * conditional with c- notation. allow_parallel specifies whether it may - * appear bundled with other instructions. allow_reused_qubits specifies - * whether it is legal for the instruction to use a qubit more than once in - * its parameter list. allow_different_index_sizes specifies whether it's legal - * to have different "index sizes" for different parameters, for instance - * q[1,2] in one parameter and q[1,2,3,4,5] in another. + * allow_conditional specifies whether the instruction can be made conditional with c- notation. + * allow_parallel specifies whether it may appear bundled with other instructions. + * allow_reused_qubits specifies whether it is legal for the instruction + * to use a qubit more than once in its parameter list. + * allow_different_index_sizes specifies whether it's legal to have different "index sizes" for different parameters, + * for instance q[1,2] in one parameter and q[1,2,3,4,5] in another. */ Instruction::Instruction( - const std::string &name, - const std::string ¶m_types, + std::string name, + const std::optional ¶m_types, bool allow_conditional, bool allow_parallel, bool allow_reused_qubits, bool allow_different_index_sizes ) : - name(name), - param_types(types::from_spec(param_types)), - allow_conditional(allow_conditional), - allow_parallel(allow_parallel), - allow_reused_qubits(allow_reused_qubits), - allow_different_index_sizes(allow_different_index_sizes) + name{ std::move(name) }, + param_types{ types::from_spec(param_types.value_or("")) }, + allow_conditional{ allow_conditional }, + allow_parallel{ allow_parallel }, + allow_reused_qubits{ allow_reused_qubits }, + allow_different_index_sizes{ allow_different_index_sizes } {} /** @@ -53,21 +52,15 @@ bool Instruction::operator==(const Instruction& rhs) const { /** * Stream << overload for instructions. */ -std::ostream &operator<<(std::ostream &os, const Instruction &insn) { - os << insn.name << insn.param_types; - return os; +std::ostream &operator<<(std::ostream &os, const Instruction &instruction) { + return os << instruction.name << instruction.param_types; } /** * Stream << overload for instruction references. */ -std::ostream &operator<<(std::ostream &os, const InstructionRef &insn) { - if (insn.empty()) { - os << "unresolved"; - } else { - os << *insn; - } - return os; +std::ostream &operator<<(std::ostream &os, const InstructionRef &instruction) { + return instruction.empty() ? os << "unresolved" : os << *instruction; } } // namespace instruction @@ -97,7 +90,7 @@ instruction::InstructionRef deserialize(const ::tree::cbor::MapReader &map) { if (!map.count("n")) { return {}; } - auto insn = tree::make( + auto instruction = tree::make( map.at("n").as_string(), "", map.at("c").as_bool(), @@ -107,9 +100,9 @@ instruction::InstructionRef deserialize(const ::tree::cbor::MapReader &map) { ); auto ar = map.at("t").as_array(); for (const auto &element : ar) { - insn->param_types.add(::tree::base::deserialize(element.as_binary())); + instruction->param_types.add(::tree::base::deserialize(element.as_binary())); } - return insn; + return instruction; } } // namespace primitives diff --git a/src/v1x/cqasm-parse-helper.cpp b/src/v1x/cqasm-parse-helper.cpp index 2c91115fe..a2b6b478c 100644 --- a/src/v1x/cqasm-parse-helper.cpp +++ b/src/v1x/cqasm-parse-helper.cpp @@ -145,21 +145,8 @@ void ParseHelper::push_error(const error::ParseError &error) { /** * Builds and pushes an error. */ -void ParseHelper::push_error( - const std::string &message, - int first_line, - int first_column, - int last_line, - int last_column) { - - result.errors.emplace_back( - message, - file_name, - static_cast(first_line), - static_cast(first_column), - static_cast(last_line), - static_cast(last_column) - ); +void ParseHelper::push_error(const std::string &message, const annotations::SourceLocation::Range &range) { + result.errors.emplace_back(message, file_name, range); } } // namespace cqasm::v1x::parser diff --git a/src/v1x/cqasm-parser.y b/src/v1x/cqasm-parser.y index 2ae504eea..038b35a64 100644 --- a/src/v1x/cqasm-parser.y +++ b/src/v1x/cqasm-parser.y @@ -43,13 +43,12 @@ void free_string(char *s) { /** * Attaches a source location annotation object to the given node pointer. */ - #define ADD_SOURCE_LOCATION(v) \ - v->set_annotation(cqasm::annotations::SourceLocation( \ - helper.file_name, \ - yyloc.first_line, \ - yyloc.first_column, \ - yyloc.last_line, \ - yyloc.last_column)) + #define ADD_SOURCE_LOCATION(v) \ + v->set_annotation(cqasm::annotations::SourceLocation( \ + helper.file_name, \ + { { static_cast(yyloc.first_line), static_cast(yyloc.first_column) }, \ + { static_cast(yyloc.last_line), static_cast(yyloc.last_column) } } \ + )) /** * Constructs an empty, new node of type T and places it into v. v is almost @@ -67,16 +66,20 @@ void free_string(char *s) { * location annotation of the object to the extents of whatever rule is * being matched. */ - #define FROM(t, s) \ - t = s; \ - { \ - auto *loc = t->get_annotation_ptr(); \ - if (!loc) { \ - ADD_SOURCE_LOCATION(t); \ - } else { \ - loc->expand_to_include(yyloc.first_line, yyloc.first_column); \ - loc->expand_to_include(yyloc.last_line, yyloc.last_column); \ - } \ + #define FROM(t, s) \ + t = s; \ + { \ + auto *loc = t->get_annotation_ptr(); \ + if (!loc) { \ + ADD_SOURCE_LOCATION(t); \ + } else { \ + loc->expand_to_include( \ + { static_cast(yyloc.first_line), static_cast(yyloc.first_column) } \ + ); \ + loc->expand_to_include( \ + { static_cast(yyloc.last_line), static_cast(yyloc.last_column) } \ + ); \ + } \ } } @@ -679,9 +682,7 @@ void yyerror(YYLTYPE* yyllocp, yyscan_t unused, cqasm::v1x::parser::ParseHelper (void)unused; helper.push_error( std::string(msg), - yyllocp->first_line, - yyllocp->first_column, - yyllocp->last_line, - yyllocp->last_column + { { static_cast(yyllocp->first_line), static_cast(yyllocp->first_column) }, + { static_cast(yyllocp->last_line), static_cast(yyllocp->last_column) } } ); } diff --git a/src/v1x/cqasm-scope.cpp b/src/v1x/cqasm-scope.cpp new file mode 100644 index 000000000..7b3e9fb2a --- /dev/null +++ b/src/v1x/cqasm-scope.cpp @@ -0,0 +1,20 @@ +#include "v1x/cqasm-scope.hpp" + + +namespace cqasm::v1x::analyzer { + +/** + * Creates a scope from a table of mappings, functions, and an instruction set. + */ +Scope::Scope( + resolver::MappingTable mappings, + resolver::FunctionTable functions, + resolver::InstructionTable instruction_set) +: mappings{ std::move(mappings) } +, functions{ std::move(functions) } +, instruction_set{ std::move(instruction_set) } +, block{} +, within_loop{ false } +{} + +} // namespace cqasm::v1x::analyzer diff --git a/src/v1x/cqasm-semantic.tree b/src/v1x/cqasm-semantic.tree index 44dff887b..460059cd5 100644 --- a/src/v1x/cqasm-semantic.tree +++ b/src/v1x/cqasm-semantic.tree @@ -179,8 +179,7 @@ annotated { # The condition for starting another iteration. condition: external One; - # The updating assignment, done at the end of the loop body and upon - # continue. + # The updating assignment, done at the end of the loop body and upon continue. update: Maybe; # The loop body. diff --git a/src/v1x/cqasm-types.cpp b/src/v1x/cqasm-types.cpp index 36e3d8922..fafe47ee6 100644 --- a/src/v1x/cqasm-types.cpp +++ b/src/v1x/cqasm-types.cpp @@ -168,35 +168,37 @@ static void mat_size(std::ostream &os, tree::signed_size_t nrows, tree::signed_s std::ostream &operator<<(std::ostream &os, const Type &type) { if (type.empty()) { os << "!EMPTY"; + } else if (type->as_qubit()) { + os << types::qubit_type_name; } else if (type->as_bool()) { - os << "bool/bit"; + os << types::bool_type_name << "/" << types::bit_type_name; } else if (type->as_axis()) { - os << "axis"; + os << types::axis_type_name; } else if (type->as_int()) { - os << "int"; + os << types::integer_type_name; } else if (type->as_real()) { - os << "real"; + os << types::real_type_name; } else if (type->as_complex()) { - os << "complex"; - } else if (auto real_mat = type->as_real_matrix()) { - os << "real "; - mat_size(os, real_mat->num_rows, real_mat->num_cols); - } else if (auto complex_mat = type->as_complex_matrix()) { - os << "complex "; - mat_size(os, complex_mat->num_rows, complex_mat->num_cols); + os << types::complex_type_name; + } else if (auto rm = type->as_real_matrix()) { + os << types::real_type_name << " "; + mat_size(os, rm->num_rows, rm->num_cols); + } else if (auto cm = type->as_complex_matrix()) { + os << types::complex_type_name << " "; + mat_size(os, cm->num_rows, cm->num_cols); } else if (type->as_string()) { - os << "string"; + os << types::string_type_name; } else if (type->as_json()) { - os << "json"; - } else if (type->as_qubit()) { - os << "qubit"; + os << types::json_type_name; } else { // Fallback when no friendly repr is known. return os << *type; } + if (type->assignable) { os << " reference"; } + return os; } diff --git a/src/v3x/AnalyzeTreeGenAstVisitor.cpp b/src/v3x/AnalyzeTreeGenAstVisitor.cpp index 101ae8c00..0d2f50b32 100644 --- a/src/v3x/AnalyzeTreeGenAstVisitor.cpp +++ b/src/v3x/AnalyzeTreeGenAstVisitor.cpp @@ -2,17 +2,18 @@ #include "v3x/cqasm-ast-gen.hpp" #include "v3x/cqasm-analyzer.hpp" -#include // for_each, transform +#include // any_of, for_each #include +#include // assert #include // tail -#include namespace cqasm::v3x::analyzer { AnalyzeTreeGenAstVisitor::AnalyzeTreeGenAstVisitor(Analyzer &analyzer) : analyzer_{ analyzer } -, result_{} {} +, result_{} +{} std::any AnalyzeTreeGenAstVisitor::visit_node(ast::Node &/* node */) { throw error::AnalysisError{ "unimplemented" }; @@ -21,8 +22,11 @@ std::any AnalyzeTreeGenAstVisitor::visit_node(ast::Node &/* node */) { std::any AnalyzeTreeGenAstVisitor::visit_program(ast::Program &program_ast) { result_.root = tree::make(); result_.root->api_version = analyzer_.api_version; - visit_version(*program_ast.version); - visit_statement_list(*program_ast.statements); + result_.root->version = std::any_cast>(visit_version(*program_ast.version)); + auto [block, variables, functions] = std::any_cast(visit_global_block(*program_ast.block)); + result_.root->block = block; + result_.root->variables = variables; + result_.root->functions = functions; return result_; } @@ -52,23 +56,17 @@ std::any AnalyzeTreeGenAstVisitor::visit_version(ast::Version &node) { ret->items = analyzer_.api_version; } ret->copy_annotation(node); - - // Update program's version - result_.root->version = ret; - return ret; } -std::any AnalyzeTreeGenAstVisitor::visit_statement_list(ast::StatementList &node) { - for (const auto &statement_ast : node.items) { - try { - statement_ast->visit(*this); - } catch (error::AnalysisError &err) { - err.context(node); - result_.errors.push_back(std::move(err)); - } - } - return {}; +std::any AnalyzeTreeGenAstVisitor::visit_global_block(ast::GlobalBlock &node) { + visit_block(node); + return GlobalBlockReturnT{ analyzer_.current_block(), analyzer_.current_variables(), analyzer_.global_functions() }; +} + +std::any AnalyzeTreeGenAstVisitor::visit_local_block(ast::LocalBlock &node) { + visit_block(node); + return LocalBlockReturnT{ analyzer_.current_block(), analyzer_.current_variables() }; } std::any AnalyzeTreeGenAstVisitor::visit_annotated(ast::Annotated &node) { @@ -101,44 +99,11 @@ std::any AnalyzeTreeGenAstVisitor::visit_annotation_data(ast::AnnotationData &no return ret; } -/* - * Build a semantic type - * It can be a simple type T, of size 1, - * or an array type TArray, which size is given by the syntactic type - */ -template -types::Type AnalyzeTreeGenAstVisitor::visit_variable_type(const ast::Variable &variable_ast, - std::string_view type_name) const { - - if (variable_ast.size.empty()) { - return tree::make(1); - } else if (variable_ast.size->value > 0) { - return tree::make(variable_ast.size->value); - } else { - throw error::AnalysisError{ fmt::format("declaring {} array of size <= 0", type_name) }; - } -} - std::any AnalyzeTreeGenAstVisitor::visit_variable(ast::Variable &node) { auto ret = tree::make(); try { - auto type_name = node.typ->name; - types::Type type{}; - if (type_name == "qubit") { - type = visit_variable_type(node, "qubit"); - } else if (type_name == "bit") { - type = visit_variable_type(node, "bit"); - } else if (type_name == "axis") { - type = tree::make(3); - } else if (type_name == "bool") { - type = visit_variable_type(node, "bool"); - } else if (type_name == "int") { - type = visit_variable_type(node, "int"); - } else if (type_name == "float") { - type = visit_variable_type(node, "real"); - } else { - throw error::AnalysisError("unknown type \"" + type_name + "\""); - } + // Build semantic type from syntactic type + auto type = build_semantic_type(node.typ); // Construct variable // Use the location tag of the identifier to record where the variable was defined @@ -148,120 +113,20 @@ std::any AnalyzeTreeGenAstVisitor::visit_variable(ast::Variable &node) { ret->annotations = std::any_cast>(visit_annotated(*node.as_annotated())); ret->copy_annotation(*identifier); - // Update program's variables - // And register mapping - result_.root->variables.add(ret); - analyzer_.register_mapping(identifier->name, tree::make(ret)); - } catch (error::AnalysisError &err) { - err.context(node); - result_.errors.push_back(std::move(err)); - ret.reset(); - } - return ret; -} - -bool check_qubit_and_bit_indices_have_same_size(const values::Values &operands) { - size_t qubit_indices_size{}; - size_t bit_indices_size{}; - // Instruction operands can be, whether variables references or index references - // Variables can be of type qubit, bit, qubit array, or bit array - // Qubits and bits have a single index, arrays have a size - // Index references point to a qubit array or bit array - for (const auto &operand : operands) { - if (auto variable_ref = operand->as_variable_ref()) { - const auto &variable = *variable_ref->variable; - if (variable.typ->as_qubit()) { - qubit_indices_size += 1; - } else if (auto qubit_array = variable.typ->as_qubit_array()) { - qubit_indices_size += qubit_array->size; - } else if (variable.typ->as_bit()) { - bit_indices_size += 1; - } else if (auto bit_array = variable.typ->as_bit_array()) { - bit_indices_size += bit_array->size; - } - } else if (auto index_ref = operand->as_index_ref()) { - const auto &variable = *index_ref->variable; - if (variable.typ->as_qubit() || variable.typ->as_qubit_array()) { - qubit_indices_size += index_ref->indices.size(); - } else if (variable.typ->as_bit() || variable.typ->as_bit_array()) { - bit_indices_size += index_ref->indices.size(); - } - } - } - return qubit_indices_size == bit_indices_size; -} - -std::any AnalyzeTreeGenAstVisitor::visit_measure_instruction(ast::MeasureInstruction &node) { - auto ret = tree::Maybe(); - try { - // Set operand list - // Notice operands have to be added in this order - // Otherwise instruction resolution would fail - auto operands = values::Values(); - operands.add(std::any_cast(visit_expression(*node.lhs))); - operands.add(std::any_cast(visit_expression(*node.rhs))); - - // Resolve the instruction - // For a measure instruction, this resolution will check that - // the first operand is of bit type, and that - // the second operand is of qubit type - ret.set(analyzer_.resolve_instruction(node.name->name, operands)); + // Add the variable to the current scope + analyzer_.add_variable_to_current_scope(ret); - // Check qubit and bit indices have the same size - if (!ret->instruction.empty()) { - if (!check_qubit_and_bit_indices_have_same_size(operands)) { - throw error::AnalysisError{ "qubit and bit indices have different sizes" }; - } - } - - // Set condition code - ret->condition.set(tree::make(true)); - - // Copy annotation data - ret->annotations = std::any_cast>(visit_annotated(*node.as_annotated())); - ret->copy_annotation(node); - - // Update program's statements - result_.root->statements.add(ret); - } catch (error::AnalysisError &err) { - err.context(node); - result_.errors.push_back(std::move(err)); - ret.reset(); - } - return ret; -} - -std::any AnalyzeTreeGenAstVisitor::visit_instruction(ast::Instruction &node) { - auto ret = tree::Maybe(); - try { - // Set operand list - auto operands = values::Values(); - for (const auto &operand_expr : node.operands->items) { - operands.add(std::any_cast(visit_expression(*operand_expr))); - } - - // Resolve the instruction - ret.set(analyzer_.resolve_instruction(node.name->name, operands)); - - // Set condition code - ret->condition.set(tree::make(true)); - - // Copy annotation data - ret->annotations = std::any_cast>(visit_annotated(*node.as_annotated())); - ret->copy_annotation(node); - - // Update program's statements - result_.root->statements.add(ret); + // Register the variable + analyzer_.register_variable(identifier->name, tree::make(ret)); } catch (error::AnalysisError &err) { err.context(node); result_.errors.push_back(std::move(err)); ret.reset(); } - return ret; } -/* +/** * Promote a value to a given type, * or error if the promotion is not valid */ @@ -275,7 +140,7 @@ values::Value promote_or_error(const values::Value &rhs_value, const types::Type } void do_assignment( - tree::Maybe &assignment_instruction, + tree::Maybe &assignment_statement, const values::Value &lhs_value, const values::Value &rhs_value) { @@ -300,11 +165,11 @@ void do_assignment( } } - assignment_instruction.emplace(lhs_value, promoted_rhs_value); + assignment_statement.emplace(lhs_value, promoted_rhs_value); } std::any AnalyzeTreeGenAstVisitor::visit_initialization(ast::Initialization &node) { - auto ret = tree::Maybe(); + auto ret = tree::Maybe(); try { // Analyze the right-hand side operand // @@ -322,25 +187,100 @@ std::any AnalyzeTreeGenAstVisitor::visit_initialization(ast::Initialization &nod // Perform assignment do_assignment(ret, lhs_value, rhs_value); - // Set condition code - ret->condition.set(tree::make(true)); + // Copy annotation data + ret->annotations = std::any_cast>(visit_annotated(*node.as_annotated())); + ret->copy_annotation(node); + + // Add the statement to the current scope + analyzer_.add_statement_to_current_scope(ret); + } catch (error::AnalysisError &err) { + err.context(node); + result_.errors.push_back(std::move(err)); + ret.reset(); + } + return ret; +} + +bool AnalyzeTreeGenAstVisitor::current_block_has_return_statement() { + return std::any_of(analyzer_.current_block()->statements.begin(), analyzer_.current_block()->statements.end(), + [](const auto &statement) { return statement->as_return_statement(); }); +} + +void AnalyzeTreeGenAstVisitor::current_block_return_statements_promote_or_error(const tree::Maybe &return_type) { + std::for_each(analyzer_.current_block()->statements.begin(), analyzer_.current_block()->statements.end(), + [&return_type](const auto &statement) { + if (auto return_statement = statement->as_return_statement(); return_statement) { + assert(!return_statement->return_value.empty()); + const auto promoted_return_value = promote_or_error(return_statement->return_value, return_type); + return_statement->return_value.set(promoted_return_value); + } + }); +} + +/** + * Convenience function for extracting the types of a list of variables. + */ +types::Types types_of(const tree::Any &variables) { + types::Types types{}; + for (const auto &variable : variables) { + types.add(variable->typ); + } + return types; +} + +std::any AnalyzeTreeGenAstVisitor::visit_function(ast::Function &node) { + auto ret = tree::make(); + analyzer_.push_scope(); + + try { + // Name + const auto identifier = node.name; + ret->name = identifier->name; + + // Return type + if (!node.return_type.empty()) { + ret->return_type = build_semantic_type(node.return_type); + } + + // Parameters + const auto ¶meters = std::any_cast(visit_local_block(*node.parameters)).second; + auto parameter_types = types_of(parameters); + + // Block + auto [block, variables] = std::any_cast(visit_local_block(*node.block)); + ret->block = block; + ret->variables = variables; + + // Return statement and return type checks + if (current_block_has_return_statement() && node.return_type.empty()) { + throw error::AnalysisError{ "found return statement but function does not have a return type" }; + } else if (!current_block_has_return_statement() && !node.return_type.empty()) { + throw error::AnalysisError{ "function has a return type but return statement was not found" }; + } else if (current_block_has_return_statement() && !node.return_type.empty()) { + current_block_return_statements_promote_or_error(ret->return_type); + } // Copy annotation data ret->annotations = std::any_cast>(visit_annotated(*node.as_annotated())); ret->copy_annotation(node); - // Update program's statements - result_.root->statements.add(ret); + // Add the function to the global scope + analyzer_.add_function_to_global_scope(ret); + + // Register the function + analyzer_.register_function(ret->name, parameter_types, tree::make(ret)); } catch (error::AnalysisError &err) { err.context(node); result_.errors.push_back(std::move(err)); ret.reset(); } + + analyzer_.pop_scope(); return ret; } -std::any AnalyzeTreeGenAstVisitor::visit_assignment_instruction(ast::AssignmentInstruction &node) { - auto ret = tree::Maybe(); +std::any AnalyzeTreeGenAstVisitor::visit_assignment_statement(ast::AssignmentStatement &node) { + auto ret = tree::Maybe(); try { // Analyze the operands const auto lhs_value = std::any_cast(visit_expression(*node.lhs)); @@ -349,22 +289,152 @@ std::any AnalyzeTreeGenAstVisitor::visit_assignment_instruction(ast::AssignmentI // Check assignability of the left-hand side if (bool assignable = lhs_value->as_reference(); !assignable) { throw error::AnalysisError{ "left-hand side of assignment statement must be assignable" }; - } else { - ret->lhs = lhs_value; } // Perform assignment do_assignment(ret, lhs_value, rhs_value); - // Set condition code - ret->condition.set(tree::make(true)); + // Copy annotation data + ret->annotations = std::any_cast>(visit_annotated(*node.as_annotated())); + ret->copy_annotation(node); + + // Add the statement to the current scope + analyzer_.add_statement_to_current_scope(ret); + } catch (error::AnalysisError &err) { + err.context(node); + result_.errors.push_back(std::move(err)); + ret.reset(); + } + return ret; +} + +std::any AnalyzeTreeGenAstVisitor::visit_return_statement(ast::ReturnStatement &node) { + auto ret = tree::make( + std::any_cast(visit_expression(*node.return_value))); + + // Copy annotation data + ret->annotations = std::any_cast>(visit_annotated(*node.as_annotated())); + ret->copy_annotation(node); + + // Add the statement to the current scope + analyzer_.add_statement_to_current_scope(ret); + + return ret; +} + +std::any AnalyzeTreeGenAstVisitor::visit_expression_statement(ast::ExpressionStatement &node) { + auto ret = tree::make(); + try { + if (auto function_call = node.expression->as_function_call(); function_call) { + ret->return_value = std::any_cast(visit_function_call(*function_call)).get_ptr(); + + // Copy annotation data + ret->annotations = std::any_cast>( + visit_annotated(*node.as_annotated())); + // Expression statements get the source location information from their expressions + ret->copy_annotation(*node.expression); + + // Add the statement to the current scope + analyzer_.add_statement_to_current_scope(ret); + } else { + throw error::AnalysisError{ "expression statement is not of function call type" }; + } + } catch (error::AnalysisError &err) { + // Expression statements get the source location information from their expressions + err.context(*node.expression); + result_.errors.push_back(std::move(err)); + ret.reset(); + } + return ret; +} + +bool check_qubit_and_bit_indices_have_same_size(const values::Values &operands) { + size_t qubit_indices_size{}; + size_t bit_indices_size{}; + // Instruction operands can be, whether variables references or index references + // Variables can be of type qubit, bit, qubit array, or bit array + // Qubits and bits have a single index, arrays have a size + // Index references point to a qubit array or bit array + for (const auto &operand : operands) { + if (auto variable_ref = operand->as_variable_ref()) { + const auto &variable = *variable_ref->variable; + if (variable.typ->as_qubit()) { + qubit_indices_size += 1; + } else if (auto qubit_array = variable.typ->as_qubit_array()) { + qubit_indices_size += qubit_array->size; + } else if (variable.typ->as_bit()) { + bit_indices_size += 1; + } else if (auto bit_array = variable.typ->as_bit_array()) { + bit_indices_size += bit_array->size; + } + } else if (auto index_ref = operand->as_index_ref()) { + const auto &variable = *index_ref->variable; + if (variable.typ->as_qubit() || variable.typ->as_qubit_array()) { + qubit_indices_size += index_ref->indices.size(); + } else if (variable.typ->as_bit() || variable.typ->as_bit_array()) { + bit_indices_size += index_ref->indices.size(); + } + } + } + return qubit_indices_size == bit_indices_size; +} + +std::any AnalyzeTreeGenAstVisitor::visit_gate(ast::Gate &node) { + auto ret = tree::Maybe(); + try { + // Set operand list + auto operands = values::Values(); + for (const auto &operand_expr : node.operands->items) { + operands.add(std::any_cast(visit_expression(*operand_expr))); + } + + // Resolve the instruction + ret.set(analyzer_.resolve_instruction(node.name->name, operands)); + + // Copy annotation data + ret->annotations = std::any_cast>(visit_annotated(*node.as_annotated())); + ret->copy_annotation(node); + + // Add the statement to the current scope + analyzer_.add_statement_to_current_scope(ret); + } catch (error::AnalysisError &err) { + err.context(node); + result_.errors.push_back(std::move(err)); + ret.reset(); + } + + return ret; +} + +std::any AnalyzeTreeGenAstVisitor::visit_measure_instruction(ast::MeasureInstruction &node) { + auto ret = tree::Maybe(); + try { + // Set operand list + // Notice operands have to be added in this order + // Otherwise instruction resolution would fail + auto operands = values::Values(); + operands.add(std::any_cast(visit_expression(*node.lhs))); + operands.add(std::any_cast(visit_expression(*node.rhs))); + + // Resolve the instruction + // For a measure instruction, this resolution will check that + // the first operand is of bit type, and that + // the second operand is of qubit type + ret.set(analyzer_.resolve_instruction(node.name->name, operands)); + + // Check qubit and bit indices have the same size + if (!ret->instruction.empty()) { + if (!check_qubit_and_bit_indices_have_same_size(operands)) { + throw error::AnalysisError{ "qubit and bit indices have different sizes" }; + } + } // Copy annotation data ret->annotations = std::any_cast>(visit_annotated(*node.as_annotated())); ret->copy_annotation(node); - // Update program's statements - result_.root->statements.add(ret); + // Add the statement to the current scope + analyzer_.add_statement_to_current_scope(ret); } catch (error::AnalysisError &err) { err.context(node); result_.errors.push_back(std::move(err)); @@ -384,20 +454,22 @@ std::any AnalyzeTreeGenAstVisitor::visit_expression(ast::Expression &node) { } } -/* +/** * Convenience function for visiting a function call given the function's name and arguments */ values::Value AnalyzeTreeGenAstVisitor::visit_function_call( const tree::One &name, - const tree::One &arguments) { + const tree::Maybe &arguments) { auto function_arguments = values::Values(); - std::for_each(arguments->items.begin(), arguments->items.end(), - [&function_arguments, this](const auto node_argument) { - function_arguments.add(std::any_cast(visit_expression(*node_argument))); - }); + if (!arguments.empty()) { + std::for_each(arguments->items.begin(), arguments->items.end(), + [&function_arguments, this](const auto node_argument) { + function_arguments.add(std::any_cast(visit_expression(*node_argument))); + }); + } const auto function_name = name->name; - auto ret = analyzer_.call_function(function_name, function_arguments); + auto ret = analyzer_.resolve_function(function_name, function_arguments); if (ret.empty()) { throw error::AnalysisError{ "function implementation returned empty value" }; } @@ -408,7 +480,7 @@ std::any AnalyzeTreeGenAstVisitor::visit_function_call(ast::FunctionCall &node) return visit_function_call(node.name, node.arguments); } -/* +/** * Convenience function for visiting unary operators */ std::any AnalyzeTreeGenAstVisitor::visit_unary_operator( @@ -417,11 +489,12 @@ std::any AnalyzeTreeGenAstVisitor::visit_unary_operator( return visit_function_call( tree::make(std::string{ "operator" } + name), - tree::make(tree::Any{ expression }) + tree::Maybe{ + tree::make(tree::Any{ expression }).get_ptr() } ); } -/* +/** * Convenience function for visiting binary operators */ std::any AnalyzeTreeGenAstVisitor::visit_binary_operator( @@ -431,7 +504,8 @@ std::any AnalyzeTreeGenAstVisitor::visit_binary_operator( return visit_function_call( tree::make(std::string{ "operator" } + name), - tree::make(tree::Any{ lhs, rhs }) + tree::Maybe{ + tree::make(tree::Any{ lhs, rhs }).get_ptr() } ); } @@ -534,7 +608,7 @@ std::any AnalyzeTreeGenAstVisitor::visit_ternary_conditional_expression(ast::Ter ); } -/* +/** * Check out of range accesses from any index in an input list to an array of a given size */ void check_out_of_range(const IndexListT &indices, primitives::Int size) { @@ -605,30 +679,13 @@ std::any AnalyzeTreeGenAstVisitor::visit_index_range(ast::IndexRange &index_rang } std::any AnalyzeTreeGenAstVisitor::visit_identifier(ast::Identifier &node) { - return analyzer_.resolve_mapping(node.name); -} - -/* - * Transform an input array of values into an array of a given Type - * Pre condition: all the values in the input array can be promoted to Type - */ -template -/* static */ tree::One AnalyzeTreeGenAstVisitor::build_array_value_from_promoted_values( - const values::Values &values, const types::Type &type) { - - auto ret = tree::make(); - ret->value.get_vec().resize(values.size()); - std::transform(values.begin(), values.end(), ret->value.begin(), - [&type](const auto const_value) { - return values::promote(const_value, type); - }); - return ret; + return analyzer_.resolve_variable(node.name); } -/* +/** * Transform an input array into a const array of Type * Pre conditions: - * Type can only be Bool, Int, or Real + * Type can only be Bool, Int, or Float * All the values in the input array can be promoted to Type */ /* static */ values::Value AnalyzeTreeGenAstVisitor::build_value_from_promoted_values( @@ -638,19 +695,19 @@ template return build_array_value_from_promoted_values(values, type); } else if (types::type_check(type, tree::make())) { return build_array_value_from_promoted_values(values, type); - } else if (types::type_check(type, tree::make())) { - return build_array_value_from_promoted_values(values, type); + } else if (types::type_check(type, tree::make())) { + return build_array_value_from_promoted_values(values, type); } else { - throw error::AnalysisError{ "expecting Bool, Int, or Real type in initialization list" }; + throw error::AnalysisError{ "expecting Bool, Int, or Float type in initialization list" }; } } -/* +/** * If any element of the initialization list is not a const boolean, const int, or const float, throw an error */ void check_initialization_list_element_type(const values::Value &value) { - if (!(value->as_const_bool() || value->as_const_int() || value->as_const_real())) { - throw error::AnalysisError{ "expecting a const bool, const int, or const real value" }; + if (!(value->as_const_bool() || value->as_const_int() || value->as_const_float())) { + throw error::AnalysisError{ "expecting a const bool, const int, or const float value" }; } } @@ -706,25 +763,15 @@ std::any AnalyzeTreeGenAstVisitor::visit_integer_literal(ast::IntegerLiteral &no } std::any AnalyzeTreeGenAstVisitor::visit_float_literal(ast::FloatLiteral &node) { - auto ret = tree::make(node.value); + auto ret = tree::make(node.value); return values::Value{ ret }; } -/** - * Shorthand for parsing an expression and promoting it to the given type, - * constructed in-place with the type_args parameter pack. - * Returns empty when the cast fails. - */ -template -values::Value AnalyzeTreeGenAstVisitor::analyze_as(ast::Expression &expression, TypeArgs... type_args) { - return values::promote(std::any_cast(expression.visit(*this)), tree::make(type_args...)); -} - /** * Shorthand for parsing an expression to a constant integer. */ primitives::Int AnalyzeTreeGenAstVisitor::visit_const_int(ast::Expression &expression) { - if (auto int_value = analyze_as(expression); !int_value.empty()) { + if (auto int_value = visit_as(expression); !int_value.empty()) { if (auto const_int_value = int_value->as_const_int()) { return const_int_value->value; } diff --git a/src/v3x/BuildTreeGenAstVisitor.cpp b/src/v3x/BuildTreeGenAstVisitor.cpp index 61cce46d2..981a317f4 100644 --- a/src/v3x/BuildTreeGenAstVisitor.cpp +++ b/src/v3x/BuildTreeGenAstVisitor.cpp @@ -1,6 +1,7 @@ #include "cqasm-annotations.hpp" #include "cqasm-tree.hpp" #include "v3x/cqasm-ast.hpp" +#include "v3x/cqasm-types.hpp" #include "v3x/BuildTreeGenAstVisitor.hpp" #include "v3x/CustomErrorListener.hpp" @@ -35,19 +36,29 @@ void BuildTreeGenAstVisitor::syntaxError(size_t line, size_t char_position_in_li error_listener_p_->syntaxError(line, char_position_in_line, text); } +/** + * ANTLR provides a zero-based character position in line + * We change it here to a one-based index, which is the more human-readable, and the common option in text editors + */ void BuildTreeGenAstVisitor::setNodeAnnotation(const ast::One &node, antlr4::Token *token) const { auto token_size = token->getStopIndex() - token->getStartIndex() + 1; - // ANTLR provides a zero-based character position in line - // We change it here to a one-based index, which is the more human-readable, and the common option in text editors - node->set_annotation(cqasm::annotations::SourceLocation{ + node->set_annotation(annotations::SourceLocation{ file_name_, - static_cast(token->getLine()), - static_cast(token->getCharPositionInLine() + 1), - static_cast(token->getLine()), - static_cast(token->getCharPositionInLine() + 1 + token_size) + { { static_cast(token->getLine()), static_cast(token->getCharPositionInLine() + 1) }, + { static_cast(token->getLine()), static_cast(token->getCharPositionInLine() + 1 + token_size) } } }); } +void BuildTreeGenAstVisitor::expandNodeAnnotation(const One &node, antlr4::Token *token) const { + auto token_size = token->getStopIndex() - token->getStartIndex() + 1; + if (auto source_location = node->get_annotation_ptr()) { + source_location->expand_to_include(annotations::SourceLocation::Index{ + static_cast(token->getLine()), + static_cast(token->getCharPositionInLine() + 1 + token_size) + }); + } +} + std::int64_t BuildTreeGenAstVisitor::get_int_value(size_t line, size_t char_position_in_line, const std::string &text) const { try { return std::stoll(text); @@ -85,14 +96,20 @@ double BuildTreeGenAstVisitor::get_float_value(antlr4::tree::TerminalNode *node) } std::any BuildTreeGenAstVisitor::visitProgram(CqasmParser::ProgramContext *context) { - auto ret = cqasm::tree::make(); + auto ret = tree::make(); ret->version = std::any_cast>(visitVersion(context->version())); - ret->statements = std::any_cast>(visitStatements(context->statements())); + ret->block = context->globalBlock() + ? std::any_cast>(visitGlobalBlock(context->globalBlock())) + : tree::make(); return ret; } +std::any BuildTreeGenAstVisitor::visitStatementSeparator(CqasmParser::StatementSeparatorContext *) { + return {}; +} + std::any BuildTreeGenAstVisitor::visitVersion(CqasmParser::VersionContext *context) { - auto ret = cqasm::tree::make(); + auto ret = tree::make(); const auto token = context->VERSION_NUMBER()->getSymbol(); const auto &text = context->VERSION_NUMBER()->getText(); const std::regex pattern{ "([0-9]+)(?:\\.([0-9]+))?" }; @@ -107,194 +124,215 @@ std::any BuildTreeGenAstVisitor::visitVersion(CqasmParser::VersionContext *conte return ret; } -std::any BuildTreeGenAstVisitor::visitStatements(CqasmParser::StatementsContext *context) { - auto ret = cqasm::tree::make(); - const auto &statements = context->statement(); +std::any BuildTreeGenAstVisitor::visitGlobalBlock(CqasmParser::GlobalBlockContext *context) { + auto ret = tree::make(); + const auto &statements = context->globalBlockStatement(); std::for_each(statements.begin(), statements.end(), [this, &ret](const auto &statement_ctx) { - ret->items.add(std::any_cast>(statement_ctx->accept(this))); + ret->statements.add(std::any_cast>(statement_ctx->accept(this))); }); return ret; } -std::any BuildTreeGenAstVisitor::visitStatementSeparator(CqasmParser::StatementSeparatorContext *) { - return {}; +std::any BuildTreeGenAstVisitor::visitLocalBlock(CqasmParser::LocalBlockContext *context) { + auto ret = tree::make(); + const auto &statements = context->localBlockStatement(); + std::for_each(statements.begin(), statements.end(), [this, &ret](const auto &statement_ctx) { + ret->statements.add(std::any_cast>(statement_ctx->accept(this))); + }); + return ret; } -std::any BuildTreeGenAstVisitor::visitQubitTypeDeclaration(CqasmParser::QubitTypeDeclarationContext *context) { - auto array_size_declaration_ctx = context->arraySizeDeclaration(); - auto size = (array_size_declaration_ctx) - ? tree::Maybe{ std::any_cast>(array_size_declaration_ctx->accept(this)).get_ptr() } - : tree::Maybe{}; - auto ret = cqasm::tree::make( - One{ cqasm::tree::make(context->IDENTIFIER()->getText()) }, - cqasm::tree::make(context->QUBIT_TYPE()->getText()), - size - ); - const auto token = context->IDENTIFIER()->getSymbol(); - setNodeAnnotation(ret, token); - return One{ ret }; +std::any BuildTreeGenAstVisitor::visitGlobalBlockStatement(CqasmParser::GlobalBlockStatementContext *context) { + if (auto local_block_statement_ctx = context->localBlockStatement(); local_block_statement_ctx) { + return local_block_statement_ctx->accept(this); + } + assert(context->functionDeclaration()); + return context->functionDeclaration()->accept(this); +} + +std::any BuildTreeGenAstVisitor::visitLocalBlockStatement(CqasmParser::LocalBlockStatementContext *context) { + if (auto variable_declaration_ctx = context->variableDeclaration(); variable_declaration_ctx) { + return variable_declaration_ctx->accept(this); + } else if (auto instruction_ctx = context->instruction(); instruction_ctx) { + return instruction_ctx->accept(this); + } else if (auto assignment_statement_ctx = context->assignmentStatement(); assignment_statement_ctx) { + return assignment_statement_ctx->accept(this); + } else if (auto return_statement_ctx = context->returnStatement(); return_statement_ctx) { + return return_statement_ctx->accept(this); + } else if (auto expression_statement_ctx = context->expressionStatement(); expression_statement_ctx) { + return expression_statement_ctx->accept(this); + } + throw error::AnalysisError{ "unknown local block statement type" }; } -std::any BuildTreeGenAstVisitor::visitBitTypeDeclaration(CqasmParser::BitTypeDeclarationContext *context) { - auto array_size_declaration_ctx = context->arraySizeDeclaration(); - auto size = (array_size_declaration_ctx) - ? tree::Maybe{ std::any_cast>(array_size_declaration_ctx->accept(this)).get_ptr() } - : tree::Maybe{}; - auto ret = cqasm::tree::make( - One{ cqasm::tree::make(context->IDENTIFIER()->getText()) }, - cqasm::tree::make(context->BIT_TYPE()->getText()), - size - ); - const auto token = context->IDENTIFIER()->getSymbol(); - setNodeAnnotation(ret, token); - return One{ ret }; +std::any BuildTreeGenAstVisitor::visitVariableDeclaration(CqasmParser::VariableDeclarationContext *context) { + if (auto variable_definition_ctx = context->variableDefinition(); variable_definition_ctx) { + return variable_definition_ctx->accept(this); + } + assert(context->variableInitialization()); + return context->variableInitialization()->accept(this); } -std::any BuildTreeGenAstVisitor::visitAxisTypeDefinition(CqasmParser::AxisTypeDeclarationContext *context) { - auto size = tree::make(3); - auto ret = cqasm::tree::make( - One{ cqasm::tree::make(context->IDENTIFIER()->getText()) }, - cqasm::tree::make(context->AXIS_TYPE()->getText()), - size - ); - const auto token = context->IDENTIFIER()->getSymbol(); - setNodeAnnotation(ret, token); - return One{ ret }; +std::any BuildTreeGenAstVisitor::visitVariableDefinition(CqasmParser::VariableDefinitionContext *context) { + return One{ visitVariable(context) }; } -std::any BuildTreeGenAstVisitor::visitAxisTypeInitialization(CqasmParser::AxisTypeDeclarationContext *context) { - auto ret = cqasm::tree::make(); - ret->var = std::any_cast>(visitAxisTypeDefinition(context)); +std::any BuildTreeGenAstVisitor::visitVariableInitialization(CqasmParser::VariableInitializationContext *context) { + auto ret = tree::make(); + ret->var = visitClassicalVariable(context); ret->rhs = std::any_cast>(context->expression()->accept(this)); - const auto token = context->EQUALS()->getSymbol(); - setNodeAnnotation(ret, token); + setNodeAnnotation(ret, context->EQUALS()->getSymbol()); return One{ ret }; } -std::any BuildTreeGenAstVisitor::visitAxisTypeDeclaration(CqasmParser::AxisTypeDeclarationContext *context) { - return (context->expression()) // rhs - ? visitAxisTypeInitialization(context) - : visitAxisTypeDefinition(context); +std::any BuildTreeGenAstVisitor::visitFunctionDeclaration(CqasmParser::FunctionDeclarationContext *context) { + auto ret = tree::make(); + ret->name = tree::make(context->IDENTIFIER()->getText()); + ret->parameters = context->parameters() + ? std::any_cast>(context->parameters()->accept(this)) + : tree::make(); + ret->return_type = context->type() + ? tree::Maybe{ std::any_cast>(context->type()->accept(this)).get_ptr() } + : tree::Maybe{}; + ret->block = context->localBlock() + ? std::any_cast>(context->localBlock()->accept(this)) + : tree::make(); + setNodeAnnotation(ret, context->IDENTIFIER()->getSymbol()); + return One{ ret }; } -std::any BuildTreeGenAstVisitor::visitBoolTypeDefinition(CqasmParser::BoolTypeDeclarationContext *context) { - auto array_size_declaration_ctx = context->arraySizeDeclaration(); - auto size = (array_size_declaration_ctx) - ? tree::Maybe{ std::any_cast>(array_size_declaration_ctx->accept(this)).get_ptr() } - : tree::Maybe{}; - auto ret = cqasm::tree::make( - One{ cqasm::tree::make(context->IDENTIFIER()->getText()) }, - cqasm::tree::make(context->BOOL_TYPE()->getText()), - size - ); - const auto token = context->IDENTIFIER()->getSymbol(); - setNodeAnnotation(ret, token); +std::any BuildTreeGenAstVisitor::visitParameters(CqasmParser::ParametersContext *context) { + auto ret = tree::make(); + const auto &variable_definitions = context->variableDefinition(); + std::for_each(variable_definitions.begin(), variable_definitions.end(), + [this, &ret](const auto &variable_definition_ctx) { + ret->statements.add(std::any_cast>(variable_definition_ctx->accept(this))); + }); + return ret; +} + +std::any BuildTreeGenAstVisitor::visitAssignmentStatement(CqasmParser::AssignmentStatementContext *context) { + auto ret = tree::make(); + ret->lhs = std::any_cast>(context->expression(0)->accept(this)); + ret->rhs = std::any_cast>(context->expression(1)->accept(this)); + setNodeAnnotation(ret, context->EQUALS()->getSymbol()); return One{ ret }; } -std::any BuildTreeGenAstVisitor::visitBoolTypeInitialization(CqasmParser::BoolTypeDeclarationContext *context) { - auto ret = cqasm::tree::make(); - ret->var = std::any_cast>(visitBoolTypeDefinition(context)); - ret->rhs = std::any_cast>(context->expression()->accept(this)); - const auto token = context->EQUALS()->getSymbol(); - setNodeAnnotation(ret, token); +std::any BuildTreeGenAstVisitor::visitReturnStatement(CqasmParser::ReturnStatementContext *context) { + auto ret = tree::make(); + ret->return_value = std::any_cast>(context->expression()->accept(this)); + setNodeAnnotation(ret, context->RETURN()->getSymbol()); return One{ ret }; } -std::any BuildTreeGenAstVisitor::visitBoolTypeDeclaration(CqasmParser::BoolTypeDeclarationContext *context) { - return (context->expression()) // rhs - ? visitBoolTypeInitialization(context) - : visitBoolTypeDefinition(context); +std::any BuildTreeGenAstVisitor::visitExpressionStatement(CqasmParser::ExpressionStatementContext *context) { + auto ret = tree::make(); + ret->expression = std::any_cast>(context->expression()->accept(this)); + // Expression statements get the source location information from their expressions + return One{ ret }; } -std::any BuildTreeGenAstVisitor::visitIntTypeDefinition(CqasmParser::IntTypeDeclarationContext *context) { - auto array_size_declaration_ctx = context->arraySizeDeclaration(); - auto size = (array_size_declaration_ctx) - ? tree::Maybe{ std::any_cast>(array_size_declaration_ctx->accept(this)).get_ptr() } - : tree::Maybe{}; - auto ret = cqasm::tree::make( - One{ cqasm::tree::make(context->IDENTIFIER()->getText()) }, - cqasm::tree::make(context->INT_TYPE()->getText()), - size - ); - const auto token = context->IDENTIFIER()->getSymbol(); - setNodeAnnotation(ret, token); +std::any BuildTreeGenAstVisitor::visitGate(CqasmParser::GateContext *context) { + auto ret = tree::make(); + ret->name = tree::make(context->IDENTIFIER()->getText()); + ret->operands = std::any_cast>(visitExpressionList(context->expressionList())); + setNodeAnnotation(ret, context->IDENTIFIER()->getSymbol()); return One{ ret }; } -std::any BuildTreeGenAstVisitor::visitIntTypeInitialization(CqasmParser::IntTypeDeclarationContext *context) { - auto ret = cqasm::tree::make(); - ret->var = std::any_cast>(visitIntTypeDefinition(context)); - ret->rhs = std::any_cast>(context->expression()->accept(this)); - const auto token = context->EQUALS()->getSymbol(); - setNodeAnnotation(ret, token); +std::any BuildTreeGenAstVisitor::visitMeasureInstruction(CqasmParser::MeasureInstructionContext *context) { + auto ret = tree::make(); + ret->name = tree::make(context->MEASURE()->getText()); + ret->lhs = std::any_cast>(context->expression(0)->accept(this)); + ret->rhs = std::any_cast>(context->expression(1)->accept(this)); + setNodeAnnotation(ret, context->MEASURE()->getSymbol()); return One{ ret }; } -std::any BuildTreeGenAstVisitor::visitIntTypeDeclaration(CqasmParser::IntTypeDeclarationContext *context) { - return (context->expression()) // rhs - ? visitIntTypeInitialization(context) - : visitIntTypeDefinition(context); +std::any BuildTreeGenAstVisitor::visitType(CqasmParser::TypeContext *context) { + if (auto quantum_type_ctx = context->quantumType(); quantum_type_ctx) { + return quantum_type_ctx->accept(this); + } + assert(context->classicalType()); + return context->classicalType()->accept(this); } -std::any BuildTreeGenAstVisitor::visitFloatTypeDefinition(CqasmParser::FloatTypeDeclarationContext *context) { - auto array_size_declaration_ctx = context->arraySizeDeclaration(); - auto size = (array_size_declaration_ctx) - ? tree::Maybe{ std::any_cast>(array_size_declaration_ctx->accept(this)).get_ptr() } - : tree::Maybe{}; - auto ret = cqasm::tree::make( - One{ cqasm::tree::make(context->IDENTIFIER()->getText()) }, - cqasm::tree::make(context->FLOAT_TYPE()->getText()), - size - ); - const auto token = context->IDENTIFIER()->getSymbol(); - setNodeAnnotation(ret, token); - return One{ ret }; +std::any BuildTreeGenAstVisitor::visitQubitType(CqasmParser::QubitTypeContext *context) { + auto ret = tree::make( + tree::make(types::qubit_type_name), + getArraySize(context->arraySizeDeclaration())); + setNodeAnnotation(ret, context->QUBIT_TYPE()->getSymbol()); + if (context->arraySizeDeclaration()) { + expandNodeAnnotation(ret, context->arraySizeDeclaration()->CLOSE_BRACKET()->getSymbol()); + } + return ret; } -std::any BuildTreeGenAstVisitor::visitFloatTypeInitialization(CqasmParser::FloatTypeDeclarationContext *context) { - auto ret = cqasm::tree::make(); - ret->var = std::any_cast>(visitFloatTypeDefinition(context)); - ret->rhs = std::any_cast>(context->expression()->accept(this)); - const auto token = context->EQUALS()->getSymbol(); - setNodeAnnotation(ret, token); - return One{ ret }; +std::any BuildTreeGenAstVisitor::visitBitType(CqasmParser::BitTypeContext *context) { + auto ret = tree::make( + tree::make(types::bit_type_name), + getArraySize(context->arraySizeDeclaration())); + setNodeAnnotation(ret, context->BIT_TYPE()->getSymbol()); + if (context->arraySizeDeclaration()) { + expandNodeAnnotation(ret, context->arraySizeDeclaration()->CLOSE_BRACKET()->getSymbol()); + } + return ret; } -std::any BuildTreeGenAstVisitor::visitFloatTypeDeclaration(CqasmParser::FloatTypeDeclarationContext *context) { - return (context->expression()) // rhs - ? visitFloatTypeInitialization(context) - : visitFloatTypeDefinition(context); +std::any BuildTreeGenAstVisitor::visitAxisType(CqasmParser::AxisTypeContext *context) { + auto ret = tree::make( + tree::make(types::axis_type_name), + tree::Maybe{ tree::make(3) }); + setNodeAnnotation(ret, context->AXIS_TYPE()->getSymbol()); + return ret; } -std::any BuildTreeGenAstVisitor::visitArraySizeDeclaration(CqasmParser::ArraySizeDeclarationContext *context) { - auto int_ctx = context->INTEGER_LITERAL(); - return cqasm::tree::make(get_int_value(int_ctx)); +std::any BuildTreeGenAstVisitor::visitBoolType(CqasmParser::BoolTypeContext *context) { + auto ret = tree::make( + tree::make(types::bool_type_name), + getArraySize(context->arraySizeDeclaration())); + setNodeAnnotation(ret, context->BOOL_TYPE()->getSymbol()); + if (context->arraySizeDeclaration()) { + expandNodeAnnotation(ret, context->arraySizeDeclaration()->CLOSE_BRACKET()->getSymbol()); + } + return ret; } -std::any BuildTreeGenAstVisitor::visitMeasureInstruction(CqasmParser::MeasureInstructionContext *context) { - auto ret = cqasm::tree::make(); - ret->name = cqasm::tree::make(context->MEASURE()->getText()); - ret->condition = cqasm::tree::Maybe{}; - ret->lhs = std::any_cast>(context->expression(0)->accept(this)); - ret->rhs = std::any_cast>(context->expression(1)->accept(this)); - const auto token = context->MEASURE()->getSymbol(); - setNodeAnnotation(ret, token); - return One{ ret }; +std::any BuildTreeGenAstVisitor::visitIntType(CqasmParser::IntTypeContext *context) { + auto ret = tree::make( + tree::make(types::integer_type_name), + getArraySize(context->arraySizeDeclaration())); + setNodeAnnotation(ret, context->INT_TYPE()->getSymbol()); + if (context->arraySizeDeclaration()) { + expandNodeAnnotation(ret, context->arraySizeDeclaration()->CLOSE_BRACKET()->getSymbol()); + } + return ret; } -std::any BuildTreeGenAstVisitor::visitInstruction(CqasmParser::InstructionContext *context) { - auto ret = cqasm::tree::make(); - ret->name = cqasm::tree::make(context->IDENTIFIER()->getText()); - ret->condition = cqasm::tree::Maybe{}; - ret->operands = std::any_cast>(visitExpressionList(context->expressionList())); - const auto token = context->IDENTIFIER()->getSymbol(); - setNodeAnnotation(ret, token); - return One{ ret }; +std::any BuildTreeGenAstVisitor::visitFloatType(CqasmParser::FloatTypeContext *context) { + auto ret = tree::make( + tree::make(types::float_type_name), + getArraySize(context->arraySizeDeclaration())); + setNodeAnnotation(ret, context->FLOAT_TYPE()->getSymbol()); + if (context->arraySizeDeclaration()) { + expandNodeAnnotation(ret, context->arraySizeDeclaration()->CLOSE_BRACKET()->getSymbol()); + } + return ret; +} + +tree::Maybe BuildTreeGenAstVisitor::getArraySize(CqasmParser::ArraySizeDeclarationContext *context) { + return (context) + ? tree::Maybe{ std::any_cast>(context->accept(this)).get_ptr() } + : tree::Maybe{}; +} + +std::any BuildTreeGenAstVisitor::visitArraySizeDeclaration(CqasmParser::ArraySizeDeclarationContext *context) { + return tree::make(get_int_value(context->INTEGER_LITERAL())); } std::any BuildTreeGenAstVisitor::visitExpressionList(CqasmParser::ExpressionListContext *context) { - auto ret = cqasm::tree::make(); + auto ret = tree::make(); const auto &expressions = context->expression(); std::for_each(expressions.begin(), expressions.end(), [this, &ret](auto &expression_ctx) { ret->items.add(std::any_cast>(expression_ctx->accept(this))); @@ -303,7 +341,7 @@ std::any BuildTreeGenAstVisitor::visitExpressionList(CqasmParser::ExpressionList } std::any BuildTreeGenAstVisitor::visitIndexList(CqasmParser::IndexListContext *context) { - auto ret = cqasm::tree::make(); + auto ret = tree::make(); const auto &index_entries = context->indexEntry(); std::for_each(index_entries.begin(), index_entries.end(), [this, &ret](auto &index_entry_ctx) { auto index_entry = std::any_cast>(index_entry_ctx->accept(this)); @@ -313,13 +351,13 @@ std::any BuildTreeGenAstVisitor::visitIndexList(CqasmParser::IndexListContext *c } std::any BuildTreeGenAstVisitor::visitIndexItem(CqasmParser::IndexItemContext *context) { - return One{ cqasm::tree::make( + return One{ tree::make( std::any_cast>(context->expression()->accept(this)) )}; } std::any BuildTreeGenAstVisitor::visitIndexRange(CqasmParser::IndexRangeContext *context) { - return One{ cqasm::tree::make( + return One{ tree::make( std::any_cast>(context->expression(0)->accept(this)), std::any_cast>(context->expression(1)->accept(this)) )}; @@ -334,22 +372,19 @@ std::any BuildTreeGenAstVisitor::visitUnaryPlusMinusExpression(CqasmParser::Unar return std::any_cast>(context->expression()->accept(this)); } auto ret = tree::make(std::any_cast>(context->expression()->accept(this))); - const auto token = context->MINUS()->getSymbol(); - setNodeAnnotation(ret, token); + setNodeAnnotation(ret, context->MINUS()->getSymbol()); return One{ ret }; } std::any BuildTreeGenAstVisitor::visitBitwiseNotExpression(CqasmParser::BitwiseNotExpressionContext *context) { auto ret = tree::make(std::any_cast>(context->expression()->accept(this))); - const auto token = context->BITWISE_NOT_OP()->getSymbol(); - setNodeAnnotation(ret, token); + setNodeAnnotation(ret, context->BITWISE_NOT_OP()->getSymbol()); return One{ ret }; } std::any BuildTreeGenAstVisitor::visitLogicalNotExpression(CqasmParser::LogicalNotExpressionContext *context) { auto ret = tree::make(std::any_cast>(context->expression()->accept(this))); - const auto token = context->LOGICAL_NOT_OP()->getSymbol(); - setNodeAnnotation(ret, token); + setNodeAnnotation(ret, context->LOGICAL_NOT_OP()->getSymbol()); return One{ ret }; } @@ -428,73 +463,68 @@ std::any BuildTreeGenAstVisitor::visitTernaryConditionalExpression(CqasmParser:: std::any_cast>(context->expression(1)->accept(this)), std::any_cast>(context->expression(2)->accept(this)) ); - const auto token = context->TERNARY_CONDITIONAL_OP()->getSymbol(); - setNodeAnnotation(ret, token); + setNodeAnnotation(ret, context->TERNARY_CONDITIONAL_OP()->getSymbol()); return One{ ret }; } std::any BuildTreeGenAstVisitor::visitFunctionCall(CqasmParser::FunctionCallContext *context) { auto ret = tree::make(); - ret->name = cqasm::tree::make(context->IDENTIFIER()->getText()); - ret->arguments = std::any_cast>(context->expressionList()->accept(this)); - const auto token = context->IDENTIFIER()->getSymbol(); - setNodeAnnotation(ret, token); + ret->name = tree::make(context->IDENTIFIER()->getText()); + ret->arguments = context->expressionList() + ? Maybe{ std::any_cast>(context->expressionList()->accept(this)).get_ptr() } + : Maybe{}; + setNodeAnnotation(ret, context->IDENTIFIER()->getSymbol()); return One{ ret }; } std::any BuildTreeGenAstVisitor::visitIndex(CqasmParser::IndexContext *context) { - auto ret = cqasm::tree::make(); - ret->expr = cqasm::tree::make(context->IDENTIFIER()->getText()); + auto ret = tree::make(); + ret->expr = tree::make(context->IDENTIFIER()->getText()); ret->indices = std::any_cast>(visitIndexList(context->indexList())); - const auto token = context->IDENTIFIER()->getSymbol(); - setNodeAnnotation(ret, token); + setNodeAnnotation(ret, context->IDENTIFIER()->getSymbol()); return One{ ret }; } std::any BuildTreeGenAstVisitor::visitIdentifier(CqasmParser::IdentifierContext *context) { - auto ret = cqasm::tree::make(context->IDENTIFIER()->getText()); - const auto token = context->IDENTIFIER()->getSymbol(); - setNodeAnnotation(ret, token); + auto ret = tree::make(context->IDENTIFIER()->getText()); + setNodeAnnotation(ret, context->IDENTIFIER()->getSymbol()); return One{ ret }; } std::any BuildTreeGenAstVisitor::visitAxisInitializationList(CqasmParser::AxisInitializationListContext *context) { - auto expression_list = cqasm::tree::make(); + auto expression_list = tree::make(); const auto &expressions = context->expression(); std::for_each(expressions.begin(), expressions.end(), [this, &expression_list](auto &expression_ctx) { expression_list->items.add(std::any_cast>(expression_ctx->accept(this))); }); - auto ret = cqasm::tree::make(expression_list); + auto ret = tree::make(expression_list); return One{ ret }; } std::any BuildTreeGenAstVisitor::visitInitializationList(CqasmParser::InitializationListContext *context) { - auto ret = cqasm::tree::make( + auto ret = tree::make( std::any_cast>(visitExpressionList(context->expressionList()))); return One{ ret }; } std::any BuildTreeGenAstVisitor::visitBooleanLiteral(CqasmParser::BooleanLiteralContext *context) { auto value = get_bool_value(context->BOOLEAN_LITERAL()); - auto ret = cqasm::tree::make(value); - const auto token = context->BOOLEAN_LITERAL()->getSymbol(); - setNodeAnnotation(ret, token); + auto ret = tree::make(value); + setNodeAnnotation(ret, context->BOOLEAN_LITERAL()->getSymbol()); return One{ ret }; } std::any BuildTreeGenAstVisitor::visitIntegerLiteral(CqasmParser::IntegerLiteralContext *context) { auto value = get_int_value(context->INTEGER_LITERAL()); - auto ret = cqasm::tree::make(value); - const auto token = context->INTEGER_LITERAL()->getSymbol(); - setNodeAnnotation(ret, token); + auto ret = tree::make(value); + setNodeAnnotation(ret, context->INTEGER_LITERAL()->getSymbol()); return One{ ret }; } std::any BuildTreeGenAstVisitor::visitFloatLiteral(CqasmParser::FloatLiteralContext *context) { auto value = get_float_value(context->FLOAT_LITERAL()); - auto ret = cqasm::tree::make(value); - const auto token = context->FLOAT_LITERAL()->getSymbol(); - setNodeAnnotation(ret, token); + auto ret = tree::make(value); + setNodeAnnotation(ret, context->FLOAT_LITERAL()->getSymbol()); return One{ ret }; } diff --git a/src/v3x/CMakeLists.txt b/src/v3x/CMakeLists.txt index 6627281fe..5fcf782b2 100644 --- a/src/v3x/CMakeLists.txt +++ b/src/v3x/CMakeLists.txt @@ -13,6 +13,7 @@ set(CQASM_V3X_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-primitives.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-py.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-resolver.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-scope.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-types.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-values.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm.cpp" diff --git a/src/v3x/CqasmLexer.g4 b/src/v3x/CqasmLexer.g4 index 910f0b22d..252faad8c 100644 --- a/src/v3x/CqasmLexer.g4 +++ b/src/v3x/CqasmLexer.g4 @@ -81,6 +81,7 @@ OPEN_PARENS: '('; CLOSE_PARENS: ')'; PLUS: '+'; // this token is shared by UNARY_PLUS_OP and PLUS_OP MINUS: '-'; // this token is shared by UNARY_MINUS_OP and MINUS_OP +ARROW: '->'; // Operators // UNARY_PLUS_OP: '+'; @@ -118,6 +119,8 @@ AXIS_TYPE: 'axis'; BOOL_TYPE: 'bool'; INT_TYPE: 'int'; FLOAT_TYPE: 'float'; +FUNCTION: 'def'; +RETURN: 'return'; // Numeric literals BOOLEAN_LITERAL: 'true' | 'false'; diff --git a/src/v3x/CqasmParser.g4 b/src/v3x/CqasmParser.g4 index 49a57c426..948ad8cf0 100644 --- a/src/v3x/CqasmParser.g4 +++ b/src/v3x/CqasmParser.g4 @@ -10,25 +10,73 @@ options { // The use of alternative labels simplifies the visitor classes // by removing the need to implement some methods, // which would otherwise contain boilerplate code (e.g. 'statement' and 'expression') -program: statementSeparator* version statements statementSeparator* EOF; + +program: statementSeparator* version globalBlock? statementSeparator* EOF; + +statementSeparator: NEW_LINE | SEMICOLON; version: VERSION VERSION_NUMBER; -statements: (statementSeparator+ statement)*; +globalBlock: (statementSeparator+ globalBlockStatement)+; -statementSeparator: NEW_LINE | SEMICOLON; +globalBlockStatement: + localBlockStatement + | functionDeclaration + ; + +// Current implementation of the semantic parser will only allow function call expressions as expression statements +// Notice expression statements are checked for before instructions +// This way, code like h(q[0]) is parsed as a function call to a function h with a q[0] parameter +// And not like a gate h with a (q[0]) expression +localBlockStatement: + variableDeclaration + | assignmentStatement + | returnStatement + | expressionStatement + | instruction + ; + +variableDeclaration: + variableDefinition + | variableInitialization + ; + +assignmentStatement: expression EQUALS expression; + +returnStatement: RETURN expression; -statement: - QUBIT_TYPE arraySizeDeclaration? IDENTIFIER # qubitTypeDeclaration - | BIT_TYPE arraySizeDeclaration? IDENTIFIER # bitTypeDeclaration - | AXIS_TYPE IDENTIFIER (EQUALS expression)? # axisTypeDeclaration - | BOOL_TYPE arraySizeDeclaration? IDENTIFIER (EQUALS expression)? # boolTypeDeclaration - | INT_TYPE arraySizeDeclaration? IDENTIFIER (EQUALS expression)? # intTypeDeclaration - | FLOAT_TYPE arraySizeDeclaration? IDENTIFIER (EQUALS expression)? # floatTypeDeclaration - | expression EQUALS MEASURE expression # measureInstruction - | IDENTIFIER expressionList # instruction +expressionStatement: expression; + +instruction: + expression EQUALS MEASURE expression # measureInstruction + | IDENTIFIER expressionList # gate + ; + +functionDeclaration: FUNCTION IDENTIFIER OPEN_PARENS parameters? CLOSE_PARENS (ARROW type)? + OPEN_BRACE localBlock? statementSeparator* CLOSE_BRACE; + +parameters: variableDefinition (statementSeparator* COMMA statementSeparator* variableDefinition)*; + +type: quantumType | classicalType; + +quantumType: + QUBIT_TYPE arraySizeDeclaration? # qubitType + | BIT_TYPE arraySizeDeclaration? # bitType ; +classicalType: + AXIS_TYPE # axisType + | BOOL_TYPE arraySizeDeclaration? # boolType + | INT_TYPE arraySizeDeclaration? # intType + | FLOAT_TYPE arraySizeDeclaration? # floatType + ; + +localBlock: (statementSeparator+ localBlockStatement)+; + +variableDefinition: type IDENTIFIER; + +variableInitialization: classicalType IDENTIFIER EQUALS expression; + arraySizeDeclaration: OPEN_BRACKET INTEGER_LITERAL CLOSE_BRACKET; expressionList: expression (COMMA expression)*; @@ -42,6 +90,8 @@ indexEntry: | expression COLON expression # indexRange ; +// Current implementation of the semantic parser will expect constants +// for all the expressions of the arithmetic operators expression: OPEN_PARENS expression CLOSE_PARENS # parensExpression | (PLUS | MINUS) expression # unaryPlusMinusExpression diff --git a/src/v3x/CustomErrorListener.cpp b/src/v3x/CustomErrorListener.cpp index 9d6153334..9ae1709d1 100644 --- a/src/v3x/CustomErrorListener.cpp +++ b/src/v3x/CustomErrorListener.cpp @@ -1,3 +1,4 @@ +#include "cqasm-annotations.hpp" #include "cqasm-error.hpp" #include "v3x/CustomErrorListener.hpp" @@ -8,8 +9,7 @@ namespace cqasm::v3x::parser { CustomErrorListener::CustomErrorListener(const std::optional &file_name) -: file_name_{ file_name } -{ +: file_name_{ file_name } { if (file_name_.has_value() && file_name_.value().empty()) { file_name_ = std::nullopt; } @@ -24,13 +24,14 @@ void CustomErrorListener::syntaxError( // ANTLR provides a zero-based character position in line // We change it here to a one-based index, which is the more human-readable, and the common option in text editors + auto token_size = offendingSymbol + ? offendingSymbol->getText().size() + : 0; throw error::ParseError{ msg, file_name_, - static_cast(line), - static_cast(charPositionInLine + 1), - static_cast(line), - static_cast(charPositionInLine + 1 + (offendingSymbol ? offendingSymbol->getText().size() : 0)) + { { static_cast(line), static_cast(charPositionInLine + 1) }, + { static_cast(line), static_cast(charPositionInLine + 1 + token_size) } } }; } diff --git a/src/v3x/cqasm-analyzer.cpp b/src/v3x/cqasm-analyzer.cpp index 5e981d9de..ddecac7af 100644 --- a/src/v3x/cqasm-analyzer.cpp +++ b/src/v3x/cqasm-analyzer.cpp @@ -2,6 +2,7 @@ * Implementation for \ref include/v3x/cqasm-analyzer.hpp "v3x/cqasm-analyzer.hpp". */ +#include "cqasm-error.hpp" #include "v3x/AnalyzeTreeGenAstVisitor.hpp" #include "v3x/cqasm-analyzer.hpp" #include "v3x/cqasm-functions.hpp" @@ -17,36 +18,50 @@ namespace cqasm::v3x::analyzer { /** * Creates a new semantic analyzer. + * Creates a global scope. */ Analyzer::Analyzer(const primitives::Version &api_version) : api_version{ api_version } -, instruction_set{} { +, scope_stack_{ Scope{} } +{ if (api_version != "3.0") { throw std::invalid_argument{ "this analyzer only supports cQASM 3.0" }; } + global_scope().block = tree::make(); } +[[nodiscard]] Scope &Analyzer::global_scope() { return scope_stack_.back(); } +[[nodiscard]] Scope &Analyzer::current_scope() { return scope_stack_.front(); } +[[nodiscard]] tree::One Analyzer::current_block() { return current_scope().block; } +[[nodiscard]] tree::Any &Analyzer::current_variables() { return current_scope().variables; } +[[nodiscard]] tree::Any &Analyzer::global_functions() { return global_scope().functions; } + +[[nodiscard]] const Scope &Analyzer::global_scope() const { return scope_stack_.back(); } +[[nodiscard]] const Scope &Analyzer::current_scope() const { return scope_stack_.front(); } +[[nodiscard]] const tree::Any &Analyzer::current_variables() const { return current_scope().variables; } +[[nodiscard]] const tree::Any &Analyzer::global_functions() const { return global_scope().functions; } + /** * Registers mappings for pi, eu (aka e, 2.718...), tau and im (imaginary unit). */ void Analyzer::register_default_mappings() { static constexpr double tau = 2 * std::numbers::pi; - register_mapping("x", tree::make(primitives::Axis{ 1, 0, 0 })); - register_mapping("y", tree::make(primitives::Axis{ 0, 1, 0 })); - register_mapping("z", tree::make(primitives::Axis{ 0, 0, 1 })); - register_mapping("true", tree::make(true)); - register_mapping("false", tree::make(false)); - register_mapping("pi", tree::make(std::numbers::pi)); - register_mapping("eu", tree::make(std::numbers::e)); - register_mapping("tau", tree::make(tau)); - register_mapping("im", tree::make(primitives::Complex(0.0, 1.0))); + register_variable("x", tree::make(primitives::Axis{ 1, 0, 0 })); + register_variable("y", tree::make(primitives::Axis{ 0, 1, 0 })); + register_variable("z", tree::make(primitives::Axis{ 0, 0, 1 })); + register_variable("true", tree::make(true)); + register_variable("false", tree::make(false)); + register_variable("pi", tree::make(std::numbers::pi)); + register_variable("eu", tree::make(std::numbers::e)); + register_variable("tau", tree::make(tau)); + register_variable("im", tree::make(primitives::Complex(0.0, 1.0))); } /** * Registers a number of default functions, such as the operator functions, and the usual trigonometric functions. */ void Analyzer::register_default_functions() { - cqasm::v3x::functions::register_default_functions_into(functions); + functions::register_default_function_impls_into(global_scope().function_impl_table); } /** @@ -73,9 +88,8 @@ AnalysisResult Analyzer::analyze(parser::ParseResult &&parse_result) { AnalysisResult result; result.errors = std::move(parse_result.errors); return result; - } else { - return analyze(*parse_result.root->as_program()); } + return analyze(*parse_result.root->as_program()); } /** @@ -121,79 +135,171 @@ AnalysisResult Analyzer::analyze_string(const std::string &data, const std::opti } /** - * Resolves a mapping. - * Throws NameResolutionFailure if no mapping by the given name exists. + * Pushes a new empty scope to the top of the scope stack. + */ +void Analyzer::push_scope() { + scope_stack_.emplace_front(); + current_scope().block = tree::make(); +} + +/** + * Pops a scope from the top of the scope stack. + */ +void Analyzer::pop_scope() { + scope_stack_.pop_front(); +} + +/** + * Adds a statement to the current scope. + */ +void Analyzer::add_statement_to_current_scope(const tree::One &statement) { + if (current_block().empty()) { + throw error::AnalysisError{ "trying to add a statement but current block is empty" }; + } + + // Add the statement to the current block + current_block()->statements.add(statement); + + // Expand the source location annotation of the block to include the statement + if (auto statement_sl = statement->get_annotation_ptr()) { + if (auto block_sl = current_block()->get_annotation_ptr()) { + block_sl->expand_to_include(statement_sl->range.first); + block_sl->expand_to_include(statement_sl->range.last); + } else { + current_block()->set_annotation(*statement_sl); + } + } +} + +/** + * Adds a variable to the current scope. */ -values::Value Analyzer::resolve_mapping(const std::string &name) const { - return mappings.resolve(name); +void Analyzer::add_variable_to_current_scope(const tree::One &variable) { + current_variables().add(variable); } /** - * Registers a mapping. + * Adds a function to the global scope. */ -void Analyzer::register_mapping(const std::string &name, const values::Value &value) { - mappings.add(name, value); +void Analyzer::add_function_to_global_scope(const tree::One &function) { + global_functions().add(function); } /** - * Calls a function. + * Resolves a variable. + * Throws NameResolutionFailure if no variable by the given name exists. + */ +values::Value Analyzer::resolve_variable(const std::string &name) const { + for (const auto &scope : scope_stack_) { + try { + return scope.variable_table.resolve(name); + } catch (const error::AnalysisError &) { + continue; + } + } + throw resolver::NameResolutionFailure{ fmt::format("failed to resolve variable '{}'", name) }; +} + +/** + * Registers a variable. + */ +void Analyzer::register_variable(const std::string &name, const values::Value &value) { + current_scope().variable_table.add(name, value); +} + +/** + * Resolves a function implementation. * Throws NameResolutionFailure if no function by the given name exists, - * OverloadResolutionFailure if no overload of the function exists for the given arguments, or otherwise - * returns the value returned by the function. + * OverloadResolutionFailure if no overload of the function exists for the given arguments, + * or otherwise returns the value returned by the function. */ -values::Value Analyzer::call_function(const std::string &name, const values::Values &args) const { - return functions.call(name, args); +values::Value Analyzer::resolve_function_impl(const std::string &name, const values::Values &args) const { + return global_scope().function_impl_table.resolve(name, args); } /** - * Registers a function, usable within expressions. + * Resolves a function. + * Tries to call a function implementation first. + * If it doesn't succeed, tries to call a function. + * Throws NameResolutionFailure if no function by the given name exists, + * OverloadResolutionFailure if no overload of the function exists for the given arguments, + * or otherwise returns the value returned by the function. */ -void Analyzer::register_function( +values::Value Analyzer::resolve_function(const std::string &name, const values::Values &args) const { + try { + return global_scope().function_impl_table.resolve(name, args); + } catch (const error::AnalysisError &) {} + return global_scope().function_table.resolve(name, args); +} + +/** + * Registers a function implementation, usable within expressions. + */ +void Analyzer::register_function_impl( const std::string &name, const types::Types ¶m_types, - const resolver::FunctionImpl &impl -) { - functions.add(name, param_types, impl); + const resolver::FunctionImpl &impl) { + + global_scope().function_impl_table.add(name, param_types, impl); } /** - * Convenience method for registering a function. + * Convenience method for registering a function implementation. * The param_types are specified as a string, * converted to types::Types for the other overload using types::from_spec. */ -void Analyzer::register_function( +void Analyzer::register_function_impl( const std::string &name, const std::string ¶m_types, - const resolver::FunctionImpl &impl -) { - functions.add(name, types::from_spec(param_types), impl); + const resolver::FunctionImpl &impl) { + + global_scope().function_impl_table.add(name, types::from_spec(param_types), impl); +} + +/** + * Convenience method for registering a function. + */ +void Analyzer::register_function( + const std::string &name, + const types::Types ¶m_types, + const values::Value &value) { + + global_scope().function_table.add(name, param_types, value); } /** * Resolves an instruction. * Throws NameResolutionFailure if no instruction by the given name exists, - * OverloadResolutionFailure if no overload exists for the given arguments, or otherwise - * returns the resolved instruction node. + * OverloadResolutionFailure if no overload exists for the given arguments, + * or otherwise returns the resolved instruction node. * Annotation data, line number information, and the condition still need to be set by the caller. */ [[nodiscard]] tree::One Analyzer::resolve_instruction( const std::string &name, const values::Values &args) const { - return instruction_set.resolve(name, args); + for (const auto &scope : scope_stack_) { + try { + return scope.instruction_table.resolve(name, args); + } catch (const error::AnalysisError &) { + continue; + } + } + throw resolver::ResolutionFailure{ + fmt::format("failed to resolve instruction '{}' with argument pack {}", name, values::types_of(args)) }; } /** * Registers an instruction type. */ void Analyzer::register_instruction(const instruction::Instruction &instruction) { - instruction_set.add(instruction); + current_scope().instruction_table.add(instruction); } /** - * Convenience method for registering an instruction type. The arguments - * are passed straight to instruction::Instruction's constructor. + * Convenience method for registering an instruction type. + * The arguments are passed straight to instruction::Instruction's constructor. */ -void Analyzer::register_instruction(const std::string &name, const std::string ¶m_types) { +void Analyzer::register_instruction(const std::string &name, const std::optional ¶m_types) { register_instruction(instruction::Instruction(name, param_types)); } diff --git a/src/v3x/cqasm-ast.tree b/src/v3x/cqasm-ast.tree index be93fa4d8..b08df5975 100644 --- a/src/v3x/cqasm-ast.tree +++ b/src/v3x/cqasm-ast.tree @@ -57,7 +57,7 @@ expression { } float_literal { - value: cqasm::v3x::primitives::Real; + value: cqasm::v3x::primitives::Float; } index { @@ -75,7 +75,7 @@ expression { function_call { name: One; - arguments: One; + arguments: Maybe; } unary_expression { @@ -157,64 +157,89 @@ annotation_data { operands: One; } +type { + name: One; + size: Maybe; +} + # Represents a node that carries annotation data annotated { # Zero or more annotations attached to this object. annotations: Any; statement { - # One variable declaration of some type. - variable { - name: One; - typ: One; - size: Maybe; - } + block_statement { + # One variable declaration of some type. + variable { + name: One; + typ: One; + } - # An initialization is a variable declaration plus an assignment instruction. - initialization { - var: One; - rhs: One; - } + # An initialization is a variable declaration plus an assignment instruction. + initialization { + var: One; + rhs: One; + } - instruction_base { - # A gate. instruction { - name: One; - condition: Maybe; - operands: One; + gate { + name: One; + operands: One; + } + + # For some instructions, like the measure instruction, + # we want to differentiate between left hand side and right and side operands. + # For a measure instruction, the right hand side operand should be a qubit, + # and the left hand side operand a bit. + measure_instruction { + name: One; + lhs: One; + rhs: One; + } } - assignment_instruction { - condition: Maybe; + assignment_statement { lhs: One; rhs: One; } - # For some instructions, like the measure instruction, - # we want to differentiate between left hand side and right and side operands. - # For a measure instruction, the right hand side operand should be a qubit, - # and the left hand side operand a bit. - measure_instruction { - name: One; - condition: Maybe; - lhs: One; - rhs: One; + return_statement { + return_value: One; + } + + expression_statement { + expression: One; } } - } -} -statement_list { - items: Any; + # Parameters will actually be a list of variables + # But that is already enforced at the grammar level + function { + name: One; + parameters: One; + return_type: Maybe; + block: One; + } + } } version { items: cqasm::v3x::primitives::Version; } +block { + global_block { + statements: Any; + } + + local_block { + statements: Any; + } +} + root { program { version: One; - statements: One; + block: One; } } diff --git a/src/v3x/cqasm-functions.cpp b/src/v3x/cqasm-functions.cpp index 2a37032fb..e719dd6c8 100644 --- a/src/v3x/cqasm-functions.cpp +++ b/src/v3x/cqasm-functions.cpp @@ -3,31 +3,31 @@ namespace cqasm::v3x::functions { /** - * Registers a bunch of functions usable during constant propagation into the given function table. + * Registers a bunch of functions for which we have a C++ implementation into the given function table. */ -void register_default_functions_into(resolver::FunctionTable &table) { - table.add("operator-", types::from_spec("r"), op_neg_r); +void register_default_function_impls_into(resolver::FunctionImplTable &table) { + table.add("operator-", types::from_spec("f"), op_neg_f); table.add("operator-", types::from_spec("i"), op_neg_i); - table.add("operator+", types::from_spec("rr"), op_add_rr); + table.add("operator+", types::from_spec("ff"), op_add_ff); table.add("operator+", types::from_spec("ii"), op_add_ii); - table.add("operator-", types::from_spec("rr"), op_sub_rr); + table.add("operator-", types::from_spec("ff"), op_sub_ff); table.add("operator-", types::from_spec("ii"), op_sub_ii); - table.add("operator*", types::from_spec("rr"), op_mul_rr); + table.add("operator*", types::from_spec("ff"), op_mul_ff); table.add("operator*", types::from_spec("ii"), op_mul_ii); - table.add("operator/", types::from_spec("rr"), op_div_rr); + table.add("operator/", types::from_spec("ff"), op_div_ff); table.add("operator/", types::from_spec("ii"), op_div_ii); table.add("operator%", types::from_spec("ii"), op_mod_ii); - table.add("operator**", types::from_spec("rr"), op_pow_rr); + table.add("operator**", types::from_spec("ff"), op_pow_ff); - table.add("operator==", types::from_spec("rr"), op_eq_rr); - table.add("operator!=", types::from_spec("rr"), op_ne_rr); - table.add("operator>=", types::from_spec("rr"), op_ge_rr); - table.add("operator>", types::from_spec("rr"), op_gt_rr); - table.add("operator<=", types::from_spec("rr"), op_le_rr); - table.add("operator<", types::from_spec("rr"), op_lt_rr); + table.add("operator==", types::from_spec("ff"), op_eq_ff); + table.add("operator!=", types::from_spec("ff"), op_ne_ff); + table.add("operator>=", types::from_spec("ff"), op_ge_ff); + table.add("operator>", types::from_spec("ff"), op_gt_ff); + table.add("operator<=", types::from_spec("ff"), op_le_ff); + table.add("operator<", types::from_spec("ff"), op_lt_ff); table.add("operator==", types::from_spec("ii"), op_eq_ii); table.add("operator!=", types::from_spec("ii"), op_ne_ii); @@ -56,26 +56,26 @@ void register_default_functions_into(resolver::FunctionTable &table) { table.add("operator^^", types::from_spec("bb"), op_lxor_bb); table.add("operator||", types::from_spec("bb"), op_lor_bb); - table.add("operator?:", types::from_spec("brr"), op_tcnd_brr); + table.add("operator?:", types::from_spec("bff"), op_tcnd_bff); table.add("operator?:", types::from_spec("bii"), op_tcnd_bii); table.add("operator?:", types::from_spec("bbb"), op_tcnd_bbb); - table.add("sqrt", types::from_spec("r"), fn_sqrt_r); - table.add("exp", types::from_spec("r"), fn_exp_r); - table.add("log", types::from_spec("r"), fn_log_r); - table.add("sin", types::from_spec("r"), fn_sin_r); - table.add("cos", types::from_spec("r"), fn_cos_r); - table.add("tan", types::from_spec("r"), fn_tan_r); - table.add("sinh", types::from_spec("r"), fn_sinh_r); - table.add("cosh", types::from_spec("r"), fn_cosh_r); - table.add("tanh", types::from_spec("r"), fn_tanh_r); - table.add("asin", types::from_spec("r"), fn_asin_r); - table.add("acos", types::from_spec("r"), fn_acos_r); - table.add("atan", types::from_spec("r"), fn_atan_r); - table.add("asinh", types::from_spec("r"), fn_asinh_r); - table.add("acosh", types::from_spec("r"), fn_acosh_r); - table.add("atanh", types::from_spec("r"), fn_atanh_r); - table.add("abs", types::from_spec("r"), fn_abs_r); + table.add("sqrt", types::from_spec("f"), fn_sqrt_f); + table.add("exp", types::from_spec("f"), fn_exp_f); + table.add("log", types::from_spec("f"), fn_log_f); + table.add("sin", types::from_spec("f"), fn_sin_f); + table.add("cos", types::from_spec("f"), fn_cos_f); + table.add("tan", types::from_spec("f"), fn_tan_f); + table.add("sinh", types::from_spec("f"), fn_sinh_f); + table.add("cosh", types::from_spec("f"), fn_cosh_f); + table.add("tanh", types::from_spec("f"), fn_tanh_f); + table.add("asin", types::from_spec("f"), fn_asin_f); + table.add("acos", types::from_spec("f"), fn_acos_f); + table.add("atan", types::from_spec("f"), fn_atan_f); + table.add("asinh", types::from_spec("f"), fn_asinh_f); + table.add("acosh", types::from_spec("f"), fn_acosh_f); + table.add("atanh", types::from_spec("f"), fn_atanh_f); + table.add("abs", types::from_spec("f"), fn_abs_f); table.add("abs", types::from_spec("i"), fn_abs_i); } diff --git a/src/v3x/cqasm-instruction.cpp b/src/v3x/cqasm-instruction.cpp index f45e18aa2..0f800dd08 100644 --- a/src/v3x/cqasm-instruction.cpp +++ b/src/v3x/cqasm-instruction.cpp @@ -15,9 +15,9 @@ namespace instruction { * param_types is a shorthand type specification string as parsed by cqasm::types::from_spec(). * If you need more control, you can also manipulate param_types directly. */ -Instruction::Instruction(const std::string &name, const std::string ¶m_types) -: name{ name } -, param_types{ types::from_spec(param_types) } +Instruction::Instruction(std::string name, const std::optional ¶m_types) +: name{ std::move(name) } +, param_types{ types::from_spec(param_types.value_or("")) } {} /** @@ -30,17 +30,15 @@ bool Instruction::operator==(const Instruction& rhs) const { /** * Stream << overload for instructions. */ -std::ostream &operator<<(std::ostream &os, const Instruction &insn) { - return os << insn.name << insn.param_types; +std::ostream &operator<<(std::ostream &os, const Instruction &instruction) { + return os << instruction.name << instruction.param_types; } /** * Stream << overload for instruction references. */ -std::ostream &operator<<(std::ostream &os, const InstructionRef &insn) { - return insn.empty() - ? os << "unresolved" - : os << *insn; +std::ostream &operator<<(std::ostream &os, const InstructionRef &instruction) { + return instruction.empty() ? os << "unresolved" : os << *instruction; } } // namespace instruction @@ -56,7 +54,7 @@ void serialize(const instruction::InstructionRef &obj, ::tree::cbor::MapWriter & map.append_string("n", obj->name); auto aw = map.append_array("t"); for (const auto &t : obj->param_types) { - aw.append_binary(::tree::base::serialize(t)); + aw.append_binary(::tree::base::serialize(::tree::base::Maybe{ t.get_ptr() })); } aw.close(); } @@ -66,12 +64,12 @@ instruction::InstructionRef deserialize(const ::tree::cbor::MapReader &map) { if (!map.count("n")) { return {}; } - auto insn = tree::make(map.at("n").as_string(), ""); + auto instruction = tree::make(map.at("n").as_string(), ""); auto ar = map.at("t").as_array(); for (const auto &element : ar) { - insn->param_types.add(::tree::base::deserialize(element.as_binary())); + instruction->param_types.add(::tree::base::deserialize(element.as_binary())); } - return insn; + return instruction; } } // namespace primitives diff --git a/src/v3x/cqasm-primitives.cpp b/src/v3x/cqasm-primitives.cpp index 77c931e17..fe9419e65 100644 --- a/src/v3x/cqasm-primitives.cpp +++ b/src/v3x/cqasm-primitives.cpp @@ -77,18 +77,18 @@ Int deserialize(const ::tree::cbor::MapReader &map) { } /** - * Real + * Float */ template <> -Real initialize() { return 0.0; } +Float initialize() { return 0.0; } template <> -void serialize(const Real &obj, ::tree::cbor::MapWriter &map) { +void serialize(const Float &obj, ::tree::cbor::MapWriter &map) { map.append_float("x", obj); } template <> -Real deserialize(const ::tree::cbor::MapReader &map) { +Float deserialize(const ::tree::cbor::MapReader &map) { return map.at("x").as_float(); } diff --git a/src/v3x/cqasm-resolver.cpp b/src/v3x/cqasm-resolver.cpp index ae97a2b81..cdb72716f 100644 --- a/src/v3x/cqasm-resolver.cpp +++ b/src/v3x/cqasm-resolver.cpp @@ -18,48 +18,48 @@ using Types = types::Types; using Value = values::Value; using Values = values::Values; + +//---------------// +// VariableTable // +//---------------// + /** - * Adds a mapping. + * Adds a variable. */ -void MappingTable::add(const std::string &name, const Value &value) { - if (auto it = table.find(name); it != table.end()) { - table.erase(it); - } +void VariableTable::add(const std::string &name, const Value &value) { + table.erase(name); table.insert(std::make_pair(name, value)); } /** - * Resolves a mapping. - * Throws NameResolutionFailure if no mapping by the given name exists. + * Resolves a variable. + * Throws NameResolutionFailure if no variable by the given name exists. */ -Value MappingTable::resolve(const std::string &name) const { - if (auto entry = table.find(name); entry == table.end()) { - throw NameResolutionFailure{ fmt::format("failed to resolve mapping '{}'", name) }; - } else { - return Value(entry->second->clone()); +Value VariableTable::resolve(const std::string &name) const { + if (auto entry = table.find(name); entry != table.end()) { + return entry->second->clone(); } + throw NameResolutionFailure{ fmt::format("failed to resolve variable '{}'", name) }; } -/** - * Grants read access to the underlying map. - */ -const std::unordered_map &MappingTable::get_table() const { - return table; -} -FunctionTable::FunctionTable() +//-------------------// +// FunctionImplTable // +//-------------------// + +FunctionImplTable::FunctionImplTable() : resolver(std::make_unique>()) {} -FunctionTable::~FunctionTable() = default; -FunctionTable::FunctionTable(const FunctionTable& t) +FunctionImplTable::~FunctionImplTable() = default; +FunctionImplTable::FunctionImplTable(const FunctionImplTable& t) : resolver(std::make_unique>(*t.resolver)) {} -FunctionTable::FunctionTable(FunctionTable&& t) noexcept +FunctionImplTable::FunctionImplTable(FunctionImplTable&& t) noexcept : resolver(std::move(t.resolver)) {} -FunctionTable& FunctionTable::operator=(const FunctionTable& t) { +FunctionImplTable& FunctionImplTable::operator=(const FunctionImplTable& t) { resolver = std::make_unique>( OverloadedNameResolver(*t.resolver)); return *this; } -FunctionTable& FunctionTable::operator=(FunctionTable&& t) noexcept { +FunctionImplTable& FunctionImplTable::operator=(FunctionImplTable&& t) noexcept { resolver = std::move(t.resolver); return *this; } @@ -67,7 +67,7 @@ FunctionTable& FunctionTable::operator=(FunctionTable&& t) noexcept { /** * Registers a function. * The param_types variadic specifies the amount and types of the parameters that - * (this particular overload of) the function expects. + * this particular overload of the function expects. * The C++ implementation of the function can assume that * the value list it gets is of the right size and the values are of the right types. * @@ -75,17 +75,17 @@ FunctionTable& FunctionTable::operator=(FunctionTable&& t) noexcept { * However, the overload resolution engine will always use the last applicable overload it finds, * so adding does have the effect of overriding. */ -void FunctionTable::add(const std::string &name, const Types ¶m_types, const FunctionImpl &impl) { +void FunctionImplTable::add(const std::string &name, const Types ¶m_types, const FunctionImpl &impl) { resolver->add_overload(name, impl, param_types); } /** - * Calls a function. + * Resolves a function. * Throws NameResolutionFailure if no function by the given name exists, * OverloadResolutionFailure if no overload of the function exists for the given arguments, or otherwise * returns the value returned by the function. */ -Value FunctionTable::call(const std::string &name, const Values &args) const { +Value FunctionImplTable::resolve(const std::string &name, const Values &args) const { // Resolve the function and type-check/promote the argument list. auto resolution = resolver->resolve(name, args); @@ -93,6 +93,61 @@ Value FunctionTable::call(const std::string &name, const Values &args) const { return resolution.first(resolution.second); } + +//---------------// +// FunctionTable // +//---------------// + +FunctionTable::FunctionTable() +: resolver(std::make_unique>()) {} +FunctionTable::~FunctionTable() = default; +FunctionTable::FunctionTable(const FunctionTable& t) +: resolver(std::make_unique>(*t.resolver)) {} +FunctionTable::FunctionTable(FunctionTable&& t) noexcept +: resolver(std::move(t.resolver)) {} +FunctionTable& FunctionTable::operator=(const FunctionTable& t) { + resolver = std::make_unique>( + OverloadedNameResolver(*t.resolver)); + return *this; +} +FunctionTable& FunctionTable::operator=(FunctionTable&& t) noexcept { + resolver = std::move(t.resolver); + return *this; +} + +/** + * Registers a function. + * The param_types variadic specifies the amount and types of the parameters that + * this particular overload of the function expects. + * value should be of type values::FunctionRef. + * + * This method does not contain any intelligence to override previously added overloads. + * However, the overload resolution engine will always use the last applicable overload it finds, + * so adding does have the effect of overriding. + */ +void FunctionTable::add(const std::string &name, const Types ¶m_types, const values::Value &value) { + resolver->add_overload(name, value, param_types); +} + +/** + * Resolves a function. + * Throws NameResolutionFailure if no function by the given name exists, + * OverloadResolutionFailure if no overload of the function exists for the given arguments, or otherwise + * returns the value returned by the function. + */ +Value FunctionTable::resolve(const std::string &name, const Values &args) const { + // Resolve the function and type-check/promote the argument list. + auto [function_ref, promoted_args] = resolver->resolve(name, args); + + // Call the function with the type-checked/promoted argument list, and return its result. + return tree::make(function_ref, promoted_args); +} + + +//------------------// +// InstructionTable // +//------------------// + InstructionTable::InstructionTable() : resolver(std::make_unique>()) {} InstructionTable::~InstructionTable() = default; diff --git a/src/v3x/cqasm-scope.cpp b/src/v3x/cqasm-scope.cpp new file mode 100644 index 000000000..dbe12c2ce --- /dev/null +++ b/src/v3x/cqasm-scope.cpp @@ -0,0 +1,22 @@ +#include "v3x/cqasm-scope.hpp" + + +namespace cqasm::v3x::analyzer { + +/** + * Creates a scope from a table of variables, functions, and instructions. + */ +Scope::Scope( + resolver::VariableTable variable_table, + resolver::FunctionImplTable function_impl_table, + resolver::FunctionTable function_table, + resolver::InstructionTable instruction_table, + tree::One block) +: variable_table{ std::move(variable_table) } +, function_impl_table{ std::move(function_impl_table) } +, function_table{ std::move(function_table) } +, instruction_table{ std::move(instruction_table) } +, block{ std::move(block) } +{} + +} // namespace cqasm::v3x::analyzer diff --git a/src/v3x/cqasm-semantic.tree b/src/v3x/cqasm-semantic.tree index c208b2198..4fdf9db4f 100644 --- a/src/v3x/cqasm-semantic.tree +++ b/src/v3x/cqasm-semantic.tree @@ -47,36 +47,37 @@ annotated { annotations: Any; statement { - instruction_base { - # Condition (C- notation). - # When there is no condition, this is a constant boolean set to true. - condition: external One; - - # A regular instruction (gate). - instruction { - # Instruction type as registered through the API. - instruction: cqasm::v3x::instruction::InstructionRef; - - # Name as it appears in the cQASM file. - name: cqasm::v3x::primitives::Str; - - # Operands for the instruction. - operands: external Any; - } - - assignment_instruction { - # The assignment target. - lhs: external One; - - # The value to assign. - rhs: external One; - } + # A regular instruction (a gate, or a measure instruction). + instruction { + instruction: cqasm::v3x::instruction::InstructionRef; + name: cqasm::v3x::primitives::Str; + operands: external Any; + } + + assignment_statement { + lhs: external One; + rhs: external One; + } + + return_statement { + return_value: external One; + } + + function_call_statement { + return_value: external Maybe; } } variable { name: cqasm::v3x::primitives::Str; - typ: external One; + typ: external One; + } + + function { + name: cqasm::v3x::primitives::Str; + return_type: external Maybe; + block: One; + variables: Any; } } @@ -84,6 +85,10 @@ version { items: cqasm::v3x::primitives::Version; } +block { + statements: Any; +} + program { # API version. # This may be greater than or equal to the file version. @@ -93,8 +98,11 @@ program { # File version. version: One; - # The list of statements. - statements: Any; + # The global scope block. + block: One; + + # The list of functions. + functions: Any; # The list of variables. variables: Any; diff --git a/src/v3x/cqasm-types.cpp b/src/v3x/cqasm-types.cpp index d29df295d..d3740482d 100644 --- a/src/v3x/cqasm-types.cpp +++ b/src/v3x/cqasm-types.cpp @@ -18,13 +18,13 @@ namespace cqasm::v3x::types { * - a = axis (x, y, and z vectors) * - b = bool * - i = int - * - r = real + * - f = float * - c = complex * - V = qubit array * - W = bit array * - X = bool array * - Y = int array - * - Z = real array + * - Z = float array */ Types from_spec(const std::string &spec) { Types types; @@ -35,13 +35,13 @@ Types from_spec(const std::string &spec) { case 'a': types.add_raw(new types::Axis()); break; case 'b': types.add_raw(new types::Bool()); break; case 'i': types.add_raw(new types::Int()); break; - case 'r': types.add_raw(new types::Real()); break; + case 'f': types.add_raw(new types::Float()); break; case 'c': types.add_raw(new types::Complex()); break; case 'V': types.add_raw(new types::QubitArray()); break; case 'W': types.add_raw(new types::BitArray()); break; case 'X': types.add_raw(new types::BoolArray()); break; case 'Y': types.add_raw(new types::IntArray()); break; - case 'Z': types.add_raw(new types::RealArray()); break; + case 'Z': types.add_raw(new types::FloatArray()); break; default: throw std::invalid_argument("unknown type code encountered"); } } @@ -67,18 +67,18 @@ primitives::Int size_of(const Type &type) { */ std::ostream &operator<<(std::ostream &os, const Type &type) { if (type.empty()) { os << "!EMPTY"; } - else if (type->as_qubit()) { os << "qubit"; } - else if (type->as_bit()) { os << "bit"; } - else if (type->as_axis()) { os << "axis"; } - else if (type->as_bool()) { os << "bool"; } - else if (type->as_int()) { os << "int"; } - else if (type->as_real()) { os << "real"; } - else if (type->as_complex()) { os << "complex"; } - else if (type->as_qubit_array()) { os << "qubit array"; } - else if (type->as_bit_array()) { os << "bit array"; } - else if (type->as_bool_array()) { os << "bool array"; } - else if (type->as_int_array()) { os << "int array"; } - else if (type->as_real_array()) { os << "real array"; } + else if (type->as_qubit()) { os << types::qubit_type_name; } + else if (type->as_bit()) { os << types::bit_type_name; } + else if (type->as_axis()) { os << types::axis_type_name; } + else if (type->as_bool()) { os << types::bool_type_name; } + else if (type->as_int()) { os << types::integer_type_name; } + else if (type->as_float()) { os << types::float_type_name; } + else if (type->as_complex()) { os << types::complex_type_name; } + else if (type->as_qubit_array()) { os << types::qubit_array_type_name; } + else if (type->as_bit_array()) { os << types::bit_array_type_name; } + else if (type->as_bool_array()) { os << types::bool_array_type_name; } + else if (type->as_int_array()) { os << types::integer_array_type_name; } + else if (type->as_float_array()) { os << types::float_array_type_name; } else { // Fallback when no friendly repr is known return os << *type; diff --git a/src/v3x/cqasm-types.tree b/src/v3x/cqasm-types.tree index 2de2c5be7..1835f4dd1 100644 --- a/src/v3x/cqasm-types.tree +++ b/src/v3x/cqasm-types.tree @@ -34,8 +34,8 @@ type_base { # Type of an integer (signed 64-bit). int {} - # Type of a real number (IEEE double). - real {} + # Type of a float number (IEEE double). + float {} # Type of a complex number (2x IEEE double). complex {} @@ -45,7 +45,7 @@ type_base { bool_array {} int_array {} - real_array {} + float_array {} bit_array {} qubit_array {} } diff --git a/src/v3x/cqasm-values.cpp b/src/v3x/cqasm-values.cpp index 26ccf908d..e71bbb060 100644 --- a/src/v3x/cqasm-values.cpp +++ b/src/v3x/cqasm-values.cpp @@ -8,7 +8,6 @@ #include "v3x/cqasm-types.hpp" #include "v3x/cqasm-semantic.hpp" -#include #include #include #include // runtime_error @@ -20,8 +19,12 @@ namespace cqasm::v3x::values { * Type-checks and (if necessary) promotes the given value to the given type. * Returns null if the check/promotion fails, * otherwise returns the constructed value by way of a smart pointer. + * * If the type was an exact match, this may return the given value without modification or a clone thereof. - */ + * + * For a variable or a return value, a promotion is just a check. + * If the check is successful, the variable or return value is returned +*/ Value promote(const Value &value, const types::Type &type) { // If the types match exactly, just return the original value if (types::type_check(type, type_of(value))) { @@ -34,83 +37,90 @@ Value promote(const Value &value, const types::Type &type) { if (type->as_int()) { if (const auto &const_bool = value->as_const_bool()) { ret = tree::make(static_cast(const_bool->value)); - } else if (const auto variable_ref = value->as_variable_ref(); variable_ref && - types::type_check(variable_ref->variable->typ, tree::make())) { - ret = value; + } else if (value->as_variable_ref() || value->as_function_call()) { + if (types::type_check(type_of(value), tree::make())) { + ret = value; + } } } // Boolean arrays promote to integer arrays if (type->as_int_array()) { if (const auto &const_bool_array = value->as_const_bool_array()) { ret = promote_array_value_to_array_type(const_bool_array); - } else if (const auto variable_ref = value->as_variable_ref(); variable_ref) { - if (types::type_check(variable_ref->variable->typ, tree::make())) { + } else if (value->as_variable_ref() || value->as_function_call()) { + if (types::type_check(type_of(value), tree::make())) { ret = value; } } } - // Booleans and integers promote to real - if (type->as_real()) { + // Booleans and integers promote to float + if (type->as_float()) { if (const auto &const_bool = value->as_const_bool()) { - ret = tree::make(static_cast(const_bool->value)); + ret = tree::make(static_cast(const_bool->value)); } else if (const auto &const_int = value->as_const_int()) { - ret = tree::make(static_cast(static_cast(const_int->value))); - } else if (const auto variable_ref = value->as_variable_ref(); variable_ref) { - if (types::type_check(variable_ref->variable->typ, tree::make()) || - types::type_check(variable_ref->variable->typ, tree::make())) { + ret = tree::make(static_cast(static_cast(const_int->value))); + } else if (value->as_variable_ref() || value->as_function_call()) { + if (types::type_check(type_of(value), tree::make()) || + types::type_check(type_of(value), tree::make())) { ret = value; } } } - // Boolean and integer arrays promote to real arrays - if (type->as_real_array()) { + // Boolean and integer arrays promote to float arrays + if (type->as_float_array()) { if (const auto &const_bool_array = value->as_const_bool_array()) { - ret = promote_array_value_to_array_type(const_bool_array); + ret = promote_array_value_to_array_type(const_bool_array); } else if (const auto &const_int_array = value->as_const_int_array()) { - ret = promote_array_value_to_array_type(const_int_array); - } else if (const auto variable_ref = value->as_variable_ref(); variable_ref) { - if (types::type_check(variable_ref->variable->typ, tree::make()) || - types::type_check(variable_ref->variable->typ, tree::make())) { + ret = promote_array_value_to_array_type(const_int_array); + } else if (value->as_variable_ref() || value->as_function_call()) { + if (types::type_check(type_of(value), tree::make()) || + types::type_check(type_of(value), tree::make())) { ret = value; } } } - // Booleans, integers and reals promote to complex + // Booleans, integers and floats promote to complex if (type->as_complex()) { if (const auto &const_bool = value->as_const_bool()) { ret = tree::make(static_cast(const_bool->value)); } else if (const auto &const_int = value->as_const_int()) { ret = tree::make(static_cast(static_cast(const_int->value))); - } else if (const auto &const_real = value->as_const_real()) { - ret = tree::make(static_cast(const_real->value)); - } else if (const auto variable_ref = value->as_variable_ref(); variable_ref) { - if (types::type_check(variable_ref->variable->typ, tree::make()) || - types::type_check(variable_ref->variable->typ, tree::make()) || - types::type_check(variable_ref->variable->typ, tree::make())) { + } else if (const auto &const_float = value->as_const_float()) { + ret = tree::make(static_cast(const_float->value)); + } else if (value->as_variable_ref() || value->as_function_call()) { + if (types::type_check(type_of(value), tree::make()) || + types::type_check(type_of(value), tree::make()) || + types::type_check(type_of(value), tree::make())) { ret = value; } } } - // Boolean, integer, and real arrays promote to axis + // Boolean, integer, and float arrays promote to axis + // But the returned value is a float array + // TODO: why cannot we just return an axis? if (type->as_axis()) { if (const auto &const_bool_array = value->as_const_bool_array()) { - assert(const_bool_array->value.size() == 3); - ret = promote_array_value_to_array_type(const_bool_array); + if (const_bool_array->value.size() == 3) { + ret = promote_array_value_to_array_type(const_bool_array); + } } else if(const auto &const_int_array = value->as_const_int_array()) { - assert(const_int_array->value.size() == 3); - ret = promote_array_value_to_array_type(const_int_array); - } else if(const auto &const_real_array = value->as_const_real_array()) { - assert(const_real_array->value.size() == 3); - ret = tree::make(const_real_array->value); - } else if (const auto variable_ref = value->as_variable_ref(); variable_ref) { - if (types::type_check(variable_ref->variable->typ, tree::make()) || - types::type_check(variable_ref->variable->typ, tree::make()) || - types::type_check(variable_ref->variable->typ, tree::make())) { - assert(types::size_of(variable_ref->variable->typ) == 3); - ret = value; + if (const_int_array->value.size() == 3) { + ret = promote_array_value_to_array_type(const_int_array); + } + } else if(const auto &const_float_array = value->as_const_float_array()) { + if (const_float_array->value.size() == 3) { + ret = tree::make(const_float_array->value); + } + } else if (value->as_variable_ref() || value->as_function_call()) { + if (types::type_check(type_of(value), tree::make()) || + types::type_check(type_of(value), tree::make()) || + types::type_check(type_of(value), tree::make())) { + if (types::size_of(type_of(value)) == 3) { + ret = value; + } } } } @@ -130,10 +140,10 @@ bool check_promote(const types::Type &from_type, const types::Type &to_type) { if (types::type_check(from_type, to_type)) { return true; } else if (from_type->as_bool()) { - return to_type->as_int() || to_type->as_real() || to_type->as_complex(); + return to_type->as_int() || to_type->as_float() || to_type->as_complex(); } else if (from_type->as_int()) { - return to_type->as_real() || to_type->as_complex(); - } else if (from_type->as_real()) { + return to_type->as_float() || to_type->as_complex(); + } else if (from_type->as_float()) { return to_type->as_complex(); } return false; @@ -152,8 +162,8 @@ types::Type element_type_of(const types::Type &type) { return tree::make(); } else if (types::type_check(type, tree::make())) { return tree::make(); - } else if (types::type_check(type, tree::make())) { - return tree::make(); + } else if (types::type_check(type, tree::make())) { + return tree::make(); } else { throw std::runtime_error{ fmt::format("type ({}) is not of array type", type) }; } @@ -169,16 +179,16 @@ types::Type type_of(const Value &value) { return tree::make(); } else if (value->as_const_int()) { return tree::make(); - } else if (value->as_const_real()) { - return tree::make(); + } else if (value->as_const_float()) { + return tree::make(); } else if (value->as_const_complex()) { return tree::make(); } else if (value->as_const_bool_array()) { return tree::make(); } else if (value->as_const_int_array()) { return tree::make(); - } else if (value->as_const_real_array()) { - return tree::make(); + } else if (value->as_const_float_array()) { + return tree::make(); } else if (auto index = value->as_index_ref()) { // If the size of the index is 1, return the type of the element (qubit, bit, bool...) // Otherwise, return the type of the variable it refers to (qubit array, bit array, bool array...) @@ -189,6 +199,11 @@ types::Type type_of(const Value &value) { } } else if (auto var = value->as_variable_ref()) { return var->variable->typ; + } else if (auto function_ref_ptr = value->as_function_ref()) { + return function_ref_ptr->function->return_type; + } else if (auto function_call = value->as_function_call()) { + auto function_ref = function_call->function; + return function_ref->function->return_type; } else { throw std::runtime_error("unknown type!"); } @@ -211,18 +226,29 @@ types::Types types_of(const Values &values) { primitives::Int size_of(const Value &value) { if (value->as_const_axis()) { return 3; - } else if (value->as_const_bool() || value->as_const_int() || value->as_const_real() || value->as_const_complex()) { + } else if (value->as_const_bool() || value->as_const_int() || value->as_const_float() || value->as_const_complex()) { return 1; } else if (auto bool_array = value->as_const_bool_array()) { return static_cast(bool_array->value.size()); } else if (auto int_array = value->as_const_int_array()) { return static_cast(int_array->value.size()); - } else if (auto real_array = value->as_const_real_array()) { - return static_cast(real_array->value.size()); + } else if (auto float_array = value->as_const_float_array()) { + return static_cast(float_array->value.size()); } else if (auto index = value->as_index_ref()) { return static_cast(index->indices.size()); } else if (auto var = value->as_variable_ref()) { return types::size_of(var->variable->typ); + } else if (auto function_ref_ptr = value->as_function_ref()) { + auto return_type = function_ref_ptr->function->return_type; + return !return_type.empty() + ? types::size_of(return_type) + : primitives::Int{ 0 }; + } else if (auto function_call = value->as_function_call()) { + auto function_ref = function_call->function; + auto return_type = function_ref->function->return_type; + return !return_type.empty() + ? types::size_of(return_type) + : primitives::Int{ 0 }; } else { throw std::runtime_error("unknown type!"); } diff --git a/src/v3x/cqasm-values.tree b/src/v3x/cqasm-values.tree index e95c2f06f..548704069 100644 --- a/src/v3x/cqasm-values.tree +++ b/src/v3x/cqasm-values.tree @@ -25,52 +25,63 @@ namespace cqasm namespace v3x namespace values -# Constant value -constant { - # Represents an axis value (x, y, and z vectors). - const_axis { - value: cqasm::v3x::primitives::Axis; +value_base { + # Constant value + constant { + # Represents an axis value (x, y, and z vectors). + const_axis { + value: cqasm::v3x::primitives::Axis; + } + + const_bool { + value: cqasm::v3x::primitives::Bool; + } + + const_int { + value: cqasm::v3x::primitives::Int; + } + + const_float { + value: cqasm::v3x::primitives::Float; + } + + const_complex { + value: cqasm::v3x::primitives::Complex; + } + + const_bool_array { + value: Many; + } + + const_int_array { + value: Many; + } + + const_float_array { + value: Many; + } } - const_bool { - value: cqasm::v3x::primitives::Bool; + # Reference to some storage location + reference { + # Represents an index for single-gate-multiple-qubit notation. + # The indices must not repeat. + index_ref { + variable: external Link; + indices: Many; + } + + variable_ref { + variable: external Link; + } + + function_ref { + function: external Link; + } } - const_int { - value: cqasm::v3x::primitives::Int; - } - - const_real { - value: cqasm::v3x::primitives::Real; - } - - const_complex { - value: cqasm::v3x::primitives::Complex; - } - - const_bool_array { - value: Many; - } - - const_int_array { - value: Many; - } - - const_real_array { - value: Many; - } -} - -# Reference to some storage location -reference { - # Represents an index for single-gate-multiple-qubit notation. - # The indices must not repeat. - index_ref { - variable: external Link; - indices: Many; - } - - variable_ref { - variable: external Link; + function_call { + function: One; + arguments: Any; } } diff --git a/src/v3x/cqasm.cpp b/src/v3x/cqasm.cpp index a5ae81a92..d36e0b798 100644 --- a/src/v3x/cqasm.cpp +++ b/src/v3x/cqasm.cpp @@ -58,10 +58,10 @@ analyzer::Analyzer default_analyzer(const std::string &api_version) { analyzer.register_instruction("cnot", "QV"); analyzer.register_instruction("cnot", "VQ"); analyzer.register_instruction("cnot", "VV"); - analyzer.register_instruction("cr", "QQr"); - analyzer.register_instruction("cr", "QVr"); - analyzer.register_instruction("cr", "VQr"); - analyzer.register_instruction("cr", "VVr"); + analyzer.register_instruction("cr", "QQf"); + analyzer.register_instruction("cr", "QVf"); + analyzer.register_instruction("cr", "VQf"); + analyzer.register_instruction("cr", "VVf"); analyzer.register_instruction("crk", "QQi"); analyzer.register_instruction("crk", "QVi"); analyzer.register_instruction("crk", "VQi"); @@ -81,12 +81,12 @@ analyzer::Analyzer default_analyzer(const std::string &api_version) { analyzer.register_instruction("mx90", "V"); analyzer.register_instruction("my90", "Q"); analyzer.register_instruction("my90", "V"); - analyzer.register_instruction("rx", "Qr"); - analyzer.register_instruction("rx", "Vr"); - analyzer.register_instruction("ry", "Qr"); - analyzer.register_instruction("ry", "Vr"); - analyzer.register_instruction("rz", "Qr"); - analyzer.register_instruction("rz", "Vr"); + analyzer.register_instruction("rx", "Qf"); + analyzer.register_instruction("rx", "Vf"); + analyzer.register_instruction("ry", "Qf"); + analyzer.register_instruction("ry", "Vf"); + analyzer.register_instruction("rz", "Qf"); + analyzer.register_instruction("rz", "Vf"); analyzer.register_instruction("s", "Q"); analyzer.register_instruction("s", "V"); analyzer.register_instruction("sdag", "Q"); diff --git a/test/cqasm-annotations.cpp b/test/cqasm-annotations.cpp index d01620569..1b47ba461 100644 --- a/test/cqasm-annotations.cpp +++ b/test/cqasm-annotations.cpp @@ -9,34 +9,34 @@ using namespace cqasm::annotations; TEST(source_location_constructor, null_file_name__no_line_numbers__no_column_numbers) { - auto location = SourceLocation{ std::nullopt, 0, 0, 0, 0 }; + auto location = SourceLocation{ std::nullopt, {} }; EXPECT_EQ(fmt::format("{}", location), ""); } TEST(source_location_constructor, no_file_name__no_line_numbers__no_column_numbers) { - auto location = SourceLocation{ "", 0, 0, 0, 0 }; + auto location = SourceLocation{ "", {} }; EXPECT_EQ(fmt::format("{}", location), ""); } TEST(source_location_constructor, null_file_name__yes_line_numbers__no_column_numbers) { - auto location = SourceLocation{ std::nullopt, 10, 0, 10, 0 }; + auto location = SourceLocation{ std::nullopt, { { 10, 0 }, { 10, 0 } } }; EXPECT_EQ(fmt::format("{}", location), ":10"); } TEST(source_location_constructor, no_file_name__yes_line_numbers__no_column_numbers) { - auto location = SourceLocation{ "", 10, 0, 10, 0 }; + auto location = SourceLocation{ "", { { 10, 0 }, { 10, 0 } } }; EXPECT_EQ(fmt::format("{}", location), ":10"); } TEST(source_location_constructor, null_file_name__yes_line_numbers__yes_column_numbers) { - auto location = SourceLocation{ std::nullopt, 10, 12, 10, 15 }; + auto location = SourceLocation{ std::nullopt, { { 10, 12 }, { 10, 15 } } }; EXPECT_EQ(fmt::format("{}", location), ":10:12..15"); } TEST(source_location_constructor, no_file_name__yes_line_numbers__yes_column_numbers) { - auto location = SourceLocation{ "", 10, 12, 10, 15 }; + auto location = SourceLocation{ "", { { 10, 12 }, { 10, 15 } } }; EXPECT_EQ(fmt::format("{}", location), ":10:12..15"); } TEST(source_location_constructor, yes_file_name__yes_line_numbers__yes_column_numbers) { - auto location = SourceLocation{ "input.cq", 10, 12, 10, 15 }; + auto location = SourceLocation{ "input.cq", { { 10, 12 }, { 10, 15 } } }; EXPECT_EQ(fmt::format("{}", location), "input.cq:10:12..15"); } TEST(source_location_constructor, unknown_file_name__yes_line_numbers__yes_column_numbers) { - auto location = SourceLocation{ "", 10, 12, 10, 15 }; + auto location = SourceLocation{ "", { { 10, 12 }, { 10, 15 } } }; EXPECT_EQ(fmt::format("{}", location), ":10:12..15"); } diff --git a/test/cqasm-error.cpp b/test/cqasm-error.cpp index 4a77342d2..7bbc3437b 100644 --- a/test/cqasm-error.cpp +++ b/test/cqasm-error.cpp @@ -30,52 +30,52 @@ TEST(constructor_message_node, message_and_node_without_location) { } TEST(constructor_message_node, message_and_node_with_empty_location) { auto node = FakeNode{}; - node.set_annotation(SourceLocation("")); + node.set_annotation(SourceLocation{}); auto err = Error{ "syntax error", &node }; EXPECT_EQ(fmt::format("{}", err), "Error at : syntax error"); } TEST(constructor_message_node, message_and_node_with_location) { auto node = FakeNode{}; - node.set_annotation(SourceLocation("input.cq", 10, 12, 10, 15)); + node.set_annotation(SourceLocation{ "input.cq", { { 10, 12 }, { 10, 15 } } }); auto err = Error{ "syntax error", &node }; EXPECT_EQ(fmt::format("{}", err), "Error at input.cq:10:12..15: syntax error"); } TEST(constructor_message_location, empty_message) { - auto err = Error{ "", std::make_shared("") }; + auto err = Error{ "", std::make_shared() }; EXPECT_EQ(fmt::format("{}", err), "Error at : "); } TEST(constructor_message_location, message_and_empty_location) { - auto err = Error{ "syntax error", std::make_shared("") }; + auto err = Error{ "syntax error", std::make_shared() }; EXPECT_EQ(fmt::format("{}", err), "Error at : syntax error"); } TEST(constructor_message_location, message_and_location) { - auto err = Error{ "syntax error", std::make_shared("input.cq", 10, 12, 10, 15) }; + auto err = Error{ "syntax error", std::make_shared("input.cq", SourceLocation::Range{ { 10, 12 } , { 10, 15 } } ) }; EXPECT_EQ(fmt::format("{}", err), "Error at input.cq:10:12..15: syntax error"); } TEST(constructor_message_location_fields, empty_message) { - auto err = Error{ "", "", 0, 0, 0, 0 }; + auto err = Error{ "", std::nullopt, SourceLocation::Range{} }; EXPECT_EQ(fmt::format("{}", err), "Error at : "); } TEST(constructor_message_location_fields, message_and_empty_location) { - auto err = Error{ "syntax error", "", 0, 0, 0, 0 }; + auto err = Error{ "syntax error", std::nullopt, SourceLocation::Range{} }; EXPECT_EQ(fmt::format("{}", err), "Error at : syntax error"); } TEST(constructor_message_location_fields, message_and_location) { - auto err = Error{ "syntax error", "input.cq", 10, 12, 10, 15 }; + auto err = Error{ "syntax error", "input.cq", SourceLocation::Range{ { 10, 12 }, { 10, 15 } } }; EXPECT_EQ(fmt::format("{}", err), "Error at input.cq:10:12..15: syntax error"); } TEST(context, location) { auto node_1 = FakeNode{}; - node_1.set_annotation(SourceLocation("input.cq", 10, 12, 10, 15)); + node_1.set_annotation(SourceLocation("input.cq", SourceLocation::Range{ { 10, 12 }, { 10, 15 } })); auto err = Error{ "syntax error", &node_1 }; auto node_2 = FakeNode{}; - node_2.set_annotation(SourceLocation("input.cq", 20, 22, 20, 25)); + node_2.set_annotation(SourceLocation("input.cq", SourceLocation::Range{ { 20, 22 }, { 20, 25 } })); err.context(node_2); EXPECT_EQ(fmt::format("{}", err), "Error at input.cq:10:12..15: syntax error"); } @@ -88,7 +88,7 @@ TEST(context, no_location_and_node_does_not_have_source_location) { TEST(context, no_location_and_node_has_source_location) { auto err = Error{ "syntax error" }; auto node_2 = FakeNode{}; - node_2.set_annotation(SourceLocation("input.cq", 20, 22, 20, 25)); + node_2.set_annotation(SourceLocation("input.cq", SourceLocation::Range{ { 20, 22 }, { 20, 25 } })); err.context(node_2); EXPECT_EQ(fmt::format("{}", err), "Error at input.cq:20:22..25: syntax error"); } @@ -103,15 +103,15 @@ TEST(what, message_and_null_location) { EXPECT_EQ(std::string{ err.what() }, "Error: syntax error"); } TEST(what, message_and_empty_location) { - auto err = Error{ "syntax error", std::make_shared("") }; + auto err = Error{ "syntax error", std::make_shared() }; EXPECT_EQ(std::string{ err.what() }, "Error at : syntax error"); } TEST(what, message_and_location_with_unknown_file_name) { - auto err = Error{ "syntax error", "", 10, 12, 10, 15 }; + auto err = Error{ "syntax error", std::nullopt, SourceLocation::Range{ { 10, 12 }, { 10, 15 } } }; EXPECT_EQ(std::string{ err.what() }, "Error at :10:12..15: syntax error"); } TEST(what, message_and_location_with_known_file_name) { - auto err = Error{ "syntax error", "input.cq", 10, 12, 10, 15 }; + auto err = Error{ "syntax error", "input.cq", SourceLocation::Range{ { 10, 12 }, { 10, 15 } } }; EXPECT_EQ(std::string{ err.what() }, "Error at input.cq:10:12..15: syntax error"); } @@ -156,7 +156,7 @@ TEST(to_json, message_and_empty_location) { ); } TEST(to_json, message_and_location_with_unknown_file_name) { - auto err = Error{ "syntax error", "", 10, 12, 10, 15 }; + auto err = Error{ "syntax error", std::nullopt, SourceLocation::Range{ { 10, 12 }, { 10, 15 } } }; EXPECT_EQ(err.to_json(), R"({)" R"("range":{)" @@ -169,7 +169,7 @@ TEST(to_json, message_and_location_with_unknown_file_name) { ); } TEST(to_json, message_and_location_with_known_file_name) { - auto err = Error{ "syntax error", "input.cq", 10, 12, 10, 15 }; + auto err = Error{ "syntax error", "input.cq", SourceLocation::Range{ { 10, 12 }, { 10, 15 } } }; EXPECT_EQ(err.to_json(), R"({)" R"("range":{)" diff --git a/test/cqasm-result.cpp b/test/cqasm-result.cpp index c898eac4d..86b841ada 100644 --- a/test/cqasm-result.cpp +++ b/test/cqasm-result.cpp @@ -24,7 +24,7 @@ TEST(to_json, v1x_parser_ast) { auto ast_result = cqasm::v1x::parser::parse_file(input_file_path.generic_string()); auto json_result = to_json(ast_result); auto expected_json_result = std::string{ - R"delim({"Program":{"version":{"Version":{"items":"1.0","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:1:9..12"}},"num_qubits":{"IntegerLiteral":{"value":"2","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:2:8..9"}},"statements":{"StatementList":{"items":[{"Bundle":{"items":[{"Instruction":{"name":{"Identifier":{"name":"wait","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:4:1..5"}},"condition":"-","operands":{"ExpressionList":{"items":[{"IntegerLiteral":{"value":"1","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:4:6..7"}}],"source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:4:6..7"}},"annotations":"[]","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:4:1..7"}}],"annotations":"[]","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:4:1..7"}}],"source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:2:1..5:7"}},"source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:1:1..5:1"}})delim" + R"delim({"Program":{"version":{"Version":{"items":"1.0","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:1:9..12"}},"num_qubits":{"IntegerLiteral":{"value":"2","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:2:8..9"}},"statements":{"StatementList":{"items":[{"Bundle":{"items":[{"Instruction":{"name":{"Identifier":{"name":"wait","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:4:1..5"}},"condition":"-","operands":{"ExpressionList":{"items":[{"IntegerLiteral":{"value":"1","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:4:6..7"}}],"source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:4:6..7"}},"annotations":"[]","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:4:1..7"}}],"annotations":"[]","source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:4:1..7"}}],"source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:2:9..5:1"}},"source_location":"res/v1x/parsing/misc/wait_not_ok_1/input.cq:1:1..5:1"}})delim" }; EXPECT_EQ(json_result, expected_json_result); } @@ -62,7 +62,7 @@ TEST(to_json, v3x_parser_ast) { auto ast_result = cqasm::v3x::parser::parse_file(input_file_path.generic_string(), std::nullopt); auto json_result = to_json(ast_result); auto expected_json_result = std::string{ - R"delim({"Program":{"version":{"Version":{"items":"3","source_location":":1:9..10"}},"statements":{"StatementList":{"items":[{"Variable":{"name":{"Identifier":{"name":"b"}},"typ":{"Keyword":{"name":"bit"}},"size":{"IntegerLiteral":{"value":"0"}},"annotations":"[]","source_location":":3:8..9"}}]}}}})delim" + R"delim({"Program":{"version":{"Version":{"items":"3","source_location":":1:9..10"}},"block":{"GlobalBlock":{"statements":[{"Variable":{"name":{"Identifier":{"name":"b"}},"typ":{"Type":{"name":{"Keyword":{"name":"bit"}},"size":{"IntegerLiteral":{"value":"0"}},"source_location":":3:1..7"}},"annotations":"[]","source_location":":3:8..9"}}]}}}})delim" }; EXPECT_EQ(json_result, expected_json_result); } @@ -71,7 +71,7 @@ TEST(to_json, v3x_analyzer_errors) { auto semantic_ast_result = cqasm::v3x::default_analyzer().analyze_file(input_file_path.generic_string()); auto json_result = to_json(semantic_ast_result); auto expected_json_result = std::string{ - R"delim({"errors":[{"range":{"start":{"line":3,"character":8},"end":{"line":3,"character":9}},"message":"declaring bit array of size <= 0","severity":1,"relatedInformation":[{"location":{"uri":"file:///res%2Fv3x%2Fparsing%2Fbit_array_definition%2Fbit_array_of_0_b%2Finput.cq","range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}}},"message":""}]}]})delim" + R"delim({"errors":[{"range":{"start":{"line":3,"character":8},"end":{"line":3,"character":9}},"message":"found bit array of size <= 0","severity":1,"relatedInformation":[{"location":{"uri":"file:///res%2Fv3x%2Fparsing%2Fbit_array_definition%2Fbit_array_of_0_b%2Finput.cq","range":{"start":{"line":0,"character":0},"end":{"line":0,"character":0}}},"message":""}]}]})delim" }; EXPECT_EQ(json_result, expected_json_result); } @@ -80,7 +80,7 @@ TEST(to_json, v3x_analyzer_ast) { auto semantic_ast_result = cqasm::v3x::default_analyzer().analyze_file(input_file_path.generic_string()); auto json_result = to_json(semantic_ast_result); auto expected_json_result = std::string{ - R"delim({"Program":{"api_version":"3.0","version":{"Version":{"items":"3"}},"statements":"[]","variables":[{"Variable":{"name":"b","typ":{"BitArray":{"size":"17"}},"annotations":"[]"}}]}})delim" + R"delim({"Program":{"api_version":"3.0","version":{"Version":{"items":"3"}},"block":{"Block":{"statements":"[]"}},"functions":"[]","variables":[{"Variable":{"name":"b","typ":{"BitArray":{"size":"17"}},"annotations":"[]"}}]}})delim" }; EXPECT_EQ(json_result, expected_json_result); } diff --git a/test/v3x/cpp/AnalyzeTreeGenAstVisitor.cpp b/test/v3x/cpp/AnalyzeTreeGenAstVisitor.cpp index 7ea4807f4..5bce951e0 100644 --- a/test/v3x/cpp/AnalyzeTreeGenAstVisitor.cpp +++ b/test/v3x/cpp/AnalyzeTreeGenAstVisitor.cpp @@ -1,4 +1,5 @@ #include "cqasm-error.hpp" +#include "mock_analyze_tree_gen_ast_visitor.hpp" #include "mock_analyzer.hpp" #include "v3x/cqasm-ast-gen.hpp" #include "v3x/cqasm-values.hpp" @@ -13,28 +14,29 @@ namespace error = cqasm::error; namespace values = cqasm::v3x::values; -class VisitFunctionCallTest : public ::testing::Test { +namespace cqasm::v3x::analyzer { + +class VisitFunctionResolveTest : public ::testing::Test { protected: void SetUp() override {} - void ExpectAnalyzerCallFunctionCall(const values::Value &function_return_value) { - EXPECT_CALL(analyzer, call_function(::testing::_, ::testing::_)) + void ExpectAnalyzerResolveFunctionOK(const values::Value &function_return_value) { + EXPECT_CALL(analyzer, resolve_function(::testing::_, ::testing::_)) .WillOnce(::testing::Return(function_return_value)); } - void ExpectAnalyzerCallFunctionThrow(const std::string& error_message) { - EXPECT_CALL(analyzer, call_function(::testing::_, ::testing::_)) + void ExpectAnalyzerResolveFunctionThrow(const std::string& error_message) { + EXPECT_CALL(analyzer, resolve_function(::testing::_, ::testing::_)) .WillRepeatedly(::testing::Throw(std::runtime_error{ error_message.c_str() })); } analyzer::MockAnalyzer analyzer; analyzer::AnalyzeTreeGenAstVisitor visitor{ analyzer }; }; - -/* +/** * visit_function_call(name, arguments) is a private method, but we can test it through visit_function_call(node) */ -TEST_F(VisitFunctionCallTest, analyzer_call_function_returns_a_non_empty_value) { - const auto &function_return_value = values::Value{ cqasm::tree::make(0) }; - ExpectAnalyzerCallFunctionCall(function_return_value); +TEST_F(VisitFunctionResolveTest, analyzer_resolve_function_returns_a_non_empty_value) { + const auto &function_return_value = values::Value{ cqasm::tree::make(0) }; + ExpectAnalyzerResolveFunctionOK(function_return_value); auto name = cqasm::tree::make("function_that_returns_a_non_empty_value"); auto arguments = cqasm::tree::make(cqasm::tree::Any{}); @@ -43,9 +45,9 @@ TEST_F(VisitFunctionCallTest, analyzer_call_function_returns_a_non_empty_value) EXPECT_TRUE(ret.equals(function_return_value)); } -TEST_F(VisitFunctionCallTest, analyzer_call_function_returns_an_empty_value) { +TEST_F(VisitFunctionResolveTest, analyzer_resolve_function_returns_an_empty_value) { const auto &function_return_value = values::Value{}; - ExpectAnalyzerCallFunctionCall(function_return_value); + ExpectAnalyzerResolveFunctionOK(function_return_value); auto name = cqasm::tree::make("function_that_returns_an_empty_value"); auto arguments = cqasm::tree::make(cqasm::tree::Any{}); @@ -54,10 +56,10 @@ TEST_F(VisitFunctionCallTest, analyzer_call_function_returns_an_empty_value) { ThrowsMessage(::testing::HasSubstr("function implementation returned empty value"))); } -TEST_F(VisitFunctionCallTest, analyzer_call_function_throws) { +TEST_F(VisitFunctionResolveTest, analyzer_resolve_function_throws) { const auto &function_name = std::string{ "function_that_is_not_registered" }; const auto &error_message = fmt::format("failed to resolve '{}'", function_name); - ExpectAnalyzerCallFunctionThrow(error_message); + ExpectAnalyzerResolveFunctionThrow(error_message); auto name = cqasm::tree::make(function_name); auto arguments = cqasm::tree::make(cqasm::tree::Any{}); @@ -65,3 +67,78 @@ TEST_F(VisitFunctionCallTest, analyzer_call_function_throws) { EXPECT_THAT([&]() { visitor.visit_function_call(function_call); }, ThrowsMessage(::testing::HasSubstr(error_message.c_str()))); } + + +class VisitFunctionTest : public ::testing::Test { +protected: + void SetUp() override {} + void TearDown() override { + EXPECT_EQ(analyzer.scope_stack().size(), 1); + } + + std::string function_name = "f"; + tree::One name = cqasm::tree::make(function_name); + tree::One parameters = tree::make(); + tree::Maybe return_type_empty; + tree::Maybe return_type_bool = + tree::make(tree::make("bool"), tree::Maybe{}); + tree::Maybe return_type_int = + tree::make(tree::make("int"), tree::Maybe{}); + tree::One block = tree::make(); + tree::One return_statement = + tree::make(tree::make(42)); + + analyzer::MockAnalyzer analyzer; + analyzer::MockAnalyzeTreeGenAstVisitor visitor{ analyzer }; +}; + +TEST_F(VisitFunctionTest, function__no_return_type__yes_return_statement) { + block->statements.add(return_statement); + auto function = ast::Function{ name, parameters, return_type_empty, block }; + auto result = std::any_cast>(visitor.visit_function(function)); + EXPECT_TRUE(result.empty()); + EXPECT_TRUE(analyzer.global_functions().empty()); + EXPECT_EQ(visitor.result().errors.size(), 1); + EXPECT_THAT(visitor.result().errors[0].what(), ::testing::HasSubstr( + "found return statement but function does not have a return type")); +} + +TEST_F(VisitFunctionTest, function__yes_return_type__no_return_statement) { + auto function = ast::Function{ name, parameters, return_type_int, block }; + auto result = std::any_cast>(visitor.visit_function(function)); + EXPECT_TRUE(result.empty()); + EXPECT_TRUE(analyzer.global_functions().empty()); + EXPECT_EQ(visitor.result().errors.size(), 1); + EXPECT_THAT(visitor.result().errors[0].what(), ::testing::HasSubstr( + "function has a return type but return statement was not found")); +} + +TEST_F(VisitFunctionTest, function__no_return_type__no_return_statement) { + auto function = ast::Function{ name, parameters, return_type_empty, block }; + auto result = std::any_cast>(visitor.visit_function(function)); + EXPECT_FALSE(result.empty()); + EXPECT_EQ(analyzer.global_functions().size(), 1); + EXPECT_TRUE(visitor.result().errors.empty()); +} + +TEST_F(VisitFunctionTest, function__yes_return_type__yes_return_statement) { + block->statements.add(return_statement); + auto function = ast::Function{ name, parameters, return_type_int, block }; + auto result = std::any_cast>(visitor.visit_function(function)); + EXPECT_FALSE(result.empty()); + EXPECT_EQ(analyzer.global_functions().size(), 1); + EXPECT_TRUE(visitor.result().errors.empty()); +} + +TEST_F(VisitFunctionTest, return_value_cannot_be_promoted_to_return_type) { + block->statements.add(return_statement); + auto function = ast::Function{ name, parameters, return_type_bool, block }; + auto result = std::any_cast>(visitor.visit_function(function)); + EXPECT_TRUE(result.empty()); + EXPECT_TRUE(analyzer.global_functions().empty()); + EXPECT_EQ(visitor.result().errors.size(), 1); + EXPECT_THAT(visitor.result().errors[0].what(), ::testing::HasSubstr( + "type of right-hand side (int) could not be coerced to left-hand side (bool)")); +} + +} // namespace cqasm::v3x::analyzer diff --git a/test/v3x/cpp/CMakeLists.txt b/test/v3x/cpp/CMakeLists.txt index 02736e4e6..5b6ae7f46 100644 --- a/test/v3x/cpp/CMakeLists.txt +++ b/test/v3x/cpp/CMakeLists.txt @@ -3,6 +3,7 @@ target_sources(${PROJECT_NAME}_test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-analyzer.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-functions.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-parse-helper.cpp" + "${CMAKE_CURRENT_SOURCE_DIR}/cqasm-values.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/matcher_values.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/parsing.cpp" ) diff --git a/test/v3x/cpp/cqasm-analyzer.cpp b/test/v3x/cpp/cqasm-analyzer.cpp index ed071e9ec..b8b4f55d2 100644 --- a/test/v3x/cpp/cqasm-analyzer.cpp +++ b/test/v3x/cpp/cqasm-analyzer.cpp @@ -1,6 +1,7 @@ #include "cqasm-error.hpp" #include "cqasm-tree.hpp" #include "cqasm-version.hpp" +#include "mock_analyzer.hpp" #include "v3x/cqasm-analyzer.hpp" #include "v3x/cqasm-ast.hpp" #include "v3x/cqasm-parse-result.hpp" @@ -26,8 +27,8 @@ class AnalyzerAnalyzeTest : public ::testing::Test { version_parser = [this]() { return version_3_0; }; parser = [this]() { auto one_version = tree::make( version_3_0 ); - auto one_statement_list = tree::make(); - auto one_program = tree::make(one_version, one_statement_list); + auto one_global_block = tree::make(); + auto one_program = tree::make(one_version, one_global_block); return parser::ParseResult{ one_program, error::ParseErrors{} }; }; } @@ -81,4 +82,61 @@ TEST_F(AnalyzerAnalyzeTest, parser_throws) { ThrowsMessage(::testing::HasSubstr(parser_error_message))); } +TEST(Analyzer, constructor) { + MockAnalyzer analyzer{}; + EXPECT_EQ(analyzer.scope_stack().size(), 1); + EXPECT_FALSE(analyzer.current_block().empty()); + EXPECT_TRUE(analyzer.current_variables().empty()); + EXPECT_TRUE(analyzer.global_functions().empty()); +} +TEST(Analyzer, push_scope) { + MockAnalyzer analyzer{}; + analyzer.push_scope(); + EXPECT_EQ(analyzer.scope_stack().size(), 2); +} +TEST(Analyzer, pop_scope) { + MockAnalyzer analyzer{}; + analyzer.pop_scope(); + EXPECT_TRUE(analyzer.scope_stack().empty()); +} +TEST(Analyzer, add_statement_to_current_scope) { + MockAnalyzer analyzer{}; + auto statement = tree::make(tree::make(42)); + analyzer.add_statement_to_current_scope(statement); + EXPECT_EQ(analyzer.current_block()->statements.size(), 1); +} +TEST(Analyzer, add_statement_with_source_location_information_to_current_scope) { + MockAnalyzer analyzer{}; + auto statement = tree::make(tree::make(42)); + const auto &statement_source_location = annotations::SourceLocation{ "input.cq", { { 10, 20 }, { 11, 10 } } }; + statement->set_annotation(statement_source_location); + analyzer.add_statement_to_current_scope(statement); + EXPECT_EQ(analyzer.current_block()->statements.size(), 1); + const auto &block_source_location = analyzer.current_block()->get_annotation(); + EXPECT_EQ(block_source_location.file_name, statement_source_location.file_name); + EXPECT_EQ(block_source_location.range, statement_source_location.range); +} +TEST(Analyzer, add_statement_with_source_location_information_to_current_scope_and_block_has_source_location_information) { + MockAnalyzer analyzer{}; + // 10 15 20 25 30 + // 5 < + // 8 > + const auto &block_initial_source_location = annotations::SourceLocation{ "input.cq", { { 5, 15 }, { 8, 30 } } }; + analyzer.current_block()->set_annotation(block_initial_source_location); + auto statement = tree::make(tree::make(42)); + // 10 15 20 25 30 + // 10 < + // 11 > + const auto &statement_source_location = annotations::SourceLocation{ "input.cq", { { 10, 10 }, { 11, 20 } } }; + statement->set_annotation(statement_source_location); + analyzer.add_statement_to_current_scope(statement); + EXPECT_EQ(analyzer.current_block()->statements.size(), 1); + // 10 15 20 25 30 + // 5 < + // 11 > + const auto &block_final_source_location = analyzer.current_block()->get_annotation(); + EXPECT_EQ(block_final_source_location.file_name, "input.cq"); + EXPECT_EQ(block_final_source_location.range, (annotations::SourceLocation::Range{ { 5, 15 }, { 11, 20 } })); +} + } // namespace cqasm::v3x::analyzer diff --git a/test/v3x/cpp/cqasm-functions.cpp b/test/v3x/cpp/cqasm-functions.cpp index 5d91696b7..07ab9984e 100644 --- a/test/v3x/cpp/cqasm-functions.cpp +++ b/test/v3x/cpp/cqasm-functions.cpp @@ -9,24 +9,24 @@ namespace primitives = cqasm::v3x::primitives; namespace values = cqasm::v3x::values; -TEST(op_neg_r, r_0) { EXPECT_EQ((invoke_unary(0.)), 0.); } -TEST(op_neg_r, r_5) { EXPECT_EQ((invoke_unary(5.)), -5.); } -TEST(op_neg_r, r_m5) { EXPECT_EQ((invoke_unary(-5.)), 5.); } +TEST(op_neg_f, f_0) { EXPECT_EQ((invoke_unary(0.)), 0.); } +TEST(op_neg_f, f_5) { EXPECT_EQ((invoke_unary(5.)), -5.); } +TEST(op_neg_f, f_m5) { EXPECT_EQ((invoke_unary(-5.)), 5.); } TEST(op_neg_i, i_0) { EXPECT_EQ((invoke_unary(0)), 0); } TEST(op_neg_i, i_5) { EXPECT_EQ((invoke_unary(5)), -5); } TEST(op_neg_i, i_m5) { EXPECT_EQ((invoke_unary(-5)), 5); } -TEST(op_add_rr, rr_m5_5) { EXPECT_EQ((invoke_binary(-5., 5.)), 0.); } +TEST(op_add_ff, ff_m5_5) { EXPECT_EQ((invoke_binary(-5., 5.)), 0.); } TEST(op_add_ii, ii_m5_5) { EXPECT_EQ((invoke_binary(-5, 5)), 0); } -TEST(op_sub_rr, rr_m5_5) { EXPECT_EQ((invoke_binary(-5., 5.)), -10.); } +TEST(op_sub_ff, ff_m5_5) { EXPECT_EQ((invoke_binary(-5., 5.)), -10.); } TEST(op_sub_ii, ii_m5_5) { EXPECT_EQ((invoke_binary(-5, 5)), -10); } -TEST(op_mul_rr, rr_m5_5) { EXPECT_EQ((invoke_binary(-5., 5.)), -25.); } +TEST(op_mul_ff, ff_m5_5) { EXPECT_EQ((invoke_binary(-5., 5.)), -25.); } TEST(op_mul_ii, ii_m5_5) { EXPECT_EQ((invoke_binary(-5, 5)), -25); } -TEST(op_div_rr, rr_m5_5) { EXPECT_EQ((invoke_binary(-5., 5.)), -1.); } +TEST(op_div_ff, ff_m5_5) { EXPECT_EQ((invoke_binary(-5., 5.)), -1.); } TEST(op_div_ii, ii_m5_5) { EXPECT_EQ((invoke_binary(-5, 5)), -1); } TEST(op_div_ii, ii_8_3) { EXPECT_EQ((invoke_binary(8, 3)), 2); } @@ -37,14 +37,14 @@ TEST(op_mod_ii, ii_m1_m3) { EXPECT_EQ((invoke_binary(-1, - TEST(op_mod_ii, ii_0_m3) { EXPECT_EQ((invoke_binary(0, -3)), 0); } TEST(op_mod_ii, ii_1_m3) { EXPECT_EQ((invoke_binary(1, -3)), 1); } -TEST(op_pow_rr, r_m5_5) { EXPECT_EQ((invoke_binary(-5., 5.)), -3125.); } +TEST(op_pow_ff, f_m5_5) { EXPECT_EQ((invoke_binary(-5., 5.)), -3125.); } -TEST(op_eq_rr, rr_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), true); } -TEST(op_ne_rr, rr_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), false); } -TEST(op_ge_rr, rr_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), true); } -TEST(op_gt_rr, rr_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), false); } -TEST(op_le_rr, rr_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), true); } -TEST(op_lt_rr, rr_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), false); } +TEST(op_eq_ff, ff_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), true); } +TEST(op_ne_ff, ff_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), false); } +TEST(op_ge_ff, ff_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), true); } +TEST(op_gt_ff, ff_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), false); } +TEST(op_le_ff, ff_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), true); } +TEST(op_lt_ff, ff_2_2) { EXPECT_EQ((invoke_binary(2., 2.)), false); } TEST(op_eq_ii, ii_2_2) { EXPECT_EQ((invoke_binary(2, 2)), true); } TEST(op_ne_ii, ii_2_2) { EXPECT_EQ((invoke_binary(2, 2)), false); } @@ -73,22 +73,22 @@ TEST(op_land_bb, bb_true_true) { EXPECT_EQ((invoke_binary TEST(op_lxor_bb, bb_true_true) { EXPECT_EQ((invoke_binary(true, true)), false); } TEST(op_lor_bb, bb_true_true) { EXPECT_EQ((invoke_binary(true, true)), true); } -TEST(op_tcnd_brr, brr_true_m5_5) { EXPECT_EQ((invoke_ternary(true, -5., 5.)), -5.); } +TEST(op_tcnd_bff, bff_true_m5_5) { EXPECT_EQ((invoke_ternary(true, -5., 5.)), -5.); } TEST(op_tcnd_bii, bii_true_m5_5) { EXPECT_EQ((invoke_ternary(true, -5, 5)), -5); } TEST(op_tcnd_bbb, bbb_true_true_false) { EXPECT_EQ((invoke_ternary(true, true, false)), true); } -TEST(fn_sqrt_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), 1.41421, 0.00001); } -TEST(fn_exp_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), 7.38905, 0.00001); } -TEST(fn_log_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), 0.69314, 0.00001); } -TEST(fn_sin_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), 0.90929, 0.00001); } -TEST(fn_cos_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), -0.41614, 0.00001); } -TEST(fn_tan_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), -2.18503, 0.00001); } -TEST(fn_sinh_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), 3.62686, 0.00001); } -TEST(fn_cosh_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), 3.76219, 0.00001); } -TEST(fn_tanh_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), 0.96402, 0.00001); } -TEST(fn_asin_r, r_point_2) { EXPECT_NEAR((invoke_unary(.2)), 0.20135, 0.00001); } -TEST(fn_acos_r, r_point_2) { EXPECT_NEAR((invoke_unary(.2)), 1.36943, 0.00001); } -TEST(fn_atan_r, r_point_2) { EXPECT_NEAR((invoke_unary(.2)), 0.19739, 0.00001); } -TEST(fn_asinh_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), 1.44363, 0.00001); } -TEST(fn_acosh_r, r_2) { EXPECT_NEAR((invoke_unary(2.)), 1.31695, 0.00001); } -TEST(fn_atanh_r, r_point_2) { EXPECT_NEAR((invoke_unary(.2)), 0.20273, 0.00001); } +TEST(fn_sqrt_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), 1.41421, 0.00001); } +TEST(fn_exp_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), 7.38905, 0.00001); } +TEST(fn_log_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), 0.69314, 0.00001); } +TEST(fn_sin_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), 0.90929, 0.00001); } +TEST(fn_cos_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), -0.41614, 0.00001); } +TEST(fn_tan_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), -2.18503, 0.00001); } +TEST(fn_sinh_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), 3.62686, 0.00001); } +TEST(fn_cosh_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), 3.76219, 0.00001); } +TEST(fn_tanh_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), 0.96402, 0.00001); } +TEST(fn_asin_f, f_point_2) { EXPECT_NEAR((invoke_unary(.2)), 0.20135, 0.00001); } +TEST(fn_acos_f, f_point_2) { EXPECT_NEAR((invoke_unary(.2)), 1.36943, 0.00001); } +TEST(fn_atan_f, f_point_2) { EXPECT_NEAR((invoke_unary(.2)), 0.19739, 0.00001); } +TEST(fn_asinh_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), 1.44363, 0.00001); } +TEST(fn_acosh_f, f_2) { EXPECT_NEAR((invoke_unary(2.)), 1.31695, 0.00001); } +TEST(fn_atanh_f, f_point_2) { EXPECT_NEAR((invoke_unary(.2)), 0.20273, 0.00001); } diff --git a/test/v3x/cpp/cqasm-functions.hpp b/test/v3x/cpp/cqasm-functions.hpp index 80cf36d89..ee21bb155 100644 --- a/test/v3x/cpp/cqasm-functions.hpp +++ b/test/v3x/cpp/cqasm-functions.hpp @@ -5,7 +5,7 @@ namespace values = cqasm::v3x::values; -/* +/** * Convenience function templates for invoking operators and functions: * * - F is the operator or function being invoked. diff --git a/test/v3x/cpp/cqasm-parse-helper.cpp b/test/v3x/cpp/cqasm-parse-helper.cpp index b9251e516..f14257689 100644 --- a/test/v3x/cpp/cqasm-parse-helper.cpp +++ b/test/v3x/cpp/cqasm-parse-helper.cpp @@ -27,13 +27,7 @@ class ParseHelperParseTest : public ::testing::Test { } void ExpectScannerParseThrowsParseError() { EXPECT_CALL(*scanner_up, parse()) - .WillRepeatedly(::testing::Throw(ParseError{ - parse_error_message, - file_name, - first_line, - first_column, - last_line, - last_column })); + .WillRepeatedly(::testing::Throw(ParseError{ parse_error_message, file_name, range })); } void ExpectScannerParseThrowsRuntimeError() { EXPECT_CALL(*scanner_up, parse()) @@ -46,18 +40,15 @@ class ParseHelperParseTest : public ::testing::Test { } void ExpectScannerParseReturnsWellFormedRoot() { auto one_version = tree::make( version_3_0 ); - auto one_statement_list = tree::make(); - auto one_program = tree::make(one_version, one_statement_list); + auto one_global_block = tree::make(); + auto one_program = tree::make(one_version, one_global_block); auto parse_result = ParseResult{ one_program, error::ParseErrors{} }; EXPECT_CALL(*scanner_up, parse()) .WillOnce(::testing::Return(parse_result)); } std::string file_name = "input.cq"; - std::uint32_t first_line = 10; - std::uint32_t first_column = 12; - std::uint32_t last_line = 10; - std::uint32_t last_column = 15; + annotations::SourceLocation::Range range{ { 10, 12 }, { 10, 15 } }; std::string parse_error_message = "parse error"; std::string runtime_error_message = "runtime error"; @@ -78,9 +69,9 @@ TEST_F(ParseHelperParseTest, scanner_parse_throws_parse_error) { fmt::format("{}", errors[0]), fmt::format("Error at {}:{}:{}..{}: {}", file_name, - first_line, - first_column, - last_column, + range.first.line, + range.first.column, + range.last.column, parse_error_message) ); } diff --git a/test/v3x/cpp/cqasm-values.cpp b/test/v3x/cpp/cqasm-values.cpp new file mode 100644 index 000000000..2f1cf9638 --- /dev/null +++ b/test/v3x/cpp/cqasm-values.cpp @@ -0,0 +1,154 @@ +#include "v3x/cqasm-semantic-gen.hpp" +#include "v3x/cqasm-values.hpp" + +#include + + +namespace cqasm::v3x::values { + +// bool, int, float, axis types +static const types::Type bool_type = tree::make(1); +static const types::Type int_type = tree::make(1); +static const types::Type float_type = tree::make(1); +static const types::Type axis_type = tree::make(3); + +// bool, int, float array types +static const types::Type bool_array_of_3_type = tree::make(3); +static const types::Type bool_array_of_4_type = tree::make(4); +static const types::Type bool_array_of_10_type = tree::make(10); +static const types::Type int_array_of_3_type = tree::make(3); +static const types::Type float_array_of_3_type = tree::make(3); + +// bool, int, float, axis values + static const values::Value bool_false_value = tree::make(false); +static const values::Value bool_true_value = tree::make(true); +static const values::Value int_0_value = tree::make(0); +static const values::Value int_1_value = tree::make(1); +static const values::Value int_2_value = tree::make(2); +static const values::Value int_3_value = tree::make(3); +static const values::Value int_4_value = tree::make(4); +static const values::Value int_5_value = tree::make(5); +static const values::Value int_6_value = tree::make(6); +static const values::Value float_0_0_value = tree::make(0.0); +static const values::Value float_1_0_value = tree::make(1.0); +static const values::Value axis_x_value = tree::make(); + +// bool, int, float array values +static const values::Value bool_array_of_2_value = tree::make( + tree::Many{ bool_true_value, bool_false_value }); +static const values::Value bool_array_of_3_value = tree::make( + tree::Many{ bool_true_value, bool_false_value, bool_false_value }); +static const values::Value int_array_of_3_value = tree::make( + tree::Many{ int_1_value, int_0_value, int_0_value }); +static const values::Value float_array_of_3_value = tree::make( + tree::Many{ float_1_0_value, float_0_0_value, float_0_0_value }); + +// bool semantic variable +static const auto bool_variable = tree::make("b", bool_type); + +// bool array semantic variables +static const auto bool_array_of_3_variable = tree::make("ba3", bool_array_of_3_type); +static const auto bool_array_of_10_variable = tree::make("ba10", bool_array_of_10_type); + +// bool variable ref value +static const values::Value bool_variable_ref = tree::make(bool_variable); + +// bool array variable ref value +static const values::Value bool_array_of_3_variable_ref = tree::make(bool_array_of_3_variable); + +// index ref values +static const auto index_2_value = tree::make(bool_array_of_10_variable, + tree::Many{ int_2_value }); +static const auto index_2_to_5_value = tree::make(bool_array_of_10_variable, + tree::Many{ int_2_value, int_3_value, int_4_value, int_5_value }); +static const auto index_2_4_6_value = tree::make(bool_array_of_10_variable, + tree::Many{ int_2_value, int_4_value, int_6_value }); + +// Semantic function returning bool +static const auto function_returning_bool = tree::make("fb", bool_type); + +// Semantic function returning bool array +static const auto function_returning_bool_array_of_3 = tree::make("fba", bool_array_of_3_type); + +// Function returning bool value +static const values::Value function_returning_bool_value = tree::make(function_returning_bool); + +// Function returning bool array value +static const values::Value function_returning_bool_array_of_3_value = tree::make(function_returning_bool_array_of_3); + +// bool return value +static const values::Value bool_return_value = tree::make(tree::make(function_returning_bool)); + +// bool array return value +static const values::Value bool_array_of_3_return_value = tree::make( + tree::make(function_returning_bool_array_of_3)); + +TEST(promote, bool_to_bool) { EXPECT_TRUE(promote(bool_true_value, bool_type)->equals(*bool_true_value)); } +TEST(promote, bool_to_int) { EXPECT_TRUE(promote(bool_true_value, int_type)->equals(*int_1_value)); } +TEST(promote, bool_to_float) { EXPECT_TRUE(promote(bool_true_value, float_type)->equals(*float_1_0_value)); } +TEST(promote, int_to_int) { EXPECT_TRUE(promote(int_1_value, int_type)->equals(*int_1_value)); } +TEST(promote, int_to_float) { EXPECT_TRUE(promote(int_1_value, float_type)->equals(*float_1_0_value)); } +TEST(promote, float_to_float) { EXPECT_TRUE(promote(float_1_0_value, float_type)->equals(*float_1_0_value)); } + +TEST(promote, bool_array_to_bool_array) { EXPECT_TRUE(promote(bool_array_of_3_value, bool_array_of_3_type)->equals(*bool_array_of_3_value)); } +TEST(promote, bool_array_to_int_array) { EXPECT_TRUE(promote(bool_array_of_3_value, int_array_of_3_type)->equals(*int_array_of_3_value)); } +TEST(promote, bool_array_to_float_array) { EXPECT_TRUE(promote(bool_array_of_3_value, float_array_of_3_type)->equals(*float_array_of_3_value)); } +TEST(promote, int_array_to_int_array) { EXPECT_TRUE(promote(int_array_of_3_value, int_array_of_3_type)->equals(*int_array_of_3_value)); } +TEST(promote, int_array_to_float_array) { EXPECT_TRUE(promote(int_array_of_3_value, float_array_of_3_type)->equals(*float_array_of_3_value)); } +TEST(promote, float_array_to_float_array) { EXPECT_TRUE(promote(float_array_of_3_value, float_array_of_3_type)->equals(*float_array_of_3_value)); } + +// For a variable or a return value, a promotion is just a check. +// If the check is successful, the variable or return value is returned +TEST(promote, bool_variable_ref_to_int) { EXPECT_TRUE(promote(bool_variable_ref, int_type)->equals(*bool_variable_ref)); } +TEST(promote, bool_array_variable_ref_to_int_array) { EXPECT_TRUE(promote(bool_array_of_3_variable_ref, int_array_of_3_type)->equals(*bool_array_of_3_variable_ref)); } +TEST(promote, bool_return_value_to_int) { EXPECT_TRUE(promote(bool_return_value, int_type)->equals(*bool_return_value)); } +TEST(promote, bool_array_return_value_to_int_array) { EXPECT_TRUE(promote(bool_array_of_3_return_value, int_array_of_3_type)->equals(*bool_array_of_3_return_value)); } + +// bool, int, and float arrays of 3 elements, when promoted to axis, are converted to float arrays of 3 elements +TEST(promote, bool_array_of_3_to_axis) { EXPECT_TRUE(promote(bool_array_of_3_value, axis_type)->equals(*float_array_of_3_value)); } +TEST(promote, int_array_of_3_to_axis) { EXPECT_TRUE(promote(int_array_of_3_value, axis_type)->equals(*float_array_of_3_value)); } +TEST(promote, float_array_of_3_to_axis) { EXPECT_TRUE(promote(float_array_of_3_value, axis_type)->equals(*float_array_of_3_value)); } + +TEST(promote, int_to_bool) { EXPECT_TRUE(promote(int_1_value, bool_type).empty()); } +TEST(promote, float_to_bool) { EXPECT_TRUE(promote(float_1_0_value, bool_type).empty()); } +TEST(promote, float_to_int) { EXPECT_TRUE(promote(float_1_0_value, int_type).empty()); } + +TEST(promote, int_array_to_bool_array) { EXPECT_TRUE(promote(int_array_of_3_value, bool_array_of_3_type).empty()); } +TEST(promote, float_array_to_bool_array) { EXPECT_TRUE(promote(float_array_of_3_value, bool_array_of_3_type).empty()); } +TEST(promote, float_array_to_int_array) { EXPECT_TRUE(promote(float_array_of_3_value, int_array_of_3_type).empty()); } + +TEST(promote, bool_array_to_bool) { EXPECT_TRUE(promote(bool_array_of_3_value, bool_type).empty()); } +TEST(promote, bool_array_variable_ref_to_bool) { EXPECT_TRUE(promote(bool_array_of_3_variable_ref, bool_type).empty()); } +TEST(promote, bool_array_return_value_to_bool) { EXPECT_TRUE(promote(bool_array_of_3_return_value, bool_type).empty()); } + +TEST(promote, bool_to_axis) { EXPECT_TRUE(promote(bool_true_value, axis_type).empty()); } +TEST(promote, bool_variable_ref_to_axis) { EXPECT_TRUE(promote(bool_variable_ref, axis_type).empty()); } +TEST(promote, bool_return_value_to_axis) { EXPECT_TRUE(promote(bool_return_value, axis_type).empty()); } +TEST(promote, bool_array_of_2_to_axis) { EXPECT_TRUE(promote(bool_array_of_2_value, axis_type).empty()); } + +TEST(type_of, index_2_value) { EXPECT_TRUE(types::type_check(type_of(index_2_value), bool_type)); } +TEST(type_of, index_2_to_5_value) { EXPECT_TRUE(types::type_check(type_of(index_2_to_5_value), bool_array_of_4_type)); } +TEST(type_of, index_2_4_6_value) { EXPECT_TRUE(types::type_check(type_of(index_2_4_6_value), bool_array_of_3_type)); } +TEST(type_of, bool_variable_ref) { EXPECT_TRUE(types::type_check(type_of(bool_variable_ref), bool_type)); } +TEST(type_of, function_with_bool_return_type) { EXPECT_TRUE(types::type_check(type_of(function_returning_bool_value), bool_type)); } +TEST(type_of, function_with_bool_array_return_type) { EXPECT_TRUE(types::type_check(type_of(function_returning_bool_array_of_3_value), bool_array_of_3_type)); } +TEST(type_of, function_call_to_function_with_bool_return_type) { EXPECT_TRUE(types::type_check(type_of(bool_return_value), bool_type)); } +TEST(type_of, function_call_to_function_with_bool_array_return_type) { EXPECT_TRUE(types::type_check(type_of(bool_array_of_3_return_value), bool_array_of_3_type)); } + +TEST(size_of, const_axis) { EXPECT_EQ(size_of(axis_x_value), 3); } +TEST(size_of, const_bool) { EXPECT_EQ(size_of(bool_true_value), 1); } +TEST(size_of, const_int) { EXPECT_EQ(size_of(int_1_value), 1); } +TEST(size_of, const_float) { EXPECT_EQ(size_of(float_1_0_value), 1); } +TEST(size_of, const_bool_array) { EXPECT_EQ(size_of(bool_array_of_3_value), 3); } +TEST(size_of, const_int_array) { EXPECT_EQ(size_of(int_array_of_3_value), 3); } +TEST(size_of, const_float_array) { EXPECT_EQ(size_of(float_array_of_3_value), 3); } +TEST(size_of, bool_b_10__b_2) { EXPECT_EQ(size_of(index_2_value), 1); } +TEST(size_of, bool_b_10__b_2_to_5) { EXPECT_EQ(size_of(index_2_to_5_value), 4); } +TEST(size_of, bool_b_10__b_2_4_6) { EXPECT_EQ(size_of(index_2_4_6_value), 3); } +TEST(size_of, bool_variable_ref) { EXPECT_EQ(size_of(bool_variable_ref), 1); } +TEST(size_of, function_returning_bool) { EXPECT_EQ(size_of(function_returning_bool_value), 1); } +TEST(size_of, function_returning_bool_array_of_3) { EXPECT_EQ(size_of(function_returning_bool_array_of_3_value), 3); } +TEST(size_of, bool_return_value) { EXPECT_EQ(size_of(bool_return_value), 1); } +TEST(size_of, bool_array_of_3_return_value) { EXPECT_EQ(size_of(bool_array_of_3_return_value), 3); } + +} // namespace cqasm::v3x::values diff --git a/test/v3x/cpp/mock_analyze_tree_gen_ast_visitor.hpp b/test/v3x/cpp/mock_analyze_tree_gen_ast_visitor.hpp new file mode 100644 index 000000000..b682b2b6e --- /dev/null +++ b/test/v3x/cpp/mock_analyze_tree_gen_ast_visitor.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "v3x/AnalyzeTreeGenAstVisitor.hpp" +#include "v3x/cqasm-analysis-result.hpp" +#include "v3x/cqasm-analyzer.hpp" + +#include + + +namespace cqasm::v3x::analyzer { + +struct MockAnalyzeTreeGenAstVisitor : public AnalyzeTreeGenAstVisitor { + explicit MockAnalyzeTreeGenAstVisitor(Analyzer &analyzer) : AnalyzeTreeGenAstVisitor{ analyzer } {} + + [[nodiscard]] AnalysisResult &result() { return result_; } +}; + +} // namespace cqasm::v3x::analyzer diff --git a/test/v3x/cpp/mock_analyzer.hpp b/test/v3x/cpp/mock_analyzer.hpp index 95c4723e9..b4b23ad0b 100644 --- a/test/v3x/cpp/mock_analyzer.hpp +++ b/test/v3x/cpp/mock_analyzer.hpp @@ -9,9 +9,22 @@ namespace cqasm::v3x::analyzer { -class MockAnalyzer : public Analyzer { -public: - MOCK_METHOD((values::Value), call_function, (const std::string &name, const values::Values &args), (const)); +struct MockAnalyzer : public Analyzer { + MOCK_METHOD((AnalysisResult), analyze, (const std::function &version_parser, const std::function &parser)); + MOCK_METHOD((values::Value), resolve_function, (const std::string &name, const values::Values &args), (const)); + + [[nodiscard]] std::list &scope_stack() { return scope_stack_; } + + [[nodiscard]] Scope &global_scope() { return Analyzer::global_scope(); } + [[nodiscard]] Scope ¤t_scope() { return Analyzer::current_scope(); } + [[nodiscard]] tree::One current_block() { return Analyzer::current_block(); } + [[nodiscard]] tree::Any ¤t_variables() { return Analyzer::current_variables(); } + [[nodiscard]] tree::Any &global_functions() { return Analyzer::global_functions(); } + + [[nodiscard]] const Scope &global_scope() const { return Analyzer::global_scope(); } + [[nodiscard]] const Scope ¤t_scope() const { return Analyzer::current_scope(); } + [[nodiscard]] const tree::Any ¤t_variables() const { return Analyzer::current_variables(); } + [[nodiscard]] const tree::Any &global_functions() const { return Analyzer::global_functions(); } }; } // namespace cqasm::v3x::analyzer diff --git a/test/v3x/cpp/parsing.cpp b/test/v3x/cpp/parsing.cpp index 6f884dec8..b55e0914c 100644 --- a/test/v3x/cpp/parsing.cpp +++ b/test/v3x/cpp/parsing.cpp @@ -73,7 +73,7 @@ class ParsingTest : public ::testing::Test { analyzer.register_instruction("cnot", "QQ"); analyzer.register_instruction("cnot", "VV"); - analyzer.register_instruction("cr", "QQr"); + analyzer.register_instruction("cr", "QQf"); analyzer.register_instruction("crk", "QQi"); analyzer.register_instruction("cz", "QQ"); analyzer.register_instruction("h", "Q"); @@ -85,9 +85,9 @@ class ParsingTest : public ::testing::Test { analyzer.register_instruction("measure", "WQ"); // bit array = qubit analyzer.register_instruction("mx90", "Q"); analyzer.register_instruction("my90", "Q"); - analyzer.register_instruction("rx", "Qr"); - analyzer.register_instruction("ry", "Qr"); - analyzer.register_instruction("rz", "Qr"); + analyzer.register_instruction("rx", "Qf"); + analyzer.register_instruction("ry", "Qf"); + analyzer.register_instruction("rz", "Qf"); analyzer.register_instruction("s", "Q"); analyzer.register_instruction("sdag", "Q"); analyzer.register_instruction("x", "Q"); diff --git a/test/v3x/python/test_analysis_result.py b/test/v3x/python/test_analysis_result.py index fd9d16d61..091fa1fb8 100644 --- a/test/v3x/python/test_analysis_result.py +++ b/test/v3x/python/test_analysis_result.py @@ -9,7 +9,7 @@ def test_to_json_with_analyzer_errors(self): program_str = "version 3; bit[0] b" v3x_analyzer = cq.Analyzer() actual_errors_json = v3x_analyzer.analyze_string_to_json(program_str) - expected_errors_json = '''{"errors":[{"range":{"start":{"line":1,"character":19},"end":{"line":1,"character":20}},"message":"declaring bit array of size <= 0","severity":1}]}''' + expected_errors_json = '''{"errors":[{"range":{"start":{"line":1,"character":19},"end":{"line":1,"character":20}},"message":"found bit array of size <= 0","severity":1}]}''' self.assertEqual(actual_errors_json, expected_errors_json) def test_to_json_with_analyzer_ast(self): @@ -17,5 +17,5 @@ def test_to_json_with_analyzer_ast(self): program_str = "version 3; bit[17] b" v3x_analyzer = cq.Analyzer() actual_ast_json = v3x_analyzer.analyze_string_to_json(program_str) - expected_ast_json = '''{"Program":{"api_version":"3.0","version":{"Version":{"items":"3"}},"statements":"[]","variables":[{"Variable":{"name":"b","typ":{"BitArray":{"size":"17"}},"annotations":"[]"}}]}}''' + expected_ast_json = '''{"Program":{"api_version":"3.0","version":{"Version":{"items":"3"}},"block":{"Block":{"statements":"[]"}},"functions":"[]","variables":[{"Variable":{"name":"b","typ":{"BitArray":{"size":"17"}},"annotations":"[]"}}]}}''' self.assertEqual(actual_ast_json, expected_ast_json) diff --git a/test/v3x/python/test_parse_result.py b/test/v3x/python/test_parse_result.py index 5e06f0ce8..85b84be27 100644 --- a/test/v3x/python/test_parse_result.py +++ b/test/v3x/python/test_parse_result.py @@ -17,5 +17,5 @@ def test_to_json_with_parser_ast(self): program_str = "version 1.0; bit[0] b" v3x_analyzer = cq.Analyzer() actual_ast_json = v3x_analyzer.parse_string_to_json(program_str) - expected_ast_json = '''{"Program":{"version":{"Version":{"items":"1.0","source_location":":1:9..12"}},"statements":{"StatementList":{"items":[{"Variable":{"name":{"Identifier":{"name":"b"}},"typ":{"Keyword":{"name":"bit"}},"size":{"IntegerLiteral":{"value":"0"}},"annotations":"[]","source_location":":1:21..22"}}]}}}}''' + expected_ast_json = '''{"Program":{"version":{"Version":{"items":"1.0","source_location":":1:9..12"}},"block":{"GlobalBlock":{"statements":[{"Variable":{"name":{"Identifier":{"name":"b"}},"typ":{"Type":{"name":{"Keyword":{"name":"bit"}},"size":{"IntegerLiteral":{"value":"0"}},"source_location":":1:14..20"}},"annotations":"[]","source_location":":1:21..22"}}]}}}}''' self.assertEqual(actual_ast_json, expected_ast_json) diff --git a/test/v3x/python/test_v3x_analyzer.py b/test/v3x/python/test_v3x_analyzer.py index dabddbdb8..fb57676a2 100644 --- a/test/v3x/python/test_v3x_analyzer.py +++ b/test/v3x/python/test_v3x_analyzer.py @@ -11,24 +11,24 @@ def test_parse_string_returning_ast(self): self.assertEqual(ast.version.items[0], 3) - qubit_array = ast.statements.items[0] + qubit_array = ast.block.statements[0] self.assertEqual(qubit_array.name.name, "b'q'") - self.assertEqual(qubit_array.typ.name, "b'qubit'") - self.assertEqual(qubit_array.size.value, 5) + self.assertEqual(qubit_array.typ.name.name, "b'qubit'") + self.assertEqual(qubit_array.typ.size.value, 5) - bit_array = ast.statements.items[1] + bit_array = ast.block.statements[1] self.assertEqual(bit_array.name.name, "b'b'") - self.assertEqual(bit_array.typ.name, "b'bit'") - self.assertEqual(bit_array.size.value, 5) + self.assertEqual(bit_array.typ.name.name, "b'bit'") + self.assertEqual(bit_array.typ.size.value, 5) - h_instruction = ast.statements.items[2] + h_instruction = ast.block.statements[2] self.assertEqual(h_instruction.name.name, "b'h'") h_operand = h_instruction.operands.items[0] self.assertEqual(h_operand.expr.name, "b'q'") self.assertEqual(h_operand.indices.items[0].first.value, 0) self.assertEqual(h_operand.indices.items[0].last.value, 4) - measure_instruction = ast.statements.items[3] + measure_instruction = ast.block.statements[3] self.assertEqual(measure_instruction.name.name, "b'measure'") self.assertEqual(measure_instruction.lhs.name, "b'b'") self.assertEqual(measure_instruction.rhs.name, "b'q'") @@ -47,7 +47,7 @@ def test_analyze_string_returning_ast(self): self.assertEqual(ast.version.items[0], 3) - h_instruction = ast.statements[0] + h_instruction = ast.block.statements[0] self.assertEqual(h_instruction.name, "b'h'") h_operand = h_instruction.operands[0] self.assertEqual(h_operand.variable.name, "b'q'") @@ -59,7 +59,7 @@ def test_analyze_string_returning_ast(self): self.assertEqual(h_operand.indices[3].value, 3) self.assertEqual(h_operand.indices[4].value, 4) - measure_instruction = ast.statements[1] + measure_instruction = ast.block.statements[1] self.assertEqual(measure_instruction.name, "b'measure'") measure_bit_operand = measure_instruction.operands[0] self.assertEqual(measure_bit_operand.variable.name, "b'b'") diff --git a/test_package/src/example.cpp b/test_package/src/example.cpp index cb57527d9..6d3479dd1 100644 --- a/test_package/src/example.cpp +++ b/test_package/src/example.cpp @@ -166,7 +166,7 @@ int main() { ] ) )"); - assert(clone->get_annotation().filename == "../../res/grover.cq"); + assert(clone->get_annotation().file_name == "../../res/grover.cq"); struct MyAnnotationType { int number; }; @@ -181,7 +181,7 @@ int main() { assert(clone->has_annotation()); assert(clone->get_annotation_ptr()->number == 42); assert(clone->get_annotation().number == 42); - assert(clone->get_annotation().filename == "../../res/grover.cq"); + assert(clone->get_annotation().file_name == "../../res/grover.cq"); say_hello(); }