Home | History | Annotate | Download | only in hidl
      1 /*
      2  * Copyright (C) 2016 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 ARRAY_TYPE_H_
     18 
     19 #define ARRAY_TYPE_H_
     20 
     21 #include "Reference.h"
     22 #include "Type.h"
     23 
     24 #include <vector>
     25 
     26 namespace android {
     27 
     28 struct ConstantExpression;
     29 
     30 struct ArrayType : public Type {
     31     ArrayType(const Reference<Type>& elementType, ConstantExpression* size, Scope* parent);
     32 
     33     bool isArray() const override;
     34     bool deepCanCheckEquality(std::unordered_set<const Type*>* visited) const override;
     35 
     36     const Type* getElementType() const;
     37 
     38     void appendDimension(ConstantExpression *size);
     39     size_t countDimensions() const;
     40 
     41     std::string typeName() const override;
     42 
     43     std::vector<const Reference<Type>*> getReferences() const override;
     44 
     45     std::vector<const ConstantExpression*> getConstantExpressions() const override;
     46 
     47     // Extends existing array by adding another dimension.
     48     status_t resolveInheritance() override;
     49 
     50     status_t validate() const override;
     51 
     52     std::string getCppType(StorageMode mode,
     53                            bool specifyNamespaces) const override;
     54 
     55     std::string getInternalDataCppType() const;
     56 
     57     std::string getJavaType(bool forInitializer) const override;
     58 
     59     std::string getJavaWrapperType() const override;
     60 
     61     std::string getVtsType() const override;
     62 
     63     void emitReaderWriter(
     64             Formatter &out,
     65             const std::string &name,
     66             const std::string &parcelObj,
     67             bool parcelObjIsPointer,
     68             bool isReader,
     69             ErrorMode mode) const override;
     70 
     71     void emitReaderWriterEmbedded(
     72             Formatter &out,
     73             size_t depth,
     74             const std::string &name,
     75             const std::string &sanitizedName,
     76             bool nameIsPointer,
     77             const std::string &parcelObj,
     78             bool parcelObjIsPointer,
     79             bool isReader,
     80             ErrorMode mode,
     81             const std::string &parentName,
     82             const std::string &offsetText) const override;
     83 
     84     void emitResolveReferences(
     85             Formatter &out,
     86             const std::string &name,
     87             bool nameIsPointer,
     88             const std::string &parcelObj,
     89             bool parcelObjIsPointer,
     90             bool isReader,
     91             ErrorMode mode) const override;
     92 
     93     void emitResolveReferencesEmbedded(
     94             Formatter &out,
     95             size_t depth,
     96             const std::string &name,
     97             const std::string &sanitizedName,
     98             bool nameIsPointer,
     99             const std::string &parcelObj,
    100             bool parcelObjIsPointer,
    101             bool isReader,
    102             ErrorMode mode,
    103             const std::string &parentName,
    104             const std::string &offsetText) const override;
    105 
    106     void emitJavaDump(
    107             Formatter &out,
    108             const std::string &streamName,
    109             const std::string &name) const override;
    110 
    111     bool needsEmbeddedReadWrite() const override;
    112     bool deepNeedsResolveReferences(std::unordered_set<const Type*>* visited) const override;
    113     bool resultNeedsDeref() const override;
    114 
    115     void emitJavaReaderWriter(
    116             Formatter &out,
    117             const std::string &parcelObj,
    118             const std::string &argName,
    119             bool isReader) const override;
    120 
    121     void emitJavaFieldInitializer(
    122             Formatter &out, const std::string &fieldName) const override;
    123 
    124     void emitJavaFieldReaderWriter(
    125             Formatter &out,
    126             size_t depth,
    127             const std::string &parcelName,
    128             const std::string &blobName,
    129             const std::string &fieldName,
    130             const std::string &offset,
    131             bool isReader) const override;
    132 
    133     void emitVtsTypeDeclarations(Formatter& out) const override;
    134 
    135     bool deepIsJavaCompatible(std::unordered_set<const Type*>* visited) const override;
    136     bool deepContainsPointer(std::unordered_set<const Type*>* visited) const override;
    137 
    138     void getAlignmentAndSize(size_t *align, size_t *size) const override;
    139 
    140    private:
    141     Reference<Type> mElementType;
    142     std::vector<ConstantExpression*> mSizes;
    143 
    144     size_t dimension() const;
    145 
    146     DISALLOW_COPY_AND_ASSIGN(ArrayType);
    147 };
    148 
    149 }  // namespace android
    150 
    151 #endif  // ARRAY_TYPE_H_
    152 
    153