File: extensions.hpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (112 lines) | stat: -rw-r--r-- 4,426 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef COMPILER_EXTENSIONS_H_INCLUDED
#define COMPILER_EXTENSIONS_H_INCLUDED

#include <map>
#include <string>
#include <vector>

#include <components/interpreter/types.hpp>

namespace Compiler
{
    class Literals;

    /// Typedef for script arguments string
    /** Every character reperesents an argument to the command. All arguments are required until a /, after which
        every argument is optional. <BR>
        Eg: fff/f represents 3 required floats followed by one optional float <BR>
        f - Float <BR>
        c - String, case smashed <BR>
        l - Integer <BR>
        s - Short <BR>
        S - String, case preserved <BR>
        x - Optional, ignored string argument. Emits a parser warning when this argument is supplied. <BR>
        X - Optional, ignored numeric expression. Emits a parser warning when this argument is supplied. <BR>
        z - Optional, ignored string or numeric argument. Emits a parser warning when this argument is supplied. <BR>
        j - A piece of junk (either . or a specific keyword)
    **/
    typedef std::string ScriptArgs;

    /// Typedef for script return char
    /** The character represents the type of data being returned. <BR>
        f - float <BR>
        S - String (Cell names) <BR>
        l - Integer
    **/
    typedef char ScriptReturn;

    /// \brief Collection of compiler extensions
    class Extensions
    {

        struct Function
        {
            char mReturn;
            ScriptArgs mArguments;
            int mCode;
            int mCodeExplicit;
            int mSegment;
        };

        struct Instruction
        {
            ScriptArgs mArguments;
            int mCode;
            int mCodeExplicit;
            int mSegment;
        };

        int mNextKeywordIndex;
        std::map<std::string, int> mKeywords;
        std::map<int, Function> mFunctions;
        std::map<int, Instruction> mInstructions;

    public:
        Extensions();

        int searchKeyword(const std::string& keyword) const;
        ///< Return extension keyword code, that is assigned to the string \a keyword.
        /// - if no match is found 0 is returned.
        /// - keyword must be all lower case.

        bool isFunction(int keyword, ScriptReturn& returnType, ScriptArgs& argumentType, bool& explicitReference) const;
        ///< Is this keyword registered with a function? If yes, return return and argument
        /// types.
        /// \param explicitReference In: has explicit reference; Out: set to false, if
        /// explicit reference is not available for this instruction.

        bool isInstruction(int keyword, ScriptArgs& argumentType, bool& explicitReference) const;
        ///< Is this keyword registered with a function? If yes, return argument types.
        /// \param explicitReference In: has explicit reference; Out: set to false, if
        /// explicit reference is not available for this instruction.

        void registerFunction(std::string_view keyword, ScriptReturn returnType, std::string_view argumentType,
            int code, int codeExplicit = -1);
        ///< Register a custom function
        /// - keyword must be all lower case.
        /// - keyword must be unique
        /// - if explicit references are not supported, segment5codeExplicit must be set to -1
        /// \note Currently only segment 3 and segment 5 opcodes are supported.

        void registerInstruction(
            std::string_view keyword, std::string_view argumentType, int code, int codeExplicit = -1);
        ///< Register a custom instruction
        /// - keyword must be all lower case.
        /// - keyword must be unique
        /// - if explicit references are not supported, segment5codeExplicit must be set to -1
        /// \note Currently only segment 3 and segment 5 opcodes are supported.

        void generateFunctionCode(int keyword, std::vector<Interpreter::Type_Code>& code, Literals& literals,
            const std::string& id, int optionalArguments) const;
        ///< Append code for function to \a code.

        void generateInstructionCode(int keyword, std::vector<Interpreter::Type_Code>& code, Literals& literals,
            const std::string& id, int optionalArguments) const;
        ///< Append code for function to \a code.

        void listKeywords(std::vector<std::string>& keywords) const;
        ///< Append all known keywords to \a kaywords.
    };
}

#endif