ScummVM API documentation
lingo-codegen.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef DIRECTOR_LINGO_LINGO_CODEGEN_H
23 #define DIRECTOR_LINGO_LINGO_CODEGEN_H
24 
25 #include "director/lingo/lingo.h"
26 #include "director/lingo/lingo-ast.h"
27 
28 namespace Director {
29 
31 public:
32  LingoCompiler();
33  virtual ~LingoCompiler() {}
34 
35  ScriptContext *compileAnonymous(const Common::U32String &code, uint32 preprocFlags = 0);
36  ScriptContext *compileLingo(const Common::U32String &code, LingoArchive *archive, ScriptType type, CastMemberID id, const Common::String &scriptName, bool anonyomous = false, uint32 preprocFlags = kLPPNone);
37  ScriptContext *compileLingoV4(Common::SeekableReadStreamEndian &stream, uint16 lctxIndex, LingoArchive *archive, const Common::String &archName, uint16 version);
38 
39  int code1(inst code) { _currentAssembly->push_back(code); return _currentAssembly->size() - 1; }
40  int code2(inst code_1, inst code_2) { int o = code1(code_1); code1(code_2); return o; }
41  int code3(inst code_1, inst code_2, inst code_3) { int o = code1(code_1); code1(code_2); code1(code_3); return o; }
42  int code4(inst code_1, inst code_2, inst code_3, inst code_4) { int o = code1(code_1); code1(code_2); code1(code_3); code1(code_4); return o; }
43  int codeCmd(const Common::String &s, int numpar);
44  int codeFloat(double f);
45  int codeFunc(const Common::String &s, int numpar);
46  int codeInt(int val);
47  int codeString(const char *s);
48  void codeVarSet(const Common::String &name);
49  void codeVarRef(const Common::String &name);
50  void codeVarGet(const Common::String &name);
51  int getTheFieldID(int entity, const Common::String &field, bool silent = false);
52  void registerFactory(Common::String &s);
53  void registerMethodVar(const Common::String &name, VarType type = kVarGeneric);
54  void updateLoopJumps(uint nextTargetPos, uint exitTargetPos);
55 
56  LingoArchive *_assemblyArchive;
57  ScriptContext *_assemblyContext;
58  Common::SharedPtr<Node> _assemblyAST;
59  int32 _assemblyId;
60  ScriptData *_currentAssembly;
61  bool _indef;
62  uint _linenumber;
63  uint _colnumber;
64  uint _bytenumber;
65  const char *_lines[3];
66  bool _inFactory;
67  LoopNode *_currentLoop;
68  bool _refMode;
69 
71 
72  bool _hadError;
73 
74 public:
75  virtual bool visitScriptNode(ScriptNode *node);
76  virtual bool visitFactoryNode(FactoryNode *node);
77  virtual bool visitHandlerNode(HandlerNode *node);
78  virtual bool visitCmdNode(CmdNode *node);
79  virtual bool visitPutIntoNode(PutIntoNode *node);
80  virtual bool visitPutAfterNode(PutAfterNode *node);
81  virtual bool visitPutBeforeNode(PutBeforeNode *node);
82  virtual bool visitSetNode(SetNode *node);
83  virtual bool visitGlobalNode(GlobalNode *node);
84  virtual bool visitPropertyNode(PropertyNode *node);
85  virtual bool visitInstanceNode(InstanceNode *node);
86  virtual bool visitIfStmtNode(IfStmtNode *node);
87  virtual bool visitIfElseStmtNode(IfElseStmtNode *node);
88  virtual bool visitRepeatWhileNode(RepeatWhileNode *node);
89  virtual bool visitRepeatWithToNode(RepeatWithToNode *node);
90  virtual bool visitRepeatWithInNode(RepeatWithInNode *node);
91  virtual bool visitNextRepeatNode(NextRepeatNode *node);
92  virtual bool visitExitRepeatNode(ExitRepeatNode *node);
93  virtual bool visitExitNode(ExitNode *node);
94  virtual bool visitReturnNode(ReturnNode *node);
95  virtual bool visitTellNode(TellNode *node);
96  virtual bool visitWhenNode(WhenNode *node);
97  virtual bool visitDeleteNode(DeleteNode *node);
98  virtual bool visitHiliteNode(HiliteNode *node);
99  virtual bool visitAssertErrorNode(AssertErrorNode *node);
100  virtual bool visitIntNode(IntNode *node);
101  virtual bool visitFloatNode(FloatNode *node);
102  virtual bool visitSymbolNode(SymbolNode *node);
103  virtual bool visitStringNode(StringNode *node);
104  virtual bool visitListNode(ListNode *node);
105  virtual bool visitPropListNode(PropListNode *node);
106  virtual bool visitPropPairNode(PropPairNode *node);
107  virtual bool visitFuncNode(FuncNode *node);
108  virtual bool visitVarNode(VarNode *node);
109  virtual bool visitParensNode(ParensNode *node);
110  virtual bool visitUnaryOpNode(UnaryOpNode *node);
111  virtual bool visitBinaryOpNode(BinaryOpNode *node);
112  virtual bool visitFrameNode(FrameNode *node);
113  virtual bool visitMovieNode(MovieNode *node);
114  virtual bool visitIntersectsNode(IntersectsNode *node);
115  virtual bool visitWithinNode(WithinNode *node);
116  virtual bool visitTheNode(TheNode *node);
117  virtual bool visitTheOfNode(TheOfNode *node);
118  virtual bool visitTheNumberOfNode(TheNumberOfNode *node);
119  virtual bool visitTheLastNode(TheLastNode *node);
120  virtual bool visitTheDateTimeNode(TheDateTimeNode *node);
121  virtual bool visitMenuNode(MenuNode *node);
122  virtual bool visitMenuItemNode(MenuItemNode *node);
123  virtual bool visitSoundNode(SoundNode *node);
124  virtual bool visitSpriteNode(SpriteNode *node);
125  virtual bool visitChunkExprNode(ChunkExprNode *node);
126 
127 private:
128  int parse(const char *code);
129 
130 public:
131  // lingo-preprocessor.cpp
132  Common::U32String codePreprocessor(const Common::U32String &code, LingoArchive *archive, ScriptType type, CastMemberID id, uint32 flags);
133  MethodHash prescanMethods(const Common::U32String &code);
134 
135  // lingo-patcher.cpp
136  Common::U32String patchLingoCode(const Common::U32String &line, LingoArchive *archive, ScriptType type, CastMemberID id, int linenumber);
137 };
138 
139 } // End of namespace Director
140 
141 #endif
Definition: lingo-ast.h:755
Definition: lingo-ast.h:800
Definition: lingo-ast.h:710
Definition: str.h:59
Definition: lingo-ast.h:815
Definition: lingo.h:298
Definition: lingo-ast.h:567
Definition: lingo-ast.h:518
Definition: lingo-ast.h:443
Definition: lingo-ast.h:460
Definition: lingo-ast.h:738
Definition: lingo-ast.h:941
Definition: array.h:52
Definition: lingo-ast.h:925
Definition: lingo-ast.h:786
Definition: lingo-ast.h:1016
Definition: lingo-ast.h:315
Definition: lingo-ast.h:160
Definition: lingo-ast.h:971
Definition: lingo-ast.h:296
Definition: archive.h:35
Definition: lingo-ast.h:1002
Definition: lingo-ast.h:644
Definition: lingo-ast.h:724
Definition: lingo-ast.h:279
Definition: lingo-ast.h:547
Definition: lingo-ast.h:333
Definition: lingo-ast.h:894
void push_back(const T &element)
Definition: array.h:180
Definition: lingo-ast.h:682
Definition: lingo-ast.h:860
Definition: lingo-ast.h:401
Definition: ustr.h:57
Definition: lingo-ast.h:670
Definition: lingo-ast.h:696
Definition: lingo-ast.h:350
Definition: lingo-ast.h:1030
Definition: lingo-codegen.h:30
Definition: lingo-ast.h:496
Definition: lingo-ast.h:265
Definition: lingo-ast.h:832
size_type size() const
Definition: array.h:315
Definition: lingo-ast.h:582
Definition: lingo-ast.h:616
Definition: lingo-ast.h:772
Definition: lingo-ast.h:557
Definition: lingo-ast.h:957
Definition: stream.h:944
Definition: lingo-ast.h:877
Definition: lingo-ast.h:985
Definition: lingo-ast.h:908
Definition: ptr.h:159
Definition: lingo-ast.h:479
Definition: lingo-ast.h:846
Definition: lingo-ast.h:367
Definition: lingo-ast.h:658
Definition: lingo-ast.h:253
Definition: types.h:414
Definition: lingo-ast.h:630
Definition: lingo-ast.h:537
Definition: lingo-ast.h:384
Definition: lingo-object.h:213
Definition: lingo-ast.h:429
Definition: lingo-ast.h:599
Definition: lingo-ast.h:415