/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// FORMS.CPP - Definitions for ADL Parser Generic & Utility Forms Classes #include"adlc.hpp"
//------------------------------Static Initializers---------------------------- // allocate arena used by forms
AdlArena *Form::arena = Form::generate_arena(); // = Form::generate_arena();
AdlArena *Form::generate_arena() { return (new AdlArena);
}
// Constructor and Destructor
NameList::NameList() : _cur(0), _max(4), _iter(0), _justReset(true) {
_names = (constchar**) AdlAllocateHeap(_max*sizeof(char*));
}
NameList::~NameList() { // The following free is a double-free, and crashes the program: //free(_names); // not owner of strings
}
// Return 'true' if current entry is signal bool NameList::current_is_signal() { constchar *entry = current(); return is_signal(entry);
}
// Return true if entry is a signal bool NameList::is_signal(constchar *entry) { return ( (strcmp(entry,NameList::_signal) == 0) ? true : false);
}
// Search for a name in the list bool NameList::search(constchar *name) { constchar *entry; for(reset(); (entry = iter()) != NULL; ) { if(!strcmp(entry,name)) returntrue;
} returnfalse;
}
// Return index of name in list int NameList::index(constchar *name) { int cnt = 0; constchar *entry; for(reset(); (entry = iter()) != NULL; ) { if(!strcmp(entry,name)) return cnt;
cnt++;
} return Not_in_list;
}
// Return name at index in list constchar *NameList::name(intptr_t index) { return ( index < _cur ? _names[index] : NULL);
}
//------------------------------NameAndList------------------------------------ // Storage for a name and an associated list of names
NameAndList::NameAndList(char *name) : _name(name) {
}
NameAndList::~NameAndList() {
}
// Add to entries in list void NameAndList::add_entry(constchar *entry) {
_list.addName(entry);
}
// Access the name and its associated list. constchar *NameAndList::name() const { return _name; } void NameAndList::reset() { _list.reset(); } constchar *NameAndList::iter() { return _list.iter(); }
// Return the "index" entry in the list, zero-based constchar *NameAndList::operator[](int index) {
assert( index >= 0, "Internal Error(): index less than 0.");
_list.reset(); constchar *entry = _list.iter(); // Iterate further if it isn't at index 0. for ( int position = 0; position != index; ++position ) {
entry = _list.iter();
}
if (strcmp(name,"ConI")==0) return Form::idealI; if (strcmp(name,"ConP")==0) return Form::idealP; if (strcmp(name,"ConN")==0) return Form::idealN; if (strcmp(name,"ConNKlass")==0) return Form::idealNKlass; if (strcmp(name,"ConL")==0) return Form::idealL; if (strcmp(name,"ConF")==0) return Form::idealF; if (strcmp(name,"ConD")==0) return Form::idealD; if (strcmp(name,"Bool")==0) return Form::idealI;
if (strcmp(name,"sRegI")==0) return Form::idealI; if (strcmp(name,"sRegP")==0) return Form::idealP; if (strcmp(name,"sRegF")==0) return Form::idealF; if (strcmp(name,"sRegD")==0) return Form::idealD; if (strcmp(name,"sRegL")==0) return Form::idealL; return Form::none;
}
if (strcmp(name,"RegI")==0) return Form::idealI; if (strcmp(name,"RegP")==0) return Form::idealP; if (strcmp(name,"RegF")==0) return Form::idealF; if (strcmp(name,"RegD")==0) return Form::idealD; if (strcmp(name,"RegL")==0) return Form::idealL;
//------------------------------FormList--------------------------------------- // Destructor
FormList::~FormList() { // // This list may not own its elements // Form *cur = _root; // Form *next = NULL; // for( ; (cur = next) != NULL; ) { // next = (Form *)cur->_next; // delete cur; // }
};
// Return # of name-Form pairs in dict int FormDict::Size(void) const { return _form.Size();
}
// Insert inserts the given key-value pair into the dictionary. The prior // value of the key is returned; NULL if the key was not previously defined. const Form *FormDict::Insert(constchar *name, Form *form) { return (Form*)_form.Insert((void*)name, (void*)form);
}
// Finds the value of a given key; or NULL if not found. // The dictionary is NOT changed. const Form *FormDict::operator [](constchar *name) const { return (Form*)_form[name];
}
//------------------------------FormDict::private------------------------------ // Disable public use of constructor, copy-ctor, operator =, operator ==
FormDict::FormDict( ) : _form(cmpkey,hashkey) {
assert( false, "NotImplemented");
}
FormDict::FormDict( const FormDict & fd) : _form(fd._form) {
}
FormDict &FormDict::operator =( const FormDict &rhs) {
assert( false, "NotImplemented");
_form = rhs._form; return *this;
} // == compares two dictionaries; they must have the same keys (their keys // must match using CmpKey) and they must have the same values (pointer // comparison). If so 1 is returned, if not 0 is returned. bool FormDict::operator ==(const FormDict &d) const {
assert( false, "NotImplemented"); returnfalse;
}
// Print out the dictionary contents as key-value pairs staticvoid dumpkey (constvoid* key) { fprintf(stdout, "%s", (char*) key); } staticvoid dumpform(constvoid* form) { fflush(stdout); ((Form*)form)->dump(); }
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.