Classes. Code Generation for Objects. Compiling Methods. Dynamic Dispatch. The Need for Dispatching CS412/CS413
|
|
- Hollie Bruce
- 6 years ago
- Views:
Transcription
1 Classes CS4/CS43 Introduction to Comilers Tim Teitelbaum Lecture : Imlementing Objects 8 March 5 Comonents ields/instance variables values ma dier rom object to object usuall mutable methods values shared b all objects o a class usuall immutable comonent visibilit: ublic/rivate/rotected CS 4/43 Sring 5 Introduction to Comilers CS 4/43 Sring 5 Introduction to Comilers Code Generation or Objects Methods Generating method Generating method calls (disatching) Constructors and destructors Fields Memor laout Generating to access ields Field alignment Comiling Methods Methods look like unctions, are te-checked like unctions what is dierent? Argument list: imlicit receiver argument Calling sequence: use disatch vector instead o juming to absolute address CS 4/43 Sring 5 Introduction to Comilers 3 CS 4/43 Sring 5 Introduction to Comilers 4 The Need or Disatching Eamle: interace Point { int (); int (); loat (); class ColoredPoint imlements Point { loat () { return sqrt(*+*); class imlements Point { loat () { return sqrt(*+*+z*z); Point ; i (cond) = new ColoredPoint(); else = new (); int n =.(); Comiler can t tell what to run when method is called! Dnamic Disatch Solution: disatch vector (disatch table, selector table ) Entries in the table are ointers to method Pointers are comuted dnamicall! I T <: S, then vector or objects o te S is a rei o vector or objects o te T object reerence object laout disatch vector method CS 4/43 Sring 5 Introduction to Comilers 5 CS 4/43 Sring 5 Introduction to Comilers 6
2 Wh It Works I S <: T and is a method o an object o te T, then Objects o te S inherit ; can be overridden b S Pointer to has same inde in the or te T and S! Staticall generate to look u ointer to method Pointer values determined dnamicall Point reerence laout z vector getz CS 4/43 Sring 5 Introduction to Comilers 7 Disatch Vector Looku Ever method has its own small integer inde Inde is used to look u method in disatch vector interace A { C <: B <: A void (); (); A class B imlements A { void () () { B,g,h void g() g() { void h() h() { C,g,h,e class C etends B { void e() e() { 3 CS 4/43 Sring 5 Introduction to Comilers 8 Disatch Vector Laouts Inde o is the same in an object o te T <: A Methods ma have multile imlementations For subclasses with unrelated tes I subclass overrides method To eecute a method i: Looku entr i in vector Eecute ointed to b entr value A B C g h g h e 3 Code Generation: Disatch Vectors Allocate one disatch vector er class Objects o same class eecute same method Staticall allocate disatch vectors.data LenList:.long _LenList_irst.long _LenList_rest.long _LenList_length CS 4/43 Sring 5 Introduction to Comilers 9 CS 4/43 Sring 5 Introduction to Comilers Interaces, Abstract Classes Classes deine a te and some values (methods) Interaces are ure object tes : no imlementation no disatch vector: onl a laout Abstract classes are halwa: deine some methods leave others unimlemented no objects (instances) o abstract class needed onl or concrete classes Method Arguments Methods have a secial variable (Java, C++: this) called the receiver object Historicall (Smalltalk): method calls thought o as messages sent to receivers Receiver object is (imlicit) argument to method class A { int int(int,, int int) ) { comile as int int(a this, int,int) ) { CS 4/43 Sring 5 Introduction to Comilers CS 4/43 Sring 5 Introduction to Comilers
3 Static Methods In Java, can declare methods static the have no receiver object Called eactl like al unctions don t need to enter into disatch vector don t need imlicit etra argument or receiver Treated as methods as wa o getting unctions inside the class scoe (access to module internals or semantic analsis) Not reall methods Code Generation: Method Calls Code or unction calls: re-call + ost-call Pre-unction-call : Save registers Push arameters Pre-method call: Save registers Push arameters Push receiver object reerence Looku method in disatch vector CS 4/43 Sring 5 Introduction to Comilers 3 CS 4/43 Sring 5 Introduction to Comilers 4 o.oo(,3); ea eb [eb+4] Eamle oo oo (object) () () ush $3 $3 ush $ $ ush %ea mov (%ea), %eb call call *4(%eb) add $, %es Object Laout Object consists o: Methods Fields Object laout consists o: Pointer to, which contains ointers to methods Fields laout (static data) () CS 4/43 Sring 5 Introduction to Comilers 5 CS 4/43 Sring 5 Introduction to Comilers 6 Allocation o Objects Objects can be stack- or hea-allocated Stack allocation: (C++) Point ; (stack) (static data) Inheritance and Object Laout Method coied down rom suerclass i not overridden b subclass Fields also inherited (needed b inherited in general) Hea: (C++) Point * = new Point; (Java) Point = new Point(); (stack) (hea) (static data) Inheritance: add ields, methods Etend laout Etend disatch vector A suerte object can be used whenever a subte object can be used CS 4/43 Sring 5 Introduction to Comilers 7 CS 4/43 Sring 5 Introduction to Comilers 8 3
4 Inheritance and Object Laout Code Sharing Shae class class Shae { Point LL, LL, UR; UR; void void (int which, Point ); ); class class ColoredRect etends Shae { int intcolor; void voidsetcolor(int col); col); color: int setcolor ColoredRect color: int setcolor Machine or Shae. Don t actuall have to co! Works with searate comilation: can inherit without suerclass source CS 4/43 Sring 5 Introduction to Comilers 9 CS 4/43 Sring 5 Introduction to Comilers Field Osets Osets o ields rom beginning o object known staticall, same or all subclasses Eamle: class Shae { Point LL LL /* /* 4 */ */,, UR; /* /* 8 */ */ void (int which, Point ); ); class ColoredRect etends Shae { Color c; c; /* /* */ */ void setcolor(color c_); Osets known or stack and hea allocated objects Field Alignment In man rocessors, a 3-bit load must be to an address divisible b 4, address o 64-bit load must be divisible b 8 In rest (e.g., Pentium), loads are aster i aligned -- avoids etra load Fields should be aligned c struct { int ; char c; int ; char d; int z; double e; d z e CS 4/43 Sring 5 Introduction to Comilers CS 4/43 Sring 5 Introduction to Comilers Accessing Fields Access ields o current object Access equivalent to this. Current method has this as argument Access ields o other objects Access o the orm o. In both cases: Use ointer to object Add oset to the ield Access o. deends on the kind o allocation o o Stack allocation: stack access (%eb + stack oset) Hea allocation: stack access + dereerence CS 4/43 Sring 5 Introduction to Comilers 3 Code Generation: Allocation Hea allocation: o = new C() Allocate hea sace or object Store ointer to disatch vector Stack allocation: Push object on stack Pointer to on stack ush $6 # 3 ields+ call call _GC_malloc mov $LenList_, (%ea) add $4, $4, %es sub sub $6, %es # 3 ields+ mov $LenList_, -4(%eb) CS 4/43 Sring 5 Introduction to Comilers 4 4
5 Constructors Java, C++: classes can declare object constructors that create new objects: new C(,, z) Other languages (Modula-3): objects constructed b new C ; no initialization class LenList { int len; Cell head, tail; LenList() { len = ; Need to know when objects are constructed Hea:new statement Stack:at the beginning o their scoe (blocks or locals, rocedures or arguments, rogram or globals) Comiling Constructors Comiled like methods: seudo-variable this assed to constructor return value is this l = new LenList(); LenList() { len = ; ush $6 $6 # 3 ields+ call call _GC_malloc mov $LenList_, (%ea) add add $4, $4, %es ush %ea call call LenList$constructor add add $4, $4, %es LenList$constructor: ush %eb mov %es,%eb mov 8(%eb), ea ea mov $, $, 4(%ea) mov %eb,%es o o %eb ret ret CS 4/43 Sring 5 Introduction to Comilers 5 CS 4/43 Sring 5 Introduction to Comilers 6 Destructors Analsis and Otimizations In some languages (e.g., C++), objects can also declare to eecute when objects are destructed Hea: when invoking delete (elicit de-allocation) Stack: when scoe o variables ends End o blocks or local variables End o rogram or global variables End o rocedure or unction arguments Datalow analsis reasons about variables and values Records (objects) consist o a collection o variables (ields) analsis must searatel kee track o individual ields Diicult analsis or hea-allocated objects Object lietime outlives rocedure lietime Need to erorm inter-rocedural analsis Constructors/destructors: must take their eects into account CS 4/43 Sring 5 Introduction to Comilers 7 CS 4/43 Sring 5 Introduction to Comilers 8 Class Hierarch Analsis Method calls = dnamic, via disatch vectors Overhead o going through Prohibits unction inlining Makes other inter-rocedural analses less recise Static analsis o dnamic method calls Determine ossible methods invoked at each call site Need to determine rincial tes o objects at each rogram oint (Class Hierarch Analsis) I analsis determines object o is alwas o te T (not subte), then it recisel knows the or o.oo() Otimizations: transorm dnamic method calls into static calls, inline method calls Summar Method disatch accomlished using disatch vector, imlicit method receiver argument No disatch o static methods needed Inheritance causes etension o ields as well as methods; can be shared Field alignment: declaration order matters! Each real class has a single disatch vector in data segment: installed at object creation or constructor Analsis more diicult in the resence o objects Class hierarch analsis = recisel determine object class CS 4/43 Sring 5 Introduction to Comilers 9 CS 4/43 Sring 5 Introduction to Comilers 3 5
Classes. Compiling Methods. Code Generation for Objects. Implementing Objects. Methods. Fields
Classes Implementing Objects Components fields/instance variables values differ from to usuall mutable methods values shared b all s of a class usuall immutable component visibilit: public/private/protected
More informationSimple example. Analysis of programs with pointers. Points-to relation. Program model. Points-to graph. Ordering on points-to relation
Simle eamle Analsis of rograms with ointers := 5 tr := @ *tr := 9 := rogram S1 S2 S3 S4 deendences What are the deendences in this rogram? Problem: just looking at variable names will not give ou the correct
More informationCompiler construction
This lecture Compiler construction Lecture 5: Project etensions Magnus Mreen Spring 2018 Chalmers Universit o Technolog Gothenburg Universit Some project etensions: Arras Pointers and structures Object-oriented
More informationDefinition. Pointers. Outline. Why pointers? Definition. Memory Organization Overview. by Ziad Kobti. Definition. Pointers enable programmers to:
Pointers by Ziad Kobti Deinition When you declare a variable o any tye, say: int = ; The system will automatically allocated the required memory sace in a seciic location (tained by the system) to store
More informationWho. Winter Compiler Construction Generic compiler structure. Mailing list and forum. IC compiler. How
Winter 2007-2008 Comiler Construction 0368-3133 Mooly Sagiv and Roman Manevich School of Comuter Science Tel-Aviv University Who Roman Manevich Schreiber Oen-sace (basement) Tel: 640-5358 rumster@ost.tau.ac.il
More informationObject Oriented Languages. Hwansoo Han
Object Oriented Languages Hwansoo Han Object-Oriented Languages An object is an abstract data tpe Encapsulates data, operations and internal state behind a simple, consistent interface. z Data Code Data
More informationStorage Allocation CSE 143. Pointers, Arrays, and Dynamic Storage Allocation. Pointer Variables. Pointers: Review. Pointers and Types
CSE 143 Pointers, Arrays, and Dynamic Storage Allocation [Chater 4,. 148-157, 172-177] Storage Allocation Storage (memory) is a linear array of cells (bytes) Objects of different tyes often reuire differing
More informationModule Mechanisms CS412/413. Modules + abstract types. Abstract types. Multiple Implementations. How to type-check?
CS412/413 Introduction to Compilers and Translators Andrew Mers Cornell Universit Lecture 19: ADT mechanisms 10 March 00 Module Mechanisms Last time: modules, was to implement ADTs Module collection of
More informationReview. Type equivalence. Java declarations. Type equivalence. Declared vs. implicit subtyping. CS 412 Introduction to Compilers
CS 412 Introdution to Comilers Andrew Mers Cornell Universit Leture 21: Subting 16 Marh 01 Review Multile imlementations suorted b subting Subting harateried b new judgement: S
More informationAnnouncements. CSCI 334: Principles of Programming Languages. Lecture 19: C++
Announcements CSCI 4: Principles of Programming Languages Lecture 19: C++ HW8 pro tip: the HW7 solutions have a complete, correct implementation of the CPS version of bubble sort in SML. All ou need to
More informationProgramming Language Dilemma Fall 2002 Lecture 1 Introduction to Compilation. Compilation As Translation. Starting Point
Programming Language Dilemma 6.035 Fall 2002 Lecture 1 Introduction to Compilation Martin Rinard Laborator for Computer Science Massachusetts Institute of Technolog Stored program computer How to instruct
More informationImplementing Object-Oriented Languages. Implementing instance variable access. Implementing dynamic dispatching (virtual functions)
Implementing Object-Oriented Languages Implementing instance variable access Ke features: inheritance (possibl multiple) subtping & subtpe polmorphism message passing, dnamic binding, run-time tpe testing
More informationCS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 17: Types and Type-Checking 25 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 What Are Types? Types describe the values possibly
More informationLecture06: Pointers 4/1/2013
Lecture06: Pointers 4/1/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C 1 Pointers A ointer is a variable that contains the (memory) address of another variable What is a memory address?
More informationRemember: The equation of projection. Imaging Geometry 1. Basic Geometric Coordinate Transforms. C306 Martin Jagersand
Imaging Geometr 1. Basic Geometric Coordinate Transorms emember: The equation o rojection Cartesian coordinates: (,, z) ( z, z ) C36 Martin Jagersand How do we develo a consistent mathematical ramework
More informationThe code generator must statically assign a location in the AR for each temporary add $a0 $t1 $a0 ; $a0 = e 1 + e 2 addiu $sp $sp 4 ; adjust $sp (!
Lecture Outline Code Generation (II) Adapted from Lectures b Profs. Ale Aiken and George Necula (UCB) Allocating temporaries in the Activation Record Let s optimie cgen a little Code generation for OO
More informationRecords. ADTs. Objects as Records. Objects as ADTs. Objects CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 15: Objects 25 Feb 05
Records CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 15: Objects 25 Feb 05 Objects combine features of records and abstract data types Records = aggregate data structures Combine several
More informationTypical Compiler. Ahead- of- time compiler. Compilers... that target interpreters. Interpreter 12/9/15. compile time. run time
Ahead- of- time Tpical Compiler compile time C source C 86 assembl 86 assembler 86 machine Source Leical Analzer Snta Analzer Semantic Analzer Analsis Intermediate Code Generator Snthesis run time 86 machine
More informationPointers and Memory Allocation p. 1. Brooklyn College. Michael Lampis. CISC 3130 Notes. Pointers and Memory Allocation
Pointers and Memory Allocation CISC 3130 Notes Michael Lamis mlamis@cs.ntua.gr Brooklyn College Pointers and Memory Allocation. 1 int x; Pointers x Pointers and Memory Allocation. 2 Pointers int x; int
More informationPointers CMPE-013/L. Pointers. Pointers What do they do? Pointers What are pointers? Gabriel Hugh Elkaim Winter 2014
CMPE-013/L A Variable's versus A Variable's Value In some situations, we will want to work with a variable's address in memor, rather than the value it contains Gabriel Hugh Elkaim Winter 2014 Variable
More informationCS S-11 Memory Management 1
CS414-2017S-11 Management 1 11-0: Three places in memor that a program can store variables Call stack Heap Code segment 11-1: Eecutable Code Code Segment Static Storage Stack Heap 11-2: Three places in
More informationCS 450: COMPUTER GRAPHICS 2D TRANSFORMATIONS SPRING 2016 DR. MICHAEL J. REALE
CS 45: COMUTER GRAHICS 2D TRANSFORMATIONS SRING 26 DR. MICHAEL J. REALE INTRODUCTION Now that we hae some linear algebra under our resectie belts, we can start ug it in grahics! So far, for each rimitie,
More informationLecture 04 Control Flow II. Stephen Checkoway University of Illinois at Chicago CS 487 Fall 2017 Based on Michael Bailey s ECE 422
Lecture 04 Control Flow II Stehen Checkoway University of Illinois at Chicago CS 487 Fall 2017 Based on Michael Bailey s ECE 422 Function calls on 32-bit x86 Stack grows down (from high to low addresses)
More informationLinear Data Structure Linked List
. Definition. Reresenting List in C. Imlementing the oerations a. Inserting a node b. Deleting a node c. List Traversal. Linked imlementation of Stack 5. Linked imlementation of Queue 6. Circular List
More informationCS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE
CS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 05 DR. MICHAEL J. REALE OPENGL POINTS AND LINES OPENGL POINTS AND LINES In OenGL, there are different constants used to indicate what ind of rimitive
More informationSemantics. Names. Binding Time
/24/ CSE 3302 Programming Languages Semantics Chengkai Li, Weimin He Spring Names Names: identif language entities variables, procedures, functions, constants, data tpes, Attributes: properties of names
More informationComputer Graphics. Computer Graphics. Lecture 3 Line & Circle Drawing
Comuter Grahics Comuter Grahics Lecture 3 Line & Circle Drawing Comuter Grahics Towards the Ideal Line We can onl do a discrete aroimation Illuminate iels as close to the true ath as ossible, consider
More informationGabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming
1 CMPE 013/L Gabriel Hugh Elkaim Sring 2013 2 A Variable's versus A Variable's Value In some situations, we will want to work with a variable's address in memor, rather than the value it contains Variable
More informationC++ Addendum: Inheritance of Special Member Functions. Constructors Destructor Construction and Destruction Order Assignment Operator
C++ Addendum: Inheritance of Special Member Functions Constructors Destructor Construction and Destruction Order Assignment Operator What s s Not Inherited? The following methods are not inherited: Constructors
More informationSemantics (cont.) Symbol Table. Static Scope. Static Scope. Static Scope. CSE 3302 Programming Languages. Static vs. Dynamic Scope
-2-1 CSE 3302 Programming Languages Semantics (cont.) Smbol Table Smbol Table: maintain bindings. Can be viewed as functions that map names to their attributes. Names SmbolTable Attributes Chengkai Li,
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationCS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE
CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate
More informationLecture 3: C Programm
0 3 E CS 1 Lecture 3: C Programm ing Reading Quiz Note the intimidating red border! 2 A variable is: A. an area in memory that is reserved at run time to hold a value of particular type B. an area in memory
More informationCS 1613 Lecture 24. Figure 1. Program p01.
Consider a rogram that is required to find all values larger than the average in a list of integers. The list is stored in a file. The rogram must read and store the list to fulfill its requirement. The
More informationCS153: Compilers Lecture 11: Compiling Objects
CS153: Compilers Lecture 11: Compiling Objects Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 3 due today Project 4 out Due Thursday Oct 25 (16 days) Project 5 released
More informationData, memory. Pointers and Dynamic Variables. Example. Pointers Variables (or Pointers) Fall 2018, CS2
Data, memor Pointers and Dnamic Variables Fall 2018, CS2 memor address: ever bte is identified b a numeric address in the memor. a data value requiring multiple btes are stored consecutivel in memor cells
More informationStatus. We ll do code generation first... Outline
Status Run-time Environments Lecture 11 We have covered the ront-end phases Lexical analysis Parsin Semantic analysis Next are the back-end phases Optimization Code eneration We ll do code eneration irst...
More informationEquality-Based Translation Validator for LLVM
Equality-Based Translation Validator for LLVM Michael Ste, Ross Tate, and Sorin Lerner University of California, San Diego {mste,rtate,lerner@cs.ucsd.edu Abstract. We udated our Peggy tool, reviously resented
More informationCS5620 Intro to Computer Graphics
CS560 Reminder - Pieline Polgon at [(,9), (5,7), (8,9)] Polgon at [ ] D Model Transformations Reminder - Pieline Object Camera Cli Normalied device Screen Inut: Polgons in normalied device Model-view Projection
More information7. Extensions and Annotations. Prof. Nagl, Informatik 3 (Software Engineering)
7. Extensions and Annotations 1 Extensions and Annotations Aims Further imortant asects yielding to extensions o / annotations to architectural languages: not urther isolated view but details o ex. architecture
More informationWritten by John Bell for CS 342, Spring 2018
Advanced OO Concepts Written by John Bell for CS 342, Spring 2018 Based on chapter 3 of The Object-Oriented Thought Process by Matt Weisfeld, with additional material from other sources. Constructors Constructors
More informationG52CPP C++ Programming Lecture 10. Dr Jason Atkin
G52CPP C++ Programming Lecture 10 Dr Jason Atkin 1 Last lecture Constructors Default constructor needs no parameters Default parameters Inline functions Like safe macros in some ways Function definitions
More informationPointers (1A) Young Won Lim 12/4/17
Pointers (1A) Coyright (c) 2010-2017 Young W. Lim. Permission is granted to coy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More informationOptimizing Dynamic Memory Management!
Otimizing Dynamic Memory Management! 1 Goals of this Lecture! Hel you learn about:" Details of K&R hea mgr" Hea mgr otimizations related to Assignment #6" Faster free() via doubly-linked list, redundant
More informationSimple example. Analysis of programs with pointers. Program model. Points-to relation
Simple eample Analsis of programs with pointers := 5 ptr := & *ptr := 9 := program S1 S2 S3 S4 What are the defs and uses of in this program? Problem: just looking at variable names will not give ou the
More informationExample: Runtime Memory Allocation: Example: Dynamical Memory Allocation: Some Comments: Allocate and free dynamic memory
Runtime Memory Allocation: Examle: All external and static variables Global systemcontrol Suose we want to design a rogram for handling student information: tyedef struct { All dynamically allocated variables
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationOptional: Building a processor from scratch
Optional: Building a processor from scratch In this assignment we are going build a computer processor from the ground up, starting with transistors, and ending with a small but powerful processor. The
More information(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University
(12-1) OOP: Polymorphism in C++ D & D Chapter 12 Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University Key Concepts Polymorphism virtual functions Virtual function tables
More informationToday s lecture. CS 314 fall 01 C++ 1, page 1
Today s lecture Midterm Thursday, October 25, 6:10-7:30pm general information, conflicts Object oriented programming Abstract data types (ADT) Object oriented design C++ classes CS 314 fall 01 C++ 1, page
More informationToday's Topics. CISC 458 Winter J.R. Cordy
Today's Topics Last Time Semantics - the meaning of program structures Stack model of expression evaluation, the Expression Stack (ES) Stack model of automatic storage, the Run Stack (RS) Today Managing
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More informationCS250 Final Review Questions
CS250 Final Review Questions The following is a list of review questions that you can use to study for the final. I would first make sure you review all previous exams and make sure you fully understand
More informationIntroduction to Shape and Pointer Analysis
Introduction to Shape and Pointer Analsis CS 502 Lecture 11 10/30/08 Some slides adapted from Nielson, Nielson, Hankin Principles of Program Analsis Analsis of the Heap Thus far, we have focussed on control
More informationInheritance, Polymorphism and the Object Memory Model
Inheritance, Polymorphism and the Object Memory Model 1 how objects are stored in memory at runtime? compiler - operations such as access to a member of an object are compiled runtime - implementation
More informationDesign issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?
Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables
More informationCS 132 Compiler Construction, Fall 2011 Instructor: Jens Palsberg Multiple Choice Exam, Dec 6, 2011
CS 132 Compiler Construction, Fall 2011 Instructor: Jens Palsberg Multiple Choice Eam, Dec 6, 2011 ID Name This eam consists of 22 questions. Each question has four options, eactl one of which is correct,
More informationAdministrivia. CMSC433, Fall 2001 Programming Language Technology and Paradigms. Administrivia (cont.) Project 1. Copy constructor.
CMSC433, Fall 2001 Programming Language Technology and Paradigms Alan Sussman September 4, 2001 Administrivia Quiz answers posted on Exams web page C++ readings from textbook posted on Readings web page
More informationCS252 Graduate Computer Architecture Spring 2014 Lecture 6: Modern Out- of- Order Processors
CS252 Graduate Comuter Architecture Sring 2014 Lecture 6: Modern Out- of- Order Processors Krste Asanovic krste@eecs.berkeley.edu htt://inst.eecs.berkeley.edu/~cs252/s14 CS252, Sring 2014, Lecture 6 Last
More informationChapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures
Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of
More informationMonday, September 28, 2015
Monda, September 28, 2015 Topics for toda Chapter 6: Mapping High-level to assembl-level The Pep/8 run-time stack (6.1) Stack-relative addressing (,s) SP manipulation Stack as scratch space Global variables
More informationC++ Inheritance and Encapsulation
C++ Inheritance and Encapsulation Private and Protected members Inheritance Type Public Inheritance Private Inheritance Protected Inheritance Special method inheritance 1 Private Members Private members
More informationEMBEDDED SYSTEMS PROGRAMMING OO Basics
EMBEDDED SYSTEMS PROGRAMMING 2014-15 OO Basics CLASS, METHOD, OBJECT... Class: abstract description of a concept Object: concrete realization of a concept. An object is an instance of a class Members Method:
More informationIntroduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1
Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Inheritance Consider a new type Square. Following how we declarations for the Rectangle and Circle classes we could declare it as follows:
More informationConstructors and Destructors. OOC 4 th Sem, B Div Prof. Mouna M. Naravani
Constructors and Destructors OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani A constructor guarantees that an object created by the class will be initialized automatically. Ex: create an object integer
More informationRegister Allocation 3/16/11. What a Smart Allocator Needs to Do. Global Register Allocation. Global Register Allocation. Outline.
What a Smart Allocator Needs to Do Register Allocation Global Register Allocation Webs and Graph Coloring Node Splitting and Other Transformations Determine ranges for each variable can benefit from using
More informationData Abstraction. Hwansoo Han
Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed
More informationSemantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 13: Types and Type-Checking 19 Feb 07 Semantic Analysis Last time: Semantic errors related to scopes Symbol tables Name resolution This lecture:
More informationPointers, Arrays and Parameters
Pointers, Arrays and Parameters This exercise is different from our usual exercises. You don t have so much a problem to solve by creating a program but rather some things to understand about the programming
More informationG52CPP C++ Programming Lecture 13
G52CPP C++ Programming Lecture 13 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture Function pointers Arrays of function pointers Virtual and non-virtual functions vtable and
More information! A data structure representing a list. ! A series of nodes chained together in sequence. ! A separate pointer (the head) points to the first
Ch. 17: Linked Lists 17.1 Introduction to Linked Lists! A data structure reresenting a list! A series of nodes chained together in sequence CS 2308 Sring 2015 Jill Seaman - Each node oints to one other
More informationDerived and abstract data types. TDT4205 Lecture 15
1 Derived and abstract data types TDT4205 Lecture 15 2 Where we were We ve looked at static semantics for primitive types and how it relates to type checking We ve hinted at derived types using a multidimensional
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationG Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 9 Robert Grimm, New York University 1 Review Last week Modules 2 Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More information2. The object-oriented paradigm!
2. The object-oriented paradigm! Plan for this section:! n Look at things we have to be able to do with a programming language! n Look at Java and how it is done there" Note: I will make a lot of use of
More informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More informationLecture 7: Objects (Chapter 15) CS 1110 Introduction to Computing Using Python
htt://www.cs.cornell.edu/courses/cs1110/2018s Lecture 7: Objects (Chater 15) CS 1110 Introduction to Comuting Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]
More informationPOLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors
POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual
More informationPOLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE
Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public
More informationVIRTUAL FUNCTIONS Chapter 10
1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions
More informationObject-Oriented Programming
Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object
More informationSo far, system calls have had easy syntax. Integer, character string, and structure arguments.
Pointers Page 1 So far, system calls have had easy syntax Wednesday, September 30, 2015 10:45 AM Integer, character string, and structure arguments. But this is not always true. Today, we begin to explore
More informationSemantic Analysis and Type Checking
Semantic Analysis and Type Checking The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the program based on
More informationCS 61B Discussion 5: Inheritance II Fall 2014
CS 61B Discussion 5: Inheritance II Fall 2014 1 WeirdList Below is a partial solution to the WeirdList problem from homework 3 showing only the most important lines. Part A. Complete the implementation
More informationCascade 2.0. C static analysis tool with an SMT backend. Wei Wang, Clark Barrett, Thomas Wies
Cascade 2.0 C static analysis tool with an SMT backend Wei Wang, Clark Barrett, Thomas Wies htt://cascade.cims.nyu.edu Overview Memory models Flat memory model Burstall memory model Partition memory model
More informationCompiler Construction Lent Term 2015 Lectures 10, 11 (of 16)
Compiler Construction Lent Term 15 Lectures 10, 11 (of 16) 1. Slang.2 (Lecture 10) 1. In lecture code walk of slang2_derive 2. Assorted topics (Lecture 11) 1. Exceptions 2. Objects 3. Stacks vs. Register
More informationBidirectional Object Layout for Separate Compilation
Proceedings of the 1995 AM onference on Object-Oriented Programming Sstems, Languages, and Applications (OOPSLA) Bidirectional Object Laout for Separate ompilation Andrew. Mers MI Laborator for omputer
More informationThe compilation process is driven by the syntactic structure of the program as discovered by the parser
Semantic Analysis The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the program based on its syntactic structure
More informationPre-defined class JFrame. Object & Class an analogy
CS1M Lecture 17 Mar 29, 25 1 Announcements: Project 4 due Sunda 4/3 at 6pm Use Keboard class or reading input Section in classrooms this week Previous Lecture: Selection statement Reading input using Keboard
More informationCSC 1214: Object-Oriented Programming
CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:
More informationAlgorithms & Data Structures
GATE- 2016-17 Postal Correspondence 1 Algorithms & Data Structures Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key
More informationCSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community
CSCI-12 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community http://csc.cs.rit.edu 1. Provide a detailed explanation of what the following code does: 1 public boolean checkstring
More informationJAVA MOCK TEST JAVA MOCK TEST II
http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More information14. Memory API. Operating System: Three Easy Pieces
14. Memory API Oerating System: Three Easy Pieces 1 Memory API: malloc() #include void* malloc(size_t size) Allocate a memory region on the hea. w Argument size_t size : size of the memory block(in
More informationBasic Types and Arrays. Pointers. Records and Pointers. Record Definition. Creating a Record. Pointer. Basic Types. Arrays
Basic Tyes and Arrays ointers SE 6 Data Structures Lecture Basic Tyes integer, real (floating oint), boolean (0,), character Arrays A[099] : integer array A 0 6 7 99 A[] /9/0 ointers and Lists- Lecture
More informationSee the CS 2704 notes on C++ Class Basics for more details and examples. Data Structures & OO Development I
Polynomial Class Polynomial(); Polynomial(const string& N, const vector& C); Polynomial operator+(const Polynomial& RHS) const; Polynomial operator-(const Polynomial& RHS) const; Polynomial operator*(const
More informationC++ (classes) Hwansoo Han
C++ (classes) Hwansoo Han Inheritance Relation among classes shape, rectangle, triangle, circle, shape rectangle triangle circle 2 Base Class: shape Members of a class Methods : rotate(), move(), Shape(),
More informationJava and C CSE 351 Spring
Java and C CSE 351 Spring 2018 https://xkcd.com/801/ Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: get_mpg: pushq
More information