本文整理汇总了C++中ProgramFail函数的典型用法代码示例。如果您正苦于以下问题:C++ ProgramFail函数的具体用法?C++ ProgramFail怎么用?C++ ProgramFail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ProgramFail函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseBlock
/* parse a block of code and return what mode it returned in */
enum RunMode ParseBlock(struct ParseState *Parser, int AbsorbOpenBrace, int Condition)
{
if (AbsorbOpenBrace && LexGetToken(Parser, NULL, TRUE) != TokenLeftBrace)
ProgramFail(Parser, "'{' expected");
if (Parser->Mode == RunModeSkip || !Condition)
{
/* condition failed - skip this block instead */
enum RunMode OldMode = Parser->Mode;
Parser->Mode = RunModeSkip;
while (ParseStatement(Parser, TRUE) == ParseResultOk)
{}
Parser->Mode = OldMode;
}
else
{
/* just run it in its current mode */
while (ParseStatement(Parser, TRUE) == ParseResultOk)
{}
}
if (LexGetToken(Parser, NULL, TRUE) != TokenRightBrace)
ProgramFail(Parser, "'}' expected");
return Parser->Mode;
}
示例2: StdioBaseScanf
/* internal do-anything v[s][n]scanf() formatting system with input from strings or FILE * */
int StdioBaseScanf(struct ParseState *Parser, FILE *Stream, char *StrIn, char *Format, struct StdVararg *Args)
{
struct Value *ThisArg = Args->Param[0];
int ArgCount = 0;
void *ScanfArg[MAX_SCANF_ARGS];
if (Args->NumArgs > MAX_SCANF_ARGS)
ProgramFail(Parser, "too many arguments to scanf() - %d max", MAX_SCANF_ARGS);
for (ArgCount = 0; ArgCount < Args->NumArgs; ArgCount++)
{
ThisArg = (struct Value *)((char *)ThisArg + MEM_ALIGN(sizeof(struct Value) + TypeStackSizeValue(ThisArg)));
if (ThisArg->Typ->Base == TypePointer)
ScanfArg[ArgCount] = ThisArg->Val->Pointer;
else if (ThisArg->Typ->Base == TypeArray)
ScanfArg[ArgCount] = &ThisArg->Val->ArrayMem[0];
else
ProgramFail(Parser, "non-pointer argument to scanf() - argument %d after format", ArgCount+1);
}
if (Stream != NULL)
return fscanf(Stream, Format, ScanfArg[0], ScanfArg[1], ScanfArg[2], ScanfArg[3], ScanfArg[4], ScanfArg[5], ScanfArg[6], ScanfArg[7], ScanfArg[8], ScanfArg[9]);
else
return sscanf(StrIn, Format, ScanfArg[0], ScanfArg[1], ScanfArg[2], ScanfArg[3], ScanfArg[4], ScanfArg[5], ScanfArg[6], ScanfArg[7], ScanfArg[8], ScanfArg[9]);
}
示例3: ProgramFail
/* read a file into memory */
char *PlatformReadFile(const char *FileName)
{
struct stat FileInfo;
char *ReadText;
FILE *InFile;
int BytesRead;
if (stat(FileName, &FileInfo))
ProgramFail(NULL, "can't read file %s\n", FileName);
ReadText = malloc(FileInfo.st_size + 1);
if (ReadText == NULL)
ProgramFail(NULL, "out of memory\n");
InFile = fopen(FileName, "r");
if (InFile == NULL)
ProgramFail(NULL, "can't read file %s\n", FileName);
BytesRead = fread(ReadText, 1, FileInfo.st_size, InFile);
if (BytesRead == 0)
ProgramFail(NULL, "can't read file %s\n", FileName);
ReadText[BytesRead] = '\0';
fclose(InFile);
return ReadText;
}
示例4: ParseDeclarationAssignment
/* assign an initial value to a variable */
void ParseDeclarationAssignment(struct ParseState *Parser, struct Value *NewVariable, int DoAssignment)
{
struct Value *CValue;
int ArrayIndex;
enum LexToken Token = TokenComma;
if (LexGetToken(Parser, NULL, FALSE) == TokenLeftBrace)
{
/* this is an array initialiser */
LexGetToken(Parser, NULL, TRUE);
for (ArrayIndex = 0; (Parser->Mode != RunModeRun && Token == TokenComma) || (Parser->Mode == RunModeRun && ArrayIndex < NewVariable->Typ->ArraySize); ArrayIndex++)
{
struct Value *ArrayElement = NULL;
if (Token != TokenComma)
ProgramFail(Parser, "comma expected");
if (Parser->Mode == RunModeRun)
ArrayElement = VariableAllocValueFromExistingData(Parser, NewVariable->Typ->FromType, (union AnyValue *)(&NewVariable->Val->ArrayMem[0] + TypeSize(NewVariable->Typ->FromType, 0, TRUE) * ArrayIndex), TRUE, NewVariable);
if (!ExpressionParse(Parser, &CValue))
ProgramFail(Parser, "expression expected");
if (Parser->Mode == RunModeRun && DoAssignment)
{
ExpressionAssign(Parser, ArrayElement, CValue, FALSE, NULL, 0, FALSE);
VariableStackPop(Parser, CValue);
VariableStackPop(Parser, ArrayElement);
}
Token = LexGetToken(Parser, NULL, TRUE);
}
if (Token == TokenComma)
Token = LexGetToken(Parser, NULL, TRUE);
if (Token != TokenRightBrace)
ProgramFail(Parser, "'}' expected");
}
else
{
/* this is a normal expression initialiser */
if (!ExpressionParse(Parser, &CValue))
ProgramFail(Parser, "expression expected");
if (Parser->Mode == RunModeRun && DoAssignment)
{
ExpressionAssign(Parser, NewVariable, CValue, FALSE, NULL, 0, FALSE);
VariableStackPop(Parser, CValue);
}
}
}
示例5: TypeParseIdentPart
/* parse a type - the part which is repeated with each identifier in a declaration list */
void TypeParseIdentPart(struct ParseState *Parser, struct ValueType *BasicTyp, struct ValueType **Typ, char **Identifier)
{
struct ParseState Before;
enum LexToken Token;
struct Value *LexValue;
int Done = FALSE;
*Typ = BasicTyp;
*Identifier = StrEmpty;
while (!Done)
{
ParserCopy(&Before, Parser);
Token = LexGetToken(Parser, &LexValue, TRUE);
switch (Token)
{
case TokenOpenBracket:
if (*Typ != NULL)
ProgramFail(Parser, "bad type declaration");
TypeParse(Parser, Typ, Identifier, NULL);
if (LexGetToken(Parser, NULL, TRUE) != TokenCloseBracket)
ProgramFail(Parser, "')' expected");
break;
case TokenAsterisk:
if (*Typ == NULL)
ProgramFail(Parser, "bad type declaration");
*Typ = TypeGetMatching(Parser, *Typ, TypePointer, 0, StrEmpty, TRUE);
break;
case TokenIdentifier:
if (*Typ == NULL || *Identifier != StrEmpty)
ProgramFail(Parser, "bad type declaration");
*Identifier = LexValue->Val->Identifier;
Done = TRUE;
break;
default: ParserCopy(Parser, &Before); Done = TRUE; break;
}
}
if (*Typ == NULL)
ProgramFail(Parser, "bad type declaration");
if (*Identifier != StrEmpty)
{
/* parse stuff after the identifier */
*Typ = TypeParseBack(Parser, *Typ);
}
}
示例6: ParseDeclaration
/* declare a variable or function */
int ParseDeclaration(struct ParseState *Parser, enum LexToken Token)
{
char *Identifier;
struct ValueType *BasicType;
struct ValueType *Typ;
struct Value *NewVariable = NULL;
int IsStatic = FALSE;
int FirstVisit = FALSE;
Picoc *pc = Parser->pc;
TypeParseFront(Parser, &BasicType, &IsStatic);
do
{
TypeParseIdentPart(Parser, BasicType, &Typ, &Identifier);
if ((Token != TokenVoidType && Token != TokenStructType && Token != TokenUnionType && Token != TokenEnumType) && Identifier == pc->StrEmpty)
ProgramFail(Parser, "identifier expected");
if (Identifier != pc->StrEmpty)
{
/* handle function definitions */
if (LexGetToken(Parser, NULL, FALSE) == TokenOpenBracket)
{
ParseFunctionDefinition(Parser, Typ, Identifier);
return FALSE;
}
else
{
if (Typ == &pc->VoidType && Identifier != pc->StrEmpty)
ProgramFail(Parser, "can't define a void variable");
if (Parser->Mode == RunModeRun || Parser->Mode == RunModeGoto)
NewVariable = VariableDefineButIgnoreIdentical(Parser, Identifier, Typ, IsStatic, &FirstVisit);
if (LexGetToken(Parser, NULL, FALSE) == TokenAssign)
{
/* we're assigning an initial value */
LexGetToken(Parser, NULL, TRUE);
ParseDeclarationAssignment(Parser, NewVariable, !IsStatic || FirstVisit);
}
}
}
Token = LexGetToken(Parser, NULL, FALSE);
if (Token == TokenComma)
LexGetToken(Parser, NULL, TRUE);
} while (Token == TokenComma);
return TRUE;
}
示例7: ParserCopy
/* parse a type - the part at the end after the identifier. eg. array specifications etc. */
struct ValueType *TypeParseBack(struct ParseState *Parser, struct ValueType *FromType)
{
enum LexToken Token;
struct ParseState Before;
ParserCopy(&Before, Parser);
Token = LexGetToken(Parser, NULL, TRUE);
if (Token == TokenLeftSquareBracket)
{
/* add another array bound */
enum RunMode OldMode = Parser->Mode;
int ArraySize;
Parser->Mode = RunModeRun;
ArraySize = ExpressionParseInt(Parser);
Parser->Mode = OldMode;
if (LexGetToken(Parser, NULL, TRUE) != TokenRightSquareBracket)
ProgramFail(Parser, "']' expected");
return TypeGetMatching(Parser, TypeParseBack(Parser, FromType), TypeArray, ArraySize, StrEmpty, TRUE);
}
else
{
/* the type specification has finished */
ParserCopy(Parser, &Before);
return FromType;
}
}
示例8: while
/* given a parent type, get a matching derived type and make one if necessary.
* Identifier should be registered with the shared string table. */
struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *ParentType, enum BaseType Base, int ArraySize, const char *Identifier, int AllowDuplicates)
{
int Sizeof;
int AlignBytes;
struct ValueType *ThisType = ParentType->DerivedTypeList;
while (ThisType != NULL && (ThisType->Base != Base || ThisType->ArraySize != ArraySize || ThisType->Identifier != Identifier))
ThisType = ThisType->Next;
if (ThisType != NULL)
{
if (AllowDuplicates)
return ThisType;
else
ProgramFail(Parser, "tipo de dato '%s' ya existe", Identifier);
}
switch (Base)
{
case TypePointer: Sizeof = sizeof(void *); AlignBytes = PointerAlignBytes; break;
case TypeArray: Sizeof = ArraySize * ParentType->Sizeof; AlignBytes = ParentType->AlignBytes; break;
case TypeEnum: Sizeof = sizeof(int); AlignBytes = IntAlignBytes; break;
default: Sizeof = 0; AlignBytes = 0; break; /* structs and unions will get bigger when we add members to them */
}
return TypeAdd(Parser, ParentType, Base, ArraySize, Identifier, Sizeof, AlignBytes);
}
示例9: TypeParseEnum
/* parse an enum declaration */
void TypeParseEnum(struct ParseState *Parser, struct ValueType **Typ){
struct Value *LexValue;
struct Value InitValue;
enum LexToken Token;
int EnumValue = 0;
char *EnumIdentifier;
Picoc *pc = Parser->pc;
Token = LexGetToken(Parser, &LexValue, FALSE);
if (Token == TokenIdentifier){
LexGetToken(Parser, &LexValue, TRUE);
EnumIdentifier = LexValue->Val->Identifier;
Token = LexGetToken(Parser, NULL, FALSE);
}
else{
static char TempNameBuf[7] = "^e0000";
EnumIdentifier = PlatformMakeTempName(pc, TempNameBuf);
}
TypeGetMatching(pc, Parser, &pc->UberType, TypeEnum, 0, EnumIdentifier, Token != TokenLeftBrace);
*Typ = &pc->IntType;
if (Token != TokenLeftBrace){
/* use the already defined enum */
if ((*Typ)->Members == NULL)
ProgramFail(Parser, "enum '%s' isn't defined", EnumIdentifier);
return;
}
if (pc->TopStackFrame != NULL) ProgramFail(Parser, "enum definitions can only be globals");
LexGetToken(Parser, NULL, TRUE);
(*Typ)->Members = &pc->GlobalTable;
memset((void *)&InitValue, '\0', sizeof(struct Value));
InitValue.Typ = &pc->IntType;
InitValue.Val = (union AnyValue *)&EnumValue;
do {
if (LexGetToken(Parser, &LexValue, TRUE) != TokenIdentifier)
ProgramFail(Parser, "identifier expected");
EnumIdentifier = LexValue->Val->Identifier;
if (LexGetToken(Parser, NULL, FALSE) == TokenAssign){
LexGetToken(Parser, NULL, TRUE);
EnumValue = ExpressionParseInt(Parser);
}
VariableDefine(pc, Parser, EnumIdentifier, &InitValue, NULL, FALSE);
Token = LexGetToken(Parser, NULL, TRUE);
if (Token != TokenComma && Token != TokenRightBrace)
ProgramFail(Parser, "comma expected");
EnumValue++;
} while (Token == TokenComma);
}
示例10: VariableGet
/* get the value of a variable. must be defined. Ident must be registered */
void VariableGet(struct ParseState *Parser, const char *Ident, struct Value **LVal)
{
if (TopStackFrame == NULL || !TableGet(&TopStackFrame->LocalTable, Ident, LVal, NULL, NULL, NULL))
{
if (!TableGet(&GlobalTable, Ident, LVal, NULL, NULL, NULL))
ProgramFail(Parser, "'%s' is undefined", Ident);
}
}
示例11: LexHashEndif
/* handle a #endif directive */
void LexHashEndif(struct ParseState *Parser)
{
if (Parser->HashIfLevel == 0)
ProgramFail(Parser, "#endif without #if");
Parser->HashIfLevel--;
if (Parser->HashIfEvaluateToLevel > Parser->HashIfLevel)
Parser->HashIfEvaluateToLevel = Parser->HashIfLevel;
}
示例12: VariableStackFramePop
/* remove a stack frame */
void VariableStackFramePop(struct ParseState *Parser)
{
if (TopStackFrame == NULL)
ProgramFail(Parser, "stack is empty - can't go back");
ParserCopy(Parser, &TopStackFrame->ReturnParser);
TopStackFrame = TopStackFrame->PreviousStackFrame;
HeapPopStackFrame();
}
示例13: VariableDefinePlatformVar
/* define a global variable shared with a platform global. Ident will be registered */
void VariableDefinePlatformVar(struct ParseState *Parser, char *Ident, struct ValueType *Typ, union AnyValue *FromValue, int IsWritable)
{
struct Value *SomeValue = VariableAllocValueAndData(NULL, 0, IsWritable, NULL, TRUE);
SomeValue->Typ = Typ;
SomeValue->Val = FromValue;
if (!TableSet((TopStackFrame == NULL) ? &GlobalTable : &TopStackFrame->LocalTable, TableStrRegister(Ident), SomeValue, Parser ? Parser->FileName : NULL, Parser ? Parser->Line : 0, Parser ? Parser->CharacterPos : 0))
ProgramFail(Parser, "'%s' is already defined", Ident);
}
示例14: PicocParse
/* quick scan a source file for definitions */
void PicocParse(const char *FileName, const char *Source, int SourceLen, int RunIt, int CleanupNow, int CleanupSource, int EnableDebugger)
{
struct ParseState Parser;
enum ParseResult Ok;
struct CleanupTokenNode *NewCleanupNode;
char *RegFileName = TableStrRegister(FileName);
void *Tokens = LexAnalyse(RegFileName, Source, SourceLen, NULL);
/* allocate a cleanup node so we can clean up the tokens later */
if (!CleanupNow)
{
NewCleanupNode = HeapAllocMem(sizeof(struct CleanupTokenNode));
if (NewCleanupNode == NULL)
ProgramFail(NULL, "out of memory");
NewCleanupNode->Tokens = Tokens;
if (CleanupSource)
NewCleanupNode->SourceText = Source;
else
NewCleanupNode->SourceText = NULL;
NewCleanupNode->Next = CleanupTokenList;
CleanupTokenList = NewCleanupNode;
}
/* do the parsing */
LexInitParser(&Parser, Source, Tokens, RegFileName, RunIt, EnableDebugger);
do {
Ok = ParseStatement(&Parser, TRUE);
} while (Ok == ParseResultOk);
if (Ok == ParseResultError)
ProgramFail(&Parser, "parse error");
/* clean up */
if (CleanupNow)
HeapFreeMem(Tokens);
}
示例15: LexHashElse
/* handle a #else directive */
void LexHashElse(struct ParseState *Parser)
{
if (Parser->HashIfEvaluateToLevel == Parser->HashIfLevel - 1)
Parser->HashIfEvaluateToLevel++; /* #if was not active, make this next section active */
else if (Parser->HashIfEvaluateToLevel == Parser->HashIfLevel)
{
/* #if was active, now go inactive */
if (Parser->HashIfLevel == 0)
ProgramFail(Parser, "#else without #if");
Parser->HashIfEvaluateToLevel--;
}
}