Example #1
0
void Recurse(TiXmlNode * pParentNode, CCObject * pParentObj)
{
  std::string keyValue;
  for (TiXmlNode * pNode = pParentNode->FirstChild(); pNode; pNode = pNode->NextSiblingElement())
  {
    TiXmlElement * pNodeNE = pNode->ToElement();
    if (pNodeNE == NULL) continue;
    const char * szValue = pNodeNE->Value();
    const char * szText = pNodeNE->GetText();
    if (_stricmp(szValue, "key") == 0)
    {
      keyValue = szText;
    }
    else if (_stricmp(szValue, "dict") == 0)
    {
      CCDictionary * pNewDict = new CCDictionary;
      addObject(pParentObj, keyValue, pNewDict);
        
      Recurse(pNode, pNewDict);
    }
    else if (_stricmp(szValue, "array") == 0)
    {
      CCArray * pNewArray = new CCArray();
      addObject(pParentObj, keyValue, pNewArray);
        
      Recurse(pNode, pNewArray);
    }
    else if (_stricmp(szValue, "string") == 0)
    {
      const char * szIn = szText == NULL ? "" : szText;
      std::wstring ret = ConvertToWString(szIn);
      CCString * pString = new CCString(ret.c_str());
      addObject(pParentObj, keyValue, pString);
    }
    else if (_stricmp(szValue, "false") == 0 || _stricmp(szValue, "true") == 0)
    {
      CCBool * pBool = new CCBool(_stricmp(szValue, "true") == 0);
      addObject(pParentObj, keyValue, pBool);
    }
    else if (_stricmp(szValue, "integer") == 0)
    {
      CCInteger * pInt = new CCInteger(atoi(szText));
      addObject(pParentObj, keyValue, pInt);
    }
    else if (_stricmp(szValue, "real") == 0)
    {
      CCReal * pReal = new CCReal(atof(szText));
      addObject(pParentObj, keyValue, pReal);
    }
    else if (_stricmp(szValue, "date") == 0)
    {
      CCDate * pDate = new CCDate(getTimeFromString(szText));
      addObject(pParentObj, keyValue, pDate);
    }
    else
    {
      assert(!"unknown value");
    }
  }
}
Example #2
0
void f2_fft_indexed(int log2n, const complex_t *pIn, complex_t *pOut)
{
    const complex_t wn_table[16]={
      complex_t::from_float(1,     -2.44929359829471e-16),
      complex_t::from_float(-1,     1.22464679914735e-16),
      complex_t::from_float(6.12323399573677e-17, 1),
      complex_t::from_float(0.707106781186548,         0.707106781186547),
      complex_t::from_float(0.923879532511287,          0.38268343236509),
      complex_t::from_float(0.98078528040323 ,        0.195090322016128),
      complex_t::from_float(0.995184726672197 ,       0.0980171403295606),
      complex_t::from_float(0.998795456205172,         0.049067674327418),
      complex_t::from_float(0.999698818696204,        0.0245412285229123),
      complex_t::from_float(0.999924701839145,        0.0122715382857199),
      complex_t::from_float(0.999981175282601,       0.00613588464915448),
      complex_t::from_float(0.999995293809576,       0.00306795676296598),
      complex_t::from_float(0.999998823451702,       0.00153398018628477),
      complex_t::from_float(0.999999705862882,      0.000766990318742704),
      complex_t::from_float(0.999999926465718,      0.000383495187571396),
      complex_t::from_float(0.999999981616429,      0.000191747597310703)
    };

    int n=1<<log2n;
    complex_t wn=wn_table[log2n];
    int bIn=0;
    int sIn=1;
    int bOut=0;
    int sOut=1;

    run_function_old<void>(
        IfElse([&](){ return n<=2; },
            [&](){
                if (n == 1){
                    pOut[bOut+0] = pIn[bIn+0];
                }else if (n == 2){
                    pOut[bOut+0] = pIn[bIn+0]+pIn[bIn+sIn];
                    pOut[bOut+sOut] = pIn[bIn+0]-pIn[bIn+sIn];
                }
            },
            Sequence(
                [&](){
                    n=n/2;
                },
                Recurse([&](){ return make_hls_state_tuple(n,wn*wn,bIn,2*sIn,bOut,sOut); }),
                Recurse([&](){ return make_hls_state_tuple(n,wn*wn,bIn+sIn,2*sIn,bOut+sOut*n,sOut); }),
                [&](){
                    complex_t w=complex_t::from_int(1);

                    for (int j=0;j<n;j++){
                        complex_t t1 = w*pOut[bOut+n+j];
                        complex_t t2 = pOut[bOut+j]-t1;
                        pOut[bOut+j] = pOut[bOut+j]+t1;
                        pOut[bOut+j+n] = t2;
                        w = w*wn; // This introduces quite a lot of numerical error
                    }
                }
            )
        ),
        n, wn, bIn, sIn, bOut, sOut
    );
}
Example #3
0
void CpWhile( void )
{
//=================

// Compile a WHILE statement.
//    WHILE( expr )DO <:label> -- block while
//    WHILE( expr )   <:label> -- block while
//    WHILE( expr ) STATEMENT  -- one line while

    CSExtn();
    InitLoop( CS_WHILE );
    CSCond( CSHead->bottom );
    if( RecNOpn() && RecNextOpr( OPR_COL ) ) {
        BlockLabel();
    } else if( RecKeyWord( "DO" ) &&
               ( RecNextOpr( OPR_TRM ) || RecNextOpr( OPR_COL ) ) ) {
        CITNode->opn.ds = DSOPN_PHI;
        BlockLabel();
    } else {
        Recurse();
        GLabel( CSHead->cycle );
        FiniLoop();
        DelCSNode();
    }
}
Example #4
0
int Main( int argc, char ** argv )
{
    // change recurse to 5-10 to see stack faults without page outs
    Recurse(300);

   return 0;
}
bool IPlatformFile::IterateDirectoryStatRecursively(const TCHAR* Directory, FDirectoryStatVisitor& Visitor)
{
	class FStatRecurse : public FDirectoryStatVisitor
	{
	public:
		IPlatformFile&			PlatformFile;
		FDirectoryStatVisitor&	Visitor;
		FStatRecurse(IPlatformFile&	InPlatformFile, FDirectoryStatVisitor& InVisitor)
			: PlatformFile(InPlatformFile)
			, Visitor(InVisitor)
		{
		}
		virtual bool Visit(const TCHAR* FilenameOrDirectory, const FFileStatData& StatData) override
		{
			bool Result = Visitor.Visit(FilenameOrDirectory, StatData);
			if (Result && StatData.bIsDirectory)
			{
				Result = PlatformFile.IterateDirectoryStat(FilenameOrDirectory, *this);
			}
			return Result;
		}
	};
	FStatRecurse Recurse(*this, Visitor);
	return IterateDirectoryStat(Directory, Recurse);
}
bool IPlatformFile::DeleteDirectoryRecursively(const TCHAR* Directory)
{
	class FRecurse : public FDirectoryVisitor
	{
	public:
		IPlatformFile&		PlatformFile;
		FRecurse(IPlatformFile&	InPlatformFile)
			: PlatformFile(InPlatformFile)
		{
		}
		virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory)
		{
			if (bIsDirectory)
			{
				PlatformFile.IterateDirectory(FilenameOrDirectory, *this);
				PlatformFile.DeleteDirectory(FilenameOrDirectory);
			}
			else
			{
				PlatformFile.SetReadOnly(FilenameOrDirectory, false);
				PlatformFile.DeleteFile(FilenameOrDirectory);
			}
			return true; // continue searching
		}
	};
	FRecurse Recurse(*this);
	Recurse.Visit(Directory, true);
	return !DirectoryExists(Directory);
}
bool IPlatformFile::IterateDirectoryRecursively(const TCHAR* Directory, FDirectoryVisitor& Visitor)
{
	class FRecurse : public FDirectoryVisitor
	{
	public:
		IPlatformFile&		PlatformFile;
		FDirectoryVisitor&	Visitor;
		FRecurse(IPlatformFile&	InPlatformFile, FDirectoryVisitor& InVisitor)
			: PlatformFile(InPlatformFile)
			, Visitor(InVisitor)
		{
		}
		virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory)
		{
			bool Result = Visitor.Visit(FilenameOrDirectory, bIsDirectory);
			if (Result && bIsDirectory)
			{
				Result = PlatformFile.IterateDirectory(FilenameOrDirectory, *this);
			}
			return Result;
		}
	};
	FRecurse Recurse(*this, Visitor);
	return IterateDirectory(Directory, Recurse);
}
Example #8
0
int main(int argc, char **argv) {
    /* change recurse to 5-10 to see stack faults without page outs */
    int depth = 512;

    if(check_static()) {
        integrity_check_enabled = 1;
    } else {
        Print("Integrity check disabled, since statics are busted.\n");
        integrity_check_enabled = 0;
    }


    Check_Integrity_Or_Die();

    if(argc > 1) {
        depth = atoi(argv[1]);
        Print("Depth is %d\n", depth);
    }
    if(argc > 2) {
        Quiet = 1;
    }

    Recurse(depth);

    Print("Rec %d success\n", depth);

    return 0;
}
Example #9
0
void complex::Recurse(node* n, list<block*>* bl, int level)
{
   if (n==NULL)
     return;
   if (level==DIM)
     {
	bl->push_back((block *)n);
	return;
     }
   else
     {
	++level;
	Recurse(n->Left,bl,level);
	Recurse(n->Right,bl,level);
	return;
     }
}
Example #10
0
void f2_sort_indexed(uint32_t *a, int n)
{
    int split=0;
    int aBase=0;

    run_function_old<void>(
        IfElse([&](){ return n < 32; },
            [&]{
                // From Rosetta Code
                // http://rosettacode.org/wiki/Sorting_algorithms/Insertion_sort#C
                int i, j;
                uint32_t t;
                for (i = 1; i < n; i++) {
                    t = a[aBase+i];
                    for (j = i; j > 0 && t < a[aBase+j - 1]; j--) {
                        a[aBase+j] = a[aBase+j - 1];
                    }
                    a[aBase+j] = t;
                }
            },
            Sequence(
                [&](){
                    // http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#C
                    uint32_t pivot=a[aBase+n/2];
                    int i,j;
                    for(i=0, j=n-1;; i++, j--){
                        while(a[aBase+i]<pivot)
                            i++;
                        while(pivot<a[aBase+j])
                            j--;
                        if(i>=j)
                            break;
                        uint32_t tmp=a[aBase+i];
                        a[aBase+i]=a[aBase+j];
                        a[aBase+j]=tmp;
                    }
                    split=i;
                },
                Recurse([&](){ return make_hls_state_tuple(aBase,       split, 0);     }),
                Recurse([&](){ return make_hls_state_tuple(aBase+split, n-split, 0);   })
            )
        ),
        aBase, n, split
    );
}
Example #11
0
// recurses through a directory structure, performing an action on the files/directories within
unsigned int CUtils::RecurseDir(const char *szDirectory, const unsigned int iCommand)
{
	iFileCommand = iCommand;
	iFileCount = 0;

	Recurse(szDirectory);

	return iFileCount;
}
Example #12
0
void Recurse(int x)
{
    int stuff[512];

    if (x == 0) return;

    stuff[0] = x;
    Printf("calling Recurse %d\n", x);
    Recurse(x-1);
}
void ParallelStringRadixSort<StringType>
::Sort16Parallel(size_t bgn, size_t end, size_t depth, bool flip) {
  size_t cnt[1 << 16] = {};

  StringType *src = (flip ? temp_ : data_) + bgn;
  StringType *dst = (flip ? data_ : temp_) + bgn;
  uint16_t *let = letters16_ + bgn;
  size_t n = end - bgn;

  #ifdef _OPENMP
  #pragma omp parallel for schedule(static)
  #endif
  for (size_t i = 0; i < n; ++i) {
    uint16_t x = src[i][depth];
    let[i] = x == 0 ? 0 : ((x << 8) | src[i][depth + 1]);
  }

  for (size_t i = 0; i < n; ++i) {
    ++cnt[let[i]];
  }

  {
    size_t s = 0;
    for (int i = 0; i < 1 << 16; ++i) {
      std::swap(cnt[i], s);
      s += cnt[i];
    }
  }

  for (size_t i = 0; i < n; ++i) {
    std::swap(dst[cnt[let[i]]++], src[i]);
  }

  if (flip == false) {
    #ifdef _OPENMP
    #pragma omp parallel for schedule(static)
    #endif
    for (int i = 0; i < 1 << 8; ++i) {
      size_t b = i == 0 ? 0 : cnt[(i << 8) - 1];
      size_t e = cnt[i << 8];
      for (size_t j = b; j < e; ++j) {
        src[j] = dst[j];
      }
    }
  }

  #ifdef _OPENMP
  #pragma omp parallel for schedule(dynamic)
  #endif
  for (size_t i = 1; i < 1 << 16; ++i) {
    if ((i & 0xFF) != 0 && cnt[i] - cnt[i - 1] >= 1) {
      Recurse(bgn + cnt[i - 1], bgn + cnt[i], depth + 2, !flip);
    }
  }
}
Example #14
0
File: rec.c Project: Foshie/Classes
void Recurse(int x)
{
    volatile int stuff[512];

    if (x == 0) return;

    stuff[0] = stuff[511] = x;
    Print("calling Recurse %d\n", x);
    Recurse(x-1);
    Print("return from Recurse %d\n", x);
}
Example #15
0
void Recurse(ts::binary_tree_array<PixelDifferenceFeature>& tree, 
            ts::binary_tree_array<PixelDifferenceFeature>::iterator parent,
            size_t& leaf, int level, int levels)
{
   tree.set_split_data(parent, RandomFeature());
   if (level == levels - 2)
   {
      tree.set_split_child(parent, false, tree.leaf_to_child(leaf++));
      tree.set_split_child(parent, true, tree.leaf_to_child(leaf++));
      return;
   }

   auto left = tree.push_back(PixelDifferenceFeature());
   tree.set_split_child(parent, false, left);
   Recurse(tree, left, leaf, level + 1, levels);

   auto right = tree.push_back(PixelDifferenceFeature());
   tree.set_split_child(parent, true, right);
   Recurse(tree, right, leaf, level + 1, levels);
}
Example #16
0
void
CUtils::Recurse(const char * rootDir)
{
    char fullname[MAX_PATH + 1];
	HANDLE hFind;
	
	sprintf( fullname, "%s\\*", rootDir );
	hFind = FindFirstFile(fullname, &ffd);

	if(hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
	        sprintf( fullname, "%s\\%s", rootDir, ffd.cFileName );

			// directory so recurse into it
			if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				// ignore current and previous dirs
				if ((stricmp (ffd.cFileName, ".") != 0) && (strcmp (ffd.cFileName, "..") != 0))
				{
					Recurse(fullname);

					// remove it
					if (iFileCommand == DELETEALL)
						if (RemoveDirectory(fullname))
							iFileCount++;
				}
			}
			else
			{ 
				// remove now empty directory
				if (iFileCommand == DELETEALL || iFileCommand == DELETEFILESONLY)
					if (DeleteFile( fullname ))
						iFileCount++;

				// clear the attributes
				if (iFileCommand == REMOVEALLATTRIBUTES)
					if (SetFileAttributes(fullname, FILE_ATTRIBUTE_NORMAL))
						iFileCount++;
			}
		}
		while(FindNextFile(hFind, &ffd));

		FindClose( hFind );
	}

	// remove this root now we are finished with it
	if (iFileCommand == DELETEALL)
		if (RemoveDirectory(rootDir))
			iFileCount++;
}
Example #17
0
File: rec.c Project: Foshie/Classes
int main(int argc, char **argv)
{
    /* change recurse to 5-10 to see stack faults without page outs */
    int depth = 512;

    if (argc > 1) {
	depth = atoi(argv[1]);
	Print("Depth is %d\n", depth);
    }

    Recurse(depth);

    return 0;
}
void ParallelStringRadixSort<StringType>
::Sort16(size_t bgn, size_t end, size_t depth, bool flip) {
  size_t *cnt = new size_t[1 << 16]();
  PSRS_CHECK(cnt != NULL);

  StringType *src = (flip ? temp_ : data_) + bgn;
  StringType *dst = (flip ? data_ : temp_) + bgn;
  uint16_t *let = letters16_ + bgn;
  size_t n = end - bgn;

  for (size_t i = 0; i < n; ++i) {
    uint16_t x = src[i][depth];
    let[i] = x == 0 ? 0 : ((x << 8) | src[i][depth + 1]);
  }

  for (size_t i = 0; i < n; ++i) {
    ++cnt[let[i]];
  }

  size_t s = 0;
  for (int i = 0; i < 1 << 16; ++i) {
    std::swap(cnt[i], s);
    s += cnt[i];
  }

  for (size_t i = 0; i < n; ++i) {
    std::swap(dst[cnt[let[i]]++], src[i]);
  }

  if (flip == false) {
    for (int i = 0; i < 1 << 8; ++i) {
      size_t b = i == 0 ? 0 : cnt[(i << 8) - 1];
      size_t e = cnt[i << 8];
      for (size_t j = b; j < e; ++j) {
        std::swap(src[j], dst[j]);
      }
    }
  }

  for (size_t i = 1; i < 1 << 16; ++i) {
    if ((i & 0xFF) != 0 && cnt[i] - cnt[i - 1] >= 1) {
      Recurse(bgn + cnt[i - 1], bgn + cnt[i], depth + 2, !flip);
    }
  }

  delete [] cnt;
}
Example #19
0
CCObject * LoadPlist(const char * szPlistFile)
{
  TiXmlDocument doc;
  if (!LoadXMLFile(szPlistFile, doc))
  {
    return NULL;
  }

  TiXmlElement * pRoot = doc.RootElement();
  if (!pRoot)
    return NULL;

  CCDictionary * pRootDict = new CCDictionary;
  Recurse(XMLHelper::SubNode(pRoot,"dict",false), pRootDict);
  
  return pRootDict;
}
Example #20
0
// main routine: build virtual atom objects
BaseObject *AtomObject::GetVirtualObjects(BaseObject *op, HierarchyHelp *hh)
{
	BaseObject *orig = op->GetDown();

	// return if no input object is available
	if (!orig) return NULL;

	Bool dirty = FALSE;

	// generate polygonalized clone of input object
	BaseObject *main=NULL,*res=op->GetAndCheckHierarchyClone(hh,orig,HIERARCHYCLONEFLAGS_ASPOLY,&dirty,NULL,FALSE);

	// if !dirty object is already cached and doesn't need to be rebuilt
	if (!dirty) return res;
	if (!res)   return NULL;

	LONG sub;
	Bool single;
	Real srad,crad;

	// get object container
	BaseContainer *bc=op->GetDataInstance();
	BaseThread    *bt=hh->GetThread();

	// group all further objects with this null object
	main = BaseObject::Alloc(Onull);
	if (!main) goto Error;

	// get object settings
	srad   = bc->GetReal(ATOMOBJECT_SRAD);
	crad   = bc->GetReal(ATOMOBJECT_CRAD);
	sub    = bc->GetLong(ATOMOBJECT_SUB);
	single = bc->GetBool(ATOMOBJECT_SINGLE);

	// go through all child hierarchies
	if (!Recurse(hh,bt,main,res,orig->GetMl(),srad,crad,sub,single)) goto Error;
	blDelete(res);

	return main;

Error:
	blDelete(res);
	blDelete(main);
	return NULL;
}
Example #21
0
void AddFactor(dtf::factor_graph<_DataTraits>& graph, _TFactor& factor)
{
   // Generate random features
   ts::binary_tree_array<PixelDifferenceFeature> tree;
   
   // Add the tree nodes with random feature data:
   size_t leaf = 0;
   auto root = tree.push_back(PixelDifferenceFeature());
   Recurse(tree, root, leaf, 0, 8);
   factor.set_tree(ts::tree_order_by_breadth(tree));
   
   // Generate random weights
   // NOTE: Doesn't really matter whether weights are at nodes or leaves
   for (auto w = factor.energies(); w != factor.energies() + factor.energies_size(); ++w)
      *w = frand(-3.0f, 3.0f); 

   graph.push_back(factor);
}
void ParallelStringRadixSort<StringType>
::Sort8(size_t bgn, size_t end, size_t depth, bool flip) {
  // Here we do not use |new| or |malloc|. This is because:
  // 1. these may be heavy bottle-necks under multi-thread, and
  // 2. the size is sufficiently small for preventing stack overflow.
  size_t cnt[1 << 8] = {};

  StringType *src = (flip ? temp_ : data_) + bgn;
  StringType *dst = (flip ? data_ : temp_) + bgn;
  uint8_t *let = letters8_ + bgn;
  size_t n = end - bgn;

  for (size_t i = 0; i < n; ++i) {
    let[i] = src[i][depth];
  }

  for (size_t i = 0; i < n; ++i) {
    ++cnt[let[i]];
  }

  size_t s = 0;
  for (int i = 0; i < 1 << 8; ++i) {
    std::swap(cnt[i], s);
    s += cnt[i];
  }

  for (size_t i = 0; i < n; ++i) {
    std::swap(dst[cnt[let[i]]++], src[i]);
  }

  if (flip == false) {
    size_t b = 0, e = cnt[0];
    for (size_t j = b; j < e; ++j) {
      std::swap(src[j], dst[j]);
    }
  }

  for (size_t i = 1; i < 1 << 8; ++i) {
    if (cnt[i] - cnt[i - 1] >= 1) {
      Recurse(bgn + cnt[i - 1], bgn + cnt[i], depth + 1, !flip);
    }
  }
}
Example #23
0
U0 StkGrowDemo()
{
  F64 t0;

  t0=tT;
  "%X:%X\n",DEPTH,Recurse(DEPTH);
  "Time:%7.5fs\n",tT-t0;

  //If you know the max stack ahead of time...
  //Recurse2's stack is 16 because you have 1 arg,
  //a return addr and no local variables.
  t0=tT;
  "%X:%X\n",DEPTH,CallStkGrow(DEPTH*16+0x800,DEPTH*16+0x800,&Recurse2,DEPTH);
  "Time:%7.5fs\n",tT-t0;


  //$LK,"CallStkGrow","MN:CallStkGrow"$() works with multiple args.
  t0=tT;
  "%X:%X\n",DEPTH,CallStkGrow(DEPTH*32+0x800,DEPTH*32+0x800,
    &Recurse3,DEPTH,1000,2000);
  "Time:%7.5fs\n",tT-t0;
}
Example #24
0
bool Recurse(const AString& Path, const AString& Pattern, uint_t nSubDirs, bool (*fn)(const FILE_INFO *file, void *Context), void *Context)
{
	AString   pattern = ParsePathRegex(Pattern);
	FILE_INFO file;
	DIR		  *handle;
	bool      ok = true, any = IsRegexAnyPattern(pattern);

	if ((handle = opendir(Path.Valid() ? Path : ".")) != NULL) {
		struct dirent *ent;

		while (ok && ((ent = readdir(handle)) != NULL)) {
			if (SetFileData(Path, *ent, &file)) {
				if ((file.ShortName != ".") && (file.ShortName != "..")) {
					bool done = false;

					if (any || MatchPathRegex(file.ShortName, pattern)) {
						ok = (*fn)(&file, Context);
						if (!ok) break;
						done = true;
					}
					if ((nSubDirs > 0) && (file.Attrib & FILE_FLAG_IS_DIR)) {
						if (!done) {
							ok = (*fn)(&file, Context);
							if (!ok) break;
						}
						
						ok = Recurse(file.FileName, Pattern, nSubDirs - 1, fn, Context);
						if (!ok) break;
					}
				}
			}
		}

		closedir(handle);
	}

	return ok;
}
Example #25
0
bool Recurse(const AString& Path, const AString& Pattern, uint_t nSubDirs, bool (*fn)(const FILE_INFO *file, void *Context), void *Context)
{
	WIN32_FIND_DATA finddata;
	AString   pattern, pattern1 = ParsePathRegex(Pattern);
	FILE_INFO file;
	HANDLE    handle;
	bool      ok = true, any = IsRegexAnyPattern(pattern1);

	pattern = Path.CatPath("*");
	if ((handle = ::FindFirstFile(pattern, &finddata)) != INVALID_HANDLE_VALUE) {
		do {
			SetFileData(Path, finddata, &file);

			if ((file.ShortName != ".") && (file.ShortName != "..")) {
				bool done = false;

				if (any || MatchPathRegex(file.ShortName, pattern1)) {
					ok = (*fn)(&file, Context);
					if (!ok) break;
					done = true;
				}
				if ((nSubDirs > 0) && (file.Attrib & FILE_FLAG_IS_DIR)) {
					if (!done) {
						ok = (*fn)(&file, Context);
						if (!ok) break;
					}

					ok = Recurse(file.FileName, Pattern, nSubDirs - 1, fn, Context);
					if (!ok) break;
				}
			}
		} while (ok && ::FindNextFile(handle, &finddata));

		::FindClose(handle);
	}

	return ok;
}
Example #26
0
void    CpLogIf(void) {
//=================

// Process a logical IF statement.

    label_id    if_skip;

    if_skip = NextLabel();
    CSCond( if_skip );
    if( RecKeyWord( "THEN" ) &&
        ( RecNextOpr( OPR_TRM ) || RecNextOpr( OPR_COL ) ) ) {
        AddCSNode( CS_IF );
        CSHead->branch = if_skip;
        CSHead->bottom = NextLabel();
        CITNode->opn.ds = DSOPN_PHI;       // not part of the block label
        BlockLabel();
        CtrlFlgs |= CF_BAD_DO_ENDING;
    } else {
        Recurse();
        GLabel( if_skip );
        FreeLabel( if_skip );
    }
}
Example #27
0
void Recurse(int x) {
    volatile int stuff[512];

    if(x == 0)
        return;

#ifdef PARANOIA
    /* abuse the first int of the array. */
    for(stuff[1] = 1; stuff[1] < 510; stuff[1] += 1)
        stuff[stuff[1]] = stuff[1];
    stuff[1] = 1;               /* unneeded, but returns to the expected goal. */
#endif
    stuff[0] = stuff[511] = x;

    if(!Quiet || x % 100 == 0)
        Print("call %d, %x\n", x, (unsigned int)stuff);
    Check_Integrity_Or_Die();
    Recurse(x - 1);
    if(stuff[0] != x || stuff[511] != x) {
        Print
            ("rec failed: when returning, stack variables had changed.\n");
        Exit(-1);
    }
#ifdef PARANOIA
    /* abuse the first int of the array. */
    for(stuff[1] = 1; stuff[1] < 510; stuff[1] += 1) {
        if(stuff[stuff[1]] != stuff[1]) {
            Print
                ("rec failed: in paranoia mode, stack variables had changed.\n");
            Exit(-1);
        }
    }
#endif
    if(!Quiet || x % 100 == 0)
        Print("return %d\n", x);
}
void f2_strassen_indexed_v2(uint32_t *p, ipmatrix_t dst, ipmatrix_t a, ipmatrix_t b, ipfree_region_t hFree)
{
    int log2n;
    ipmatrix_t tmp1, tmp2, tmp3, tmp4;
    ipmatrix_t M1, M2, M3, M4, M5, M6, M7;

    // VHLS-HACK : The number of steps made VHLS crash, so some
    // of the lambdas have been cost, at the expense of more memory
    // in use

    run_function_old<void>(
        Sequence(
            If([&](){ return ipmatrix_log2n(a)<=4; },
                [&](){ mul_ipmatrix(p, dst,a,b); },
                Return()
            ),
            [&](){
            log2n=ipmatrix_log2n(a)-1; // Size of ipmatrix_quads

            tmp1=alloc_ipmatrix(hFree, log2n);
            tmp2=alloc_ipmatrix(hFree, log2n);
            tmp3=alloc_ipmatrix(hFree, log2n);
            tmp4=alloc_ipmatrix(hFree, log2n);

            M1=alloc_ipmatrix(hFree, log2n);
            add_ipmatrix(p, tmp1,ipmatrix_quad(a,0,0),ipmatrix_quad(a,1,1));
            add_ipmatrix(p, tmp2,ipmatrix_quad(b,0,0),ipmatrix_quad(b,1,1));

            M2=alloc_ipmatrix(hFree, log2n);
            add_ipmatrix(p, tmp3,ipmatrix_quad(a,1,0),ipmatrix_quad(a,1,1));

            },
            Recurse([&](){ return make_hls_state_tuple( M1,tmp1,tmp2, hFree); }),
            Recurse([&](){ return make_hls_state_tuple( M2,tmp3,ipmatrix_quad(b,0,0), hFree); }),
            [&](){

            M3=alloc_ipmatrix(hFree, log2n);
            sub_ipmatrix(p, tmp1,ipmatrix_quad(b,0,1),ipmatrix_quad(b,1,1));

            M4=alloc_ipmatrix(hFree, log2n);
            sub_ipmatrix(p, tmp2,ipmatrix_quad(b,1,0),ipmatrix_quad(b,0,0));

            },
            Recurse([&](){ return make_hls_state_tuple( M3,ipmatrix_quad(a,0,0),tmp1, hFree); }),
            Recurse([&](){ return make_hls_state_tuple( M4,ipmatrix_quad(a,1,1),tmp2, hFree); }),
            [&](){

            M5=alloc_ipmatrix(hFree, log2n);
            add_ipmatrix(p, tmp1,ipmatrix_quad(a,0,0),ipmatrix_quad(a,0,1));

            },
            Recurse([&](){ return make_hls_state_tuple( M5,tmp1,ipmatrix_quad(b,1,1), hFree); }),
            [&](){

            M6=alloc_ipmatrix(hFree, log2n);
            sub_ipmatrix(p, tmp1,ipmatrix_quad(a,1,0),ipmatrix_quad(a,0,0));
            add_ipmatrix(p, tmp2,ipmatrix_quad(b,0,0),ipmatrix_quad(b,0,1));

            M7=alloc_ipmatrix(hFree, log2n);
            sub_ipmatrix(p, tmp3,ipmatrix_quad(a,0,1),ipmatrix_quad(a,1,1));
            add_ipmatrix(p, tmp4,ipmatrix_quad(b,1,0),ipmatrix_quad(b,1,1));

            },
            Recurse([&](){ return make_hls_state_tuple( M6,tmp1,tmp2, hFree); }),
            Recurse([&](){ return make_hls_state_tuple( M7,tmp3,tmp4, hFree); }),
            [&](){

            add_sub_add_ipmatrix(p, ipmatrix_quad(dst,0,0), M1, M4, M5, M7);
            add_ipmatrix(p, ipmatrix_quad(dst,0,1), M3, M5);
            add_ipmatrix(p, ipmatrix_quad(dst,1,0), M2, M4);
            add_sub_add_ipmatrix(p, ipmatrix_quad(dst,1,1), M1,M3,M2,M6);
            }
        ),
        dst, a, b, hFree,
        log2n, tmp1, tmp2, tmp3, tmp4,
        M1, M2, M3, M4, M5, M6, M7
    );
}
Example #29
0
block* complex::Merge(node* n)
{
   list<block*> sub_blocks;
   Recurse(n,&sub_blocks,0);

   list<block*>::iterator sbit=sub_blocks.begin();
//   if (sbit==sub_blocks.end())
//     exit(1);

   block* b=new block(BC(*sbit),this);
//    block* b=new block(*((*sbit)->bc),this);
//   assert(b->bdry_verts.Empty());
//   (b->bc)->SetAs(BC(*sbit));
   BC(b).SetAs(BC(*sbit));
   for(int i=0;i<DIM;++i)
     BC(b)++;
   int level=(cube_bits-BC(b).Bits())/DIM;
   for(int i=0;i<level*DIM;++i)
     BC(b)--;
   BC(b).Coordinates(min);
   for(int i=0;i<level*DIM;++i)
     BC(b)++;

   vertex* v;
   int vc[DIM];
   int flag=1;
   cell_iter bvit;
   cell_iter cit;
   cobdry_iter cbit;

   while(sbit!=sub_blocks.end())
     {
	bvit=(*sbit)->bdry_verts.Begin();
	while(bvit!=(*sbit)->bdry_verts.End())
	  {
             v=(vertex*)(*bvit);
	     v->bc->Coordinates(vc);
	     flag=1;
	     for (int i=0; i<DIM; ++i)
	       flag*=(((min[i]<vc[i])&&(vc[i]<min[i]+Power2(level)))||((vc[i]==0)||(vc[i]==Power2(cube_bits/DIM))));
             if (flag)
	       {
		  if (!(v->Interior()))
		    {
		       v->MarkInterior();
		       DeleteVertex(v);
		       b->cells[0].InsertUniqueSort(v);
		    }
	       }
	     else
	       b->bdry_verts.InsertUniqueSort(v);
	     ++bvit;
	  }
	for(int i=0;i<DIM;++i)
	   {
 	      cit=(*sbit)->cells[i].Begin();
	      while(cit!=(*sbit)->cells[i].End())
	         {
	            b->cells[i].InsertUniqueSort(Ptr(cit));
	            ++cit;
	         }
	   }
	++sbit;
     }

   cit=b->cells[0].Begin();
   while(cit!=b->cells[0].End())
     {
	cbit=((vertex*)(*cit))->Cobdry()->Begin();
//      cout << "size " << (*cit)->Cobdry()->Size() << endl;
	while(cbit!=((vertex*)(*cit))->Cobdry()->End())
	   {
	      ((edge*)Ptr(cbit))->MarkInterior();
//	      b->cells[1].InsertUniqueSort(Ptr(cbit));
	      if (b->cells[1].Find(Ptr(cbit))==b->cells[1].End())
		{
		   b->cells[1].InsertUniqueSort(Ptr(cbit));
		}
	      ++cbit;
	   }
	++cit;
     }
   
   cit=b->cells[1].Begin();
   while(cit!=b->cells[1].End())
     {
	cbit=((edge*)(*cit))->Cobdry()->Begin();
//      cout << "size " << (*cit)->Cobdry()->Size() << endl;
	while(cbit!=((edge*)(*cit))->Cobdry()->End())
	   {
	      ((ncell*)Ptr(cbit))->MarkInterior();
//	      b->cells[2].InsertUniqueSort(Ptr(cbit));
	      if (b->cells[2].Find(Ptr(cbit))==b->cells[2].End())
		{
		   b->cells[2].InsertUniqueSort(Ptr(cbit));
		}
	      ++cbit;
	   }
	++cit;
     }	
	
   for(int i=3;i<DIM;++i)
     {
	cit=b->cells[i-1].Begin();
	while(cit!=b->cells[i-1].End())
	  {
	     cbit=((ncell*)(*cit))->Cobdry()->Begin();
//             cout << "size " << (*cit)->Cobdry()->Size() << endl;
	     while(cbit!=((ncell*)(*cit))->Cobdry()->End())
	       {
		  ((ncell*)Ptr(cbit))->MarkInterior();
//		  b->cells[i].InsertUniqueSort(Ptr(cbit));
		  if (b->cells[i].Find(Ptr(cbit))==b->cells[i].End())
		    {
		       b->cells[i].InsertUniqueSort(Ptr(cbit));
		    }
		  ++cbit;
	       }
	     ++cit;
	  }
     }
   
   if (n==cubes.Root)
     cubes.Root=b;
   else
     {
       node* parent=n->Parent;
       if (parent->Left==n)
         parent->Left=b;
       else
         parent->Right=b;
       b->Parent=parent;	
     }	
   
   Delete(n,0);
   
   return(b);	
}
Example #30
0
// go through every (child) object
static Bool Recurse(HierarchyHelp *hh, BaseThread *bt, BaseObject *main, BaseObject *op, const Matrix &ml, Real srad, Real crad, LONG sub, Bool single)
{
	// test if input object if polygonal
	if (op->GetType()==Opolygon)
	{
		BaseObject *tp   = NULL;
		PolyInfo	 *pli  = NULL;
		const Vector *padr = ToPoly(op)->GetPointR();
		Vector pa,pb;
		LONG       pcnt  = ToPoly(op)->GetPointCount(),i,side,a=0,b=0;
		const CPolygon *vadr = ToPoly(op)->GetPolygonR();
		LONG       vcnt  = ToPoly(op)->GetPolygonCount();
		Matrix     m;
		Neighbor	 n;

		// load names from resource
		String		 pstr = GeLoadString(IDS_ATOM_POINT);
		String		 estr = GeLoadString(IDS_ATOM_EDGE);

		// initialize neighbor class
		if (!n.Init(pcnt,vadr,vcnt,NULL)) return FALSE;

		// create separate objects
		// if this option is enabled no polygonal geometry is build - more parametric objects
		// are returned instead
		if (single)
		{
			for (i=0; i<pcnt; i++)
			{
				// alloc sphere primitive
				tp=BaseObject::Alloc(Osphere);
				if (!tp) return FALSE;

				// add phong tag
				if (!tp->MakeTag(Tphong)) return FALSE;
				tp->SetName(pstr+" "+LongToString(i));

				// set object parameters
				BaseContainer *bc = tp->GetDataInstance();
				bc->SetReal(PRIM_SPHERE_RAD,srad);
				bc->SetReal(PRIM_SPHERE_SUB,sub);

				// insert as last object under main
				tp->InsertUnderLast(main);

				// set position in local coordinates
				tp->SetRelPos(padr[i]*ml);
			}

			for (i=0; i<vcnt; i++)
			{
				// get polygon info for i-th polygon
				pli = n.GetPolyInfo(i);

				for (side=0; side<4; side++)
				{
					// only proceed if edge has not already been processed
					// and edge really exists (for triangles side 2 from c..d does not exist as c==d)
					if (pli->mark[side] || side==2 && vadr[i].c==vadr[i].d) continue;

					// alloc cylinder primitive
					tp=BaseObject::Alloc(Ocylinder);
					if (!tp) return FALSE;

					// add phong tag
					if (!tp->MakeTag(Tphong)) return FALSE;

					switch (side)
					{
						case 0: a=vadr[i].a; b=vadr[i].b; break;
						case 1: a=vadr[i].b; b=vadr[i].c; break;
						case 2: a=vadr[i].c; b=vadr[i].d; break;
						case 3: a=vadr[i].d; b=vadr[i].a; break;
					}

					tp->SetName(estr+" "+LongToString(pli->edge[side]));

					pa = padr[a]*ml;
					pb = padr[b]*ml;

					// set object parameters
					BaseContainer *bc = tp->GetDataInstance();
					bc->SetReal(PRIM_CYLINDER_RADIUS,crad);
					bc->SetReal(PRIM_CYLINDER_HEIGHT,Len(pb-pa));
					bc->SetReal(PRIM_AXIS,4);
					bc->SetLong(PRIM_CYLINDER_CAPS,FALSE);
					bc->SetLong(PRIM_CYLINDER_HSUB,1);
					bc->SetLong(PRIM_CYLINDER_SEG,sub);

					// place cylinder at edge center
					tp->SetRelPos((pa+pb)*0.5);

					// build edge matrix
					m.v3=!(pb-pa);
					RectangularSystem(m.v3,&m.v1,&m.v2);
					tp->SetRelRot(MatrixToHPB(m, tp->GetRotationOrder()));

					// insert as last object under main
					tp->InsertUnderLast(main);
				}
			}
		}
		else
		{
			// check if polygonal geometry has to be built
			tp = BuildPolyHull(ToPoly(op),ml,srad,crad,sub,hh->GetLOD(),&n,bt);

			if (tp)
			{
				tp->SetName(op->GetName());
				tp->InsertUnderLast(main);

				// check if isoparm geometry has to be built
				if (hh->GetBuildFlags()&BUILDFLAGS_ISOPARM)
				{
					LineObject *ip = BuildIsoHull(ToPoly(op),ml,srad,crad,sub,hh->GetLOD(),&n,bt);

					// isoparm always needs to be set into a polygon object
					if (ip) tp->SetIsoparm(ip);
				}
			}
		}
	}

	for (op=op->GetDown(); op; op=op->GetNext())
		if (!Recurse(hh,bt,main,op,ml*op->GetMl(),srad,crad,sub,single)) return FALSE;

	// check for user break
	return !bt || !bt->TestBreak();
}