blob: c467c5c02233b7b3519ee103999c776a5c4058bb [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
Yang Ni12398d82015-09-18 14:57:07 -070022#include <climits>
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -070023#include <fstream>
24#include <list>
25#include <map>
26#include <string>
27#include <vector>
28
29class Constant;
30class ConstantSpecification;
31class Function;
32class FunctionPermutation;
33class FunctionSpecification;
34class SpecFile;
35class Specification;
36class Scanner;
37class SystemSpecification;
38class Type;
39class TypeSpecification;
40
41enum NumberKind { SIGNED_INTEGER, UNSIGNED_INTEGER, FLOATING_POINT };
42
43// Table of type equivalences.
44struct NumericalType {
45 const char* specType; // Name found in the .spec file
46 const char* rsDataType; // RS data type
47 const char* cType; // Type in a C file
48 const char* javaType; // Type in a Java file
49 NumberKind kind;
50 /* For integers, number of bits of the number, excluding the sign bit.
51 * For floats, number of implied bits of the mantissa.
52 */
53 int significantBits;
54 // For floats, number of bits of the exponent. 0 for integer types.
55 int exponentBits;
56};
57
58/* Corresponds to one parameter line in a .spec file. These will be parsed when
59 * we instantiate the FunctionPermutation(s) that correspond to one FunctionSpecification.
60 */
61struct ParameterEntry {
62 std::string type;
63 std::string name;
64 /* Optional information on how to generate test values for this parameter. Can be:
65 * - range(low, high): Generates values between these two limits only.
66 * - above(other_parameter): The values must be greater than those of the named parameter.
67 * Used for clamp.
68 * - compatible(type): The values must also be fully representable in the specified type.
69 * - conditional: Don't verify this value the function return NaN.
70 */
71 std::string testOption;
72 std::string documentation;
73 int lineNumber;
74};
75
76/* Information about a parameter to a function. The values of all the fields should only be set by
77 * parseParameterDefinition.
78 */
79struct ParameterDefinition {
80 std::string rsType; // The Renderscript type, e.g. "uint3"
81 std::string rsBaseType; // As above but without the number, e.g. "uint"
82 std::string javaBaseType; // The type we need to declare in Java, e.g. "unsigned int"
83 std::string specType; // The type found in the spec, e.g. "f16"
84 bool isFloatType; // True if it's a floating point value
85 /* The number of entries in the vector. It should be either "1", "2", "3", or "4". It's also
86 * "1" for scalars.
87 */
88 std::string mVectorSize;
89 /* The space the vector takes in an array. It's the same as the vector size, except for size
90 * "3", where the width is "4".
91 */
92 std::string vectorWidth;
93
94 std::string specName; // e.g. x, as found in the spec file
95 std::string variableName; // e.g. inX, used both in .rs and .java
96 std::string rsAllocName; // e.g. gAllocInX
97 std::string javaAllocName; // e.g. inX
98 std::string javaArrayName; // e.g. arrayInX
99
100 // If non empty, the mininum and maximum values to be used when generating the test data.
101 std::string minValue;
102 std::string maxValue;
103 /* If non empty, contains the name of another parameter that should be smaller or equal to this
104 * parameter, i.e. value(smallerParameter) <= value(this). This is used when testing clamp.
105 */
106 std::string smallerParameter;
107
108 bool isOutParameter; // True if this parameter returns data from the script.
109 bool undefinedIfOutIsNan; // If true, we don't validate if 'out' is NaN.
110
111 int typeIndex; // Index in the TYPES array. Negative if not found in the array.
112 int compatibleTypeIndex; // Index in TYPES for which the test data must also fit.
113
114 /* Fill this object from the type, name, and testOption.
115 * isReturn is true if we're processing the "return:"
116 */
117 void parseParameterDefinition(const std::string& type, const std::string& name,
118 const std::string& testOption, int lineNumber, bool isReturn,
119 Scanner* scanner);
120};
121
122struct VersionInfo {
123 /* The range of versions a specification applies to. Zero if there's no restriction,
124 * so an API that became available at 12 and is still valid would have min:12 max:0.
125 * If non zero, both versions should be at least 9, the API level that introduced
126 * RenderScript.
127 */
Yang Ni12398d82015-09-18 14:57:07 -0700128 unsigned int minVersion;
129 unsigned int maxVersion;
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700130 // Either 0, 32 or 64. If 0, this definition is valid for both 32 and 64 bits.
131 int intSize;
132
133 VersionInfo() : minVersion(0), maxVersion(0), intSize(0) {}
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700134 /* Scan the version info from the spec file. maxApiLevel specifies the maximum level
135 * we are interested in. This may alter maxVersion. This method returns false if the
136 * minVersion is greater than the maxApiLevel.
137 */
Yang Ni12398d82015-09-18 14:57:07 -0700138 bool scan(Scanner* scanner, unsigned int maxApiLevel);
Jean-Luc Brouillet36090672015-04-07 15:15:53 -0700139 /* Return true if the target can be found whitin the range. */
140 bool includesVersion(int target) const {
141 return (minVersion == 0 || target >= minVersion) &&
142 (maxVersion == 0 || target <= maxVersion);
143 }
Yang Ni12398d82015-09-18 14:57:07 -0700144
145 static constexpr unsigned int kUnreleasedVersion = UINT_MAX;
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700146};
147
148// We have three type of definitions
149class Definition {
150protected:
151 std::string mName;
Jean-Luc Brouillet36e2be52015-04-30 14:41:24 -0700152 /* If greater than 0, this definition is deprecated. It's the API level at which
153 * we added the deprecation warning.
154 */
155 int mDeprecatedApiLevel;
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700156 std::string mDeprecatedMessage; // Optional specific warning if the API is deprecated
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700157 bool mHidden; // True if it should not be documented
158 std::string mSummary; // A one-line description
159 std::vector<std::string> mDescription; // The comments to be included in the header
160 std::string mUrl; // The URL of the detailed documentation
Jean-Luc Brouillet67923a92015-05-12 15:38:27 -0700161 int mFinalVersion; // API level at which this API was removed, 0 if API is still valid
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700162
163public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700164 Definition(const std::string& name);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700165
166 std::string getName() const { return mName; }
Jean-Luc Brouillet36e2be52015-04-30 14:41:24 -0700167 bool deprecated() const { return mDeprecatedApiLevel > 0; }
168 int getDeprecatedApiLevel() const { return mDeprecatedApiLevel; }
Jean-Luc Brouillet4a730042015-04-02 16:15:25 -0700169 std::string getDeprecatedMessage() const { return mDeprecatedMessage; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700170 bool hidden() const { return mHidden; }
171 std::string getSummary() const { return mSummary; }
172 const std::vector<std::string>& getDescription() const { return mDescription; }
173 std::string getUrl() const { return mUrl; }
Jean-Luc Brouillet67923a92015-05-12 15:38:27 -0700174 int getFinalVersion() const { return mFinalVersion; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700175
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700176 void scanDocumentationTags(Scanner* scanner, bool firstOccurence, const SpecFile* specFile);
Jean-Luc Brouillet67923a92015-05-12 15:38:27 -0700177 // Keep track of the final version of this API, if any.
178 void updateFinalVersion(const VersionInfo& info);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700179};
180
181/* Represents a constant, like M_PI. This is a grouping of the version specific specifications.
182 * We'll only have one instance of Constant for each name.
183 */
184class Constant : public Definition {
185private:
186 std::vector<ConstantSpecification*> mSpecifications; // Owned
187
188public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700189 Constant(const std::string& name) : Definition(name) {}
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700190 ~Constant();
191
192 const std::vector<ConstantSpecification*> getSpecifications() const { return mSpecifications; }
193 // This method should only be called by the scanning code.
194 void addSpecification(ConstantSpecification* spec) { mSpecifications.push_back(spec); }
195};
196
197/* Represents a type, like "float4". This is a grouping of the version specific specifications.
198 * We'll only have one instance of Type for each name.
199 */
200class Type : public Definition {
201private:
202 std::vector<TypeSpecification*> mSpecifications; // Owned
203
204public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700205 Type(const std::string& name) : Definition(name) {}
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700206 ~Type();
207
208 const std::vector<TypeSpecification*> getSpecifications() const { return mSpecifications; }
209 // This method should only be called by the scanning code.
210 void addSpecification(TypeSpecification* spec) { mSpecifications.push_back(spec); }
211};
212
213/* Represents a function, like "clamp". Even though the spec file contains many entries for clamp,
214 * we'll only have one clamp instance.
215 */
216class Function : public Definition {
217private:
218 // mName in the base class contains the lower case name, e.g. native_log
219 std::string mCapitalizedName; // The capitalized name, e.g. NativeLog
220
221 // The unique parameters between all the specifications. NOT OWNED.
222 std::vector<ParameterEntry*> mParameters;
223 std::string mReturnDocumentation;
224
225 std::vector<FunctionSpecification*> mSpecifications; // Owned
226
227public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700228 Function(const std::string& name);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700229 ~Function();
230
231 std::string getCapitalizedName() const { return mCapitalizedName; }
232 const std::vector<ParameterEntry*>& getParameters() const { return mParameters; }
233 std::string getReturnDocumentation() const { return mReturnDocumentation; }
234 const std::vector<FunctionSpecification*> getSpecifications() const { return mSpecifications; }
235
236 bool someParametersAreDocumented() const;
237
238 // The following methods should only be called by the scanning code.
239 void addParameter(ParameterEntry* entry, Scanner* scanner);
240 void addReturn(ParameterEntry* entry, Scanner* scanner);
241 void addSpecification(FunctionSpecification* spec) { mSpecifications.push_back(spec); }
242};
243
244/* Base class for TypeSpecification, ConstantSpecification, and FunctionSpecification.
245 * A specification can be specific to a range of RenderScript version or 32bits vs 64 bits.
246 * This base class contains code to parse and store this version information.
247 */
248class Specification {
249protected:
250 VersionInfo mVersionInfo;
251 void scanVersionInfo(Scanner* scanner);
252
253public:
254 VersionInfo getVersionInfo() const { return mVersionInfo; }
255};
256
257/* Defines one of the many variations of a constant. There's a one to one correspondance between
258 * ConstantSpecification objects and entries in the spec file.
259 */
260class ConstantSpecification : public Specification {
261private:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700262 Constant* mConstant; // Not owned
263
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700264 std::string mValue; // E.g. "3.1415"
265public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700266 ConstantSpecification(Constant* constant) : mConstant(constant) {}
267
268 Constant* getConstant() const { return mConstant; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700269 std::string getValue() const { return mValue; }
270
271 // Parse a constant specification and add it to specFile.
Yang Ni12398d82015-09-18 14:57:07 -0700272 static void scanConstantSpecification(Scanner* scanner, SpecFile* specFile, unsigned int maxApiLevel);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700273};
274
275enum TypeKind {
276 SIMPLE,
Stephen Hinesca51c782015-08-25 23:43:34 -0700277 RS_OBJECT,
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700278 STRUCT,
279 ENUM,
280};
281
282/* Defines one of the many variations of a type. There's a one to one correspondance between
283 * TypeSpecification objects and entries in the spec file.
284 */
285class TypeSpecification : public Specification {
286private:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700287 Type* mType; // Not owned
288
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700289 TypeKind mKind; // The kind of type specification
290
291 // If mKind is SIMPLE:
292 std::string mSimpleType; // The definition of the type
293
294 // If mKind is STRUCT:
295 std::string mStructName; // The name found after the struct keyword
296 std::vector<std::string> mFields; // One entry per struct field
297 std::vector<std::string> mFieldComments; // One entry per struct field
Jean-Luc Brouillet36e2be52015-04-30 14:41:24 -0700298 std::string mAttribute; // Some structures may have attributes
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700299
300 // If mKind is ENUM:
301 std::string mEnumName; // The name found after the enum keyword
302 std::vector<std::string> mValues; // One entry per enum value
303 std::vector<std::string> mValueComments; // One entry per enum value
304public:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700305 TypeSpecification(Type* type) : mType(type) {}
306
307 Type* getType() const { return mType; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700308 TypeKind getKind() const { return mKind; }
309 std::string getSimpleType() const { return mSimpleType; }
310 std::string getStructName() const { return mStructName; }
311 const std::vector<std::string>& getFields() const { return mFields; }
312 const std::vector<std::string>& getFieldComments() const { return mFieldComments; }
Jean-Luc Brouillet36e2be52015-04-30 14:41:24 -0700313 std::string getAttribute() const { return mAttribute; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700314 std::string getEnumName() const { return mEnumName; }
315 const std::vector<std::string>& getValues() const { return mValues; }
316 const std::vector<std::string>& getValueComments() const { return mValueComments; }
317
318 // Parse a type specification and add it to specFile.
Yang Ni12398d82015-09-18 14:57:07 -0700319 static void scanTypeSpecification(Scanner* scanner, SpecFile* specFile, unsigned int maxApiLevel);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700320};
321
322// Maximum number of placeholders (like #1, #2) in function specifications.
323const int MAX_REPLACEABLES = 4;
324
325/* Defines one of the many variations of the function. There's a one to one correspondance between
326 * FunctionSpecification objects and entries in the spec file. Some of the strings that are parts
327 * of a FunctionSpecification can include placeholders, which are "#1", "#2", "#3", and "#4". We'll
328 * replace these by values before generating the files.
329 */
330class FunctionSpecification : public Specification {
331private:
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700332 Function* mFunction; // Not owned
333
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700334 /* How to test. One of:
335 * "scalar": Generate test code that checks entries of each vector indepently. E.g. for
336 * sin(float3), the test code will call the CoreMathVerfier.computeSin 3 times.
337 * "limited": Like "scalar" but we don't generate extreme values. This is not currently
338 * enabled as we were generating to many errors.
339 * "custom": Like "scalar" but instead of calling CoreMathVerifier.computeXXX() to compute
340 * the expected value, we call instead CoreMathVerifier.verifyXXX(). This method
341 * returns a string that contains the error message, null if there's no error.
342 * "vector": Generate test code that calls the CoreMathVerifier only once for each vector.
343 * This is useful for APIs like dot() or length().
344 * "noverify": Generate test code that calls the API but don't verify the returned value.
345 * This can discover unresolved references.
Jean-Luc Brouillet66fea242015-04-09 16:47:59 -0700346 * "": Don't test. This is the default.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700347 */
348 std::string mTest;
Yang Ni12398d82015-09-18 14:57:07 -0700349 bool mInternal; // Internal. Not visible to users. (Default: false)
350 bool mIntrinsic; // Compiler intrinsic that is lowered to an internal API.
351 // (Default: false)
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700352 std::string mAttribute; // Function attributes.
353 std::string mPrecisionLimit; // Maximum precision required when checking output of this
354 // function.
355
356 // The vectors of values with which we'll replace #1, #2, ...
357 std::vector<std::vector<std::string> > mReplaceables;
358
Pirama Arumuga Nainar43d758c2015-11-13 12:54:42 -0800359 // i-th entry is true if each entry in mReplaceables[i] has an equivalent
360 // RS numerical type (i.e. present in TYPES global)
361 std::vector<bool> mIsRSTAllowed;
362
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700363 /* The collection of permutations for this specification, i.e. this class instantianted
364 * for specific values of #1, #2, etc. Owned.
365 */
366 std::vector<FunctionPermutation*> mPermutations;
367
368 // The following fields may contain placeholders that will be replaced using the mReplaceables.
369
370 /* As of this writing, convert_... is the only function with #1 in its name.
371 * The related Function object contains the name of the function without #n, e.g. convert.
372 * This is the name with the #, e.g. convert_#1_#2
373 */
374 std::string mUnexpandedName;
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700375 ParameterEntry* mReturn; // The return type. The name should be empty. Owned.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700376 std::vector<ParameterEntry*> mParameters; // The parameters. Owned.
377 std::vector<std::string> mInline; // The inline code to be included in the header
378
Pirama Arumuga Nainar43d758c2015-11-13 12:54:42 -0800379 /* Substitute the placeholders in the strings (e.g. #1, #2, ...) by the
380 * corresponding entries in mReplaceables. Substitute placeholders for RS
381 * types (#RST_1, #RST_2, ...) by the RS Data type strings (UNSIGNED_8,
382 * FLOAT_32 etc.) of the corresponding types in mReplaceables.
383 * indexOfReplaceable1 selects with value to use for #1, same for 2, 3, and
384 * 4.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700385 */
386 std::string expandString(std::string s, int indexOfReplaceable[MAX_REPLACEABLES]) const;
387 void expandStringVector(const std::vector<std::string>& in,
388 int replacementIndexes[MAX_REPLACEABLES],
389 std::vector<std::string>* out) const;
390
Pirama Arumuga Nainar43d758c2015-11-13 12:54:42 -0800391 // Helper function used by expandString to perform #RST_* substitution
392 std::string expandRSTypeInString(const std::string &s,
393 const std::string &pattern,
394 const std::string &cTypeStr) const;
395
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700396 // Fill the mPermutations field.
397 void createPermutations(Function* function, Scanner* scanner);
398
399public:
Yang Ni12398d82015-09-18 14:57:07 -0700400 FunctionSpecification(Function* function) : mFunction(function), mInternal(false),
401 mIntrinsic(false), mReturn(nullptr) {}
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700402 ~FunctionSpecification();
403
Jean-Luc Brouillet67923a92015-05-12 15:38:27 -0700404 Function* getFunction() const { return mFunction; }
Yang Ni12398d82015-09-18 14:57:07 -0700405 bool isInternal() const { return mInternal; }
406 bool isIntrinsic() const { return mIntrinsic; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700407 std::string getAttribute() const { return mAttribute; }
408 std::string getTest() const { return mTest; }
409 std::string getPrecisionLimit() const { return mPrecisionLimit; }
410
411 const std::vector<FunctionPermutation*>& getPermutations() const { return mPermutations; }
412
413 std::string getName(int replacementIndexes[MAX_REPLACEABLES]) const;
414 void getReturn(int replacementIndexes[MAX_REPLACEABLES], std::string* retType,
415 int* lineNumber) const;
416 size_t getNumberOfParams() const { return mParameters.size(); }
417 void getParam(size_t index, int replacementIndexes[MAX_REPLACEABLES], std::string* type,
418 std::string* name, std::string* testOption, int* lineNumber) const;
419 void getInlines(int replacementIndexes[MAX_REPLACEABLES],
420 std::vector<std::string>* inlines) const;
421
422 // Parse the "test:" line.
423 void parseTest(Scanner* scanner);
424
425 // Return true if we need to generate tests for this function.
Yang Ni12398d82015-09-18 14:57:07 -0700426 bool hasTests(unsigned int versionOfTestFiles) const;
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700427
Jean-Luc Brouillet36090672015-04-07 15:15:53 -0700428 bool hasInline() const { return mInline.size() > 0; }
429
430 /* Return true if this function can be overloaded. This is added by default to all
431 * specifications, so except for the very few exceptions that start the attributes
432 * with an '=' to avoid this, we'll return true.
433 */
434 bool isOverloadable() const {
435 return mAttribute.empty() || mAttribute[0] != '=';
436 }
437
Pirama Arumuga Nainar43d758c2015-11-13 12:54:42 -0800438 /* Check if RST_i is present in 's' and report an error if 'allow' is false
439 * or the i-th replacement list is not a valid candidate for RST_i
440 * replacement
441 */
442 void checkRSTPatternValidity(const std::string &s, bool allow, Scanner *scanner);
443
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700444 // Parse a function specification and add it to specFile.
Yang Ni12398d82015-09-18 14:57:07 -0700445 static void scanFunctionSpecification(Scanner* scanner, SpecFile* specFile, unsigned int maxApiLevel);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700446};
447
448/* A concrete version of a function specification, where all placeholders have been replaced by
449 * actual values.
450 */
451class FunctionPermutation {
452private:
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700453 // These are the expanded version of those found on FunctionSpecification
454 std::string mName;
455 std::string mNameTrunk; // The name without any expansion, e.g. convert
456 std::string mTest; // How to test. One of "scalar", "vector", "noverify", "limited", and
457 // "none".
458 std::string mPrecisionLimit; // Maximum precision required when checking output of this
459 // function.
460
461 // The parameters of the function. This does not include the return type. Owned.
462 std::vector<ParameterDefinition*> mParams;
463 // The return type. nullptr if a void function. Owned.
464 ParameterDefinition* mReturn;
465
466 // The number of input and output parameters. mOutputCount counts the return type.
467 int mInputCount;
468 int mOutputCount;
469
470 // Whether one of the output parameters is a float.
471 bool mHasFloatAnswers;
472
473 // The inline code that implements this function. Will be empty if not an inline.
474 std::vector<std::string> mInline;
475
476public:
477 FunctionPermutation(Function* function, FunctionSpecification* specification,
478 int replacementIndexes[MAX_REPLACEABLES], Scanner* scanner);
479 ~FunctionPermutation();
480
481 std::string getName() const { return mName; }
482 std::string getNameTrunk() const { return mNameTrunk; }
483 std::string getTest() const { return mTest; }
484 std::string getPrecisionLimit() const { return mPrecisionLimit; }
485
Jean-Luc Brouillet66fea242015-04-09 16:47:59 -0700486 const std::vector<std::string>& getInline() const { return mInline; }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700487 const ParameterDefinition* getReturn() const { return mReturn; }
488 int getInputCount() const { return mInputCount; }
489 int getOutputCount() const { return mOutputCount; }
490 bool hasFloatAnswers() const { return mHasFloatAnswers; }
491
492 const std::vector<ParameterDefinition*> getParams() const { return mParams; }
493};
494
495// An entire spec file and the methods to process it.
496class SpecFile {
497private:
498 std::string mSpecFileName;
499 std::string mHeaderFileName;
500 std::string mDetailedDocumentationUrl;
501 std::string mBriefDescription;
502 std::vector<std::string> mFullDescription;
503 // Text to insert as-is in the generated header.
504 std::vector<std::string> mVerbatimInclude;
505
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700506 /* The constants, types, and functions specifications declared in this
507 * file, in the order they are found in the file. This matters for
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700508 * header generation, as some types and inline functions depend
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700509 * on each other. Pointers not owned.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700510 */
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700511 std::list<ConstantSpecification*> mConstantSpecificationsList;
512 std::list<TypeSpecification*> mTypeSpecificationsList;
513 std::list<FunctionSpecification*> mFunctionSpecificationsList;
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700514
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700515 /* The constants, types, and functions that are documented in this file.
516 * In very rare cases, specifications for an API are split across multiple
517 * files, e.g. currently for ClearObject(). The documentation for
518 * that function must be found in the first spec file encountered, so the
519 * order of the files on the command line matters.
520 */
521 std::map<std::string, Constant*> mDocumentedConstants;
522 std::map<std::string, Type*> mDocumentedTypes;
523 std::map<std::string, Function*> mDocumentedFunctions;
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700524
525public:
526 explicit SpecFile(const std::string& specFileName);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700527
528 std::string getSpecFileName() const { return mSpecFileName; }
529 std::string getHeaderFileName() const { return mHeaderFileName; }
530 std::string getDetailedDocumentationUrl() const { return mDetailedDocumentationUrl; }
531 const std::string getBriefDescription() const { return mBriefDescription; }
532 const std::vector<std::string>& getFullDescription() const { return mFullDescription; }
533 const std::vector<std::string>& getVerbatimInclude() const { return mVerbatimInclude; }
534
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700535 const std::list<ConstantSpecification*>& getConstantSpecifications() const {
536 return mConstantSpecificationsList;
537 }
538 const std::list<TypeSpecification*>& getTypeSpecifications() const {
539 return mTypeSpecificationsList;
540 }
541 const std::list<FunctionSpecification*>& getFunctionSpecifications() const {
542 return mFunctionSpecificationsList;
543 }
544 const std::map<std::string, Constant*>& getDocumentedConstants() const {
545 return mDocumentedConstants;
546 }
547 const std::map<std::string, Type*>& getDocumentedTypes() const { return mDocumentedTypes; }
548 const std::map<std::string, Function*>& getDocumentedFunctions() const {
549 return mDocumentedFunctions;
550 }
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700551
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700552 bool hasSpecifications() const {
553 return !mDocumentedConstants.empty() || !mDocumentedTypes.empty() ||
554 !mDocumentedFunctions.empty();
555 }
556
Yang Ni12398d82015-09-18 14:57:07 -0700557 bool readSpecFile(unsigned int maxApiLevel);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700558
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700559 /* These are called by the parser to keep track of the specifications defined in this file.
560 * hasDocumentation is true if this specification containes the documentation.
561 */
562 void addConstantSpecification(ConstantSpecification* spec, bool hasDocumentation);
563 void addTypeSpecification(TypeSpecification* spec, bool hasDocumentation);
564 void addFunctionSpecification(FunctionSpecification* spec, bool hasDocumentation);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700565};
566
567// The collection of all the spec files.
568class SystemSpecification {
569private:
570 std::vector<SpecFile*> mSpecFiles;
571
572 /* Entries in the table of contents. We accumulate them in a map to sort them.
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700573 * Pointers are owned.
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700574 */
575 std::map<std::string, Constant*> mConstants;
576 std::map<std::string, Type*> mTypes;
577 std::map<std::string, Function*> mFunctions;
578
579public:
580 ~SystemSpecification();
Jean-Luc Brouillet7c078542015-03-23 16:16:08 -0700581
582 /* These are called the parser to create unique instances per name. Set *created to true
583 * if the named specification did not already exist.
584 */
585 Constant* findOrCreateConstant(const std::string& name, bool* created);
586 Type* findOrCreateType(const std::string& name, bool* created);
587 Function* findOrCreateFunction(const std::string& name, bool* created);
588
Jean-Luc Brouillet2217eb72015-04-24 14:41:48 -0700589 /* Parse the spec file and create the object hierarchy, adding a pointer to mSpecFiles.
590 * We won't include information passed the specified level.
591 */
Yang Ni12398d82015-09-18 14:57:07 -0700592 bool readSpecFile(const std::string& fileName, unsigned int maxApiLevel);
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700593 // Generate all the files.
Yang Ni12398d82015-09-18 14:57:07 -0700594 bool generateFiles(bool forVerification, unsigned int maxApiLevel) const;
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700595
596 const std::vector<SpecFile*>& getSpecFiles() const { return mSpecFiles; }
597 const std::map<std::string, Constant*>& getConstants() const { return mConstants; }
598 const std::map<std::string, Type*>& getTypes() const { return mTypes; }
599 const std::map<std::string, Function*>& getFunctions() const { return mFunctions; }
600
601 // Returns "<a href='...'> for the named specification, or empty if not found.
602 std::string getHtmlAnchor(const std::string& name) const;
Jean-Luc Brouillet36090672015-04-07 15:15:53 -0700603
604 // Returns the maximum API level specified in any spec file.
Yang Ni12398d82015-09-18 14:57:07 -0700605 unsigned int getMaximumApiLevel();
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700606};
607
608// Singleton that represents the collection of all the specs we're processing.
609extern SystemSpecification systemSpecification;
610
611// Table of equivalences of numerical types.
612extern const NumericalType TYPES[];
613extern const int NUM_TYPES;
614
Dean De Leo9309a062015-11-25 13:37:05 +0000615/* Given a renderscript type (string) calculate the vector size and base type. If the type
616 * is not a vector the vector size is 1 and baseType is just the type itself.
617 */
618void getVectorSizeAndBaseType(const std::string& type, std::string& vectorSize,
619 std::string& baseType);
620
Jean-Luc Brouilletc5184e22015-03-13 13:51:24 -0700621#endif // ANDROID_RS_API_GENERATOR_SPECIFICATION_H