MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / ArrayDef

Class ArrayDef

src/hx/cppia/Cppia.cpp:4981–5230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4979};
4980
4981struct ArrayDef : public CppiaDynamicExpr
4982{
4983 int classId;
4984 Expressions items;
4985 ArrayType arrayType;
4986
4987 ArrayDef(CppiaStream &stream)
4988 {
4989 classId = stream.getInt();
4990 ReadExpressions(items,stream);
4991 }
4992
4993
4994 const char *getName() HXCPP_OVERRIDE { return "ArrayDef"; }
4995 CppiaExpr *link(CppiaModule &inModule) HXCPP_OVERRIDE
4996 {
4997 TypeData *type = inModule.types[classId];
4998 arrayType = type->arrayType;
4999 if (!arrayType)
5000 {
5001 CPPIALOG("ArrayDef of non array-type %s\n", type->name.out_str());
5002 throw "Bad ArrayDef";
5003 }
5004 LinkExpressions(items,inModule);
5005 return this;
5006 }
5007
5008 hx::Object *runObject(CppiaCtx *ctx) HXCPP_OVERRIDE
5009 {
5010 int n = items.size();
5011 switch(arrayType)
5012 {
5013 case arrBool:
5014 {
5015 Array<bool> result = Array_obj<bool>::__new(n,n);
5016 for(int i=0;i<n;i++)
5017 {
5018 result->__unsafe_set(i,items[i]->runInt(ctx)!=0);
5019 BCR_CHECK;
5020 }
5021 return result.mPtr;
5022 }
5023 case arrUnsignedChar:
5024 {
5025 Array<unsigned char> result = Array_obj<unsigned char>::__new(n,n);
5026 for(int i=0;i<n;i++)
5027 {
5028 result->__unsafe_set(i,items[i]->runInt(ctx));
5029 BCR_CHECK;
5030 }
5031 return result.mPtr;
5032 }
5033 case arrInt:
5034 {
5035 Array<int> result = Array_obj<int>::__new(n,n);
5036 for(int i=0;i<n;i++)
5037 {
5038 result->__unsafe_set(i,items[i]->runInt(ctx));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected