add tests for parsing constant expressions.

Change-Id: Ic1f524c604fc72b9d1b7b330b608ff38ce287921
This commit is contained in:
Yifan Hong 2016-08-12 17:39:44 -07:00
parent 564cc0ab33
commit ab407f096e
3 changed files with 83 additions and 17 deletions

View file

@ -0,0 +1,33 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := android.hardware.tests.expression@1.0
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
intermediates := $(local-generated-sources-dir)
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
#
# Build IExpression.hal
#
GEN := $(intermediates)/android/hardware/tests/expression/1.0/ExpressionAll.cpp
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IExpression.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Lc++ -randroid.hardware:hardware/interfaces\
android.hardware.tests.expression@1.0::$(patsubst %.hal,%,$(notdir $(PRIVATE_DEPS)))
$(GEN): $(LOCAL_PATH)/IExpression.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
LOCAL_EXPORT_C_INCLUDE_DIRS := $(intermediates)
LOCAL_SHARED_LIBRARIES := \
libhwbinder \
libutils \
include $(BUILD_SHARED_LIBRARY)

View file

@ -0,0 +1,33 @@
package android.hardware.tests.expression@1.0;
@hal_type(type="LIGHT")
interface IExpression {
enum int_literals : int32_t {
literal = 4,
literalL = -4L,
simpleArithmetic = 4 + 1,
simpleIdentifier = literalL,
simpleIdentifier2 = literalL + simpleArithmetic,
boolExpr = 1 == 7 && !((3 != 4 || (2 < 3 <= 3 > 4)) >= 0),
bitExpr = ~42 & (1 << 3 | 16 >> 2) ^ 7,
arithmeticExpr = 2 + 3 - 4 * -7 / (10 % 3),
messyExpr = 2 + (-3&4 / 7),
paranExpr = (((((1 + 1))))),
ternary = 1?2:3,
ternary2 = 1&&2?3:4,
complicatedTernary2 = 1 - 1 && 2 + 3 || 5 ? 7 * 8 : -3
};
// const float SIMPLE_FLOAT1 = 1e20;
// const float SIMPLE_FLOAT2 = 1e-10L;
// const float SIMPLE_FLOAT3 = 1.;
// const float SIMPLE_FLOAT4 = 1.e-2;
// const float SIMPLE_FLOAT5 = 3.1416;
// const float SIMPLE_FLOAT6 = .5f;
// const float SIMPLE_FLOAT7 = 0.5e-3L;
// struct expressionist_t {
// uint8_t[1 << 10] buffer;
// };
// @param(name = "mask", normal = 1 << 5)
// setExpression(expressionist_t state, int32_t mask) generates (int32_t ret);
};

View file

@ -8,23 +8,6 @@ intermediates := $(local-generated-sources-dir)
HIDL := $(HOST_OUT_EXECUTABLES)/hidl-gen$(HOST_EXECUTABLE_SUFFIX)
#
# Build IFooCallback.hal
#
GEN := $(intermediates)/android/hardware/tests/foo/1.0/FooCallbackAll.cpp
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IFooCallback.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Lc++ -randroid.hardware:hardware/interfaces\
android.hardware.tests.foo@1.0::$(patsubst %.hal,%,$(notdir $(PRIVATE_DEPS)))
$(GEN): $(LOCAL_PATH)/IFooCallback.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build types.hal
#
@ -42,6 +25,23 @@ $(GEN): $(LOCAL_PATH)/types.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build IFooCallback.hal
#
GEN := $(intermediates)/android/hardware/tests/foo/1.0/FooCallbackAll.cpp
$(GEN): $(HIDL)
$(GEN): PRIVATE_HIDL := $(HIDL)
$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/IFooCallback.hal
$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
$(GEN): PRIVATE_CUSTOM_TOOL = \
$(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
-Lc++ -randroid.hardware:hardware/interfaces\
android.hardware.tests.foo@1.0::$(patsubst %.hal,%,$(notdir $(PRIVATE_DEPS)))
$(GEN): $(LOCAL_PATH)/IFooCallback.hal
$(transform-generated-source)
LOCAL_GENERATED_SOURCES += $(GEN)
#
# Build IFoo.hal
#