malloc deref pointer to struct syntax, minor formatting changes
This commit is contained in:
parent
59eecf37bf
commit
d865074892
2
debug.c
2
debug.c
|
@ -57,7 +57,7 @@ void DebugSetBreakpoint(struct ParseState *Parser)
|
|||
|
||||
if (FoundEntry == NULL) {
|
||||
/* add it to the table */
|
||||
struct TableEntry *NewEntry = HeapAllocMem(pc, sizeof(struct TableEntry));
|
||||
struct TableEntry *NewEntry = HeapAllocMem(pc, sizeof(*NewEntry));
|
||||
if (NewEntry == NULL)
|
||||
ProgramFailNoParser(pc, "(DebugSetBreakpoint) out of memory");
|
||||
|
||||
|
|
12
expression.c
12
expression.c
|
@ -330,7 +330,7 @@ void ExpressionStackPushValueNode(struct ParseState *Parser,
|
|||
struct ExpressionStack **StackTop, struct Value *ValueLoc)
|
||||
{
|
||||
struct ExpressionStack *StackNode = VariableAlloc(Parser->pc, Parser,
|
||||
sizeof(struct ExpressionStack), false);
|
||||
sizeof(*StackNode), false);
|
||||
StackNode->Next = *StackTop;
|
||||
StackNode->Val = ValueLoc;
|
||||
*StackTop = StackNode;
|
||||
|
@ -628,11 +628,9 @@ void ExpressionPrefixOperator(struct ParseState *Parser,
|
|||
Result->Val->Pointer = (void *)ValPtr;
|
||||
ExpressionStackPushValueNode(Parser, StackTop, Result);
|
||||
break;
|
||||
|
||||
case TokenAsterisk:
|
||||
ExpressionStackPushDereference(Parser, StackTop, TopValue);
|
||||
break;
|
||||
|
||||
case TokenSizeof:
|
||||
/* return the size of the argument */
|
||||
if (TopValue->Typ == &Parser->pc->TypeType)
|
||||
|
@ -642,7 +640,6 @@ void ExpressionPrefixOperator(struct ParseState *Parser,
|
|||
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Typ,
|
||||
TopValue->Typ->ArraySize, true));
|
||||
break;
|
||||
|
||||
default:
|
||||
/* an arithmetic operator */
|
||||
if (TopValue->Typ == &Parser->pc->FPType) {
|
||||
|
@ -669,7 +666,6 @@ void ExpressionPrefixOperator(struct ParseState *Parser,
|
|||
ProgramFail(Parser, "invalid operation");
|
||||
break;
|
||||
}
|
||||
|
||||
ExpressionPushFP(Parser, StackTop, ResultFP);
|
||||
} else if (IS_NUMERIC_COERCIBLE(TopValue)) {
|
||||
/* integer prefix arithmetic */
|
||||
|
@ -700,7 +696,6 @@ void ExpressionPrefixOperator(struct ParseState *Parser,
|
|||
ProgramFail(Parser, "invalid operation");
|
||||
break;
|
||||
}
|
||||
|
||||
ExpressionPushInt(Parser, StackTop, ResultInt);
|
||||
} else if (TopValue->Typ->Base == TypePointer) {
|
||||
/* pointer prefix arithmetic */
|
||||
|
@ -761,7 +756,6 @@ void ExpressionPostfixOperator(struct ParseState *Parser,
|
|||
ProgramFail(Parser, "invalid operation");
|
||||
break;
|
||||
}
|
||||
|
||||
ExpressionPushFP(Parser, StackTop, ResultFP);
|
||||
}
|
||||
else if (IS_NUMERIC_COERCIBLE(TopValue)) {
|
||||
|
@ -784,7 +778,6 @@ void ExpressionPostfixOperator(struct ParseState *Parser,
|
|||
ProgramFail(Parser, "invalid operation");
|
||||
break;
|
||||
}
|
||||
|
||||
ExpressionPushInt(Parser, StackTop, ResultInt);
|
||||
} else if (TopValue->Typ->Base == TypePointer) {
|
||||
/* pointer postfix arithmetic */
|
||||
|
@ -809,7 +802,6 @@ void ExpressionPostfixOperator(struct ParseState *Parser,
|
|||
ProgramFail(Parser, "invalid operation");
|
||||
break;
|
||||
}
|
||||
|
||||
StackValue = ExpressionStackPushValueByType(Parser, StackTop,
|
||||
TopValue->Typ);
|
||||
StackValue->Val->Pointer = OrigPointer;
|
||||
|
@ -1272,7 +1264,7 @@ void ExpressionStackPushOperator(struct ParseState *Parser,
|
|||
enum LexToken Token, int Precedence)
|
||||
{
|
||||
struct ExpressionStack *StackNode = VariableAlloc(Parser->pc, Parser,
|
||||
sizeof(struct ExpressionStack), false);
|
||||
sizeof(*StackNode), false);
|
||||
StackNode->Next = *StackTop;
|
||||
StackNode->Order = Order;
|
||||
StackNode->Op = Token;
|
||||
|
|
2
lex.c
2
lex.c
|
@ -567,7 +567,7 @@ enum LexToken LexScanGetToken(Picoc *pc, struct LexState *Lexer,
|
|||
int LexTokenSize(enum LexToken Token)
|
||||
{
|
||||
switch (Token) {
|
||||
case TokenIdentifier: case TokenStringConstant: return sizeof(char *);
|
||||
case TokenIdentifier: case TokenStringConstant: return sizeof(char*);
|
||||
case TokenIntegerConstant: return sizeof(long);
|
||||
case TokenCharacterConstant: return sizeof(unsigned char);
|
||||
case TokenFPConstant: return sizeof(double);
|
||||
|
|
4
parse.c
4
parse.c
|
@ -385,7 +385,7 @@ void ParseMacroDefinition(struct ParseState *Parser)
|
|||
ParserCopy(&ParamParser, Parser);
|
||||
NumParams = ParseCountParams(&ParamParser);
|
||||
MacroValue = VariableAllocValueAndData(Parser->pc, Parser,
|
||||
sizeof(struct MacroDef) + sizeof(const char *) * NumParams,
|
||||
sizeof(struct MacroDef) + sizeof(const char*) * NumParams,
|
||||
false, NULL, true);
|
||||
MacroValue->Val->MacroDef.NumParams = NumParams;
|
||||
MacroValue->Val->MacroDef.ParamName = (char**)((char*)MacroValue->Val+sizeof(struct MacroDef));
|
||||
|
@ -430,7 +430,7 @@ void ParseMacroDefinition(struct ParseState *Parser)
|
|||
/* copy the entire parser state */
|
||||
void ParserCopy(struct ParseState *To, struct ParseState *From)
|
||||
{
|
||||
memcpy((void *)To, (void *)From, sizeof(*To));
|
||||
memcpy((void*)To, (void*)From, sizeof(*To));
|
||||
}
|
||||
|
||||
/* copy where we're at in the parsing */
|
||||
|
|
|
@ -17,7 +17,7 @@ struct Node *head = NULL;
|
|||
struct Node *tail = NULL;
|
||||
|
||||
void enqueue_tail(int d) {
|
||||
struct Node *new_node = malloc(sizeof(new_node));
|
||||
struct Node *new_node = malloc(sizeof(*new_node));
|
||||
|
||||
new_node->data = d;
|
||||
new_node->next = tail;
|
||||
|
@ -35,7 +35,7 @@ void enqueue_tail(int d) {
|
|||
}
|
||||
|
||||
void enqueue_head(int d) {
|
||||
struct Node *new_node = malloc(sizeof(new_node));
|
||||
struct Node *new_node = malloc(sizeof(*new_node));
|
||||
|
||||
new_node->data = d;
|
||||
new_node->next = NULL;
|
||||
|
|
Loading…
Reference in a new issue