CodeGenerator::BlockType CodeGenerator::ProcessBlock(int flags) { infunc(CodeGenerator::ProcessBlock); // Check for a mandatory opening block if (!(flags & FLAGS_ALLOW_LINE_BLOCKS) && ((flags & FLAGS_IN_STATE) || (flags & FLAGS_IN_CLASS) || (flags & FLAGS_IN_FUNCTION))) if (CUR_TOKEN.type != TOKEN_BLOCK_OPEN) throw CompileError("(Line %d) Expecting an opening block", CUR_TOKEN.line); // Reduce the lifetime flags &= ~FLAGS_ALLOW_LINE_BLOCKS; // Determine how to read the block if (CUR_TOKEN.type == TOKEN_BLOCK_OPEN) { INC_TOKEN; while (1) { // Break if the end of the block has been reached if (CUR_TOKEN.type == TOKEN_BLOCK_CLOSE) break; ProcessStatement(flags); } return (BT_SCOPED); } else { ProcessStatement(flags | FLAGS_IGNORE_END_TOKEN); } return (BT_STATEMENT); outfunc; }
unsigned long WharfSpecialFunc (ConfigDef * config) { TermDef *pterm; register char *cur; LOCAL_DEBUG_CALLER_OUT ("%p", config); if (config == NULL) return SPECIAL_BREAK; /* checking if we have ~Folders in here */ LOCAL_DEBUG_OUT ("checking for ~folders at :%s", ""); print_trimmed_str ("config->tdata", config->tdata); print_trimmed_str ("config->tline", config->tline); print_trimmed_str ("config->cursor", config->cursor); if ((pterm = FindStatementTerm (config->tdata, &WharfSyntax)) == NULL) if (mystrncasecmp (config->tdata, "~Folders", 7) == 0) { show_error (" config line %d: ~Folders keyword is no longer supported. \nPlease Update your configuration to use ~Folder instead!\n Please Accept our apologies for any inconvinience.", config->line_count); pterm = FindStatementTerm (WHARF_FOLDER_END, &WharfSyntax); } if (pterm != NULL) { LOCAL_DEBUG_OUT ("term %p found keyword :[%s]", pterm, pterm->keyword); if (pterm->id == WHARF_FolderEnd_ID) { config->current_term = pterm; /* we are 2 levels deep, and FolderEnd will get us only 1 level up so we need to climb another level ourselves : */ LOCAL_DEBUG_OUT ("folder end - Poping out%s", ""); PopSyntax (config); PopStorage (config); return SPECIAL_SKIP; /* don't care what will happen */ } } /* processing wharf item name and icons : */ ProcessStatement (config); /* since we have have subconfig of Functions that has \n as line terminator * we are going to get entire line again at config->cursor * so lets skip 3 tokens of <name> <icon>, since those are not parts * of following function */ print_trimmed_str ("skiping 2 tokens at", config->tdata); cur = tokenskip (config->tdata, 2); print_trimmed_str ("skipped to", cur); if (*cur != '\0') { char *good_cursor; TermDef *pterm; good_cursor = config->cursor; config->cursor = cur; /* we are at the beginning of the function definition right now - lets process it : */ /* read in entire function definition */ GetNextStatement (config); /* lets find us the term for this definition */ print_trimmed_str ("config->current_data", config->current_data); LOCAL_DEBUG_OUT ("curr_data_len = %d", config->current_data_len); print_trimmed_str ("checking keyword at", config->tline); if ((pterm = FindStatementTerm (config->tline, config->syntax)) == NULL) { /* courtesy check for mistyped Folder keyword : */ if (mystrncasecmp (config->tline, "Folders", 7) == 0) { show_error (" config line %d: Folders keyword is no longer supported. \nPlease Update your configuration to use Folder instead!\n Please Accept our apologies for any inconvinience.", config->line_count); pterm = FindStatementTerm ("Folder", config->syntax); } } if (pterm == NULL) { /* we are 2 levels deep, and FolderEnd will get us only 1 level up so we need to climb another level ourselves : */ PopSyntax (config); PopStorage (config); } else { /* we have a valid function definition : */ config->current_term = pterm; /* we do not want to continue processing the rest of the config as * a functions : */ config->current_flags |= CF_LAST_OPTION; /* some wierd code to handle the fact that Folder is not really a function, * but instead a start for new nested set of Wharf items : */ LOCAL_DEBUG_OUT ("processing function definition statement...%s", ""); ProcessStatement (config); if (config->current_term->id == F_Folder) { /* in which case we let parser to carry on the parsing of the Folder item, * which will get us into nested WharfSyntax subsyntax */ config->current_flags &= ~CF_LAST_OPTION; } } /* restarting parsing from the same location : */ if (config->cursor < good_cursor) config->cursor = good_cursor; LOCAL_DEBUG_OUT ("done processing function definition statement...%s", ""); } else { show_error (" config line %d: Function is not defined for the button. Use Nop if no action is desired..", config->line_count); /* function is ommited ! */ PopSyntax (config); PopStorage (config); } print_trimmed_str ("config->tdata", config->tdata); print_trimmed_str ("config->tline", config->tline); print_trimmed_str ("config->cursor", config->cursor); /* already done processing current statement - let parser know about it : */ return SPECIAL_SKIP; }
void Parser::ProcessNextToken(int token, const char *text) { //printf(" * Loop %s [%s]\n", get_token_name(ID_FROM_TOKEN(token)), text); switch(token) { case T_LEFTBRACE: { mBraceDepth++; FlushDerived(); ClearFlag(FLAG_UNOPENED); break; } case T_COMMA: { FlushDerived(); break; } case T_COLON_COLON: { SetFlag(FLAG_COLON_COLON); break; } case T_FRIEND: { SetFlag(FLAG_FRIEND); break; } case T_ENUM: { SetFlag(FLAG_ENUM|FLAG_UNOPENED); break; } case T_MM_IGNORE_START: { mIgnore = 1; break; } case T_MM_IGNORE_END: { mIgnore = 0; break; } case T_RIGHTBRACE: { mBraceDepth--; if(!IsSet(FLAG_ENUM)) { PopScope(); ProcessStatement(); } break; } case T_CLASS: case T_STRUCT: case T_NAMESPACE: { Scope *pScope = new Scope; pScope->braceDepth = mBraceDepth; pScope->isClass = (token != T_NAMESPACE); pScope->mpName = NULL; pScope->isExposed = IsSet(FLAG_NEXT_IS_EXPOSED); mScopes.push_back(pScope); SetFlag(pScope->isClass ? FLAG_CLASS|FLAG_UNOPENED : FLAG_NAMESPACE); ClearFlag(FLAG_NEXT_IS_EXPOSED); break; } case T_BOOL: case T_CHAR: case T_DOUBLE: case T_FLOAT: case T_INT: case T_LONG: case T_SHORT: case T_VOID: case T_WCHART: { Identifier *pIdentifier = new Identifier; pIdentifier->mpName = strdup(text); pIdentifier->isKeyword = true; if(IsSet(FLAG_NEXT_IS_CONST)) { pIdentifier->isConst = true; ClearFlag(FLAG_NEXT_IS_CONST); } mIdentifiers.push_back(pIdentifier); break; } case T_IDENTIFIER: { if(IsSet(FLAG_NAMESPACE|FLAG_CLASS)) { int size = mScopes.size(); if(size > 0) { Scope *pScope = mScopes[size-1]; pScope->mpName = strdup(text); if(IsSet(FLAG_CLASS)) { if(IsExposed()) { mpGenerator->AddClass(text); //(GetFullScopeName()); } } ClearFlag(FLAG_NAMESPACE|FLAG_CLASS); } } else if(IsExposed()) { if(!IsSet(FLAG_PAREN)) { if(IsSet(FLAG_COLON_COLON)) { int size = mIdentifiers.size(); if(size > 0) { Identifier *pIdentifier = mIdentifiers[size-1]; char temp[2048]; sprintf(temp, "%s::%s", pIdentifier->mpName, text); free(pIdentifier->mpName); pIdentifier->mpName = strdup(temp); } ClearFlag(FLAG_COLON_COLON); } else { Identifier *pIdentifier = new Identifier; pIdentifier->mpName = strdup(text); pIdentifier->isBracketed = IsSet(FLAG_BRACKET); if(IsSet(FLAG_NEXT_IS_CONST)) { pIdentifier->isConst = true; ClearFlag(FLAG_NEXT_IS_CONST); } mIdentifiers.push_back(pIdentifier); } } } break; } case T_STAR: { int size = mIdentifiers.size(); if(size > 0) { Identifier *pIdentifier = mIdentifiers[size-1]; pIdentifier->starCount++; } break; } case T_LEFTPAREN: { SetFlag(FLAG_PAREN); break; } case T_MM_EXPOSE: case T_MM_EXPOSED: { SetFlag(FLAG_NEXT_IS_EXPOSED); break; } case T_LESS: { mBracketCount++; SetFlag(FLAG_BRACKET); break; } case T_GREATER: { mBracketCount--; if(mBracketCount == 0) { ClearFlag(FLAG_BRACKET); } break; } case T_CONST: { int size = mIdentifiers.size(); if(size > 0) { Identifier *pIdentifier = mIdentifiers[size-1]; pIdentifier->isConst = true; } else { SetFlag(FLAG_NEXT_IS_CONST); } break; } case T_SEMICOLON: { if(IsSet(FLAG_ENUM)) { for(unsigned int i=0; i<mIdentifiers.size(); i++) { Identifier *pIdentifier = mIdentifiers[i]; mpGenerator->AddEnum(pIdentifier->mpName, GetFullScopeName()); } mIdentifiers.clear(); ClearFlag(FLAG_ENUM|FLAG_PAREN); } else { ProcessStatement(); } break; } } }