Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ae378fe
Added position to function body
thorulf4 Jan 12, 2023
986d020
Fix issues with member hiding inherited member
thorulf4 Jan 13, 2023
a1cb315
Simplify find_index
thorulf4 Feb 2, 2023
704cb28
Added positions to variables
thorulf4 Feb 2, 2023
9b26d4b
Fit naming to current naming convention
thorulf4 Feb 2, 2023
5c3090e
Readded lost change
thorulf4 Feb 2, 2023
4744098
Fixed issue with duplicated frames in function bodies
thorulf4 Feb 2, 2023
e17b926
Added position data to struct members
thorulf4 Feb 2, 2023
287a9fb
Added position to function uid
thorulf4 Feb 21, 2023
c90894d
Improve uuid position accuracy
thorulf4 Feb 21, 2023
5a63b76
Made position of function parameter symbol more consistent
thorulf4 Feb 28, 2023
2b09033
Added a getter for instances
thorulf4 Mar 2, 2023
fd574ef
Changed frame structure to split bloated global declarations
thorulf4 Mar 15, 2023
50d287f
Made parameter declaration positions consistent with variable declara…
thorulf4 Apr 25, 2023
94fbbe9
Remove unused testing code
thorulf4 Aug 8, 2023
b9f948f
Updated libxml2 to 2.11.5 and changed source to github mirror as the …
mikucionisaau Sep 20, 2023
b2bbd4f
Added DOWNLOAD_EXTRACT_TIMESTAMP option to reduce warning noise
mikucionisaau Sep 20, 2023
f48943f
Changed the linenumber type to unsigned int for consistency
mikucionisaau Apr 12, 2024
9db3e7b
Merge branch 'main' into rebased_lsp_changes
mikucionisaau Apr 12, 2024
8019234
Improved document error reporting in unit tests (still messed up: can…
mikucionisaau Apr 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/utap/AbstractBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class AbstractBuilder : public ParserBuilder
* Function declarations
*/
void decl_parameter(const char* name, bool) override;
void func_type() override;
void decl_func_begin(const char* name) override; // n paramaters
void decl_func_end() override; // 1 block
void dynamic_load_lib(const char* name) override;
Expand Down Expand Up @@ -297,6 +298,10 @@ class AbstractBuilder : public ParserBuilder
void query_results_begin() override;
void query_results_end() override;
void query_end() override;

void builtin_decl_end() override {}
void system_decl_begin() override {}
void system_decl_end() override {}
};
} // namespace UTAP
#endif
5 changes: 5 additions & 0 deletions include/utap/DocumentBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class DocumentBuilder : public StatementBuilder
// Method for handling types
//

std::stack<declarations_t*> declarations;

declarations_t* getCurrentDeclarationBlock();

variable_t* addVariable(type_t type, const std::string& name, expression_t init, position_t pos) override;
Expand Down Expand Up @@ -170,6 +172,9 @@ class DocumentBuilder : public StatementBuilder
void query_results_begin() override;
void query_results_end() override;
void query_end() override;

void system_decl_begin() override;
void system_decl_end() override;
};
} // namespace UTAP
#endif
2 changes: 2 additions & 0 deletions include/utap/ExpressionBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ class ExpressionBuilder : public AbstractBuilder
void expr_foreach_dynamic_end(const char* name) override;
void push_dynamic_frame_of(template_t* t, std::string name); // no override
void pop_dynamic_frame_of(std::string name);

void builtin_decl_end() override;
};
} // namespace UTAP

Expand Down
6 changes: 5 additions & 1 deletion include/utap/StatementBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class StatementBuilder : public ExpressionBuilder
/** The labels of a struct. */
std::vector<std::string> labels;

/** The positions of a struct. */
std::vector<position_t> positions;

/** path to libraries*/
std::vector<std::filesystem::path> libpaths;

Expand All @@ -65,7 +68,7 @@ class StatementBuilder : public ExpressionBuilder
static void collectDependencies(std::set<symbol_t>&, type_t);

public:
explicit StatementBuilder(Document&, std::vector<std::filesystem::path> libpaths = {});
StatementBuilder(Document&, std::vector<std::filesystem::path> libpaths = {});
StatementBuilder(const StatementBuilder&) = delete;

BlockStatement& get_block();
Expand All @@ -79,6 +82,7 @@ class StatementBuilder : public ExpressionBuilder
void decl_init_list(uint32_t num) override;
void decl_field_init(const char* name) override;
void decl_parameter(const char* name, bool) override;
void func_type() override;
void decl_func_begin(const char* name) override;
void decl_func_end() override;
void dynamic_load_lib(const char* name) override;
Expand Down
8 changes: 8 additions & 0 deletions include/utap/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class ParserBuilder
* Function declarations
*/
virtual void decl_parameter(const char* name, bool ref) = 0;
virtual void func_type() = 0;
virtual void decl_func_begin(const char* name) = 0;
virtual void decl_func_end() = 0; // 1 block
virtual void dynamic_load_lib(const char* name) = 0;
Expand Down Expand Up @@ -443,6 +444,13 @@ class ParserBuilder
virtual void query_results_begin() = 0;
virtual void query_results_end() = 0;
virtual void query_end() = 0;

// Called after built in declarations have been parsed
virtual void builtin_decl_end() = 0;

// Before and after system declarations are parsed
virtual void system_decl_begin() = 0;
virtual void system_decl_end() = 0;
};

/** Error/warning messages with some arguments */
Expand Down
11 changes: 10 additions & 1 deletion include/utap/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ struct function_t : stringify_t<function_t>
std::unique_ptr<BlockStatement> body{nullptr}; /**< Pointer to the block. */
function_t() = default;
std::ostream& print(std::ostream& os) const; /**< textual representation, used to write the XML file */
position_t body_position;
};

struct progress_t
Expand Down Expand Up @@ -511,6 +512,8 @@ class Document

/** Returns the global declarations of the document. */
declarations_t& get_globals() { return global; }
frame_t get_builtin_decls() { return global.frame.get_parent(); }
declarations_t& get_system_declarations() { return system_declarations; }

/** Returns the templates of the document. */
std::list<template_t>& get_templates() { return templates; }
Expand All @@ -521,6 +524,9 @@ class Document
/** Returns the processes of the document. */
std::list<instance_t>& get_processes() { return processes; }

/** Returns the instances of the document. */
const std::list<instance_t>& get_instances() const { return instances; }

options_t& get_options();
void set_options(const options_t& options);

Expand All @@ -529,10 +535,12 @@ class Document

void add_position(uint32_t position, uint32_t offset, uint32_t line, std::shared_ptr<std::string> path);
const position_index_t::line_t& find_position(uint32_t position) const;
const position_index_t::line_t& find_first_position(uint32_t position) const;

variable_t* add_variable_to_function(function_t*, frame_t, type_t, const std::string&, expression_t initital,
position_t);
variable_t* add_variable(declarations_t*, type_t type, const std::string&, expression_t initial, position_t);
variable_t* add_variable(declarations_t*, frame_t, type_t type, const std::string&, expression_t initial,
position_t);
void add_progress_measure(declarations_t*, expression_t guard, expression_t measure);

template_t& add_template(const std::string& name, frame_t params, position_t, bool isTA = true,
Expand Down Expand Up @@ -640,6 +648,7 @@ class Document

// Global declarations
declarations_t global;
declarations_t system_declarations;

expression_t before_update;
expression_t after_update;
Expand Down
8 changes: 7 additions & 1 deletion include/utap/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class position_index_t

private:
std::vector<line_t> lines;
const line_t& find(uint32_t position, uint32_t first, uint32_t last) const;
uint32_t find_index(uint32_t position) const;

public:
/** Add information about a line to the container. */
Expand All @@ -91,6 +91,12 @@ class position_index_t
*/
const line_t& find(uint32_t position) const;

/**
* Retrieves information about the first line in the document node
* that the position argument is pointing to
*/
const position_index_t::line_t& find_first_line(uint32_t position) const;

/** Dump table to stdout. */
std::ostream& print(std::ostream&) const;
};
Expand Down
3 changes: 1 addition & 2 deletions include/utap/statement.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,9 @@ class BlockStatement : public Statement, public declarations_t

protected:
std::vector<std::unique_ptr<Statement>> stats;
frame_t frame;

public:
explicit BlockStatement(frame_t frame): frame{std::move(frame)} {}
explicit BlockStatement(frame_t frame) { this->frame = std::move(frame); }
int32_t accept(StatementVisitor* visitor) override;
bool returns() override;

Expand Down
6 changes: 5 additions & 1 deletion include/utap/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ class type_t
/** Returns the \a i'th label. */
const std::string& get_label(uint32_t) const;

/** Returns the position of i'th field in struct */
const position_t& get_field_position(uint32_t) const;

/** Returns the expression associated with the type. */
expression_t get_expression() const;

Expand Down Expand Up @@ -376,7 +379,8 @@ class type_t
static type_t create_process_set(type_t instance, position_t = position_t());

/** Creates a new record type */
static type_t create_record(const std::vector<type_t>&, const std::vector<std::string>&, position_t = position_t());
static type_t create_record(const std::vector<type_t>&, const std::vector<std::string>&,
const std::vector<position_t>&, position_t = position_t());

/** Creates a new function type */
static type_t create_function(type_t, const std::vector<type_t>&, const std::vector<std::string>&,
Expand Down
26 changes: 21 additions & 5 deletions src/DocumentBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ using std::string;

DocumentBuilder::DocumentBuilder(Document& doc, std::vector<std::filesystem::path> paths):
StatementBuilder{doc, std::move(paths)}
{}
{
declarations.push(&doc.get_globals());
}

/************************************************************
* Variable and function declarations
Expand All @@ -48,7 +50,7 @@ variable_t* DocumentBuilder::addVariable(type_t type, const std::string& name, e
if (currentFun) {
return document.add_variable_to_function(currentFun, frames.top(), type, name, init, pos);
} else {
return document.add_variable(getCurrentDeclarationBlock(), type, name, init, pos);
return document.add_variable(getCurrentDeclarationBlock(), frames.top(), type, name, init, pos);
}
}

Expand All @@ -57,9 +59,18 @@ bool DocumentBuilder::addFunction(type_t type, const std::string& name, position
return getCurrentDeclarationBlock()->add_function(type, name, pos, currentFun);
}

declarations_t* DocumentBuilder::getCurrentDeclarationBlock()
declarations_t* DocumentBuilder::getCurrentDeclarationBlock() { return declarations.top(); }

void DocumentBuilder::system_decl_begin()
{
return (currentTemplate ? currentTemplate : &document.get_globals());
declarations.push(&document.get_system_declarations());
push_frame(document.get_system_declarations().frame);
}

void DocumentBuilder::system_decl_end()
{
declarations.pop();
popFrame();
}

void DocumentBuilder::addSelectSymbolToFrame(const std::string& id, frame_t& frame, position_t pos)
Expand Down Expand Up @@ -165,12 +176,14 @@ void DocumentBuilder::proc_begin(const char* name, const bool isTA, const string
}
}

declarations.push(currentTemplate);
push_frame(currentTemplate->frame);
params = frame_t::create();
}

void DocumentBuilder::proc_end() // 1 ProcBody
{
declarations.pop();
currentTemplate = nullptr;
popFrame();
}
Expand Down Expand Up @@ -642,7 +655,10 @@ void DocumentBuilder::prechart_set(const bool pch) { currentTemplate->has_precha
void DocumentBuilder::decl_dynamic_template(const std::string& name)
{
// Should be null, but error recovery can result in proc_end not being called
currentTemplate = nullptr;
if (currentTemplate != nullptr) {
currentTemplate = nullptr;
declarations.pop();
}
/* check if name already exists */
if (frames.top().contains(name)) {
handle_error(DuplicateDefinitionError(name));
Expand Down
6 changes: 5 additions & 1 deletion src/ExpressionBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ void ExpressionBuilder::ExpressionFragments::pop(uint32_t n)

ExpressionBuilder::ExpressionBuilder(Document& doc): document{doc}
{
push_frame(document.get_globals().frame);
frame_t frame = doc.get_builtin_decls();
assert(frame != frame_t{});
push_frame(std::move(frame));
scalar_count = 0;
}

Expand All @@ -83,6 +85,8 @@ void ExpressionBuilder::push_frame(frame_t frame) { frames.push(std::move(frame)

void ExpressionBuilder::popFrame() { frames.pop(); }

void ExpressionBuilder::builtin_decl_end() { push_frame(document.get_globals().frame); }

bool ExpressionBuilder::resolve(const std::string& name, symbol_t& uid) const
{
assert(!frames.empty());
Expand Down
34 changes: 24 additions & 10 deletions src/StatementBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ void StatementBuilder::type_array_of_type(size_t n)
*/
void StatementBuilder::type_struct(PREFIX prefix, uint32_t n)
{
vector<type_t> f(fields.end() - n, fields.end());
vector<string> l(labels.end() - n, labels.end());
auto f = vector<type_t>(fields.end() - n, fields.end());
auto l = vector<string>(labels.end() - n, labels.end());
auto p = vector<position_t>(positions.end() - n, positions.end());

fields.erase(fields.end() - n, fields.end());
labels.erase(labels.end() - n, labels.end());
positions.erase(positions.end() - n, positions.end());

typeFragments.push(apply_prefix(prefix, type_t::create_record(f, l, position)));
typeFragments.push(apply_prefix(prefix, type_t::create_record(f, l, p, position)));
}

/**
Expand All @@ -152,6 +154,7 @@ void StatementBuilder::struct_field(const char* name)

fields.push_back(type);
labels.push_back(name);
positions.push_back(position);

/* Check the base type. We should check this in the type
* checker. The problem is that we do not maintain the position of
Expand Down Expand Up @@ -259,7 +262,7 @@ void StatementBuilder::decl_var(const char* name, bool hasInit)
}

// Add variable to document
addVariable(type, name, init, position_t());
addVariable(type, name, init, position);
}

// Array and struct initialisers are represented as expressions having
Expand Down Expand Up @@ -308,15 +311,18 @@ void StatementBuilder::decl_init_list(uint32_t num)
// Compute new type (each field has a label type, see decl_field_init())
vector<type_t> types;
vector<string> labels;
vector<position_t> positions;
for (uint32_t i = 0; i < num; i++) {
type_t type = fields[i].get_type();
types.push_back(type[0]);
labels.push_back(type.get_label(0));
fields[i].set_type(type[0]);
positions.push_back(fields[i].get_position());
}

// Create list expression
fragments.push(expression_t::create_nary(LIST, fields, position, type_t::create_record(types, labels, position)));
fragments.push(
expression_t::create_nary(LIST, fields, position, type_t::create_record(types, labels, positions, position)));
}

/********************************************************************
Expand All @@ -334,9 +340,8 @@ void StatementBuilder::decl_parameter(const char* name, bool ref)
params.add_symbol(name, type, position);
}

void StatementBuilder::decl_func_begin(const char* name)
void StatementBuilder::func_type()
{
// assert(currentFun == nullptr); // the parser should recover cleanly, but it does not
if (currentFun != nullptr) {
/* If currentFun != nullptr, we are in an error state. This error
* state arises when a parsing error happens in the middle of a
Expand All @@ -351,16 +356,23 @@ void StatementBuilder::decl_func_begin(const char* name)
}

type_t return_type = typeFragments[0];
typeFragments.pop();

vector<type_t> types;
vector<string> labels;
for (size_t i = 0; i < params.get_size(); i++) {
types.push_back(params[i].get_type());
labels.push_back(params[i].get_name());
}
type_t type = type_t::create_function(return_type, types, labels, position);
if (!addFunction(type, name, {})) {

typeFragments[0] = type_t::create_function(return_type, types, labels, position);
}

void StatementBuilder::decl_func_begin(const char* name)
{
type_t type = typeFragments[0];
typeFragments.pop();

if (!addFunction(type, name, position)) {
handle_error(DuplicateDefinitionError(name));
}

Expand Down Expand Up @@ -393,6 +405,8 @@ void StatementBuilder::decl_func_end()
handle_error(TypeException{"$Return_statement_expected"});
}

currentFun->body_position = position;

/* Restore global frame.
*/
popFrame();
Expand Down
3 changes: 3 additions & 0 deletions src/abstractbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ void AbstractBuilder::gantt_entry_end() { UNSUPPORTED; }

void AbstractBuilder::decl_progress(bool) { UNSUPPORTED; }
void AbstractBuilder::decl_parameter(const char* name, bool) { UNSUPPORTED; }

void AbstractBuilder::func_type() { UNSUPPORTED; }

void AbstractBuilder::decl_func_begin(const char* name) { UNSUPPORTED; }
void AbstractBuilder::decl_func_end() { UNSUPPORTED; }
void AbstractBuilder::dynamic_load_lib(const char* name) { UNSUPPORTED; }
Expand Down
Loading