ast_algorhitm.h 2.9 KB
Newer Older
victor's avatar
 
victor committed
1 2 3 4 5 6 7 8 9
#ifndef AST_ALGORHITM_H
#define AST_ALGORHITM_H

#include <QString>
#include <QList>

#include "ast_variabletype.h"
#include "ast_statement.h"
#include "ast_variable.h"
10
#include "ast_type.h"
victor's avatar
 
victor committed
11

victor's avatar
 
victor committed
12
#undef ABSTRACTSYNTAXTREE_EXPORT
victor's avatar
 
victor committed
13
#ifdef DATAFORMATS_LIBRARY
victor's avatar
 
victor committed
14 15 16 17 18
#define ABSTRACTSYNTAXTREE_EXPORT Q_DECL_EXPORT
#else
#define ABSTRACTSYNTAXTREE_EXPORT Q_DECL_IMPORT
#endif

victor's avatar
 
victor committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
namespace AST {

/** Specific algorhitm types */
enum AlgorhitmType {

    /** Regular algorhitm */
    AlgorhitmTypeRegular,

    /** Available to write only by teacher */
    AlgorhitmTypeTeacher,

    /** Testing mode entry point */
    AlgorhitmTypeTesting
};

victor's avatar
 
victor committed
34 35 36
/** Algorhitm implementation type */
enum AlgorhitmImplementationType {

37
    /** Kumir-compiled algorhitm */
victor's avatar
 
victor committed
38 39 40 41 42 43 44 45 46 47
    AlgorhitmCompiled,

    /** External or builtin algorhitm */
    AlgorhitmExternal

};

/** External reference for out-of module algorhitm */
struct AlgorhitmExternalReference {
    QString moduleName;
victor's avatar
 
victor committed
48
    int id;
victor's avatar
 
victor committed
49 50
};

victor's avatar
 
victor committed
51 52 53 54 55 56
/** Algorhitm public header */
struct AlgorhitmHeader {

    /** Algorhitm name, may be empty (for first algorhitm) */
    QString name;

victor's avatar
 
victor committed
57 58 59 60
    QString cHeader;

    QString pascalHeader;

victor's avatar
 
victor committed
61 62 63
    /** Algorhitm special type */
    enum AlgorhitmType specialType;

victor's avatar
 
victor committed
64 65 66 67 68 69
    /** Algorhitm implementation type*/
    enum AlgorhitmImplementationType implType;

    /** Algorhitm external reference, if defined */
    struct AlgorhitmExternalReference external;

victor's avatar
 
victor committed
70
    /** Return type */
71
    Type returnType;
victor's avatar
 
victor committed
72 73 74 75

    /** Formal arguments, represented as
      * references to corresponding local variables */
    QList<struct Variable *> arguments;
victor's avatar
 
victor committed
76

victor's avatar
 
victor committed
77 78 79
    /** Not empty if algorhitm header contains error,
      * but algorhitm name still reachable */
    QString error;
victor's avatar
 
victor committed
80 81 82 83 84 85
};

/** Algorhitm body (private to other components) */
struct AlgorhitmImplementation {

    /** Local variables and constants table */
victor's avatar
 
victor committed
86
    QList<struct Variable *> locals;
victor's avatar
 
victor committed
87 88

    /** Statements of pre-condition block (russian: dano) */
victor's avatar
 
victor committed
89
    QList<struct Statement *> pre;
victor's avatar
 
victor committed
90 91

    /** Statements of pre-condition block (russian: nado) */
victor's avatar
 
victor committed
92
    QList<struct Statement *> post;
victor's avatar
 
victor committed
93 94

    /** Statements of algorhitm body */
victor's avatar
 
victor committed
95 96
    QList<struct Statement *> body;

victor's avatar
 
victor committed
97 98
    /** Header lexems */
    QList<struct Lexem*> headerLexems;
victor's avatar
 
victor committed
99

victor's avatar
 
victor committed
100 101 102 103 104
    /** Begin lexems */
    QList<struct Lexem*> beginLexems;

    /** End lexems */
    QList<struct Lexem*> endLexems;
105 106 107

    QString headerRuntimeError;
    int headerRuntimeErrorLine;
victor's avatar
 
victor committed
108 109 110
};

/** Algorhitm representation */
victor's avatar
 
victor committed
111
struct ABSTRACTSYNTAXTREE_EXPORT Algorhitm {
victor's avatar
 
victor committed
112 113 114 115 116 117

    /** Public header for use in module etc. */
    struct AlgorhitmHeader header;

    /** Internal representation */
    struct AlgorhitmImplementation impl;
victor's avatar
 
victor committed
118 119 120 121 122 123

    explicit Algorhitm();
    explicit Algorhitm(const struct Algorhitm * src);
    void updateReferences(const struct Algorhitm * src,
                          const struct Data * srcData,
                          const struct Data * data);
victor's avatar
 
victor committed
124
    QString dump() const;
victor's avatar
 
victor committed
125
    ~Algorhitm();
victor's avatar
 
victor committed
126 127 128 129 130
};

}

#endif // AST_ALGORHITM_H