blob: 77fa5c18d83c6c799cbc72072a19f41c0922509d (
plain)
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
|
/***************************************************************************
* Copyright (C) 2003-2004 by David Saxton *
* david@bluehaze.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef FLOWCODE_H
#define FLOWCODE_H
#include "language.h"
#include <tqguardedptr.h>
#include <tqobject.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqvaluelist.h>
class CNItem;
class FlowPart;
class Item;
class MicroSettings;
typedef TQValueList<FlowPart*> FlowPartList;
typedef TQValueList<TQGuardedPtr<Item> > ItemList;
/**
"FlowCode" can possibly be considered a misnomer, as the output is actually Microbe.
However, the function of this class is to take a set of FlowParts, and generate the
basic from the code that they create. The 3 simple steps for usage of this function:
(1) Create an instance of this class, giving the Start point and setings
(2) Add all the subroutines present using addSubroutine()
(3) Call generateMicrobe() to get the Microbe code.
@author David Saxton
*/
class FlowCode : public Language
{
public:
FlowCode( ProcessChain *processChain, KTechlab *tqparent );
virtual void processInput( ProcessOptions options );
virtual ProcessOptions::ProcessPath::Path outputPath( ProcessOptions::ProcessPath::Path inputPath ) const;
/**
* You must set the start part
*/
void setStartPart( FlowPart *startPart );
~FlowCode();
/**
* You must add all top level subroutines using this function
*/
void addSubroutine( FlowPart *part );
/**
* Adds code at the current insertion point
*/
void addCode( const TQString& code );
/**
* Adds a code branch to the current insertion point. This will stop when the level gets
* below the original starting level (so for insertion of the contents of a for loop,
* insertion will stop at the end of that for loop).
* @param flowPart The next FlowPart to get code from
*/
void addCodeBranch( FlowPart *flowPart );
/**
* Designates a FlowPart as a stopping part (i.e. will refuse requests to addCodeBranch
* for that FlowPart until removeStopPart is called
*/
void addStopPart( FlowPart *part );
/**
* Undesignates a FlowPart as a stopping part
*/
void removeStopPart( FlowPart *part );
/**
* Generates and returns the microbe code
* @param nonVerbal if true then will not inform the user when something goes wrong
*/
TQString generateMicrobe( const ItemList &itemList, MicroSettings *settings );
/**
* Returns true if the FlowPart is a valid one for adding a branch
*/
bool isValidBranch( FlowPart *flowPart );
/**
* Generates a nice label name from the string, e.g. genLabel("callsub")
* returns "__label_callsub".
*/
static TQString genLabel( const TQString &id );
protected:
/**
* Performs indenting, removal of unnecessary labels, etc.
*/
void tidyCode();
TQStringList m_gotos; // Gotos used
TQStringList m_labels; // Labels used
FlowPartList m_subroutines;
FlowPartList m_addedParts;
FlowPartList m_stopParts;
FlowPart *p_startPart;
TQString m_code;
int m_curLevel;
};
#endif
|