Relations between Source files, Source locations and AST?

Hi,
I'm performing some rewriting of C source code. At a certain point, I would
like to add an include directive just before the first declaration inside
the main file of the translation unit (or after the last include directive,
eventually).
I tried both something like:

        // Add include directive for global structures before the first
declaration
        DeclContext::decl_iterator iterator =
Context.getTranslationUnitDecl()->decls_begin();
        Decl* first_decl = *iterator;
        rewriter.InsertText(first_decl->getLocation(), "#include \"" +
global_header_file_name + "\"");

and changing the source location to:

Context.getSourceManager().getIncludeLoc(Context.getSourceManager().getMainFileID());

but in both the cases I obtain the following error:

<invalid loc>Assertion failed: (Loc.isValid() && "Invalid location"),
function getLocationOffsetAndFileID, file
/Users/Gabriele/Documents/LLVM/llvm/tools/clang/lib/Rewrite/Core/Rewriter.cpp,
line 212.

This is probably due to the fact that I didn't understood completely the
relationship between SourceLocations, source files and AST.
Could you point me to any documentation on this subject? Or alternatively,
can you give me some hints to solve the problem?

Thank you very much!