Esempio n. 1
0
static void initAnnotationBuffers(void)
{
	int n;
	int i;

	n = omp_get_max_threads();
	annotationBuffer = callocOrExit(n, StringBuffer*);
	annotationBufferW = callocOrExit(n, StringBuffer*);
	nbPush = callocOrExit(n, int);

	for (i = 0; i < n; i++)
	{
		annotationBuffer[i] = newStringBuffer(BUFFER_SIZE);
		annotationBufferW[i] = newStringBuffer(BUFFER_SIZE);
	}
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
static void testAppendChar()
{
  MemoryPool pool = newMemoryPool();

  StringBuffer s = newStringBuffer(&pool, "A test string");
  s.appendChar(&s, '!');
  assertEquals(string, "A test string!", s.str);
  s.appendChar(&s, '-');
  assertEquals(string, "A test string!-", s.str);

  pool.drain(&pool);
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
static void testAppendString()
{
  MemoryPool pool = newMemoryPool();

  StringBuffer s = newStringBuffer(&pool, "A test string");
  s.append(&s, " - appended value");
  assertEquals(string, "A test string - appended value", s.str);
  s.append(&s, " & another value");
  assertEquals(string, "A test string - appended value & another value", s.str);
  assertTrue(s.size > strlen("A test string - appended value & another value"));

  pool.drain(&pool);
}
Esempio n. 4
0
//-----------------------------------------------------------------------------
static void testToString()
{
  MemoryPool pool = newMemoryPool();

  StringBuffer sb = newStringBuffer(&pool, "A test strin");
  sb.appendChar(&sb, 'g');
  assertEquals(string, "A test string", sb.str);

  string s = sb.toString(&sb, &pool);
  assertEquals(string, "A test string", s);
  assertEquals(unsigned_int, 13, strlen(s));

  pool.drain(&pool);
}
Esempio n. 5
0
File: debug.c Progetto: fmccabe/cafe
static DebugWaitFor cmder(debugOptPo opts, processPo p, methodPo mtd, termPo loc, insWord ins) {
  static bufferPo cmdBuffer = Null;

  if (cmdBuffer == Null)
    cmdBuffer = newStringBuffer();

  while (interactive) {
    dbgPrompt(p);
    clearBuffer(cmdBuffer);

    setEditLineCompletionCallback(cmdComplete, (void *) opts);
    retCode res = (debuggerListener == Null ? consoleInput(cmdBuffer) : inLine(debugInChnnl, cmdBuffer, "\n"));
    clearEditLineCompletionCallback();

    switch (res) {
      case Eof:
        return quitDbg;
      case Ok: {
        integer cmdLen = 0;
        char *cmdLine = getTextFromBuffer(cmdBuffer, &cmdLen);

        cmdLine = defltLine(cmdLine, cmdLen, &cmdLen);

        codePoint cmd;
        integer nxt = 0;
        cmd = nextCodePoint(cmdLine, &nxt, cmdLen);

        if (isNdChar((codePoint) cmd)) {
          cmd = 'n';
          nxt = 0;
        }

        for (int ix = 0; ix < opts->count; ix++) {
          if (opts->opts[ix].c == cmd)
            return opts->opts[ix].cmd(&cmdLine[nxt], p, loc, ins, opts->opts[ix].cl);
        }
        outMsg(debugOutChnnl, "invalid debugger command: %s\n", cmdLine);
      }
      default:
        for (int ix = 0; ix < opts->count; ix++)
          outMsg(debugOutChnnl, "%s\n", opts->opts[ix].usage);
        flushFile(debugOutChnnl);
        return moreDebug;
    }
  }
  return moreDebug;
}
Esempio n. 6
0
} SyntaxTreeVisitor;
//-----------------------------------------------------------------------------
static void visitBracketStart(SyntaxTreeVisitor*, StreamChar type);
static void visitBracketEnd(SyntaxTreeVisitor*, StreamChar type);
static void visitBracketEndMissing(SyntaxTreeVisitor*, StreamChar type);
static void visitChar(SyntaxTreeVisitor*, StreamChar c);
static Token* newToken(SyntaxTreeVisitor*, SyntaxTreeStackFrame*);
//-----------------------------------------------------------------------------
SyntaxTree newSyntaxTree(MemoryPool* const treePool, CharStream* const charStream)
{
  SyntaxTreeStackFrame firstStackFrame = {
    .pool = newMemoryPool()
  };

  firstStackFrame.list = newLinkedList(&firstStackFrame.pool);
  firstStackFrame.token = newStringBuffer(&firstStackFrame.pool, "");

  SyntaxTreeVisitor visitor = {
    .bracketVisitor = {
      .visitBracketStart = (BracketVisitStart) &visitBracketStart,
      .visitBracketEnd = (BracketVisitEnd) &visitBracketEnd,
      .visitBracketEndMissing = (BracketVisitEndMissing) &visitBracketEndMissing,
      .visitChar = (BracketVisitChar) &visitChar
    },

    .pool = treePool,
    .stackFrame = &firstStackFrame
  };

  BracketStream bracketStream = newBracketStream(charStream);
  bracketStream.visit(&bracketStream, &visitor.bracketVisitor);