00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef MICROBE_H
00022 #define MICROBE_H
00023
00024 #include <instruction.h>
00025 #include <variable.h>
00026
00027
00028 #include <qmap.h>
00029 #include <qstring.h>
00030 #include <qstringlist.h>
00031
00032 class QString;
00033 class BTreeBase;
00034 class BTreeNode;
00035 class Code;
00036 class PIC14;
00037 class PortPin;
00038
00039 typedef QValueList<PortPin> PortPinList;
00040
00041 typedef QValueList<Variable> VariableList;
00042 typedef QMap<QString,QString> AliasMap;
00043
00044 enum ExprType
00045 {
00046 unset = 1,
00047 working = 2,
00048 number = 3,
00049 variable = 4,
00050 extpin = 5,
00051 keypad = 6,
00052 };
00053
00054
00055 class SourceLine;
00056 typedef QValueList<SourceLine> SourceLineList;
00061 class SourceLine
00062 {
00063 public:
00069 SourceLine();
00070 SourceLine( const QString & text, const QString & url, int line );
00071
00072 QString text() const { return m_text; }
00073 QString url() const { return m_url; }
00074 int line() const { return m_line; }
00075
00080 static QStringList toStringList( const SourceLineList & lines );
00081
00082 protected:
00083 QString m_text;
00084 QString m_url;
00085 int m_line;
00086 };
00087
00088
00089
00094 class Microbe
00095 {
00096 public:
00097 Microbe();
00098 ~Microbe();
00099
00100 enum MistakeType
00101 {
00102 UnknownStatement = 1,
00103 InvalidPort = 2,
00104 UnassignedPin = 3,
00105 NonHighLowPinState = 4,
00106 UnassignedPort = 5,
00107 UnexpectedStatementBeforeBracket = 6,
00108 MismatchedBrackets = 7,
00109 InvalidEquals = 8,
00110 ReservedKeyword = 9,
00111 ConsecutiveOperators = 10,
00112 MissingOperator = 11,
00113 UnknownVariable = 12,
00114 UnopenableInclude = 16,
00115 DivisionByZero = 17,
00116 NumberTooBig = 18,
00117 NonConstantStep = 19,
00118 NonConstantDelay = 20,
00119 HighLowExpected = 21,
00120 InvalidComparison = 22,
00121 SubBeforeEnd = 23,
00122 LabelExpected = 24,
00123 TooManyTokens = 25,
00124 FixedStringExpected = 26,
00125 PinListExpected = 27,
00126 AliasRedefined = 28,
00127 InvalidInterrupt = 29,
00128 InterruptRedefined = 30,
00129 InterruptBeforeEnd = 31,
00130 ReadOnlyVariable = 32,
00131 WriteOnlyVariable = 33,
00132 InvalidPinMapSize = 34,
00133 VariableRedefined = 35,
00134 InvalidVariableName = 36,
00135 VariableExpected = 40,
00136 NameExpected = 41
00137 };
00138
00143 QString errorReport() const { return m_errorReport; }
00150 QString compile( const QString & url, bool showSource, bool optimize );
00155 void compileError( MistakeType type, const QString & context, const SourceLine & sourceLine );
00159 QString uniqueLabel() { return QString("__%1").arg(m_uniqueLabel++); }
00164 QString alias( const QString & alias ) const;
00168 void addAlias( const QString & name, const QString & dest );
00175 void addDelayRoutineWanted( unsigned routine );
00180 PIC14 * makePic();
00185 void setInterruptUsed( const QString & interruptName );
00189 bool isInterruptUsed( const QString & interruptName );
00193 static bool isValidVariableName( const QString & variableName );
00197 void addVariable( const Variable & variable );
00202 Variable variable( const QString & variableName ) const;
00206 bool isVariableKnown( const QString & variableName ) const;
00210 QString dest() const;
00211 void incDest();
00212 void decDest();
00213 void resetDest();
00214
00215 protected:
00220 void simplifyProgram();
00221
00222 QStringList m_usedInterrupts;
00223 SourceLineList m_program;
00224 QString m_errorReport;
00225 int m_uniqueLabel;
00226 VariableList m_variables;
00227 int m_dest;
00228 unsigned m_maxDelaySubroutine;
00229
00237 QMap<QString,QString> m_aliasList;
00244 int m_picType;
00245 };
00246
00247
00248 #endif
00249