OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdCompiler.h File Reference
#include "lib/StdBuf.h"
#include "lib/C4Log.h"
#include <assert.h>
#include <memory>
Include dependency graph for StdCompiler.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  StdCompiler
 
struct  StdCompiler::Exception
 
class  StdCompiler::NotFoundException
 
class  StdCompiler::EOFException
 
class  StdCompiler::CorruptException
 
class  StdCompilerNull
 
class  StdCompilerBinWrite
 
class  StdCompilerBinRead
 
class  StdCompilerINIWrite
 
struct  StdCompilerINIWrite::Naming
 
class  StdCompilerINIRead
 
struct  StdCompilerINIRead::NameNode
 

Functions

template<class T >
void CompileFunc (T &rStruct, StdCompiler *pComp)
 
void CompileFunc (std::string &s, StdCompiler *comp)
 
template<class T >
void CompileNewFunc (T *&pStruct, StdCompiler *pComp)
 
template<class T , typename... P>
void CompileNewFunc (T *&pStruct, StdCompiler *pComp, P &&...pars)
 
template<class T , class ContextT >
void CompileNewFuncCtx (T *&pStruct, StdCompiler *pComp, const ContextT &rCtx)
 
template<class T , class ContextT , class P >
void CompileNewFuncCtx (T *&pStruct, StdCompiler *pComp, const ContextT &rCtx, const P &rPar)
 
template<class CompT , class StructT >
void CompileFromBuf (StructT &&TargetStruct, const typename CompT::InT &SrcBuf)
 
template<class CompT , class StructT >
StructT * CompileFromBufToNew (const typename CompT::InT &SrcBuf)
 
template<class CompT , class StructT >
StructT * CompileFromBufToNewNamed (const typename CompT::InT &SrcBuf, const char *szName)
 
template<class CompT , class StructT >
CompT::OutT DecompileToBuf (const StructT &SrcStruct)
 
void StdCompilerWarnCallback (void *pData, const char *szPosition, const char *szError)
 
template<class CompT , class StructT >
bool CompileFromBuf_Log (StructT &&TargetStruct, const typename CompT::InT &SrcBuf, const char *szName)
 
template<class CompT , class StructT >
bool CompileFromBuf_LogWarn (StructT &&TargetStruct, const typename CompT::InT &SrcBuf, const char *szName)
 
template<class CompT , class StructT >
bool DecompileToBuf_Log (StructT &&TargetStruct, typename CompT::OutT *pOut, const char *szName)
 

Class Documentation

struct StdCompilerINIWrite::Naming

Definition at line 609 of file StdCompiler.h.

Collaboration diagram for StdCompilerINIWrite::Naming:
[legend]
Class Members
StdStrBuf Name
Naming * Parent

Function Documentation

template<class CompT , class StructT >
void CompileFromBuf ( StructT &&  TargetStruct,
const typename CompT::InT &  SrcBuf 
)

Definition at line 389 of file StdCompiler.h.

390 {
391  CompT Compiler;
392  Compiler.setInput(SrcBuf.getRef());
393  Compiler.Compile(TargetStruct);
394 }
template<class CompT , class StructT >
bool CompileFromBuf_Log ( StructT &&  TargetStruct,
const typename CompT::InT &  SrcBuf,
const char *  szName 
)

Definition at line 748 of file StdCompiler.h.

References StdStrBuf::getData(), StdStrBuf::getLength(), LogF(), StdCompiler::Exception::Msg, and StdCompiler::Exception::Pos.

749 {
750  try
751  {
752  CompileFromBuf<CompT>(TargetStruct, SrcBuf);
753  return true;
754  }
755  catch (StdCompiler::Exception *pExc)
756  {
757  if (!pExc->Pos.getLength())
758  LogF("ERROR: %s (in %s)", pExc->Msg.getData(), szName);
759  else
760  LogF("ERROR: %s (in %s, %s)", pExc->Msg.getData(), pExc->Pos.getData(), szName);
761  delete pExc;
762  return false;
763  }
764 }
const char * getData() const
Definition: StdBuf.h:450
size_t getLength() const
Definition: StdBuf.h:453
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

Here is the call graph for this function:

template<class CompT , class StructT >
bool CompileFromBuf_LogWarn ( StructT &&  TargetStruct,
const typename CompT::InT &  SrcBuf,
const char *  szName 
)

Definition at line 766 of file StdCompiler.h.

References StdStrBuf::getData(), StdStrBuf::getLength(), LogF(), StdCompiler::Exception::Msg, StdCompiler::Exception::Pos, and StdCompilerWarnCallback().

767 {
768  try
769  {
770  CompT Compiler;
771  Compiler.setInput(SrcBuf.getRef());
772  Compiler.setWarnCallback(StdCompilerWarnCallback, reinterpret_cast<void *>(const_cast<char *>(szName)));
773  Compiler.Compile(TargetStruct);
774  return true;
775  }
776  catch (StdCompiler::Exception *pExc)
777  {
778  if (!pExc->Pos.getLength())
779  LogF("ERROR: %s (in %s)", pExc->Msg.getData(), szName);
780  else
781  LogF("ERROR: %s (in %s, %s)", pExc->Msg.getData(), pExc->Pos.getData(), szName);
782  delete pExc;
783  return false;
784  }
785 }
const char * getData() const
Definition: StdBuf.h:450
void StdCompilerWarnCallback(void *pData, const char *szPosition, const char *szError)
size_t getLength() const
Definition: StdBuf.h:453
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

Here is the call graph for this function:

template<class CompT , class StructT >
StructT* CompileFromBufToNew ( const typename CompT::InT &  SrcBuf)

Definition at line 396 of file StdCompiler.h.

References mkPtrAdaptNoNull().

397 {
398  StructT *pStruct = nullptr;
399  CompileFromBuf<CompT>(mkPtrAdaptNoNull(pStruct), SrcBuf);
400  return pStruct;
401 }
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
Definition: StdAdaptors.h:604

Here is the call graph for this function:

template<class CompT , class StructT >
StructT* CompileFromBufToNewNamed ( const typename CompT::InT &  SrcBuf,
const char *  szName 
)

Definition at line 403 of file StdCompiler.h.

References mkNamingAdapt(), and mkPtrAdaptNoNull().

404 {
405  StructT *pStruct = nullptr;
406  CompileFromBuf<CompT>(mkNamingAdapt(mkPtrAdaptNoNull(pStruct), szName), SrcBuf);
407  return pStruct;
408 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
Definition: StdAdaptors.h:604

Here is the call graph for this function:

template<class T >
void CompileFunc ( T &  rStruct,
StdCompiler pComp 
)
inline

Definition at line 311 of file StdCompiler.h.

Referenced by StdCompiler::Value().

312 {
313  // If the compiler doesn't like this line, you tried to compile
314  // something the compiler doesn't know how to handle.
315  // Possible reasons:
316  // a) You are compiling a class/structure without a CompileFunc
317  // (you may add a specialization of this function, too)
318  // b) You are trying to compile a pointer. Use a PtrAdapt instead.
319  // c) You are trying to compile a simple value that has no
320  // fixed representation (float, int). Use safe types instead.
321  rStruct.CompileFunc(pComp);
322 }

Here is the caller graph for this function:

void CompileFunc ( std::string &  s,
StdCompiler comp 
)
inline

Definition at line 324 of file StdCompiler.h.

References StdCompiler::String().

325 {
326  comp->String(s);
327 }
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0
#define s

Here is the call graph for this function:

template<class T >
void CompileNewFunc ( T *&  pStruct,
StdCompiler pComp 
)

Definition at line 330 of file StdCompiler.h.

References StdCompiler::Value().

Referenced by StdPtrAdaptCompileNewFunc().

331 {
332  // Create new object.
333  // If this line doesn't compile, you either have to
334  // a) Define a standard constructor for T
335  // b) Specialize this function to do whatever the correct
336  // behaviour is to construct the object from compiler data
337  std::unique_ptr<T> temp(new T); // exception-safety
338  // Compile
339  pComp->Value(*temp);
340  pStruct = temp.release();
341 }
void Value(const T &rStruct)
Definition: StdCompiler.h:171

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T , typename... P>
void CompileNewFunc ( T *&  pStruct,
StdCompiler pComp,
P &&...  pars 
)

Definition at line 344 of file StdCompiler.h.

References mkParAdapt(), and StdCompiler::Value().

345 {
346  // Create new object.
347  // If this line doesn't compile, you either have to
348  // a) Define a standard constructor for T
349  // b) Specialize this function to do whatever the correct
350  // behaviour is to construct the object from compiler data
351  std::unique_ptr<T> temp(new T); // exception-safety
352  // Compile
353  pComp->Value(mkParAdapt(*temp, std::forward<P>(pars)...));
354  pStruct = temp.release();
355 }
void Value(const T &rStruct)
Definition: StdCompiler.h:171
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:456

Here is the call graph for this function:

template<class T , class ContextT >
void CompileNewFuncCtx ( T *&  pStruct,
StdCompiler pComp,
const ContextT &  rCtx 
)

Definition at line 358 of file StdCompiler.h.

References StdCompiler::Value().

Referenced by StdPtrAdaptCompileNewFunc().

359 {
360  // Create new object.
361  // If this line doesn't compile, you either have to
362  // a) Define an appropriate constructor for T
363  // b) Specialize this function to do whatever the correct
364  // behaviour is to construct the object from compiler data
365  // and context
366  std::unique_ptr<T> temp(new T(rCtx)); // exception-safety
367  // Compile
368  pComp->Value(*temp);
369  pStruct = temp.release();
370 }
void Value(const T &rStruct)
Definition: StdCompiler.h:171

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T , class ContextT , class P >
void CompileNewFuncCtx ( T *&  pStruct,
StdCompiler pComp,
const ContextT &  rCtx,
const P &  rPar 
)

Definition at line 373 of file StdCompiler.h.

References mkParAdapt(), and StdCompiler::Value().

374 {
375  // Create new object.
376  // If this line doesn't compile, you either have to
377  // a) Define an appropriate constructor for T
378  // b) Specialize this function to do whatever the correct
379  // behaviour is to construct the object from compiler data
380  // and context
381  std::unique_ptr<T> temp(new T(rCtx)); // exception-safety
382  // Compile
383  pComp->Value(mkParAdapt(*temp, rPar));
384  pStruct = temp.release();
385 }
void Value(const T &rStruct)
Definition: StdCompiler.h:171
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:456

Here is the call graph for this function:

template<class CompT , class StructT >
CompT::OutT DecompileToBuf ( const StructT &  SrcStruct)

Definition at line 410 of file StdCompiler.h.

411 {
412  CompT Compiler;
413  Compiler.Decompile(SrcStruct);
414  return Compiler.getOutput();
415 }
template<class CompT , class StructT >
bool DecompileToBuf_Log ( StructT &&  TargetStruct,
typename CompT::OutT *  pOut,
const char *  szName 
)

Definition at line 787 of file StdCompiler.h.

References StdStrBuf::getData(), LogF(), and StdCompiler::Exception::Msg.

788 {
789  if (!pOut) return false;
790  try
791  {
792  pOut->Take(DecompileToBuf<CompT>(TargetStruct));
793  return true;
794  }
795  catch (StdCompiler::Exception *pExc)
796  {
797  LogF("ERROR: %s (in %s)", pExc->Msg.getData(), szName);
798  delete pExc;
799  return false;
800  }
801 }
const char * getData() const
Definition: StdBuf.h:450
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

Here is the call graph for this function:

void StdCompilerWarnCallback ( void *  pData,
const char *  szPosition,
const char *  szError 
)

Definition at line 1038 of file StdCompiler.cpp.

References DebugLogF().

Referenced by CompileFromBuf_LogWarn().

1039 {
1040  const char *szName = reinterpret_cast<const char *>(pData);
1041  if (!szPosition || !*szPosition)
1042  DebugLogF("WARNING: %s (in %s)", szError, szName);
1043  else
1044  DebugLogF("WARNING: %s (in %s, %s)", szError, szPosition, szName);
1045 }
bool DebugLogF(const char *strMessage...)
Definition: C4Log.cpp:281

Here is the call graph for this function:

Here is the caller graph for this function: