src/main.cpp

Thu, 24 Jul 2014 16:54:45 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 24 Jul 2014 16:54:45 +0300
changeset 141
68d60e2cfa76
parent 140
04a6eb68f226
child 142
1f5518dd8146
permissions
-rw-r--r--

- now works properly (still debugging --help)

119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
133
dbbdb870c835 - changed all source files to use my correct legal name instead of my calling name
Teemu Piippo <crimsondusk64@gmail.com>
parents: 127
diff changeset
2 Copyright 2012-2014 Teemu Piippo
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. The name of the author may not be used to endorse or promote products
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 derived from this software without specific prior written permission.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 */
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "main.h"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #include "events.h"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include "commands.h"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "stringTable.h"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 #include "dataBuffer.h"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 #include "parser.h"
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 #include "lexer.h"
135
8b9132fea327 - massive refactoring continues (doesn't compile yet)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 134
diff changeset
36 #include "hginfo.h"
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
37 #include "commandline.h"
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
38 #include "enumstrings.h"
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
140
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
40 #ifdef SVN_REVISION_STRING
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
41 #define FULL_VERSION_STRING VERSION_STRING "-" SVN_REVISION_STRING;
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
42 #else
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
43 #define FULL_VERSION_STRING VERSION_STRING;
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
44 #endif
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
45
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 int main (int argc, char** argv)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 try
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 {
141
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
50 Verbosity verboselevel (Verbosity::None);
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
51 bool listcommands (false);
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
52 bool sendhelp (false);
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
53 bool test (true);
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
54
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
55 CommandLine cmdline;
141
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
56 cmdline.addOption (listcommands, 'l', "listfunctions", "List available functions");
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
57 cmdline.addOption (sendhelp, 'h', "help", "Print help text");
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
58 cmdline.addOption (test, 'x', "test", "testy test");
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
59 cmdline.addEnumeratedOption (verboselevel, 'V', "verbose", "Output more information");
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
60 StringList args = cmdline.process (argc, argv);
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
61
141
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
62 if (sendhelp)
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
63 {
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
64 // Print header
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
65 String header = APPNAME " " FULL_VERSION_STRING;
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
66 #ifdef DEBUG
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
67 header += " (debug build)";
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
68 #endif
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
69 printTo (stderr, "%1\n", header);
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
70 printTo (stderr, "usage: %1 [OPTIONS] SOURCE [OUTPUT]\n\n", argv[0]);
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
71 printTo (stderr, "Options:\n" + cmdline.describeOptions());
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
72 return EXIT_SUCCESS;
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
73 }
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
74
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
75 if (listcommands)
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 BotscriptParser parser;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 parser.setReadOnly (true);
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 parser.parseBotscript ("botc_defs.bts");
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 for (CommandInfo* comm : getCommands())
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 print ("%1\n", comm->signature());
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
141
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
84 return EXIT_SUCCESS;
137
73d057b030d0 - a bit more refactoring, adjusted the main commandline interface
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
85 }
73d057b030d0 - a bit more refactoring, adjusted the main commandline interface
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
86
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
87 if (not within (args.size(), 1, 2))
137
73d057b030d0 - a bit more refactoring, adjusted the main commandline interface
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
88 {
141
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
89 printTo (stderr, "%1: need an input file.\nUse `%1 --help` for more information\n",
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
90 argv[0]);
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
91 return EXIT_FAILURE;
127
ed4289183de6 - check for arg count before printing the header so the header doesn't appear when displaying usage
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
92 }
ed4289183de6 - check for arg count before printing the header so the header doesn't appear when displaying usage
Teemu Piippo <crimsondusk64@gmail.com>
parents: 122
diff changeset
93
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 String outfile;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
96 if (args.size() == 1)
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
97 outfile = makeObjectFileName (args[0]);
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 else
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
99 outfile = args[1];
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 // Prepare reader and writer
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 BotscriptParser* parser = new BotscriptParser;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 // We're set, begin parsing :)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 print ("Parsing script...\n");
139
cf11621ae422 - added proper commandline interface with options. synergizes very nicely with named enums. :-) added a verbosity level which does nothing just yet
Teemu Piippo <crimsondusk64@gmail.com>
parents: 138
diff changeset
106 parser->parseBotscript (args[0]);
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 print ("Script parsed successfully.\n");
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 // Parse done, print statistics and write to file
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 int globalcount = parser->getHighestVarIndex (true) + 1;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 int statelocalcount = parser->getHighestVarIndex (false) + 1;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 int stringcount = countStringsInTable();
134
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
113 print ("%1 / %2 strings\n", stringcount, Limits::MaxStringlistSize);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
114 print ("%1 / %2 global variable indices\n", globalcount, Limits::MaxGlobalVars);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
115 print ("%1 / %2 state variable indices\n", statelocalcount, Limits::MaxStateVars);
eca2fc0acaa2 - massive refactoring
Teemu Piippo <crimsondusk64@gmail.com>
parents: 133
diff changeset
116 print ("%1 / %2 events\n", parser->numEvents(), Limits::MaxEvents);
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 print ("%1 state%s1\n", parser->numStates());
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 parser->writeToFile (outfile);
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 delete parser;
141
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
121 return EXIT_SUCCESS;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 catch (std::exception& e)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 fprintf (stderr, "error: %s\n", e.what());
141
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
126 return EXIT_FAILURE;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129
138
a426c1039655 - even more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 137
diff changeset
130 // _________________________________________________________________________________________________
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 // Mutates given filename to an object filename
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 String makeObjectFileName (String s)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 // Locate the extension and chop it out
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 int extdot = s.lastIndexOf (".");
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 if (extdot >= s.length() - 4)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 s -= (s.length() - extdot);
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 s += ".o";
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143 return s;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145
138
a426c1039655 - even more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 137
diff changeset
146 // _________________________________________________________________________________________________
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
148 DataType getTypeByName (String token)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
149 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
150 token = token.toLowercase();
137
73d057b030d0 - a bit more refactoring, adjusted the main commandline interface
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
151 return (token == "int") ? TYPE_Int
73d057b030d0 - a bit more refactoring, adjusted the main commandline interface
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
152 : (token == "str") ? TYPE_String
73d057b030d0 - a bit more refactoring, adjusted the main commandline interface
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
153 : (token == "void") ? TYPE_Void
73d057b030d0 - a bit more refactoring, adjusted the main commandline interface
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
154 : (token == "bool") ? TYPE_Bool
73d057b030d0 - a bit more refactoring, adjusted the main commandline interface
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
155 : TYPE_Unknown;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158
138
a426c1039655 - even more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 137
diff changeset
159 // _________________________________________________________________________________________________
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 // Inverse operation - type name by value
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 String dataTypeName (DataType type)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 switch (type)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 {
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 case TYPE_Int: return "int"; break;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 case TYPE_String: return "str"; break;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169 case TYPE_Void: return "void"; break;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 case TYPE_Bool: return "bool"; break;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 case TYPE_Unknown: return "???"; break;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 return "";
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176
138
a426c1039655 - even more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 137
diff changeset
177 // _________________________________________________________________________________________________
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 //
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 String makeVersionString (int major, int minor, int patch)
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 {
137
73d057b030d0 - a bit more refactoring, adjusted the main commandline interface
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
181 String ver = String::fromNumber (major);
73d057b030d0 - a bit more refactoring, adjusted the main commandline interface
Teemu Piippo <crimsondusk64@gmail.com>
parents: 135
diff changeset
182 ver += "." + String::fromNumber (minor);
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
184 if (patch != 0)
141
68d60e2cfa76 - now works properly (still debugging --help)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 140
diff changeset
185 ver += String (".") + patch;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 return ver;
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 }
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189
138
a426c1039655 - even more rework
Teemu Piippo <crimsondusk64@gmail.com>
parents: 137
diff changeset
190 // _________________________________________________________________________________________________
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 //
140
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
192 String versionString()
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 {
140
04a6eb68f226 - having fun with version macros..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 139
diff changeset
194 return VERSION_STRING;
119
bdf8d46c145f - renamed source files to camelCase
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 }

mercurial