// Copyright (C) 2015 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import "gfxapi_test_include.api"
import imported "gfxapi_test_import.api"

class Tester {
  imported.Imported A
	Included B
}

////////////////////////////////////////////////////////////////
// Intrinsics tests
////////////////////////////////////////////////////////////////
u8[]   u8s
u16[]  u16s
u32[]  u32s
int[]  ints
string str

cmd void cmdClone(u8* src, u32 cnt) {
  u8s = clone(src[0:cnt])
}

cmd void cmdMake(u32 cnt) {
  u8s = make!u8(cnt)
}

cmd void cmdCopy(u8* src, u32 cnt) {
  u8s = make!u8(cnt)
  copy(u8s, src[0:cnt])
}

cmd void cmdCharsliceToString(char* s, u32 len) {
  str = as!string(s[0:len])
}

cmd void cmdCharptrToString(char* s) {
  str = as!string(s)
}

cmd void cmdSliceCasts(u16* s, u32 l) {
  u8s  = as!u8[](s[0:l])
  u16s = as!u16[](s[0:l])
  u32s = as!u32[](s[0:l])
  ints = as!int[](s[0:l])
}

////////////////////////////////////////////////////////////////
// Void, no args
////////////////////////////////////////////////////////////////
cmd void cmdVoid() {}

////////////////////////////////////////////////////////////////
// Unknown tests
////////////////////////////////////////////////////////////////
// TODO: These do not currently compile
// int unk
//
// cmd int cmdUnknownRet() {
//   i := ?
//   unk = i
//   return i
// }
//
// cmd void cmdUnknownPtr(int* p) {
//   i := ?
//   unk = i
//   p[0] = i
// }

cmd int cmdUnknownRet() {
  return ?
}

cmd void cmdUnknownWritePtr(int* p) {
  p[0] = ?
}

cmd void cmdUnknownWriteSlice(int* a) {
  count := 5
  slice := a[0:count]
  for i in (0 .. count) {
    unknown := as!int(?)
    slice[i] = unknown
  }
}

////////////////////////////////////////////////////////////////
// Commands with a single input argument
////////////////////////////////////////////////////////////////
cmd void cmdVoidU8(u8 a)         {}
cmd void cmdVoidS8(s8 a)         {}
cmd void cmdVoidU16(u16 a)       {}
cmd void cmdVoidS16(s16 a)       {}
cmd void cmdVoidF32(f32 a)       {}
cmd void cmdVoidU32(u32 a)       {}
cmd void cmdVoidS32(s32 a)       {}
cmd void cmdVoidF64(f64 a)       {}
cmd void cmdVoidU64(u64 a)       {}
cmd void cmdVoidS64(s64 a)       {}
cmd void cmdVoidBool(bool a)     {}
cmd void cmdVoidString(string a) {}

////////////////////////////////////////////////////////////////
// Commands with more than one input
////////////////////////////////////////////////////////////////
cmd void cmdVoid3Strings(string a, string b, string c) {}

////////////////////////////////////////////////////////////////
// Commands with input arrays
////////////////////////////////////////////////////////////////
cmd void cmdVoid3InArrays(u8* a, u32* b, int* c) {
  u8s = make!u8(10)
  read(b[5:15])
	read(c[5:15])
	copy(u8s, a[5:25]) // only 10 elements should be copied
}

////////////////////////////////////////////////////////////////
// Commands with input of arrays of pointers
////////////////////////////////////////////////////////////////
cmd void cmdVoidInArrayOfPointers(char** a, s32 count) {
  slice := a[0:count]
  for i in (0 .. count) {
    x := slice[i][0]
  }
}

////////////////////////////////////////////////////////////////
// Commands with a single pointer element read
////////////////////////////////////////////////////////////////
cmd void cmdVoidReadU8(u8* a)     { x := a[0] }
cmd void cmdVoidReadS8(s8* a)     { x := a[0] }
cmd void cmdVoidReadU16(u16* a)   { x := a[0] }
cmd void cmdVoidReadS16(s16* a)   { x := a[0] }
cmd void cmdVoidReadF32(f32* a)   { x := a[0] }
cmd void cmdVoidReadU32(u32* a)   { x := a[0] }
cmd void cmdVoidReadS32(s32* a)   { x := a[0] }
cmd void cmdVoidReadF64(f64* a)   { x := a[0] }
cmd void cmdVoidReadU64(u64* a)   { x := a[0] }
cmd void cmdVoidReadS64(s64* a)   { x := a[0] }
cmd void cmdVoidReadBool(bool* a) { x := a[0] }

////////////////////////////////////////////////////////////////
// Commands with multiple pointer element reads
////////////////////////////////////////////////////////////////
cmd void cmdVoidReadPtrs(f32* a, u16* b, bool* c) {
  x := a[0]
  y := b[0]
  z := c[0]
}

////////////////////////////////////////////////////////////////
// Commands with a single pointer element write
////////////////////////////////////////////////////////////////
cmd void cmdVoidWriteU8(u8* a)     { a[0] = 1 }
cmd void cmdVoidWriteS8(s8* a)     { a[0] = 1 }
cmd void cmdVoidWriteU16(u16* a)   { a[0] = 1 }
cmd void cmdVoidWriteS16(s16* a)   { a[0] = 1 }
cmd void cmdVoidWriteF32(f32* a)   { a[0] = 1 }
cmd void cmdVoidWriteU32(u32* a)   { a[0] = 1 }
cmd void cmdVoidWriteS32(s32* a)   { a[0] = 1 }
cmd void cmdVoidWriteF64(f64* a)   { a[0] = 1 }
cmd void cmdVoidWriteU64(u64* a)   { a[0] = 1 }
cmd void cmdVoidWriteS64(s64* a)   { a[0] = 1 }
cmd void cmdVoidWriteBool(bool* a) { a[0] = true }

////////////////////////////////////////////////////////////////
// Commands with multiple pointer element writes
////////////////////////////////////////////////////////////////
cmd void cmdVoidWritePtrs(f32* a, u16* b, bool* c) {
  a[0] = 10
  b[0] = 20
  c[0] = false
}

////////////////////////////////////////////////////////////////
// Commands with a return value
////////////////////////////////////////////////////////////////
cmd u8     cmdU8()      { return 0 }
cmd s8     cmdS8()      { return 0 }
cmd u16    cmdU16()     { return 0 }
cmd s16    cmdS16()     { return 0 }
cmd f32    cmdF32()     { return 0 }
cmd u32    cmdU32()     { return 0 }
cmd s32    cmdS32()     { return 0 }
cmd f64    cmdF64()     { return 0 }
cmd u64    cmdU64()     { return 0 }
cmd s64    cmdS64()     { return 0 }
cmd bool   cmdBool()    { return false }
cmd string cmdString()  { return "" }
cmd void*  cmdPointer() { return ? }

////////////////////////////////////////////////////////////////
// Commands with remapped arguments
////////////////////////////////////////////////////////////////
cmd void cmdVoid3Remapped(remapped a, remapped b, remapped c) {}

cmd void cmdVoidInArrayOfRemapped(remapped* a) { read(a[0:5]) }

cmd void cmdVoidOutArrayOfRemapped(remapped* a) { write(a[0:5]) }

cmd void cmdVoidOutArrayOfUnknownRemapped(remapped* a) {
  count := 5
  slice := a[0:count]
  for i in (0 .. count) {
    unknown := as!remapped(?)
    slice[i] = unknown
  }
}

cmd remapped cmdRemapped() { return ? }
