void SwitchScope(OBJECT sym) { int i; OBJECT new_scopes[MAX_STACK]; if( sym == nilobj ) PushScope(StartSym, FALSE, FALSE); else { i = 0; while( sym != StartSym ) { new_scopes[i++] = enclosing(sym); sym = enclosing(sym); } while( i > 0 ) PushScope(new_scopes[--i], FALSE, FALSE); } }
Context::Context() : stack_offset_(0) { types_["int"] = 0; types_["float"] = 1; PushScope(); }
bool CompileScope(CompileInstance &inst, const mtlChars &input, bool branch) { bool result = true; Scope &scope = PushScope(inst, branch); scope.parser.SetBuffer(input); mtlList<mtlChars> m; while (result && !scope.parser.IsEnd()) { switch (scope.parser.MatchPart("{%s}%|%w%w(%s){%s}%|if(%s){%s}else{%s}%|if(%s){%s}%|%s;", m, NULL)) { case 0: // SCOPE result = CompileScope(inst, m.GetFirst()->GetItem(), false); break; case 1: // FUNCTION result = CompileFunction(inst, m.GetFirst()->GetItem(), m.GetFirst()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetNext()->GetItem()); break; case 2: // CONDITION result = CompileCondition(inst, m.GetFirst()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetItem(), ""); break; case 3: // CONDITION result = CompileCondition(inst, m.GetFirst()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetItem(), m.GetFirst()->GetNext()->GetNext()->GetNext()->GetItem()); break; case 4: // STATEMENT result = CompileStatement(inst, m.GetFirst()->GetItem()); break; default: AddError(inst, "Malformed sequence", input); return false; break; } } PopScope(inst); return result; }
int StartGlobalScope(CgStruct *Cg) { // Create user's global scope: GlobalScope = NewScopeInPool(mem_CreatePool(0, 0)); PushScope(GlobalScope); return 1; } // StartGlobalScope
void LoadScopeSnapshot(OBJECT ss) { OBJECT link, x, sym; BOOLEAN tmp; assert( type(ss) == ACAT, "LoadScopeSnapshot: type(ss)!" ); PushScope(StartSym, FALSE, FALSE); for( link = LastDown(ss); link != ss; link = PrevDown(link) ) { Child(x, link); assert( type(x) == SCOPE_SNAPSHOT, "LoadScopeSnapshot: type(x)!" ); Child(sym, Down(x)); PushScope(sym, ss_npars_only(x), ss_vis_only(x)); body_ok[scope_top-1] = ss_body_ok(x); } tmp = suppress_visible; suppress_visible = ss_suppress(ss); ss_suppress(ss) = tmp; debug0(DST, D, "after LoadScopeSnapshot, scope is:") ifdebug(DST, D, DebugScope()); } /* end LoadScopeSnapshot */
bool CompileFunction(CompileInstance &inst, const mtlChars &ret_type, const mtlChars &name, const mtlChars ¶ms, const mtlChars &body) { if (!IsGlobal(inst)) { // TODO: I want to support this eventually, but I need to emit jump instructions AddError(inst, "Nested functions not allowed", name); return false; } PushScope(inst, false); inst.scopes.GetLast()->GetItem().rel_sptr = 0; // reset the relative stack pointer bool result = true; bool is_main = false; result &= DeclareVar(inst, ret_type, name, ""); if (name.Compare("main", true)) { ++inst.main; if (inst.main > 1) { AddError(inst, "Multiple entry points", ""); return false; } *inst.prog_entry = (char)inst.program.GetSize(); is_main = true; } Parser p; p.SetBuffer(params); mtlList<mtlChars> m; int stack_start = inst.scopes.GetLast()->GetItem().size; while (!p.IsEnd()) { if (p.MatchPart("%w%w", m, NULL) == 0) { result &= DeclareVar(inst, m.GetFirst()->GetItem(), m.GetFirst()->GetNext()->GetItem(), ""); } else { AddError(inst, "Parameter syntax", params); return false; } p.MatchPart(",", m); } int stack_end = inst.scopes.GetLast()->GetItem().size; result &= CompileScope(inst, body, false); PopScope(inst); if (is_main) { *inst.prog_inputs = stack_end - stack_start; EmitInstruction(inst, swsl::END); } else { // FIX: This is a placeholder to prevent the compiler from optimizing stack manipulations EmitInstruction(inst, swsl::NOP); // this should emit a SET instruction (set the value of the return value) } return result; }
SymbolTable::SymbolTable() { PushScope(); }
/** Parse opcodes in the formset IFR binary. @param FormSet Pointer of the FormSet data structure. @retval EFI_SUCCESS Opcode parse success. @retval Other Opcode parse fail. **/ EFI_STATUS ParseOpCodes ( IN FORM_BROWSER_FORMSET *FormSet ) { EFI_STATUS Status; UINT16 Index; FORM_BROWSER_FORM *CurrentForm; FORM_BROWSER_STATEMENT *CurrentStatement; UINT8 Operand; UINT8 Scope; UINTN OpCodeOffset; UINTN OpCodeLength; UINT8 *OpCodeData; UINT8 ScopeOpCode; FORMSET_STORAGE *Storage; FORMSET_DEFAULTSTORE *DefaultStore; QUESTION_DEFAULT *CurrentDefault; QUESTION_OPTION *CurrentOption; CHAR8 *AsciiString; UINT16 NumberOfStatement; UINT16 NumberOfExpression; EFI_IMAGE_ID *ImageId; EFI_HII_VALUE *Value; LIST_ENTRY *OneOfOptinMapEntryListHead; EFI_IFR_GUID_OPTIONKEY *OptionMap; ONE_OF_OPTION_MAP *OneOfOptionMap; ONE_OF_OPTION_MAP_ENTRY *OneOfOptionMapEntry; UINT8 OneOfType; EFI_IFR_ONE_OF *OneOfOpcode; HII_THUNK_CONTEXT *ThunkContext; EFI_IFR_FORM_MAP_METHOD *MapMethod; mInScopeSubtitle = FALSE; mInScopeSuppress = FALSE; mInScopeGrayOut = FALSE; CurrentDefault = NULL; CurrentOption = NULL; MapMethod = NULL; ThunkContext = UefiHiiHandleToThunkContext ((CONST HII_THUNK_PRIVATE_DATA*) mHiiThunkPrivateData, FormSet->HiiHandle); // // Set to a invalid value. // OneOfType = (UINT8) -1; // // Get the number of Statements and Expressions // CountOpCodes (FormSet, &NumberOfStatement, &NumberOfExpression); FormSet->NumberOfStatement = NumberOfStatement; mStatementIndex = 0; FormSet->StatementBuffer = AllocateZeroPool (NumberOfStatement * sizeof (FORM_BROWSER_STATEMENT)); if (FormSet->StatementBuffer == NULL) { return EFI_OUT_OF_RESOURCES; } InitializeListHead (&FormSet->StorageListHead); InitializeListHead (&FormSet->DefaultStoreListHead); InitializeListHead (&FormSet->FormListHead); InitializeListHead (&FormSet->OneOfOptionMapListHead); CurrentForm = NULL; CurrentStatement = NULL; ResetScopeStack (); OpCodeOffset = 0; while (OpCodeOffset < FormSet->IfrBinaryLength) { OpCodeData = FormSet->IfrBinaryData + OpCodeOffset; OpCodeLength = ((EFI_IFR_OP_HEADER *) OpCodeData)->Length; OpCodeOffset += OpCodeLength; Operand = ((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode; Scope = ((EFI_IFR_OP_HEADER *) OpCodeData)->Scope; // // If scope bit set, push onto scope stack // if (Scope != 0) { PushScope (Operand); } if (IsExpressionOpCode (Operand)) { continue; } // // Parse the Opcode // switch (Operand) { case EFI_IFR_FORM_SET_OP: // // check the formset GUID // if (!CompareGuid ((EFI_GUID *)(VOID *)&FormSet->Guid, (EFI_GUID *)(VOID *)&((EFI_IFR_FORM_SET *) OpCodeData)->Guid)) { return EFI_INVALID_PARAMETER; } CopyMem (&FormSet->FormSetTitle, &((EFI_IFR_FORM_SET *) OpCodeData)->FormSetTitle, sizeof (EFI_STRING_ID)); CopyMem (&FormSet->Help, &((EFI_IFR_FORM_SET *) OpCodeData)->Help, sizeof (EFI_STRING_ID)); break; case EFI_IFR_FORM_OP: // // Create a new Form for this FormSet // CurrentForm = AllocateZeroPool (sizeof (FORM_BROWSER_FORM)); ASSERT (CurrentForm != NULL); CurrentForm->Signature = FORM_BROWSER_FORM_SIGNATURE; InitializeListHead (&CurrentForm->StatementListHead); CopyMem (&CurrentForm->FormId, &((EFI_IFR_FORM *) OpCodeData)->FormId, sizeof (UINT16)); CopyMem (&CurrentForm->FormTitle, &((EFI_IFR_FORM *) OpCodeData)->FormTitle, sizeof (EFI_STRING_ID)); // // Insert into Form list of this FormSet // InsertTailList (&FormSet->FormListHead, &CurrentForm->Link); break; case EFI_IFR_FORM_MAP_OP: // // Create a new Form Map for this FormSet // CurrentForm = AllocateZeroPool (sizeof (FORM_BROWSER_FORM)); ASSERT (CurrentForm != NULL); CurrentForm->Signature = FORM_BROWSER_FORM_SIGNATURE; InitializeListHead (&CurrentForm->StatementListHead); CopyMem (&CurrentForm->FormId, &((EFI_IFR_FORM *) OpCodeData)->FormId, sizeof (UINT16)); MapMethod = (EFI_IFR_FORM_MAP_METHOD *) (OpCodeData + sizeof (EFI_IFR_FORM_MAP)); // // FormMap Form must contain at least one Map Method. // if (((EFI_IFR_OP_HEADER *) OpCodeData)->Length < ((UINTN) (UINT8 *) (MapMethod + 1) - (UINTN) OpCodeData)) { return EFI_INVALID_PARAMETER; } // // Try to find the standard form map method. // while (((UINTN) (UINT8 *) MapMethod - (UINTN) OpCodeData) < ((EFI_IFR_OP_HEADER *) OpCodeData)->Length) { if (CompareGuid ((EFI_GUID *) (VOID *) &MapMethod->MethodIdentifier, &gEfiHiiStandardFormGuid)) { CopyMem (&CurrentForm->FormTitle, &MapMethod->MethodTitle, sizeof (EFI_STRING_ID)); break; } MapMethod ++; } // // If the standard form map method is not found, the first map method title will be used. // if (CurrentForm->FormTitle == 0) { MapMethod = (EFI_IFR_FORM_MAP_METHOD *) (OpCodeData + sizeof (EFI_IFR_FORM_MAP)); CopyMem (&CurrentForm->FormTitle, &MapMethod->MethodTitle, sizeof (EFI_STRING_ID)); } // // Insert into Form list of this FormSet // InsertTailList (&FormSet->FormListHead, &CurrentForm->Link); break; // // Storage // case EFI_IFR_VARSTORE_OP: // // Create a buffer Storage for this FormSet // Storage = CreateStorage (FormSet); Storage->Type = EFI_HII_VARSTORE_BUFFER; CopyMem (&Storage->VarStoreId, &((EFI_IFR_VARSTORE *) OpCodeData)->VarStoreId, sizeof (EFI_VARSTORE_ID)); CopyMem (&Storage->Guid, &((EFI_IFR_VARSTORE *) OpCodeData)->Guid, sizeof (EFI_GUID)); CopyMem (&Storage->Size, &((EFI_IFR_VARSTORE *) OpCodeData)->Size, sizeof (UINT16)); AsciiString = (CHAR8 *) ((EFI_IFR_VARSTORE *) OpCodeData)->Name; Storage->Name = AllocateZeroPool (AsciiStrSize (AsciiString) * 2); ASSERT (Storage->Name != NULL); for (Index = 0; AsciiString[Index] != 0; Index++) { Storage->Name[Index] = (CHAR16) AsciiString[Index]; } break; case EFI_IFR_VARSTORE_NAME_VALUE_OP: // // Framework IFR doesn't support Name/Value VarStore opcode // if (ThunkContext != NULL && ThunkContext->ByFrameworkHiiNewPack) { ASSERT (FALSE); } // // Create a name/value Storage for this FormSet // Storage = CreateStorage (FormSet); Storage->Type = EFI_HII_VARSTORE_NAME_VALUE; CopyMem (&Storage->VarStoreId, &((EFI_IFR_VARSTORE_NAME_VALUE *) OpCodeData)->VarStoreId, sizeof (EFI_VARSTORE_ID)); CopyMem (&Storage->Guid, &((EFI_IFR_VARSTORE_NAME_VALUE *) OpCodeData)->Guid, sizeof (EFI_GUID)); break; case EFI_IFR_VARSTORE_EFI_OP: // // Create a EFI variable Storage for this FormSet // Storage = CreateStorage (FormSet); Storage->Type = EFI_HII_VARSTORE_EFI_VARIABLE; CopyMem (&Storage->VarStoreId, &((EFI_IFR_VARSTORE_EFI *) OpCodeData)->VarStoreId, sizeof (EFI_VARSTORE_ID)); CopyMem (&Storage->Guid, &((EFI_IFR_VARSTORE_EFI *) OpCodeData)->Guid, sizeof (EFI_GUID)); CopyMem (&Storage->Attributes, &((EFI_IFR_VARSTORE_EFI *) OpCodeData)->Attributes, sizeof (UINT32)); break; // // DefaultStore // case EFI_IFR_DEFAULTSTORE_OP: DefaultStore = AllocateZeroPool (sizeof (FORMSET_DEFAULTSTORE)); ASSERT (DefaultStore != NULL); DefaultStore->Signature = FORMSET_DEFAULTSTORE_SIGNATURE; CopyMem (&DefaultStore->DefaultId, &((EFI_IFR_DEFAULTSTORE *) OpCodeData)->DefaultId, sizeof (UINT16)); CopyMem (&DefaultStore->DefaultName, &((EFI_IFR_DEFAULTSTORE *) OpCodeData)->DefaultName, sizeof (EFI_STRING_ID)); // // Insert to DefaultStore list of this Formset // InsertTailList (&FormSet->DefaultStoreListHead, &DefaultStore->Link); break; // // Statements // case EFI_IFR_SUBTITLE_OP: CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); CurrentStatement->Flags = ((EFI_IFR_SUBTITLE *) OpCodeData)->Flags; if (Scope != 0) { mInScopeSubtitle = TRUE; } break; case EFI_IFR_TEXT_OP: CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); CopyMem (&CurrentStatement->TextTwo, &((EFI_IFR_TEXT *) OpCodeData)->TextTwo, sizeof (EFI_STRING_ID)); break; // // Questions // case EFI_IFR_ACTION_OP: CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); if (OpCodeLength == sizeof (EFI_IFR_ACTION_1)) { // // No QuestionConfig present, so no configuration string will be processed // CurrentStatement->QuestionConfig = 0; } else { CopyMem (&CurrentStatement->QuestionConfig, &((EFI_IFR_ACTION *) OpCodeData)->QuestionConfig, sizeof (EFI_STRING_ID)); } break; case EFI_IFR_RESET_BUTTON_OP: CurrentStatement = CreateStatement (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); CopyMem (&CurrentStatement->DefaultId, &((EFI_IFR_RESET_BUTTON *) OpCodeData)->DefaultId, sizeof (EFI_DEFAULT_ID)); break; case EFI_IFR_REF_OP: CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); CopyMem (&CurrentStatement->RefFormId, &((EFI_IFR_REF *) OpCodeData)->FormId, sizeof (EFI_FORM_ID)); if (OpCodeLength >= sizeof (EFI_IFR_REF2)) { CopyMem (&CurrentStatement->RefQuestionId, &((EFI_IFR_REF2 *) OpCodeData)->QuestionId, sizeof (EFI_QUESTION_ID)); if (OpCodeLength >= sizeof (EFI_IFR_REF3)) { CopyMem (&CurrentStatement->RefFormSetId, &((EFI_IFR_REF3 *) OpCodeData)->FormSetId, sizeof (EFI_GUID)); if (OpCodeLength >= sizeof (EFI_IFR_REF4)) { CopyMem (&CurrentStatement->RefDevicePath, &((EFI_IFR_REF4 *) OpCodeData)->DevicePath, sizeof (EFI_STRING_ID)); } } } break; case EFI_IFR_ONE_OF_OP: case EFI_IFR_NUMERIC_OP: CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); CurrentStatement->Flags = ((EFI_IFR_ONE_OF *) OpCodeData)->Flags; Value = &CurrentStatement->HiiValue; switch (CurrentStatement->Flags & EFI_IFR_NUMERIC_SIZE) { case EFI_IFR_NUMERIC_SIZE_1: CurrentStatement->Minimum = ((EFI_IFR_NUMERIC *) OpCodeData)->data.u8.MinValue; CurrentStatement->Maximum = ((EFI_IFR_NUMERIC *) OpCodeData)->data.u8.MaxValue; CurrentStatement->Step = ((EFI_IFR_NUMERIC *) OpCodeData)->data.u8.Step; CurrentStatement->StorageWidth = sizeof (UINT8); Value->Type = EFI_IFR_TYPE_NUM_SIZE_8; break; case EFI_IFR_NUMERIC_SIZE_2: CopyMem (&CurrentStatement->Minimum, &((EFI_IFR_NUMERIC *) OpCodeData)->data.u16.MinValue, sizeof (UINT16)); CopyMem (&CurrentStatement->Maximum, &((EFI_IFR_NUMERIC *) OpCodeData)->data.u16.MaxValue, sizeof (UINT16)); CopyMem (&CurrentStatement->Step, &((EFI_IFR_NUMERIC *) OpCodeData)->data.u16.Step, sizeof (UINT16)); CurrentStatement->StorageWidth = sizeof (UINT16); Value->Type = EFI_IFR_TYPE_NUM_SIZE_16; break; case EFI_IFR_NUMERIC_SIZE_4: CopyMem (&CurrentStatement->Minimum, &((EFI_IFR_NUMERIC *) OpCodeData)->data.u32.MinValue, sizeof (UINT32)); CopyMem (&CurrentStatement->Maximum, &((EFI_IFR_NUMERIC *) OpCodeData)->data.u32.MaxValue, sizeof (UINT32)); CopyMem (&CurrentStatement->Step, &((EFI_IFR_NUMERIC *) OpCodeData)->data.u32.Step, sizeof (UINT32)); CurrentStatement->StorageWidth = sizeof (UINT32); Value->Type = EFI_IFR_TYPE_NUM_SIZE_32; break; case EFI_IFR_NUMERIC_SIZE_8: CopyMem (&CurrentStatement->Minimum, &((EFI_IFR_NUMERIC *) OpCodeData)->data.u64.MinValue, sizeof (UINT64)); CopyMem (&CurrentStatement->Maximum, &((EFI_IFR_NUMERIC *) OpCodeData)->data.u64.MaxValue, sizeof (UINT64)); CopyMem (&CurrentStatement->Step, &((EFI_IFR_NUMERIC *) OpCodeData)->data.u64.Step, sizeof (UINT64)); CurrentStatement->StorageWidth = sizeof (UINT64); Value->Type = EFI_IFR_TYPE_NUM_SIZE_64; break; default: break; } if (Operand == EFI_IFR_ONE_OF_OP) { OneOfOpcode = (EFI_IFR_ONE_OF *) OpCodeData; OneOfType = (UINT8) (OneOfOpcode->Flags & EFI_IFR_NUMERIC_SIZE); } break; case EFI_IFR_ORDERED_LIST_OP: CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); CurrentStatement->Flags = ((EFI_IFR_ORDERED_LIST *) OpCodeData)->Flags; CurrentStatement->MaxContainers = ((EFI_IFR_ORDERED_LIST *) OpCodeData)->MaxContainers; CurrentStatement->StorageWidth = (UINT16)(CurrentStatement->MaxContainers * sizeof (UINT8)); // // No buffer type is defined in EFI_IFR_TYPE_VALUE, so a Configuration Driver // has to use FormBrowser2.Callback() to retrieve the uncommited data for // an interactive orderedlist (i.e. with EFI_IFR_FLAG_CALLBACK flag set). // CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_OTHER; CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth); break; case EFI_IFR_CHECKBOX_OP: CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); CurrentStatement->Flags = ((EFI_IFR_CHECKBOX *) OpCodeData)->Flags; CurrentStatement->StorageWidth = sizeof (BOOLEAN); CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_BOOLEAN; break; case EFI_IFR_STRING_OP: CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); // // MinSize is the minimum number of characters that can be accepted for this opcode, // MaxSize is the maximum number of characters that can be accepted for this opcode. // The characters are stored as Unicode, so the storage width should multiply 2. // CurrentStatement->Minimum = ((EFI_IFR_STRING *) OpCodeData)->MinSize; CurrentStatement->Maximum = ((EFI_IFR_STRING *) OpCodeData)->MaxSize; CurrentStatement->StorageWidth = (UINT16)((UINTN) CurrentStatement->Maximum * sizeof (UINT16)); CurrentStatement->Flags = ((EFI_IFR_STRING *) OpCodeData)->Flags; CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_STRING; CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth); break; case EFI_IFR_PASSWORD_OP: CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); // // MinSize is the minimum number of characters that can be accepted for this opcode, // MaxSize is the maximum number of characters that can be accepted for this opcode. // The characters are stored as Unicode, so the storage width should multiply 2. // CopyMem (&CurrentStatement->Minimum, &((EFI_IFR_PASSWORD *) OpCodeData)->MinSize, sizeof (UINT16)); CopyMem (&CurrentStatement->Maximum, &((EFI_IFR_PASSWORD *) OpCodeData)->MaxSize, sizeof (UINT16)); CurrentStatement->StorageWidth = (UINT16)((UINTN) CurrentStatement->Maximum * sizeof (UINT16)); CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_STRING; CurrentStatement->BufferValue = AllocateZeroPool (CurrentStatement->StorageWidth); break; case EFI_IFR_DATE_OP: CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); CurrentStatement->Flags = ((EFI_IFR_DATE *) OpCodeData)->Flags; CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_DATE; break; case EFI_IFR_TIME_OP: CurrentStatement = CreateQuestion (OpCodeData, FormSet, CurrentForm); ASSERT (CurrentStatement != NULL); CurrentStatement->Flags = ((EFI_IFR_TIME *) OpCodeData)->Flags; CurrentStatement->HiiValue.Type = EFI_IFR_TYPE_TIME; break; // // Default // case EFI_IFR_DEFAULT_OP: // // EFI_IFR_DEFAULT appear in scope of a Question, // It creates a default value for the current question. // A Question may have more than one Default value which have different default types. // CurrentDefault = AllocateZeroPool (sizeof (QUESTION_DEFAULT)); ASSERT (CurrentDefault != NULL); CurrentDefault->Signature = QUESTION_DEFAULT_SIGNATURE; CurrentDefault->Value.Type = ((EFI_IFR_DEFAULT *) OpCodeData)->Type; CopyMem (&CurrentDefault->DefaultId, &((EFI_IFR_DEFAULT *) OpCodeData)->DefaultId, sizeof (UINT16)); CopyMem (&CurrentDefault->Value.Value, &((EFI_IFR_DEFAULT *) OpCodeData)->Value, sizeof (EFI_IFR_TYPE_VALUE)); ExtendValueToU64 (&CurrentDefault->Value); // // Insert to Default Value list of current Question // InsertTailList (&CurrentStatement->DefaultListHead, &CurrentDefault->Link); break; // // Option // case EFI_IFR_ONE_OF_OPTION_OP: // // EFI_IFR_ONE_OF_OPTION appear in scope of a Question. // It create a selection for use in current Question. // CurrentOption = AllocateZeroPool (sizeof (QUESTION_OPTION)); ASSERT (CurrentOption != NULL); CurrentOption->Signature = QUESTION_OPTION_SIGNATURE; CurrentOption->Flags = ((EFI_IFR_ONE_OF_OPTION *) OpCodeData)->Flags; CurrentOption->Value.Type = ((EFI_IFR_ONE_OF_OPTION *) OpCodeData)->Type; CopyMem (&CurrentOption->Text, &((EFI_IFR_ONE_OF_OPTION *) OpCodeData)->Option, sizeof (EFI_STRING_ID)); CopyMem (&CurrentOption->Value.Value, &((EFI_IFR_ONE_OF_OPTION *) OpCodeData)->Value, sizeof (EFI_IFR_TYPE_VALUE)); ExtendValueToU64 (&CurrentOption->Value); // // Insert to Option list of current Question // InsertTailList (&CurrentStatement->OptionListHead, &CurrentOption->Link); break; // // Conditional // case EFI_IFR_NO_SUBMIT_IF_OP: case EFI_IFR_INCONSISTENT_IF_OP: break; case EFI_IFR_SUPPRESS_IF_OP: break; case EFI_IFR_GRAY_OUT_IF_OP: break; case EFI_IFR_DISABLE_IF_OP: // // Framework IFR doesn't support DisableIf opcode // if (ThunkContext != NULL && ThunkContext->ByFrameworkHiiNewPack) { ASSERT (FALSE); } // // Expression // case EFI_IFR_VALUE_OP: case EFI_IFR_READ_OP: case EFI_IFR_WRITE_OP: break; case EFI_IFR_RULE_OP: break; // // Image // case EFI_IFR_IMAGE_OP: // // Get ScopeOpcode from top of stack // PopScope (&ScopeOpCode); PushScope (ScopeOpCode); switch (ScopeOpCode) { case EFI_IFR_FORM_SET_OP: ImageId = &FormSet->ImageId; break; case EFI_IFR_FORM_OP: case EFI_IFR_FORM_MAP_OP: ImageId = &CurrentForm->ImageId; break; case EFI_IFR_ONE_OF_OPTION_OP: ImageId = &CurrentOption->ImageId; break; default: // // Make sure CurrentStatement is not NULL. // If it is NULL, 1) ParseOpCodes functions may parse the IFR wrongly. Or 2) the IFR // file is wrongly generated by tools such as VFR Compiler. // ASSERT (CurrentStatement != NULL); ImageId = &CurrentStatement->ImageId; break; } ASSERT (ImageId != NULL); CopyMem (ImageId, &((EFI_IFR_IMAGE *) OpCodeData)->Id, sizeof (EFI_IMAGE_ID)); break; // // Refresh // case EFI_IFR_REFRESH_OP: ASSERT (CurrentStatement != NULL); CurrentStatement->RefreshInterval = ((EFI_IFR_REFRESH *) OpCodeData)->RefreshInterval; break; // // Vendor specific // case EFI_IFR_GUID_OP: OptionMap = (EFI_IFR_GUID_OPTIONKEY *) OpCodeData; if (CompareGuid (&mTianoHiiIfrGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) { // // Tiano specific GUIDed opcodes // switch (((EFI_IFR_GUID_LABEL *) OpCodeData)->ExtendOpCode) { case EFI_IFR_EXTEND_OP_LABEL: // // just ignore label // break; case EFI_IFR_EXTEND_OP_CLASS: CopyMem (&FormSet->Class, &((EFI_IFR_GUID_CLASS *) OpCodeData)->Class, sizeof (UINT16)); break; case EFI_IFR_EXTEND_OP_SUBCLASS: CopyMem (&FormSet->SubClass, &((EFI_IFR_GUID_SUBCLASS *) OpCodeData)->SubClass, sizeof (UINT16)); break; default: break; } } else if (CompareGuid ((EFI_GUID *)(VOID *)&OptionMap->Guid, &mFrameworkHiiCompatibilityGuid)) { if (OptionMap->ExtendOpCode == EFI_IFR_EXTEND_OP_OPTIONKEY) { OneOfOptinMapEntryListHead = GetOneOfOptionMapEntryListHead (FormSet, OptionMap->QuestionId); if (OneOfOptinMapEntryListHead == NULL) { OneOfOptionMap = AllocateZeroPool (sizeof (ONE_OF_OPTION_MAP)); ASSERT (OneOfOptionMap != NULL); OneOfOptionMap->Signature = ONE_OF_OPTION_MAP_SIGNATURE; OneOfOptionMap->QuestionId = OptionMap->QuestionId; // // Make sure OneOfType is initialized. // ASSERT (OneOfType != (UINT8) -1); OneOfOptionMap->ValueType = OneOfType; InitializeListHead (&OneOfOptionMap->OneOfOptionMapEntryListHead); OneOfOptinMapEntryListHead = &OneOfOptionMap->OneOfOptionMapEntryListHead; InsertTailList (&FormSet->OneOfOptionMapListHead, &OneOfOptionMap->Link); } OneOfOptionMapEntry = AllocateZeroPool (sizeof (ONE_OF_OPTION_MAP_ENTRY)); ASSERT (OneOfOptionMapEntry != NULL); OneOfOptionMapEntry->Signature = ONE_OF_OPTION_MAP_ENTRY_SIGNATURE; OneOfOptionMapEntry->FwKey = OptionMap->KeyValue; CopyMem (&OneOfOptionMapEntry->Value, &OptionMap->OptionValue, sizeof (EFI_IFR_TYPE_VALUE)); InsertTailList (OneOfOptinMapEntryListHead, &OneOfOptionMapEntry->Link); } } break; // // Scope End // case EFI_IFR_END_OP: Status = PopScope (&ScopeOpCode); if (EFI_ERROR (Status)) { ResetScopeStack (); return Status; } switch (ScopeOpCode) { case EFI_IFR_FORM_SET_OP: // // End of FormSet, update FormSet IFR binary length // to stop parsing substantial OpCodes // FormSet->IfrBinaryLength = OpCodeOffset; break; case EFI_IFR_FORM_OP: case EFI_IFR_FORM_MAP_OP: // // End of Form // CurrentForm = NULL; break; case EFI_IFR_ONE_OF_OPTION_OP: // // End of Option // CurrentOption = NULL; break; case EFI_IFR_SUBTITLE_OP: mInScopeSubtitle = FALSE; break; case EFI_IFR_NO_SUBMIT_IF_OP: case EFI_IFR_INCONSISTENT_IF_OP: // // Ignore end of EFI_IFR_NO_SUBMIT_IF and EFI_IFR_INCONSISTENT_IF // break; case EFI_IFR_GRAY_OUT_IF_OP: mInScopeGrayOut = FALSE; break; default: if (IsExpressionOpCode (ScopeOpCode)) { } break; } break; default: break; } } return EFI_SUCCESS; }
int startup(int argc, char *argv[]) { int i, len; FULL_CHAR *arg; OBJECT t, y, res, s; /* current token, parser output */ BOOLEAN stdin_seen; /* TRUE when stdin file seen */ int source_file_count; /* number of source files in command */ FULL_CHAR *cross_db; /* name of cross reference database */ FULL_CHAR *outfile; /* name of output file */ FULL_CHAR *lib; /* name of library directory */ FILE *out_fp; long MemCheckLong; FULL_CHAR oname[MAX_BUFF], oval[MAX_BUFF], buff[MAX_BUFF], *p; int bp; OBJECT z; BOOLEAN seen_wordcount; #if LOCALE_ON char catname[MAX_BUFF], *loc; #endif /* find the name of the library directory, from envt or else from -D */ lib = AsciiToFull(getenv("LOUTLIB")); if( lib == (FULL_CHAR *) NULL ) lib = AsciiToFull(LIB_DIR); /* set locale if that's what we are doing */ #if LOCALE_ON loc = setlocale(LC_MESSAGES, ""); if( loc == (char *) NULL ) { Error(1, 6, "unable to initialize locale", WARN, no_fpos); loc = "C"; } sprintf(catname, "%s/%s/%s/LC_MESSAGES/errors.%s", lib, LOCALE_DIR, loc, loc); MsgCat = catopen(catname, 0); #endif /* initialise various modules, add current directory to search paths */ TotalWordCount = 0; seen_wordcount = FALSE; BackEnd = PS_BackEnd; PlainCharWidth = PLAIN_WIDTH; PlainCharHeight = PLAIN_HEIGHT; PlainFormFeed = FALSE; InitializeAll = FALSE; UseCollate = COLLATE; AllowCrossDb = TRUE; InMemoryDbIndexes = TRUE; Encapsulated = FALSE; SafeExecution = SAFE_DFT ? TRUE : FALSE; Kern = TRUE; MemInit(); InitSym(); LexInit(); InitFiles(); AddToPath(SOURCE_PATH, MakeWord(WORD, STR_EMPTY, no_fpos)); AddToPath(DATABASE_PATH, MakeWord(WORD, STR_EMPTY, no_fpos)); AddToPath(INCLUDE_PATH, MakeWord(WORD, STR_EMPTY, no_fpos)); /* read command line */ stdin_seen = FALSE; AltErrorFormat = FALSE; cross_db = CROSS_DB; outfile = STR_STDOUT; source_file_count = 0; New(CommandOptions, ACAT); for( i = 1; i < argc; i++ ) { if( *argv[i] == CH_HYPHEN ) switch( *(argv[i]+1) ) { case CH_FLAG_OUTFILE: /* read name of output file */ if( (outfile = GetArg(argv, argc, &i)) == NULL ) Error(1, 7, "usage: -o <filename>", FATAL, no_fpos); if( StringEndsWith(outfile, SOURCE_SUFFIX) ) Error(1, 28, "-o: output file name %s ends with %s", FATAL, no_fpos, outfile, SOURCE_SUFFIX); break; case CH_FLAG_SUPPRESS: /* suppress references to OldCrossDb and NewCrossDb */ AllowCrossDb = FALSE; break; case CH_FLAG_MEMCR: /* don't use in-memory database indexes */ InMemoryDbIndexes = FALSE; break; case CH_FLAG_NOKERN: /* suppress kerning */ Kern = FALSE; break; case CH_FLAG_NOCOLLATE: /* suppress local collation */ UseCollate = FALSE; break; case CH_FLAG_COLLATE: /* invoke local collation */ UseCollate = TRUE; break; case CH_FLAG_CROSS: /* read name of cross reference database */ if( (cross_db = GetArg(argv, argc, &i)) == NULL ) Error(1, 8, "usage: -c <filename>", FATAL, no_fpos); break; case CH_FLAG_ERRFILE: /* read log file name */ if( (arg = GetArg(argv, argc, &i)) == NULL ) Error(1, 9, "usage: -e <filename>", FATAL, no_fpos); ErrorInit(arg); break; case CH_FLAG_ALTERR: /* alternative error message format */ AltErrorFormat = TRUE; break; case CH_FLAG_EPSFIRST: /* -EPS produces encapsulated PostScript output */ if( !StringEqual(AsciiToFull(argv[i]+1), STR_EPS) ) Error(1, 10, "usage: -EPS", FATAL, no_fpos); Encapsulated = TRUE; break; case CH_FLAG_DIRPATH: /* add directory to database and sysdatabase paths */ if( (arg = GetArg(argv, argc, &i)) == NULL ) Error(1, 11, "usage: -D <directoryname>", FATAL, no_fpos); AddToPath(DATABASE_PATH, MakeWord(WORD, arg, no_fpos)); AddToPath(SYSDATABASE_PATH, MakeWord(WORD, arg, no_fpos)); break; case CH_FLAG_ENCPATH: /* add directory to character mapping path */ if( (arg = GetArg(argv, argc, &i)) == NULL ) Error(1, 12, "usage: -C <directoryname>", FATAL, no_fpos); AddToPath(MAPPING_PATH, MakeWord(WORD, arg, no_fpos)); break; case CH_FLAG_FNTPATH: /* add directory to font path */ if( (arg = GetArg(argv, argc, &i)) == NULL ) Error(1, 13, "usage: -F <directoryname>", FATAL, no_fpos); AddToPath(FONT_PATH, MakeWord(WORD, arg, no_fpos)); break; case CH_FLAG_HYPPATH: /* add directory to hyph path */ if( (arg = GetArg(argv, argc, &i)) == NULL ) Error(1, 14, "usage: -H <directoryname>", FATAL, no_fpos); AddToPath(HYPH_PATH, MakeWord(WORD, arg, no_fpos)); break; case CH_FLAG_INCPATH: /* add directory to include and sysinclude paths */ if( (arg = GetArg(argv, argc, &i)) == NULL ) Error(1, 15, "usage: -I <directoryname>", FATAL, no_fpos); AddToPath(INCLUDE_PATH, MakeWord(WORD, arg, no_fpos)); AddToPath(SYSINCLUDE_PATH, MakeWord(WORD, arg, no_fpos)); break; case CH_FLAG_INCLUDE: /* read sysinclude file and strip any .lt suffix */ if( (arg = GetArg(argv, argc, &i)) == NULL ) Error(1, 16, "usage: -i <filename>", FATAL, no_fpos); len = StringLength(arg) - StringLength(SOURCE_SUFFIX); if( len >= 0 && StringEqual(&arg[len], SOURCE_SUFFIX) ) StringCopy(&arg[len], STR_EMPTY); debug0(DFS, D, " calling DefineFile from main (1)"); DefineFile(arg, STR_EMPTY, no_fpos, SOURCE_FILE, SYSINCLUDE_PATH); break; case CH_FLAG_HYPHEN: /* declare hyphenation file */ if( FirstFile(HYPH_FILE) != NO_FILE ) Error(1, 17, "two -h options illegal", FATAL, no_fpos); if( (arg = GetArg(argv, argc, &i)) == NULL ) Error(1, 18, "usage: -h <filename>", FATAL, no_fpos); debug0(DFS, D, " calling DefineFile from main (2)"); DefineFile(arg, STR_EMPTY, no_fpos, HYPH_FILE, INCLUDE_PATH); DefineFile(arg, HYPH_SUFFIX, no_fpos, HYPH_PACKED_FILE, INCLUDE_PATH); break; case CH_FLAG_VERSION: fprintf(stderr, "%s\n", LOUT_VERSION); fprintf(stderr, "%-28s %s\n", "Basser Lout written by:", "Jeffrey H. Kingston ([email protected])"); fprintf(stderr, "%-28s %s\n", "Free source available from:", "ftp://ftp.cs.usyd.edu.au/jeff/lout"); fprintf(stderr, "%-28s %s %s\n", "This executable compiled:", __TIME__, __DATE__); fprintf(stderr, "%-28s %s%s%s\n", "System include directory:", lib, STR_DIR, INCL_DIR); fprintf(stderr, "%-28s %s%s%s\n", "System database directory:", lib, STR_DIR, DATA_DIR); fprintf(stderr, "Database index files created afresh automatically:%s\n", USE_STAT ? " yes" : " no"); fprintf(stderr, "Safe execution (disabling system()) is default:%s\n", SAFE_DFT ? " yes" : " no"); fprintf(stderr, "strcoll() used for sorting by default:%s\n", COLLATE ? " yes" : " no"); fprintf(stderr, "PDF compression on:%s\n", PDF_COMPRESSION ? " yes" : " no"); fprintf(stderr, "Debugging (-d, -dd, -ddd flags) available:%s\n", DEBUG_ON ? " yes" : " no"); fprintf(stderr, "\n"); fprintf(stderr, "Basser Lout comes with ABSOLUTELY NO WARRANTY.\n"); fprintf(stderr, "This is free software, and you are welcome to\n"); fprintf(stderr, "redistribute it under certain conditions. For\n"); fprintf(stderr, "details on both points, consult the GNU General\n"); fprintf(stderr, "Public License (distributed with this software).\n"); exit(0); break; case CH_FLAG_WORDS: seen_wordcount = TRUE; break; case CH_FLAG_PDF: BackEnd = PDF_BackEnd; break; case CH_FLAG_FFPLAIN: if( StringEqual(AsciiToFull(argv[i]+1), STR_PDF) ) { BackEnd = PDF_BackEnd; break; } PlainFormFeed = TRUE; /* NB NO BREAK */ case CH_FLAG_PLAIN: BackEnd = Plain_BackEnd; if( *(argv[i]+2) != '\0' ) { float len1, len2; FULL_CHAR units1, units2; if( sscanf(argv[i]+2, "%f%c%f%c",&len1,&units1,&len2,&units2) != 4 ) { Error(1, 19, "usage: lout -%c<length><length>", FATAL, no_fpos, *(argv[i]+1)); } switch( units1 ) { case CH_UNIT_CM: PlainCharWidth = len1 * CM; break; case CH_UNIT_IN: PlainCharWidth = len1 * IN; break; case CH_UNIT_PT: PlainCharWidth = len1 * PT; break; case CH_UNIT_EM: PlainCharWidth = len1 * EM; break; default: Error(1, 20, "lout -%c: units must be c, i, p, or m", FATAL, no_fpos, *(argv[i]+1)); break; } switch( units2 ) { case CH_UNIT_CM: PlainCharHeight = len2 * CM; break; case CH_UNIT_IN: PlainCharHeight = len2 * IN; break; case CH_UNIT_PT: PlainCharHeight = len2 * PT; break; case CH_UNIT_EM: PlainCharHeight = len2 * EM; break; default: Error(1, 21, "lout -%c: units must be c, i, p, or m", FATAL, no_fpos, *(argv[i]+1)); break; } } break; case CH_FLAG_INITALL: InitializeAll = TRUE; AllowCrossDb = FALSE; break; case CH_FLAG_USAGE: PrintUsage(stderr); exit(0); break; case CH_FLAG_DEBUG: debug_init(AsciiToFull(argv[i])); break; case CH_FLAG_MEMCHECK: sscanf(argv[i], "-m%ld", &MemCheckLong); MemCheck = (POINTER) MemCheckLong; fprintf(stderr, "checking memory location %ld\n", (long) MemCheck); break; case '\0': /* read stdin as file name */ if( stdin_seen ) Error(1, 23, "standard input specified twice", FATAL, no_fpos); stdin_seen = TRUE; debug0(DFS, D, " calling DefineFile from main (3)"); DefineFile(STR_STDIN, STR_EMPTY, no_fpos, SOURCE_FILE, SOURCE_PATH); break; case CH_FLAG_OPTION: /* read command-line document option */ if( sscanf(argv[i]+2, "%[^{ ] { %[^}] }", oname, oval) != 2 || StringLength(oname) == 0 || StringLength(oval) == 0 ) Error(1, 24, "error in command-line option %s", FATAL, no_fpos, argv[i]+2); y = MakeWord(WORD, oname, no_fpos); Link(CommandOptions, y); New(y, ACAT); Link(CommandOptions, y); bp = 0; for( p = oval; *p != '\0'; p++ ) switch( *p ) { case ' ': case '\t': case '\n': case '{': case '}': if( bp > 0 ) { buff[bp++] = '\0'; if( Down(y) != y ) { OBJECT g; New(g, GAP_OBJ); hspace(g) = 1; vspace(g) = 0; FposCopy(fpos(g), *no_fpos); Link(y, g); } z = MakeWord(WORD, buff, no_fpos); Link(y, z); bp = 0; } break; default: buff[bp++] = *p; break; } if( bp > 0 ) { buff[bp++] = '\0'; z = MakeWord(WORD, buff, no_fpos); Link(y, z); } if( Down(y) == y ) Error(1, 25, "error in command-line option %s", FATAL, no_fpos, argv[i]+2); break; case CH_FLAG_SAFE: /* ensure safe execution by disabling system calls */ SafeExecution = TRUE; break; case CH_FLAG_UNSAFE: /* allow unsafe execution */ SafeExecution = FALSE; break; default: PrintUsage(stderr); Error(1, 26, "unknown command line flag %s", FATAL, no_fpos, argv[i]); break; } else { /* argument is source file, strip any .lout suffix and define it */ arg = AsciiToFull(argv[i]); len = StringLength(arg) - StringLength(SOURCE_SUFFIX); if( len >= 0 && StringEqual(&arg[len], SOURCE_SUFFIX) ) StringCopy(&arg[len], STR_EMPTY); debug0(DFS, D, " calling DefineFile from main (4)"); DefineFile(AsciiToFull(argv[i]), STR_EMPTY, no_fpos, SOURCE_FILE, SOURCE_PATH); source_file_count++; } } /* for */ if( UseCollate ) { if (!setlocale (LC_COLLATE, "")) Error(1, 30, "unable to initialize collation", WARN, no_fpos); } /* start timing if required */ ifdebug(DPP, D, ProfileOn("main")); /* open output file, or stdout if none specified, and initialize printer */ if( StringEqual(outfile, STR_STDOUT) ) { #if OS_DOS /* For DOS/Win32 we need to set binary mode on stdout to prevent PDF compressed streams and xrefs from being corrupted - Uwe 12/98 */ if( BackEnd->code != PLAINTEXT && _setmode(_fileno(stdout), _O_BINARY) == -1 ) Error(1, 31, "cannot set binary mode on stdout", FATAL, no_fpos); #endif out_fp = stdout; } else { out_fp = StringFOpen(outfile, BackEnd->code == PLAINTEXT ? WRITE_TEXT : WRITE_BINARY); if( out_fp == null ) Error(1, 27, "cannot open output file %s", FATAL, no_fpos, outfile); } /* initialize miscellaneous modules */ ColourInit(); LanguageInit(); BackEnd->PrintInitialize(out_fp); /* append default directories to file search paths */ AddToPath(FONT_PATH, MakeWordThree(lib, STR_DIR, AsciiToFull(FONT_DIR))); AddToPath(HYPH_PATH, MakeWordThree(lib, STR_DIR, AsciiToFull(HYPH_DIR))); AddToPath(MAPPING_PATH, MakeWordThree(lib, STR_DIR, AsciiToFull(MAPS_DIR))); AddToPath(SYSDATABASE_PATH,MakeWordThree(lib,STR_DIR, AsciiToFull(DATA_DIR))); AddToPath(DATABASE_PATH, MakeWordThree(lib, STR_DIR, AsciiToFull(DATA_DIR))); AddToPath(SYSINCLUDE_PATH,MakeWordThree(lib, STR_DIR, AsciiToFull(INCL_DIR))); AddToPath(INCLUDE_PATH, MakeWordThree(lib, STR_DIR, AsciiToFull(INCL_DIR))); /* use stdin if no source files were mentioned */ if( source_file_count == 0 ) { debug0(DFS, D, " calling DefineFile from main (5)"); DefineFile(STR_STDIN, STR_EMPTY, no_fpos, SOURCE_FILE, SOURCE_PATH); } /* load predefined symbols into symbol table */ StartSym = nilobj; /* Not a mistake */ StartSym = load(KW_START, 0, FALSE, FALSE, TRUE, NO_PREC ); GalleySym = load(KW_GALLEY, 0, FALSE, FALSE, TRUE, NO_PREC ); ForceGalleySym= load(KW_FORCE_GALLEY, 0, FALSE, FALSE, TRUE, NO_PREC ); InputSym = load(KW_INPUT, 0, FALSE, FALSE, TRUE, NO_PREC ); PrintSym = load(KW_PRINT, 0, FALSE, FALSE, TRUE, NO_PREC ); FilterInSym = load(KW_FILTERIN, 0, FALSE, FALSE, FALSE, NO_PREC ); FilterOutSym = load(KW_FILTEROUT, 0, FALSE, FALSE, FALSE, NO_PREC ); FilterErrSym = load(KW_FILTERERR, 0, FALSE, FALSE, FALSE, NO_PREC ); OptGallSym = load(KW_OPTGALL, 0, FALSE, TRUE, FALSE, DEFAULT_PREC); VerbatimSym = load(KW_VERBATIM,VERBATIM,FALSE, TRUE, FALSE, DEFAULT_PREC); RawVerbatimSym= load(KW_RAWVERBATIM,RAW_VERBATIM,FALSE,TRUE,FALSE,DEFAULT_PREC); load(KW_BEGIN, BEGIN, FALSE, FALSE, FALSE, BEGIN_PREC ); load(KW_END, END, FALSE, FALSE, FALSE, END_PREC ); load(KW_ENV, ENV, FALSE, FALSE, FALSE, NO_PREC ); load(KW_ENVA, ENVA, FALSE, FALSE, FALSE, NO_PREC ); load(KW_ENVB, ENVB, FALSE, FALSE, FALSE, NO_PREC ); load(KW_ENVC, ENVC, FALSE, FALSE, FALSE, NO_PREC ); load(KW_ENVD, ENVD, FALSE, FALSE, FALSE, NO_PREC ); load(KW_CENV, CENV, FALSE, FALSE, FALSE, NO_PREC ); load(KW_CLOS, CLOS, FALSE, FALSE, FALSE, NO_PREC ); load(KW_LVIS, LVIS, FALSE, FALSE, FALSE, NO_PREC ); load(KW_LUSE, LUSE, FALSE, FALSE, FALSE, NO_PREC ); load(KW_LEO, LEO, FALSE, FALSE, FALSE, NO_PREC ); load(KW_LBR, LBR, FALSE, FALSE, FALSE, LBR_PREC ); load(KW_RBR, RBR, FALSE, FALSE, FALSE, RBR_PREC ); load(KW_INCLUDE, INCLUDE, FALSE, FALSE, FALSE, NO_PREC ); load(KW_SYSINCLUDE, SYS_INCLUDE, FALSE, FALSE, FALSE, NO_PREC ); load(KW_PREPEND, PREPEND, FALSE, FALSE, FALSE, NO_PREC ); load(KW_SYSPREPEND, SYS_PREPEND, FALSE, FALSE, FALSE, NO_PREC ); load(KW_DATABASE, DATABASE, FALSE, FALSE, FALSE, NO_PREC ); load(KW_SYSDATABASE, SYS_DATABASE, FALSE, FALSE, FALSE, NO_PREC ); load(KW_USE, USE, FALSE, FALSE, FALSE, NO_PREC ); load(KW_NOT_REVEALED, NOT_REVEALED, FALSE, FALSE, FALSE, NO_PREC ); load(KW_CASE, CASE, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_YIELD, YIELD, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_BACKEND, BACKEND, FALSE, FALSE, FALSE, DEFAULT_PREC); load(KW_XCHAR, XCHAR, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_FONT, FONT, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_SPACE, SPACE, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_YUNIT, YUNIT, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_ZUNIT, ZUNIT, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_BREAK, BREAK, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_UNDERLINE, UNDERLINE, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_COLOUR, COLOUR, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_COLOR, COLOUR, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_OUTLINE, OUTLINE, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_LANGUAGE, LANGUAGE, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_CURR_LANG, CURR_LANG, FALSE, FALSE, FALSE, DEFAULT_PREC); load(KW_CURR_FAMILY, CURR_FAMILY, FALSE, FALSE, FALSE, DEFAULT_PREC); load(KW_CURR_FACE, CURR_FACE, FALSE, FALSE, FALSE, DEFAULT_PREC); load(KW_CURR_YUNIT, CURR_YUNIT, FALSE, FALSE, FALSE, DEFAULT_PREC); load(KW_CURR_ZUNIT, CURR_ZUNIT, FALSE, FALSE, FALSE, DEFAULT_PREC); load(KW_COMMON, COMMON, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_RUMP, RUMP, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_MELD, MELD, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_INSERT, INSERT, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_ONE_OF, ONE_OF, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_NEXT, NEXT, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_PLUS, PLUS, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_MINUS, MINUS, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_OPEN, OPEN, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_TAGGED, TAGGED, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_WIDE, WIDE, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_HIGH, HIGH, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_HSHIFT, HSHIFT, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_VSHIFT, VSHIFT, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_BEGIN_HEADER, BEGIN_HEADER, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_END_HEADER, END_HEADER, FALSE, FALSE, FALSE, DEFAULT_PREC); load(KW_SET_HEADER, SET_HEADER, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_CLEAR_HEADER, CLEAR_HEADER, FALSE, FALSE, FALSE, DEFAULT_PREC); load(KW_ONE_COL, ONE_COL, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_ONE_ROW, ONE_ROW, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_HSCALE, HSCALE, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_VSCALE, VSCALE, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_HCOVER, HCOVER, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_VCOVER, VCOVER, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_KERN_SHRINK, KERN_SHRINK, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_SCALE, SCALE, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_HCONTRACT, HCONTRACT, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_VCONTRACT, VCONTRACT, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_HLIMITED, HLIMITED, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_VLIMITED, VLIMITED, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_HEXPAND, HEXPAND, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_VEXPAND, VEXPAND, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_STARTHVSPAN, START_HVSPAN, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_STARTHSPAN, START_HSPAN, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_STARTVSPAN, START_VSPAN, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_HSPAN, HSPAN, FALSE, FALSE, FALSE, DEFAULT_PREC); load(KW_VSPAN, VSPAN, FALSE, FALSE, FALSE, DEFAULT_PREC); load(KW_PADJUST, PADJUST, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_HADJUST, HADJUST, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_VADJUST, VADJUST, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_ROTATE, ROTATE, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_BACKGROUND, BACKGROUND, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_INCGRAPHIC, INCGRAPHIC, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_SINCGRAPHIC, SINCGRAPHIC, FALSE, TRUE, FALSE, DEFAULT_PREC); load(KW_PLAINGRAPHIC, PLAIN_GRAPHIC, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_GRAPHIC, GRAPHIC, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_LINK_SOURCE, LINK_SOURCE, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_LINK_DEST, LINK_DEST, TRUE, TRUE, FALSE, DEFAULT_PREC); load(KW_CROSS, CROSS, TRUE, TRUE, FALSE, CROSSOP_PREC); load(KW_FORCE_CROSS, FORCE_CROSS, TRUE, TRUE, FALSE, CROSSOP_PREC); load(KW_NULL, NULL_CLOS, FALSE, FALSE, TRUE, NO_PREC ); load(KW_PAGE_LABEL, PAGE_LABEL, FALSE, TRUE, TRUE, DEFAULT_PREC); #define setcat(s, mk, jn) has_mark(s)=mk, has_join(s)=jn s=load(KW_VCAT_NN, VCAT, TRUE, TRUE, FALSE, VCAT_PREC); setcat(s,FALSE,FALSE); s=load(KW_VCAT_MN, VCAT, TRUE, TRUE, FALSE, VCAT_PREC); setcat(s,TRUE, FALSE); s=load(KW_VCAT_NJ, VCAT, TRUE, TRUE, FALSE, VCAT_PREC); setcat(s,FALSE,TRUE); s=load(KW_VCAT_MJ, VCAT, TRUE, TRUE, FALSE, VCAT_PREC); setcat(s,TRUE, TRUE); s=load(KW_HCAT_NN, HCAT, TRUE, TRUE, FALSE, HCAT_PREC); setcat(s,FALSE,FALSE); s=load(KW_HCAT_MN, HCAT, TRUE, TRUE, FALSE, HCAT_PREC); setcat(s,TRUE, FALSE); s=load(KW_HCAT_NJ, HCAT, TRUE, TRUE, FALSE, HCAT_PREC); setcat(s,FALSE,TRUE); s=load(KW_HCAT_MJ, HCAT, TRUE, TRUE, FALSE, HCAT_PREC); setcat(s,TRUE, TRUE); s=load(KW_ACAT_NJ, ACAT, TRUE, TRUE, FALSE, ACAT_PREC); setcat(s,FALSE,TRUE); s=load(KW_ACAT_MJ, ACAT, TRUE, TRUE, FALSE, ACAT_PREC); setcat(s,TRUE, TRUE); /* intialize fonts and load @FontDef symbol */ FontInit(); /* intialize current time and load @Moment symbol */ InitTime(); /* initialize filter module */ FilterInit(); /* initialize enviroment table module */ EnvInit(); /* initialise scope chain to <StartSym> */ PushScope(StartSym, FALSE, FALSE); /* initialise lexical analyser */ LexPush(FirstFile(SOURCE_FILE), 0, SOURCE_FILE, 1, FALSE); /* process input files */ InitParser(cross_db); t = NewToken(BEGIN, no_fpos, 0, 0, BEGIN_PREC, StartSym); res = Parse(&t, StartSym, TRUE, TRUE); debug0(DGT, D, "calling TransferEnd(res) from main()"); DisposeObject(CommandOptions); TransferEnd(res); TransferClose(); /* close various modules */ BackEnd->PrintAfterLastPage(); BackEnd->LinkCheck(); CrossClose(); CloseFiles(); /* remove any leftover filter temporary files */ FilterScavenge(TRUE); /* print word count, if required */ if( seen_wordcount ) Error(1, 29, "total of all words printed: %d", WARN,no_fpos,TotalWordCount); /* check for unbalanced error blocks */ CheckErrorBlocks(); /* wrapup */ ifdebug(DST, DD, CheckSymSpread() ); ifdebug(ANY, D, DeleteEverySym() ); debug0(DMA, D, "at end of run:"); ifdebug(DMA, D, DebugMemory() ); ifdebug(DPP, D, ProfileOff("main")); ifdebug(DPP, D, ProfilePrint()); ifdebug(DET, D, EnvDebug()); #if LOCALE_ON catclose(MsgCat); #endif exit(0); return 0; } /* end main */
void CgContext::StartGlobalScope() { // Create user's global scope: globalScope = new Scope( this ); PushScope( this, globalScope); } // StartGlobalScope
void ReadDefinitions(OBJECT *token, OBJECT encl, unsigned char res_type) { OBJECT t, res, res_target, export_list, import_list, link, y, z; OBJECT curr_encl; BOOLEAN compulsory_par, has_import_encl; t = *token; while( res_type==LOCAL || is_string(t, KW_NAMED) || is_string(t, KW_IMPORT) ) { curr_encl = encl; if( is_string(t, KW_LANGDEF) ) { ReadLangDef(encl); t = LexGetToken(); continue; /* next definition */ } else if( type(t) == PREPEND || type(t) == SYS_PREPEND ) { ReadPrependDef(type(t), encl); Dispose(t); t = LexGetToken(); continue; /* next definition */ } else if( type(t) == INCG_REPEATED || type(t) == SINCG_REPEATED ) { ReadIncGRepeatedDef(type(t), encl); Dispose(t); t = LexGetToken(); continue; /* next definition */ } else if( type(t) == DATABASE || type(t) == SYS_DATABASE ) { ReadDatabaseDef(type(t), encl); Dispose(t); t = LexGetToken(); continue; /* next definition */ } if( !is_string(t, KW_DEF) && !is_string(t, KW_MACRO) && !is_string(t, KW_NAMED) && !is_string(t, KW_IMPORT) && !is_string(t, KW_EXTEND) && !is_string(t, KW_EXPORT) ) break; /* get import or extend list and change scope appropriately */ BodyParNotAllowed(); New(import_list, ACAT); has_import_encl = FALSE; if( is_string(t, KW_IMPORT) ) { Dispose(t); t = LexGetToken(); while( type(t) == CLOSURE || (type(t)==WORD && !is_string(t,KW_EXPORT) && !is_string(t,KW_DEF) && !is_string(t, KW_MACRO) && !is_string(t, KW_NAMED)) ) { if( type(t) == CLOSURE ) { if( type(actual(t)) == LOCAL ) { /* *** letting this through now if( res_type == NPAR && has_par(actual(t)) ) { Error(5, 46, "named parameter import %s has parameters", WARN, &fpos(t), SymName(actual(t))); } else { *** */ PushScope(actual(t), FALSE, TRUE); if( actual(t) == encl ) has_import_encl = TRUE; Link(import_list, t); /* *** } *** */ } else { Error(5, 26, "import name expected here", WARN, &fpos(t)); Dispose(t); } } else { Error(5, 27, "import %s not in scope", WARN, &fpos(t), string(t)); Dispose(t); } t = LexGetToken(); } } else if( is_string(t, KW_EXTEND) ) { Dispose(t); t = LexGetToken(); while( type(t) == CLOSURE || (type(t)==WORD && !is_string(t,KW_EXPORT) && !is_string(t,KW_DEF) && !is_string(t, KW_MACRO)) ) { if( type(t) == CLOSURE ) { if( imports(actual(t)) != nilobj ) { Error(5, 48, "%s has %s clause, so cannot be extended", WARN, &fpos(t), SymName(actual(t)), KW_IMPORT); } else if( type(actual(t)) == LOCAL ) { PushScope(actual(t), FALSE, FALSE); curr_encl = actual(t); debug1(DRD, D, " curr_encl = %s", SymName(curr_encl)); Link(import_list, t); } else { Error(5, 28, "%s symbol name expected here", WARN, &fpos(t), KW_EXTEND); Dispose(t); } } else { Error(5, 29, "extend symbol %s not in scope", WARN,&fpos(t),string(t)); Dispose(t); } t = LexGetToken(); } } /* get export list and store for setting visible flags below */ New(export_list, ACAT); if( is_string(t, KW_EXPORT) ) { Dispose(t); SuppressScope(); t = LexGetToken(); while( is_word(type(t)) && !is_string(t, KW_DEF) && !is_string(t, KW_IMPORT) && !is_string(t, KW_MACRO) && !is_string(t, KW_EXTEND) ) { Link(export_list, t); t = LexGetToken(); } UnSuppressScope(); } if( res_type == LOCAL && !is_string(t, KW_DEF) && !is_string(t, KW_MACRO) ) { Error(5, 30, "keyword %s or %s expected here", WARN, &fpos(t), KW_DEF, KW_MACRO); break; } if( res_type == NPAR && !is_string(t, KW_NAMED) ) { Error(5, 31, "keyword %s expected here", WARN, &fpos(t), KW_NAMED); break; } if( is_string(t, KW_MACRO) ) { if( Down(export_list) != export_list ) Error(5, 32, "ignoring export list of macro", WARN, &fpos(t)); res = ReadMacro(&t, curr_encl, encl); } else { SuppressScope(); Dispose(t); t = LexGetToken(); /* check for compulsory keyword */ if( res_type == NPAR && is_string(t, KW_COMPULSORY) ) { compulsory_par = TRUE; Dispose(t); t = LexGetToken(); } else compulsory_par = FALSE; /* find name of symbol and insert it */ if( !is_word(type(t)) ) { Error(5, 33, "symbol name expected here", WARN, &fpos(t)); debug1(ANY, D, "offending type is %s", Image(type(t))); UnSuppressScope(); *token = t; return; } res = InsertSym(string(t), res_type, &fpos(t), DEFAULT_PREC, FALSE, FALSE, 0, curr_encl, nilobj); if( curr_encl != encl ) visible(res) = TRUE; if( has_import_encl ) { imports_encl(res) = TRUE; debug1(DCE, D, " setting import_encl(%s) to TRUE", SymName(res)); } if( compulsory_par ) { has_compulsory(encl)++; is_compulsory(res) = TRUE; } Dispose(t); t = LexGetToken(); /* find alternative names for this symbol */ while( is_word(type(t)) && !is_string(t, KW_NAMED) && !is_string(t, KW_IMPORT) && !is_string(t, KW_FORCE) && !is_string(t, KW_INTO) && !is_string(t, KW_HORIZ) && !is_string(t, KW_PRECEDENCE) && !is_string(t, KW_ASSOC) && !is_string(t, KW_LEFT) && !is_string(t, KW_RIGHT) && !is_string(t, KW_BODY) && !is_string(t, KW_LBR) && !is_string(t, KW_BEGIN) ) { InsertAlternativeName(string(t), res, &fpos(t)); Dispose(t); t = LexGetToken(); } /* find force, if any */ if( is_string(t, KW_FORCE) ) { force_target(res) = TRUE; Dispose(t); t = LexGetToken(); if( !is_string(t, KW_INTO) && !is_string(t, KW_HORIZ) ) Error(5, 34, "%s expected here", WARN, &fpos(t), KW_INTO); } /* find horizontally, if any */ if( is_string(t, KW_HORIZ) ) { horiz_galley(res) = COLM; Dispose(t); t = LexGetToken(); /* *** want to allow KW_HORIZ with @Target form now if( !is_string(t, KW_INTO) ) Error(5, 35, "%s expected here", WARN, &fpos(t), KW_INTO); *** */ } /* find into clause, if any */ res_target = nilobj; if( is_string(t, KW_INTO) ) { UnSuppressScope(); Dispose(t); t = LexGetToken(); if( type(t) != LBR ) { Error(5, 36, "%s expected here", WARN, &fpos(t), KW_LBR); debug1(ANY, D, "offending type is %s", Image(type(t))); UnSuppressScope(); *token = t; return; } res_target = Parse(&t, curr_encl, FALSE, FALSE); SuppressScope(); if( t == nilobj ) t = LexGetToken(); } /* find precedence clause, if any */ if( is_string(t, KW_PRECEDENCE) ) { int prec = 0; UnSuppressScope(); Dispose(t); t = LexGetToken(); while( type(t) == WORD && decimaldigit(string(t)[0]) ) { prec = prec * 10 + digitchartonum(string(t)[0]); Dispose(t); t = LexGetToken(); } SuppressScope(); if( prec < MIN_PREC ) { Error(5, 37, "precedence is too low (%d substituted)", WARN, &fpos(t), MIN_PREC); prec = MIN_PREC; } else if( prec > MAX_PREC ) { Error(5, 38, "precedence is too high (%d substituted)", WARN, &fpos(t), MAX_PREC); prec = MAX_PREC; } precedence(res) = prec; } /* find associativity clause, if any */ if( is_string(t, KW_ASSOC) ) { UnSuppressScope(); Dispose(t); t = LexGetToken(); if( is_string(t, KW_LEFT) ) right_assoc(res) = FALSE; else if( !is_string(t, KW_RIGHT) ) Error(5, 39, "associativity altered to %s", WARN, &fpos(t), KW_RIGHT); SuppressScope(); Dispose(t); t = LexGetToken(); } /* find left parameter, if any */ if( is_string(t, KW_LEFT) ) { Dispose(t); t = LexGetToken(); if( type(t) != WORD ) { Error(5, 40, "cannot find %s parameter name", WARN, &fpos(t), KW_LEFT); debug1(ANY, D, "offending type is %s", Image(type(t))); UnSuppressScope(); *token = t; return; } InsertSym(string(t), LPAR, &fpos(t), DEFAULT_PREC, FALSE, FALSE, 0, res, nilobj); Dispose(t); t = LexGetToken(); } /* find named parameters, if any */ UnSuppressScope(); ReadDefinitions(&t, res, NPAR); /* find right or body parameter, if any */ if( is_string(t, KW_RIGHT) || is_string(t, KW_BODY) ) { has_body(res) = is_string(t, KW_BODY); SuppressScope(); Dispose(t); t = LexGetToken(); if( type(t) != WORD ) { Error(5, 41, "cannot find %s parameter name", WARN,&fpos(t),KW_RIGHT); debug1(ANY, D, "offending type is %s", Image(type(t))); UnSuppressScope(); *token = t; return; } InsertSym(string(t), RPAR, &fpos(t), DEFAULT_PREC, FALSE, FALSE, 0, res, nilobj); UnSuppressScope(); Dispose(t); t = LexGetToken(); } /* read local definitions and body */ if( res_target != nilobj ) InsertSym(KW_TARGET, LOCAL, &fpos(res_target), DEFAULT_PREC, FALSE, FALSE, 0, res, res_target); if( type(t) == WORD && StringEqual(string(t), KW_LBR) ) { z = NewToken(LBR, &fpos(t), 0, 0, LBR_PREC, StartSym); Dispose(t); t = z; } else if( type(t) == WORD && StringEqual(string(t), KW_BEGIN) ) { z = NewToken(BEGIN, &fpos(t), 0, 0, BEGIN_PREC, StartSym); Dispose(t); t = z; } else if( type(t) != LBR && type(t) != BEGIN ) Error(5, 42, "opening left brace or @Begin of %s expected", FATAL, &fpos(t), SymName(res)); if( type(t) == BEGIN ) actual(t) = res; PushScope(res, FALSE, FALSE); BodyParAllowed(); sym_body(res) = Parse(&t, res, TRUE, FALSE); /* set visible flag of the exported symbols */ for( link=Down(export_list); link != export_list; link=NextDown(link) ) { Child(y, link); z = SearchSym(string(y), StringLength(string(y))); if( z == nilobj || enclosing(z) != res ) Error(5, 43, "exported symbol %s is not defined in %s", WARN, &fpos(y), string(y), SymName(res)); else if( has_body(res) && type(z) == RPAR ) Error(5, 44, "body parameter %s may not be exported", WARN, &fpos(y), string(y)); else if( visible(z) ) Error(5, 45, "symbol %s exported twice", WARN, &fpos(y), string(y)); else visible(z) = TRUE; } DisposeObject(export_list); /* pop scope of res */ PopScope(); } /* pop import scopes and store imports in sym tab */ for( link=Down(import_list); link != import_list; link=NextDown(link) ) { PopScope(); } if( Down(import_list) == import_list || curr_encl != encl ) { DisposeObject(import_list); import_list = nilobj; } else { imports(res) = import_list; } BodyParAllowed(); if( t == nilobj ) t = LexGetToken(); } /* end while */ *token = t; return; } /* end ReadDefinitions */
static void ReadTokenList(OBJECT token, OBJECT res) { OBJECT t, xsym, new_par, imps, link, y; int scope_count, i; NextToken(t, res); for(;;) switch(type(t)) { case WORD: if( string(t)[0] == CH_SYMSTART ) Error(5, 11, "symbol %s unknown or misspelt", WARN, &fpos(t), string(t)); NextToken(t, res); break; case QWORD: NextToken(t, res); break; case VCAT: case HCAT: case ACAT: case CROSS: case FORCE_CROSS: case NULL_CLOS: case PAGE_LABEL: case BEGIN_HEADER: case END_HEADER: case SET_HEADER: case CLEAR_HEADER: case ONE_COL: case ONE_ROW: case WIDE: case HIGH: case HSHIFT: case VSHIFT: case HMIRROR: case VMIRROR: case HSCALE: case VSCALE: case HCOVER: case VCOVER: case SCALE: case KERN_SHRINK: case HCONTRACT: case VCONTRACT: case HLIMITED: case VLIMITED: case HEXPAND: case VEXPAND: case START_HVSPAN: case START_HSPAN: case START_VSPAN: case HSPAN: case VSPAN: case PADJUST: case HADJUST: case VADJUST: case ROTATE: case BACKGROUND: case RAW_VERBATIM: case VERBATIM: case CASE: case YIELD: case BACKEND: case XCHAR: case FONT: case SPACE: case YUNIT: case ZUNIT: case SET_CONTEXT: case GET_CONTEXT: case BREAK: case UNDERLINE: case UNDERLINE_COLOUR: case COLOUR: case TEXTURE: case OUTLINE: case LANGUAGE: case CURR_LANG: case CURR_FAMILY: case CURR_FACE: case CURR_YUNIT: case CURR_ZUNIT: case COMMON: case RUMP: case MELD: case INSERT: case ONE_OF: case NEXT: case PLUS: case MINUS: case TAGGED: case INCGRAPHIC: case SINCGRAPHIC: case PLAIN_GRAPHIC: case GRAPHIC: case LINK_SOURCE: case LINK_DEST: case LINK_DEST_NULL: case LINK_URL: case NOT_REVEALED: NextToken(t, res); break; case LUSE: case LVIS: case ENV: case USE: case DATABASE: case SYS_DATABASE: case PREPEND: case SYS_PREPEND: case INCG_REPEATED: case SINCG_REPEATED: case OPEN: Error(5, 12, "symbol %s not allowed in macro", WARN, &fpos(t), SymName(actual(t))); NextToken(t, res); break; case LBR: ReadTokenList(t, res); NextToken(t, res); break; case UNEXPECTED_EOF: Error(5, 13, "unexpected end of input", FATAL, &fpos(t)); break; case BEGIN: Error(5, 14, "%s not expected here", WARN, &fpos(t), SymName(actual(t))); NextToken(t, res); break; case RBR: if( type(token) != LBR ) Error(5, 15, "unmatched %s in macro", WARN, &fpos(t), KW_RBR); return; case END: if( type(token) != BEGIN ) Error(5, 16, "unmatched %s in macro", WARN, &fpos(t), KW_END); else { NextToken(t, res); if( type(t) != CLOSURE ) { if( type(t) == WORD && string(t)[0] == CH_SYMSTART ) Error(5, 17, "symbol %s unknown or misspelt", WARN, &fpos(t), string(t)); else Error(5, 18, "symbol name expected after %s", WARN,&fpos(t),KW_END); } else if( actual(token) != actual(t) ) Error(5, 19, "%s %s does not match %s %s", WARN, &fpos(t), SymName(actual(token)), KW_BEGIN, SymName(actual(t)), KW_END); } return; case CLOSURE: xsym = actual(t); PushScope(xsym, TRUE, FALSE); NextToken(t, res); PopScope(); if( type(t) == CROSS || type(t) == FORCE_CROSS ) { NextToken(t, res); break; } /* read named parameters */ while( type(t) == CLOSURE && enclosing(actual(t)) == xsym && type(actual(t)) == NPAR ) { new_par = t; NextToken(t, res); if( type(t) != LBR ) { if( type(t) == RBR ) { if( type(token) != LBR ) Error(5, 20, "unmatched %s in macro", WARN, &fpos(t), KW_RBR); return; } Error(5, 21, "%s must follow named parameter %s", WARN, &fpos(new_par), KW_LBR, SymName(actual(new_par))); break; } /* add import list of the named parameter to current scope */ scope_count = 0; imps = imports(actual(new_par)); if( imps != nilobj ) { for( link = Down(imps); link != imps; link = NextDown(link) ) { Child(y, link); PushScope(actual(y), FALSE, TRUE); scope_count++; } } /* read the body of the named parameter */ PushScope(actual(new_par), FALSE, FALSE); ReadTokenList(t, res); PopScope(); /* pop the scopes pushed for the import list */ for( i = 0; i < scope_count; i++ ) PopScope(); /* get next token, possibly another named parameter */ PushScope(xsym, TRUE, FALSE); NextToken(t, res); PopScope(); } /* read body parameter, if any */ if( has_body(xsym) ) { if( type(t) == LBR || type(t) == BEGIN ) { PushScope(xsym, FALSE, TRUE); PushScope(ChildSym(xsym, RPAR), FALSE, FALSE); if( type(t) == BEGIN ) actual(t) = xsym; ReadTokenList(t, res); PopScope(); PopScope(); NextToken(t, res); } else if( type(t) != RBR && type(t) != END ) Error(5, 22, "right parameter of %s must begin with %s", WARN, &fpos(t), SymName(xsym), KW_LBR); } break; default: Error(5, 23, "ReadTokenList: %s", INTERN, &fpos(t), Image(type(t))); break; } } /* end ReadTokenList */
int InitSymbolTable(CgStruct *Cg) { SourceLoc dummyLoc = { 0, 0 }; int ii, name; // Create the super-global scope and add predefined types and symbols: PushScope(NewScopeInPool(mem_CreatePool(0, 0))); UndefinedType = NewType(TYPE_BASE_UNDEFINED_TYPE | TYPE_CATEGORY_SCALAR, 0); CFloatType = NewType(TYPE_BASE_CFLOAT | TYPE_CATEGORY_SCALAR | TYPE_QUALIFIER_CONST, 1); CIntType = NewType(TYPE_BASE_CINT | TYPE_CATEGORY_SCALAR | TYPE_QUALIFIER_CONST, 1); VoidType = NewType(TYPE_BASE_VOID | TYPE_CATEGORY_SCALAR | TYPE_MISC_VOID, 0); FloatType = NewType(TYPE_BASE_FLOAT | TYPE_CATEGORY_SCALAR, 1); IntType = NewType(TYPE_BASE_INT | TYPE_CATEGORY_SCALAR, 1); BooleanType = NewType(TYPE_BASE_BOOLEAN | TYPE_CATEGORY_SCALAR, 1); CFloat1Type = NewPackedArrayType(CFloatType, 1, TYPE_QUALIFIER_CONST); CFloat2Type = NewPackedArrayType(CFloatType, 2, TYPE_QUALIFIER_CONST); CFloat3Type = NewPackedArrayType(CFloatType, 3, TYPE_QUALIFIER_CONST); CFloat4Type = NewPackedArrayType(CFloatType, 4, TYPE_QUALIFIER_CONST); CInt1Type = NewPackedArrayType(CIntType, 1, TYPE_QUALIFIER_CONST); CInt2Type = NewPackedArrayType(CIntType, 2, TYPE_QUALIFIER_CONST); CInt3Type = NewPackedArrayType(CIntType, 3, TYPE_QUALIFIER_CONST); CInt4Type = NewPackedArrayType(CIntType, 4, TYPE_QUALIFIER_CONST); Float1Type = NewPackedArrayType(FloatType, 1, 0); Float2Type = NewPackedArrayType(FloatType, 2, 0); Float3Type = NewPackedArrayType(FloatType, 3, 0); Float4Type = NewPackedArrayType(FloatType, 4, 0); Int1Type = NewPackedArrayType(IntType, 1, 0); Int2Type = NewPackedArrayType(IntType, 2, 0); Int3Type = NewPackedArrayType(IntType, 3, 0); Int4Type = NewPackedArrayType(IntType, 4, 0); Boolean1Type = NewPackedArrayType(BooleanType, 1, 0); Boolean2Type = NewPackedArrayType(BooleanType, 2, 0); Boolean3Type = NewPackedArrayType(BooleanType, 3, 0); Boolean4Type = NewPackedArrayType(BooleanType, 4, 0); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cfloat"), CFloatType, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cint"), CIntType, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, VOID_SY, VoidType, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, FLOAT_SY, FloatType, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, INT_SY, IntType, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, BOOLEAN_SY, BooleanType, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cfloat1"), CFloat1Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cfloat2"), CFloat2Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cfloat3"), CFloat3Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cfloat4"), CFloat4Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cint1"), CInt1Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cint2"), CInt2Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cint3"), CInt3Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "cint4"), CInt4Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "float1"), Float1Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "float2"), Float2Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "float3"), Float3Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "float4"), Float4Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "int1"), Int1Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "int2"), Int2Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "int3"), Int3Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "int4"), Int4Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "bool1"), Boolean1Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "bool2"), Boolean2Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "bool3"), Boolean3Type, TYPEDEF_S); AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "bool4"), Boolean4Type, TYPEDEF_S); FalseSymb = AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "false"), BooleanType, CONSTANT_S); TrueSymb = AddSymbol(&dummyLoc, CurrentScope, LookUpAddString(atable, "true"), BooleanType, CONSTANT_S); FalseSymb->details.con.value = 0; TrueSymb->details.con.value = 1; SetScalarTypeName(TYPE_BASE_NO_TYPE, LookUpAddString(atable, "***no-base-type***"), UndefinedType); SetScalarTypeName(TYPE_BASE_UNDEFINED_TYPE, LookUpAddString(atable, "***undefined-base-type***"), UndefinedType); SetScalarTypeName(TYPE_BASE_CFLOAT, LookUpAddString(atable, "cfloat"), CFloatType); SetScalarTypeName(TYPE_BASE_CINT, LookUpAddString(atable, "cint"), CIntType); SetScalarTypeName(TYPE_BASE_VOID, LookUpAddString(atable, "void"), VoidType); SetScalarTypeName(TYPE_BASE_FLOAT, LookUpAddString(atable, "float"), FloatType); SetScalarTypeName(TYPE_BASE_INT, LookUpAddString(atable, "int"), IntType); SetScalarTypeName(TYPE_BASE_BOOLEAN, LookUpAddString(atable, "bool"), BooleanType); name = LookUpAddString(atable, "***unknown-profile-base-type***"); for (ii = TYPE_BASE_FIRST_USER; ii <= TYPE_BASE_LAST_USER; ii++) SetScalarTypeName(ii, name, UndefinedType); // Add profile specific symbols and types: Cg->theHAL->RegisterNames(Cg->theHAL); AddAtom(atable, "<*** end hal specific atoms ***>"); // Initialize misc. other globals: CurrentDeclTypeSpecs.basetype = UndefinedType; CurrentDeclTypeSpecs.IsDerived = 0; CurrentDeclTypeSpecs.type = *UndefinedType; return 1; } // InitSymbolTable