A set of benchmarks to compare a new prototype MiniZinc implementation
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
3/*
4 * Main authors:
5 * Guido Tack <guido.tack@monash.edu>
6 */
7
8/* This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11
12#ifndef __MINIZINC_TYPECHECK_HH__
13#define __MINIZINC_TYPECHECK_HH__
14
15#include <minizinc/astexception.hh>
16#include <minizinc/hash.hh>
17#include <minizinc/model.hh>
18
19namespace MiniZinc {
20
21/// Scoped variable declarations
22class Scopes {
23protected:
24 typedef IdMap<VarDecl*> DeclMap;
25 struct Scope {
26 /// Whether this scope is toplevel
27 bool toplevel;
28 /// Map from identifiers to declarations
29 DeclMap m;
30 /// Constructor
31 Scope(void) : toplevel(false) {}
32 };
33 /// Stack of scopes
34 std::vector<Scope> s;
35
36public:
37 /// Constructor
38 Scopes(void);
39
40 /// Add a variable declaration
41 void add(EnvI& env, VarDecl* vd);
42
43 /// Push a new scope
44 void push(bool toplevel);
45 /// Pop topmost scope
46 void pop(void);
47
48 /// Return declaration for \a ident, or NULL if not found
49 VarDecl* find(Id* ident);
50};
51
52/// Topological sorting of items
53class TopoSorter {
54public:
55 typedef std::vector<VarDecl*> Decls;
56 typedef std::unordered_map<VarDecl*, int> PosMap;
57
58 /// List of all declarations
59 Decls decls;
60 /// Scoped declarations
61 Scopes scopes;
62 /// Map from declarations to positions
63 PosMap pos;
64 /// The model
65 Model* model;
66
67 TopoSorter(Model* model0) : model(model0) {}
68
69 /// Add a variable declaration item
70 void add(EnvI& env, VarDeclI* vd, bool handleEnums, Model* enumItems);
71 /// Get variable declaration from identifier \a id
72 VarDecl* get(EnvI& env, const ASTString& id, const Location& loc);
73
74 VarDecl* checkId(EnvI& env, const ASTString& ident, const Location& loc);
75 VarDecl* checkId(EnvI& env, Id* ident, const Location& loc);
76 /// Run the topological sorting for expression \a e
77 void run(EnvI& env, Expression* e);
78};
79
80/// Type check the model \a m
81void typecheck(Env& env, Model* m, std::vector<TypeError>& typeErrors,
82 bool ignoreUndefinedParameters, bool allowMultiAssignment, bool isFlatZinc = false);
83
84/// Type check new assign item \a ai in model \a m
85void typecheck(Env& env, Model* m, AssignI* ai);
86
87/// Output description of parameters and output variables to \a os
88void output_model_interface(Env& env, Model* m, std::ostream& os);
89
90/// Output information about variable types (enum types) to \a os
91void output_model_variable_types(Env& env, Model* m, std::ostream& os);
92
93} // namespace MiniZinc
94
95#endif