blob: 87969a63ecd94cc313a88110fe08146299c81623 [file] [log] [blame]
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_RS_API_GENERATOR_SPECIFICATION_H
18#define ANDROID_RS_API_GENERATOR_SPECIFICATION_H
19
20// See Generator.cpp for documentation of the .spec file format.
21
22#include <fstream>
23#include <list>
24#include <map>
25#include <string>
26#include <vector>
27
28class Constant;
29class ConstantSpecification;
30class Function;
31class FunctionPermutation;
32class FunctionSpecification;
33class SpecFile;
34class Specification;
35class Scanner;
36class SystemSpecification;
37class Type;
38class TypeSpecification;
39
40enum NumberKind { SIGNED_INTEGER, UNSIGNED_INTEGER, FLOATING_POINT };
41
42// Table of type equivalences.
43struct NumericalType {
44 const char* specType; // Name found in the .spec file
45 const char* rsDataType; // RS data type
46 const char* cType; // Type in a C file
47 const char* javaType; // Type in a Java file
48 NumberKind kind;
49 /* For integers, number of bits of the number, excluding the sign bit.
50 * For floats, number of implied bits of the mantissa.
51 */
52 int significantBits;
53 // For floats, number of bits of the exponent. 0 for integer types.
54 int exponentBits;
55};
56
57/* Corresponds to one parameter line in a .spec file. These will be parsed when
58 * we instantiate the FunctionPermutation(s) that correspond to one FunctionSpecification.
59 */
60struct ParameterEntry {
61 std::string type;
62 std::string name;
63 /* Optional information on how to generate test values for this parameter. Can be:
64 * - range(low, high): Generates values between these two limits only.
65 * - above(other_parameter): The values must be greater than those of the named parameter.
66 * Used for clamp.
67 * - compatible(type): The values must also be fully representable in the specified type.
68 * - conditional: Don't verify this value the function return NaN.
69 */
70 std::string testOption;
71 std::string documentation;
72 int lineNumber;
73};
74
75/* Information about a parameter to a function. The values of all the fields should only be set by
76 * parseParameterDefinition.
77 */
78struct ParameterDefinition {
79 std::string rsType; // The Renderscript type, e.g. "uint3"
80 std::string rsBaseType; // As above but without the number, e.g. "uint"
81 std::string javaBaseType; // The type we need to declare in Java, e.g. "unsigned int"
82 std::string specType; // The type found in the spec, e.g. "f16"
83 bool isFloatType; // True if it's a floating point value
84 /* The number of entries in the vector. It should be either "1", "2", "3", or "4". It's also
85 * "1" for scalars.
86 */
87 std::string mVectorSize;
88 /* The space the vector takes in an array. It's the same as the vector size, except for size
89 * "3", where the width is "4".
90 */
91 std::string vectorWidth;
92
93 std::string specName; // e.g. x, as found in the spec file
94 std::string variableName; // e.g. inX, used both in .rs and .java
95 std::string rsAllocName; // e.g. gAllocInX
96 std::string javaAllocName; // e.g. inX
97 std::string javaArrayName; // e.g. arrayInX
98
99 // If non empty, the mininum and maximum values to be used when generating the test data.
100 std::string minValue;
101 std::string maxValue;
102 /* If non empty, contains the name of another parameter that should be smaller or equal to this
103 * parameter, i.e. value(smallerParameter) <= value(this). This is used when testing clamp.
104 */
105 std::string smallerParameter;
106
107 bool isOutParameter; // True if this parameter returns data from the script.
108 bool undefinedIfOutIsNan; // If true, we don't validate if 'out' is NaN.
109
110 int typeIndex; // Index in the TYPES array. Negative if not found in the array.
111 int compatibleTypeIndex; // Index in TYPES for which the test data must also fit.
112
113 /* Fill this object from the type, name, and testOption.
114 * isReturn is true if we're processing the "return:"
115 */
116 void parseParameterDefinition(const std::string& type, const std::string& name,
117 const std::string& testOption, int lineNumber, bool isReturn,
118 Scanner* scanner);
119};
120
121struct VersionInfo {
122 /* The range of versions a specification applies to. Zero if there's no restriction,
123 * so an API that became available at 12 and is still valid would have min:12 max:0.
124 * If non zero, both versions should be at least 9, the API level that introduced
125 * RenderScript.
126 */
127 int minVersion;
128 int maxVersion;
129 // Either 0, 32 or 64. If 0, this definition is valid for both 32 and 64 bits.
130 int intSize;
131
132 VersionInfo() : minVersion(0), maxVersion(0), intSize(0) {}
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700133 /* Scan the version info from the spec file. maxApiLevel specifies the maximum level
134 * we are interested in. This may alter maxVersion. This method returns false if the
135 * minVersion is greater than the maxApiLevel.
136 */
137 bool scan(Scanner* scanner, int maxApiLevel);
Jean-Luc Brouillet36090672015-04-07 15:15:53 -0700138 /* Return true if the target can be found whitin the range. */
139 bool includesVersion(int target) const {
140 return (minVersion == 0 || target >= minVersion) &&
141 (maxVersion == 0 || target <= maxVersion);
142 }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700143};
144
145// We have three type of definitions
146class Definition {
147protected:
148 std::string mName;
Jean-Luc Brouillet36e2be52015-04-30 14:41:24 -0700149 /* If greater than 0, this definition is deprecated. It's the API level at which
150 * we added the deprecation warning.
151 */
152 int mDeprecatedApiLevel;
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700153 std::string mDeprecatedMessage; // Optional specific warning if the API is deprecated
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700154 bool mHidden; // True if it should not be documented
155 std::string mSummary; // A one-line description
156 std::vector<std::string> mDescription; // The comments to be included in the header
157 std::string mUrl; // The URL of the detailed documentation
Jean-Luc Brouillet67923a92015-05-12 15:38:27 -0700158 int mFinalVersion; // API level at which this API was removed, 0 if API is still valid
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700159
160public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700161 Definition(const std::string& name);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700162
163 std::string getName() const { return mName; }
Jean-Luc Brouillet36e2be52015-04-30 14:41:24 -0700164 bool deprecated() const { return mDeprecatedApiLevel > 0; }
165 int getDeprecatedApiLevel() const { return mDeprecatedApiLevel; }
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700166 std::string getDeprecatedMessage() const { return mDeprecatedMessage; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700167 bool hidden() const { return mHidden; }
168 std::string getSummary() const { return mSummary; }
169 const std::vector<std::string>& getDescription() const { return mDescription; }
170 std::string getUrl() const { return mUrl; }
Jean-Luc Brouillet67923a92015-05-12 15:38:27 -0700171 int getFinalVersion() const { return mFinalVersion; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700172
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700173 void scanDocumentationTags(Scanner* scanner, bool firstOccurence, const SpecFile* specFile);
Jean-Luc Brouillet67923a92015-05-12 15:38:27 -0700174 // Keep track of the final version of this API, if any.
175 void updateFinalVersion(const VersionInfo& info);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700176};
177
178/* Represents a constant, like M_PI. This is a grouping of the version specific specifications.
179 * We'll only have one instance of Constant for each name.
180 */
181class Constant : public Definition {
182private:
183 std::vector<ConstantSpecification*> mSpecifications; // Owned
184
185public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700186 Constant(const std::string& name) : Definition(name) {}
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700187 ~Constant();
188
189 const std::vector<ConstantSpecification*> getSpecifications() const { return mSpecifications; }
190 // This method should only be called by the scanning code.
191 void addSpecification(ConstantSpecification* spec) { mSpecifications.push_back(spec); }
192};
193
194/* Represents a type, like "float4". This is a grouping of the version specific specifications.
195 * We'll only have one instance of Type for each name.
196 */
197class Type : public Definition {
198private:
199 std::vector<TypeSpecification*> mSpecifications; // Owned
200
201public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700202 Type(const std::string& name) : Definition(name) {}
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700203 ~Type();
204
205 const std::vector<TypeSpecification*> getSpecifications() const { return mSpecifications; }
206 // This method should only be called by the scanning code.
207 void addSpecification(TypeSpecification* spec) { mSpecifications.push_back(spec); }
208};
209
210/* Represents a function, like "clamp". Even though the spec file contains many entries for clamp,
211 * we'll only have one clamp instance.
212 */
213class Function : public Definition {
214private:
215 // mName in the base class contains the lower case name, e.g. native_log
216 std::string mCapitalizedName; // The capitalized name, e.g. NativeLog
217
218 // The unique parameters between all the specifications. NOT OWNED.
219 std::vector<ParameterEntry*> mParameters;
220 std::string mReturnDocumentation;
221
222 std::vector<FunctionSpecification*> mSpecifications; // Owned
223
224public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700225 Function(const std::string& name);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700226 ~Function();
227
228 std::string getCapitalizedName() const { return mCapitalizedName; }
229 const std::vector<ParameterEntry*>& getParameters() const { return mParameters; }
230 std::string getReturnDocumentation() const { return mReturnDocumentation; }
231 const std::vector<FunctionSpecification*> getSpecifications() const { return mSpecifications; }
232
233 bool someParametersAreDocumented() const;
234
235 // The following methods should only be called by the scanning code.
236 void addParameter(ParameterEntry* entry, Scanner* scanner);
237 void addReturn(ParameterEntry* entry, Scanner* scanner);
238 void addSpecification(FunctionSpecification* spec) { mSpecifications.push_back(spec); }
239};
240
241/* Base class for TypeSpecification, ConstantSpecification, and FunctionSpecification.
242 * A specification can be specific to a range of RenderScript version or 32bits vs 64 bits.
243 * This base class contains code to parse and store this version information.
244 */
245class Specification {
246protected:
247 VersionInfo mVersionInfo;
248 void scanVersionInfo(Scanner* scanner);
249
250public:
251 VersionInfo getVersionInfo() const { return mVersionInfo; }
252};
253
254/* Defines one of the many variations of a constant. There's a one to one correspondance between
255 * ConstantSpecification objects and entries in the spec file.
256 */
257class ConstantSpecification : public Specification {
258private:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700259 Constant* mConstant; // Not owned
260
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700261 std::string mValue; // E.g. "3.1415"
262public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700263 ConstantSpecification(Constant* constant) : mConstant(constant) {}
264
265 Constant* getConstant() const { return mConstant; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700266 std::string getValue() const { return mValue; }
267
268 // Parse a constant specification and add it to specFile.
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700269 static void scanConstantSpecification(Scanner* scanner, SpecFile* specFile, int maxApiLevel);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700270};
271
272enum TypeKind {
273 SIMPLE,
Stephen Hinesca51c782015-08-25 23:43:34 -0700274 RS_OBJECT,
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700275 STRUCT,
276 ENUM,
277};
278
279/* Defines one of the many variations of a type. There's a one to one correspondance between
280 * TypeSpecification objects and entries in the spec file.
281 */
282class TypeSpecification : public Specification {
283private:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700284 Type* mType; // Not owned
285
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700286 TypeKind mKind; // The kind of type specification
287
288 // If mKind is SIMPLE:
289 std::string mSimpleType; // The definition of the type
290
291 // If mKind is STRUCT:
292 std::string mStructName; // The name found after the struct keyword
293 std::vector<std::string> mFields; // One entry per struct field
294 std::vector<std::string> mFieldComments; // One entry per struct field
Jean-Luc Brouillet36e2be52015-04-30 14:41:24 -0700295 std::string mAttribute; // Some structures may have attributes
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700296
297 // If mKind is ENUM:
298 std::string mEnumName; // The name found after the enum keyword
299 std::vector<std::string> mValues; // One entry per enum value
300 std::vector<std::string> mValueComments; // One entry per enum value
301public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700302 TypeSpecification(Type* type) : mType(type) {}
303
304 Type* getType() const { return mType; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700305 TypeKind getKind() const { return mKind; }
306 std::string getSimpleType() const { return mSimpleType; }
307 std::string getStructName() const { return mStructName; }
308 const std::vector<std::string>& getFields() const { return mFields; }
309 const std::vector<std::string>& getFieldComments() const { return mFieldComments; }
Jean-Luc Brouillet36e2be52015-04-30 14:41:24 -0700310 std::string getAttribute() const { return mAttribute; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700311 std::string getEnumName() const { return mEnumName; }
312 const std::vector<std::string>& getValues() const { return mValues; }
313 const std::vector<std::string>& getValueComments() const { return mValueComments; }
314
315 // Parse a type specification and add it to specFile.
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700316 static void scanTypeSpecification(Scanner* scanner, SpecFile* specFile, int maxApiLevel);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700317};
318
319// Maximum number of placeholders (like #1, #2) in function specifications.
320const int MAX_REPLACEABLES = 4;
321
322/* Defines one of the many variations of the function. There's a one to one correspondance between
323 * FunctionSpecification objects and entries in the spec file. Some of the strings that are parts
324 * of a FunctionSpecification can include placeholders, which are "#1", "#2", "#3", and "#4". We'll
325 * replace these by values before generating the files.
326 */
327class FunctionSpecification : public Specification {
328private:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700329 Function* mFunction; // Not owned
330
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700331 /* How to test. One of:
332 * "scalar": Generate test code that checks entries of each vector indepently. E.g. for
333 * sin(float3), the test code will call the CoreMathVerfier.computeSin 3 times.
334 * "limited": Like "scalar" but we don't generate extreme values. This is not currently
335 * enabled as we were generating to many errors.
336 * "custom": Like "scalar" but instead of calling CoreMathVerifier.computeXXX() to compute
337 * the expected value, we call instead CoreMathVerifier.verifyXXX(). This method
338 * returns a string that contains the error message, null if there's no error.
339 * "vector": Generate test code that calls the CoreMathVerifier only once for each vector.
340 * This is useful for APIs like dot() or length().
341 * "noverify": Generate test code that calls the API but don't verify the returned value.
342 * This can discover unresolved references.
Jean-Luc Brouillet66fea242015-04-09 16:47:59 -0700343 * "": Don't test. This is the default.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700344 */
345 std::string mTest;
346 std::string mAttribute; // Function attributes.
347 std::string mPrecisionLimit; // Maximum precision required when checking output of this
348 // function.
349
350 // The vectors of values with which we'll replace #1, #2, ...
351 std::vector<std::vector<std::string> > mReplaceables;
352
353 /* The collection of permutations for this specification, i.e. this class instantianted
354 * for specific values of #1, #2, etc. Owned.
355 */
356 std::vector<FunctionPermutation*> mPermutations;
357
358 // The following fields may contain placeholders that will be replaced using the mReplaceables.
359
360 /* As of this writing, convert_... is the only function with #1 in its name.
361 * The related Function object contains the name of the function without #n, e.g. convert.
362 * This is the name with the #, e.g. convert_#1_#2
363 */
364 std::string mUnexpandedName;
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700365 ParameterEntry* mReturn; // The return type. The name should be empty. Owned.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700366 std::vector<ParameterEntry*> mParameters; // The parameters. Owned.
367 std::vector<std::string> mInline; // The inline code to be included in the header
368
369 /* Substitute the placeholders in the strings (e.g. #1, #2, ...) by the corresponding
370 * entries in mReplaceables. indexOfReplaceable1 selects with value to use for #1,
371 * same for 2, 3, and 4.
372 */
373 std::string expandString(std::string s, int indexOfReplaceable[MAX_REPLACEABLES]) const;
374 void expandStringVector(const std::vector<std::string>& in,
375 int replacementIndexes[MAX_REPLACEABLES],
376 std::vector<std::string>* out) const;
377
378 // Fill the mPermutations field.
379 void createPermutations(Function* function, Scanner* scanner);
380
381public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700382 FunctionSpecification(Function* function) : mFunction(function), mReturn(nullptr) {}
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700383 ~FunctionSpecification();
384
Jean-Luc Brouillet67923a92015-05-12 15:38:27 -0700385 Function* getFunction() const { return mFunction; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700386 std::string getAttribute() const { return mAttribute; }
387 std::string getTest() const { return mTest; }
388 std::string getPrecisionLimit() const { return mPrecisionLimit; }
389
390 const std::vector<FunctionPermutation*>& getPermutations() const { return mPermutations; }
391
392 std::string getName(int replacementIndexes[MAX_REPLACEABLES]) const;
393 void getReturn(int replacementIndexes[MAX_REPLACEABLES], std::string* retType,
394 int* lineNumber) const;
395 size_t getNumberOfParams() const { return mParameters.size(); }
396 void getParam(size_t index, int replacementIndexes[MAX_REPLACEABLES], std::string* type,
397 std::string* name, std::string* testOption, int* lineNumber) const;
398 void getInlines(int replacementIndexes[MAX_REPLACEABLES],
399 std::vector<std::string>* inlines) const;
400
401 // Parse the "test:" line.
402 void parseTest(Scanner* scanner);
403
404 // Return true if we need to generate tests for this function.
405 bool hasTests(int versionOfTestFiles) const;
406
Jean-Luc Brouillet36090672015-04-07 15:15:53 -0700407 bool hasInline() const { return mInline.size() > 0; }
408
409 /* Return true if this function can be overloaded. This is added by default to all
410 * specifications, so except for the very few exceptions that start the attributes
411 * with an '=' to avoid this, we'll return true.
412 */
413 bool isOverloadable() const {
414 return mAttribute.empty() || mAttribute[0] != '=';
415 }
416
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700417 // Parse a function specification and add it to specFile.
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700418 static void scanFunctionSpecification(Scanner* scanner, SpecFile* specFile, int maxApiLevel);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700419};
420
421/* A concrete version of a function specification, where all placeholders have been replaced by
422 * actual values.
423 */
424class FunctionPermutation {
425private:
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700426 // These are the expanded version of those found on FunctionSpecification
427 std::string mName;
428 std::string mNameTrunk; // The name without any expansion, e.g. convert
429 std::string mTest; // How to test. One of "scalar", "vector", "noverify", "limited", and
430 // "none".
431 std::string mPrecisionLimit; // Maximum precision required when checking output of this
432 // function.
433
434 // The parameters of the function. This does not include the return type. Owned.
435 std::vector<ParameterDefinition*> mParams;
436 // The return type. nullptr if a void function. Owned.
437 ParameterDefinition* mReturn;
438
439 // The number of input and output parameters. mOutputCount counts the return type.
440 int mInputCount;
441 int mOutputCount;
442
443 // Whether one of the output parameters is a float.
444 bool mHasFloatAnswers;
445
446 // The inline code that implements this function. Will be empty if not an inline.
447 std::vector<std::string> mInline;
448
449public:
450 FunctionPermutation(Function* function, FunctionSpecification* specification,
451 int replacementIndexes[MAX_REPLACEABLES], Scanner* scanner);
452 ~FunctionPermutation();
453
454 std::string getName() const { return mName; }
455 std::string getNameTrunk() const { return mNameTrunk; }
456 std::string getTest() const { return mTest; }
457 std::string getPrecisionLimit() const { return mPrecisionLimit; }
458
Jean-Luc Brouillet66fea242015-04-09 16:47:59 -0700459 const std::vector<std::string>& getInline() const { return mInline; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700460 const ParameterDefinition* getReturn() const { return mReturn; }
461 int getInputCount() const { return mInputCount; }
462 int getOutputCount() const { return mOutputCount; }
463 bool hasFloatAnswers() const { return mHasFloatAnswers; }
464
465 const std::vector<ParameterDefinition*> getParams() const { return mParams; }
466};
467
468// An entire spec file and the methods to process it.
469class SpecFile {
470private:
471 std::string mSpecFileName;
472 std::string mHeaderFileName;
473 std::string mDetailedDocumentationUrl;
474 std::string mBriefDescription;
475 std::vector<std::string> mFullDescription;
476 // Text to insert as-is in the generated header.
477 std::vector<std::string> mVerbatimInclude;
478
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700479 /* The constants, types, and functions specifications declared in this
480 * file, in the order they are found in the file. This matters for
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700481 * header generation, as some types and inline functions depend
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700482 * on each other. Pointers not owned.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700483 */
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700484 std::list<ConstantSpecification*> mConstantSpecificationsList;
485 std::list<TypeSpecification*> mTypeSpecificationsList;
486 std::list<FunctionSpecification*> mFunctionSpecificationsList;
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700487
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700488 /* The constants, types, and functions that are documented in this file.
489 * In very rare cases, specifications for an API are split across multiple
490 * files, e.g. currently for ClearObject(). The documentation for
491 * that function must be found in the first spec file encountered, so the
492 * order of the files on the command line matters.
493 */
494 std::map<std::string, Constant*> mDocumentedConstants;
495 std::map<std::string, Type*> mDocumentedTypes;
496 std::map<std::string, Function*> mDocumentedFunctions;
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700497
498public:
499 explicit SpecFile(const std::string& specFileName);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700500
501 std::string getSpecFileName() const { return mSpecFileName; }
502 std::string getHeaderFileName() const { return mHeaderFileName; }
503 std::string getDetailedDocumentationUrl() const { return mDetailedDocumentationUrl; }
504 const std::string getBriefDescription() const { return mBriefDescription; }
505 const std::vector<std::string>& getFullDescription() const { return mFullDescription; }
506 const std::vector<std::string>& getVerbatimInclude() const { return mVerbatimInclude; }
507
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700508 const std::list<ConstantSpecification*>& getConstantSpecifications() const {
509 return mConstantSpecificationsList;
510 }
511 const std::list<TypeSpecification*>& getTypeSpecifications() const {
512 return mTypeSpecificationsList;
513 }
514 const std::list<FunctionSpecification*>& getFunctionSpecifications() const {
515 return mFunctionSpecificationsList;
516 }
517 const std::map<std::string, Constant*>& getDocumentedConstants() const {
518 return mDocumentedConstants;
519 }
520 const std::map<std::string, Type*>& getDocumentedTypes() const { return mDocumentedTypes; }
521 const std::map<std::string, Function*>& getDocumentedFunctions() const {
522 return mDocumentedFunctions;
523 }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700524
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700525 bool hasSpecifications() const {
526 return !mDocumentedConstants.empty() || !mDocumentedTypes.empty() ||
527 !mDocumentedFunctions.empty();
528 }
529
530 bool readSpecFile(int maxApiLevel);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700531
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700532 /* These are called by the parser to keep track of the specifications defined in this file.
533 * hasDocumentation is true if this specification containes the documentation.
534 */
535 void addConstantSpecification(ConstantSpecification* spec, bool hasDocumentation);
536 void addTypeSpecification(TypeSpecification* spec, bool hasDocumentation);
537 void addFunctionSpecification(FunctionSpecification* spec, bool hasDocumentation);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700538};
539
540// The collection of all the spec files.
541class SystemSpecification {
542private:
543 std::vector<SpecFile*> mSpecFiles;
544
545 /* Entries in the table of contents. We accumulate them in a map to sort them.
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700546 * Pointers are owned.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700547 */
548 std::map<std::string, Constant*> mConstants;
549 std::map<std::string, Type*> mTypes;
550 std::map<std::string, Function*> mFunctions;
551
552public:
553 ~SystemSpecification();
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700554
555 /* These are called the parser to create unique instances per name. Set *created to true
556 * if the named specification did not already exist.
557 */
558 Constant* findOrCreateConstant(const std::string& name, bool* created);
559 Type* findOrCreateType(const std::string& name, bool* created);
560 Function* findOrCreateFunction(const std::string& name, bool* created);
561
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700562 /* Parse the spec file and create the object hierarchy, adding a pointer to mSpecFiles.
563 * We won't include information passed the specified level.
564 */
565 bool readSpecFile(const std::string& fileName, int maxApiLevel);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700566 // Generate all the files.
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700567 bool generateFiles(bool forVerification, int maxApiLevel) const;
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700568
569 const std::vector<SpecFile*>& getSpecFiles() const { return mSpecFiles; }
570 const std::map<std::string, Constant*>& getConstants() const { return mConstants; }
571 const std::map<std::string, Type*>& getTypes() const { return mTypes; }
572 const std::map<std::string, Function*>& getFunctions() const { return mFunctions; }
573
574 // Returns "<a href='...'> for the named specification, or empty if not found.
575 std::string getHtmlAnchor(const std::string& name) const;
Jean-Luc Brouillet36090672015-04-07 15:15:53 -0700576
577 // Returns the maximum API level specified in any spec file.
578 int getMaximumApiLevel();
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700579};
580
581// Singleton that represents the collection of all the specs we're processing.
582extern SystemSpecification systemSpecification;
583
584// Table of equivalences of numerical types.
585extern const NumericalType TYPES[];
586extern const int NUM_TYPES;
587
588#endif // ANDROID_RS_API_GENERATOR_SPECIFICATION_H