Decaf Compiler
Classes | Macros | Typedefs | Functions
p3-analysis.c File Reference

Compiler phase 3: static analysis. More...

#include "p3-analysis.h"

Classes

struct  AnalysisData
 State/data for static analysis visitor. More...
 

Macros

#define DATA   ((AnalysisData*)visitor->data)
 Macro for more convenient access to the data inside a AnalysisVisitor data structure.
 
#define ERROR_LIST   (((AnalysisData*)visitor->data)->errors)
 Macro for more convenient access to the error list inside a AnalysisVisitor data structure.
 
#define SET_INFERRED_TYPE(T)
 Macro for shorter storing of the inferred type attribute. More...
 
#define GET_INFERRED_TYPE(N)   (DecafType)(long)ASTNode_get_attribute(N, "type")
 Macro for shorter retrieval of the inferred type attribute.
 

Typedefs

typedef struct AnalysisData AnalysisData
 State/data for static analysis visitor.
 

Functions

AnalysisDataAnalysisData_new ()
 Allocate memory for analysis data. More...
 
void AnalysisData_free (AnalysisData *data)
 Deallocate memory for analysis data. More...
 
Symbollookup_symbol_with_reporting (NodeVisitor *visitor, ASTNode *node, const char *name)
 Wrapper for lookup_symbol that reports an error if the symbol isn't found. More...
 
ErrorListanalyze (ASTNode *tree)
 Perform static analysis on an AST and return a list of errors. More...
 

Detailed Description

Compiler phase 3: static analysis.

Macro Definition Documentation

◆ SET_INFERRED_TYPE

#define SET_INFERRED_TYPE (   T)
Value:

Macro for shorter storing of the inferred type attribute.

Function Documentation

◆ AnalysisData_free()

void AnalysisData_free ( AnalysisData data)

Deallocate memory for analysis data.

Parameters
dataPointer to the structure to be deallocated

◆ AnalysisData_new()

AnalysisData* AnalysisData_new ( )

Allocate memory for analysis data.

Returns
Pointer to allocated structure

◆ analyze()

ErrorList* analyze ( ASTNode tree)

Perform static analysis on an AST and return a list of errors.

Parameters
treeRoot of AST
Returns
List of static analysis errors found (the list should be empty if no errors were found)

◆ lookup_symbol_with_reporting()

Symbol* lookup_symbol_with_reporting ( NodeVisitor visitor,
ASTNode node,
const char *  name 
)

Wrapper for lookup_symbol that reports an error if the symbol isn't found.

Parameters
visitorVisitor with the error list for reporting
nodeAST node to begin the search at
nameName of symbol to find
Returns
The Symbol if found, otherwise NULL
dummy_free
void dummy_free(void *)
Fake "free" function that does nothing.
Definition: ast.c:14
ASTNode_set_printable_attribute
void ASTNode_set_printable_attribute(ASTNode *node, const char *key, void *value, AttributeValueDOTPrinter dot_printer, Destructor dtor)
Add or change a printable attribute for an AST node.
Definition: ast.c:80
type_attr_print
void type_attr_print(void *value, FILE *output)
Simple "print" function that prints an attribute value as a Decaf type.
Definition: symbol.c:4